00001 #include <iostream> 00002 #include <cstdlib> 00003 00004 #include <QDir> 00005 #include <QCoreApplication> 00006 00007 #include "mythconfig.h" // for CONFIG_DARWIN 00008 #include "mythdirs.h" 00009 #include "mythlogging.h" 00010 00011 static QString installprefix = QString::null; 00012 static QString sharedir = QString::null; 00013 static QString libdir = QString::null; 00014 static QString confdir = QString::null; 00015 static QString themedir = QString::null; 00016 static QString pluginsdir = QString::null; 00017 static QString translationsdir = QString::null; 00018 static QString filtersdir = QString::null; 00019 00020 void InitializeMythDirs(void) 00021 { 00022 installprefix = QString(RUNPREFIX); 00023 00024 char *tmp_installprefix = std::getenv("MYTHTVDIR"); 00025 if (tmp_installprefix) 00026 installprefix = tmp_installprefix; 00027 00028 #if CONFIG_DARWIN 00029 // Work around bug in OS X where applicationDirPath() can crash 00030 // (if binary is not in a bundle, and is daemon()ized) 00031 00032 QDir prefixDir = QFileInfo(qApp->argv()[0]).dir(); 00033 #else 00034 QDir prefixDir = qApp->applicationDirPath(); 00035 #endif 00036 00037 if (QDir(installprefix).isRelative()) 00038 { 00039 // If the PREFIX is relative, evaluate it relative to our 00040 // executable directory. This can be fragile on Unix, so 00041 // use relative PREFIX values with care. 00042 00043 LOG(VB_GENERAL, LOG_DEBUG, 00044 "Relative PREFIX! (" + installprefix + ")\n\t\tappDir=" + 00045 prefixDir.canonicalPath()); 00046 00047 prefixDir.cd(installprefix); 00048 installprefix = prefixDir.canonicalPath(); 00049 } 00050 00051 LOG(VB_GENERAL, LOG_NOTICE, "Using runtime prefix = " + installprefix); 00052 00053 char *tmp_confdir = std::getenv("MYTHCONFDIR"); 00054 if (tmp_confdir) 00055 { 00056 confdir = QString(tmp_confdir); 00057 LOG(VB_GENERAL, LOG_NOTICE, QString("Read conf dir = %1").arg(confdir)); 00058 confdir.replace("$HOME", QDir::homePath()); 00059 } 00060 else 00061 confdir = QDir::homePath() + "/.mythtv"; 00062 00063 LOG(VB_GENERAL, LOG_NOTICE, 00064 QString("Using configuration directory = %1").arg(confdir)); 00065 00066 sharedir = installprefix + "/share/mythtv/"; 00067 libdir = installprefix + '/' + QString(LIBDIRNAME) + "/mythtv/"; 00068 themedir = sharedir + "themes/"; 00069 pluginsdir = libdir + "plugins/"; 00070 translationsdir = sharedir + "i18n/"; 00071 filtersdir = libdir + "filters/"; 00072 } 00073 00074 QString GetInstallPrefix(void) { return installprefix; } 00075 QString GetShareDir(void) { return sharedir; } 00076 QString GetLibraryDir(void) { return libdir; } 00077 QString GetConfDir(void) { return confdir; } 00078 QString GetThemesParentDir(void) { return themedir; } 00079 QString GetPluginsDir(void) { return pluginsdir; } 00080 QString GetTranslationsDir(void) { return translationsdir; } 00081 QString GetFiltersDir(void) { return filtersdir; } 00082 00083 // These defines provide portability for different 00084 // plugin file names. 00085 #if CONFIG_DARWIN 00086 static const QString kPluginLibPrefix = "lib"; 00087 static const QString kPluginLibSuffix = ".dylib"; 00088 #elif USING_MINGW 00089 static const QString kPluginLibPrefix = "lib"; 00090 static const QString kPluginLibSuffix = ".dll"; 00091 #else 00092 static const QString kPluginLibPrefix = "lib"; 00093 static const QString kPluginLibSuffix = ".so"; 00094 #endif 00095 00096 QString GetPluginsNameFilter(void) 00097 { 00098 return kPluginLibPrefix + '*' + kPluginLibSuffix; 00099 } 00100 00101 QString FindPluginName(const QString &plugname) 00102 { 00103 return GetPluginsDir() + kPluginLibPrefix + plugname + kPluginLibSuffix; 00104 } 00105 00106 QString GetTranslationsNameFilter(void) 00107 { 00108 return "mythfrontend_*.qm"; 00109 } 00110 00111 QString FindTranslation(const QString &translation) 00112 { 00113 return GetTranslationsDir() 00114 + "mythfrontend_" + translation.toLower() + ".qm"; 00115 } 00116 00117 QString GetFontsDir(void) 00118 { 00119 return GetShareDir() + "fonts/"; 00120 } 00121
1.6.3