+#endif
+}
+
+
+Quassel::Features Quassel::features()
+{
+ Features feats = 0;
+ for (int i = 1; i <= NumFeatures; i <<= 1)
+ feats |= (Feature)i;
+
+ return feats;
+}
+
+
+const QString &Quassel::coreDumpFileName()
+{
+ if (_coreDumpFileName.isEmpty()) {
+ QDir configDir(configDirPath());
+ _coreDumpFileName = configDir.absoluteFilePath(QString("Quassel-Crash-%1.log").arg(QDateTime::currentDateTime().toString("yyyyMMdd-hhmm")));
+ QFile dumpFile(_coreDumpFileName);
+ dumpFile.open(QIODevice::Append);
+ QTextStream dumpStream(&dumpFile);
+ dumpStream << "Quassel IRC: " << _buildInfo.baseVersion << ' ' << _buildInfo.commitHash << '\n';
+ qDebug() << "Quassel IRC: " << _buildInfo.baseVersion << ' ' << _buildInfo.commitHash;
+ dumpStream.flush();
+ dumpFile.close();
+ }
+ return _coreDumpFileName;
+}
+
+
+QString Quassel::configDirPath()
+{
+ if (!_configDirPath.isEmpty())
+ return _configDirPath;
+
+ if (Quassel::isOptionSet("datadir")) {
+ qWarning() << "Obsolete option --datadir used!";
+ _configDirPath = Quassel::optionValue("datadir");
+ }
+ else if (Quassel::isOptionSet("configdir")) {
+ _configDirPath = Quassel::optionValue("configdir");
+ }
+ else {
+#ifdef Q_OS_MAC
+ // On Mac, the path is always the same
+ _configDirPath = QDir::homePath() + "/Library/Application Support/Quassel/";
+#else
+ // We abuse QSettings to find us a sensible path on the other platforms
+# ifdef Q_OS_WIN
+ // don't use the registry
+ QSettings::Format format = QSettings::IniFormat;
+# else
+ QSettings::Format format = QSettings::NativeFormat;
+# endif
+ QSettings s(format, QSettings::UserScope, QCoreApplication::organizationDomain(), buildInfo().applicationName);
+ QFileInfo fileInfo(s.fileName());
+ _configDirPath = fileInfo.dir().absolutePath();
+#endif /* Q_OS_MAC */
+ }
+
+ if (!_configDirPath.endsWith(QDir::separator()) && !_configDirPath.endsWith('/'))
+ _configDirPath += QDir::separator();
+
+ QDir qDir(_configDirPath);
+ if (!qDir.exists(_configDirPath)) {
+ if (!qDir.mkpath(_configDirPath)) {
+ qCritical() << "Unable to create Quassel config directory:" << qPrintable(qDir.absolutePath());
+ return QString();
+ }
+ }
+
+ return _configDirPath;
+}
+
+
+QStringList Quassel::dataDirPaths()
+{
+ return _dataDirPaths;
+}
+
+
+QStringList Quassel::findDataDirPaths() const
+{
+ // We don't use QStandardPaths for now, as we still need to provide fallbacks for Qt4 and
+ // want to stay consistent.
+
+ QStringList dataDirNames;
+#ifdef Q_OS_WIN
+ dataDirNames << qgetenv("APPDATA") + QCoreApplication::organizationDomain() + "/share/apps/quassel/"
+ << qgetenv("APPDATA") + QCoreApplication::organizationDomain()
+ << QCoreApplication::applicationDirPath();
+#elif defined Q_OS_MAC
+ dataDirNames << QDir::homePath() + "/Library/Application Support/Quassel/"
+ << QCoreApplication::applicationDirPath();
+#else
+ // Linux et al
+
+ // XDG_DATA_HOME is the location for users to override system-installed files, usually in .local/share
+ // This should thus come first.
+ QString xdgDataHome = QFile::decodeName(qgetenv("XDG_DATA_HOME"));
+ if (xdgDataHome.isEmpty())
+ xdgDataHome = QDir::homePath() + QLatin1String("/.local/share");
+ dataDirNames << xdgDataHome;
+
+ // Now whatever is configured through XDG_DATA_DIRS
+ QString xdgDataDirs = QFile::decodeName(qgetenv("XDG_DATA_DIRS"));
+ if (xdgDataDirs.isEmpty())
+ dataDirNames << "/usr/local/share" << "/usr/share";
+ else
+ dataDirNames << xdgDataDirs.split(':', QString::SkipEmptyParts);
+
+ // Just in case, also check our install prefix
+ dataDirNames << QCoreApplication::applicationDirPath() + "/../share";
+
+ // Normalize and append our application name
+ for (int i = 0; i < dataDirNames.count(); i++)
+ dataDirNames[i] = QDir::cleanPath(dataDirNames.at(i)) + "/quassel/";
+
+#endif
+
+ // Add resource path and workdir just in case.
+ // Workdir should have precedence
+ dataDirNames.prepend(QCoreApplication::applicationDirPath() + "/data/");
+ dataDirNames.append(":/data/");
+
+ // Append trailing '/' and check for existence
+ auto 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;
+ }
+
+ dataDirNames.removeDuplicates();
+
+ 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/";
+ }
+ return _translationDirPath;
+}
+
+
+void Quassel::loadTranslation(const QLocale &locale)
+{
+ QTranslator *qtTranslator = QCoreApplication::instance()->findChild<QTranslator *>("QtTr");
+ QTranslator *quasselTranslator = QCoreApplication::instance()->findChild<QTranslator *>("QuasselTr");
+
+ if (qtTranslator)
+ qApp->removeTranslator(qtTranslator);
+ if (quasselTranslator)
+ qApp->removeTranslator(quasselTranslator);
+
+ // We use QLocale::C to indicate that we don't want a translation
+ if (locale.language() == QLocale::C)
+ return;
+
+ qtTranslator = new QTranslator(qApp);
+ qtTranslator->setObjectName("QtTr");
+ qApp->installTranslator(qtTranslator);
+
+ quasselTranslator = new QTranslator(qApp);
+ quasselTranslator->setObjectName("QuasselTr");
+ qApp->installTranslator(quasselTranslator);
+
+#if QT_VERSION >= 0x040800 && !defined Q_OS_MAC
+ bool success = qtTranslator->load(locale, QString("qt_"), translationDirPath());
+ if (!success)
+ qtTranslator->load(locale, QString("qt_"), QLibraryInfo::location(QLibraryInfo::TranslationsPath));
+ quasselTranslator->load(locale, QString(""), translationDirPath());
+#else
+ bool success = qtTranslator->load(QString("qt_%1").arg(locale.name()), translationDirPath());
+ if (!success)
+ qtTranslator->load(QString("qt_%1").arg(locale.name()), QLibraryInfo::location(QLibraryInfo::TranslationsPath));
+ quasselTranslator->load(QString("%1").arg(locale.name()), translationDirPath());
+#endif