+ // Provide a fallback
+#ifdef Q_OS_WIN32
+ dataDirNames << qgetenv("APPDATA") + QCoreApplication::organizationDomain() + "/share/apps/quassel/"
+ << qgetenv("APPDATA") + QCoreApplication::organizationDomain()
+ << QCoreApplication::applicationDirPath();
+ }
+#elif defined Q_WS_MAC
+ dataDirNames << QDir::homePath() + "/Library/Application Support/Quassel/"
+ << QCoreApplication::applicationDirPath();
+ }
+#else
+ dataDirNames.append("/usr/share/apps/quassel/");
+ }
+ // on UNIX, we always check our install prefix
+ QString appDir = QCoreApplication::applicationDirPath();
+ int binpos = appDir.lastIndexOf("/bin");
+ if(binpos >= 0) {
+ appDir.replace(binpos, 4, "/share");
+ appDir.append("/apps/quassel/");
+ if(!dataDirNames.contains(appDir))
+ dataDirNames.append(appDir);
+ }
+#endif
+
+ // add resource path and workdir just in case
+ dataDirNames << QCoreApplication::applicationDirPath() + "/data/"
+ << ":/data/";
+
+ // append trailing '/' and check for existence
+ QStringList::Iterator iter = dataDirNames.begin();
+ while(iter != dataDirNames.end()) {
+ if(!iter->endsWith(QDir::separator()) && !iter->endsWith('/'))
+ iter->append(QDir::separator());
+ if(!QFile::exists(*iter))
+ iter = dataDirNames.erase(iter);
+ else
+ ++iter;
+ }
+
+ return dataDirNames;
+}
+
+QString Quassel::findDataFilePath(const QString &fileName) {
+ QStringList dataDirs = dataDirPaths();
+ foreach(QString dataDir, dataDirs) {
+ QString path = dataDir + fileName;
+ if(QFile::exists(path))
+ return path;
+ }
+ return QString();
+}
+
+QStringList Quassel::scriptDirPaths() {
+ QStringList res(configDirPath() + "scripts/");
+ foreach(QString path, dataDirPaths())
+ res << path + "scripts/";
+ return res;
+}
+
+QString Quassel::translationDirPath() {
+ if(_translationDirPath.isEmpty()) {
+ // We support only one translation dir; fallback mechanisms wouldn't work else.
+ // This means that if we have a $data/translations dir, the internal :/i18n resource won't be considered.
+ foreach(const QString &dir, dataDirPaths()) {
+ if(QFile::exists(dir + "translations/")) {
+ _translationDirPath = dir + "translations/";
+ break;
+ }
+ }
+ if(_translationDirPath.isEmpty())
+ _translationDirPath = ":/i18n/";