+ break;
+ }
+}
+
+
+void Quassel::logFatalMessage(const char *msg)
+{
+#ifdef Q_OS_MAC
+ Q_UNUSED(msg)
+#else
+ QFile dumpFile(coreDumpFileName());
+ dumpFile.open(QIODevice::Append);
+ QTextStream dumpStream(&dumpFile);
+
+ dumpStream << "Fatal: " << msg << '\n';
+ dumpStream.flush();
+ dumpFile.close();
+#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_WS_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_WS_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_WS_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
+{
+ QStringList dataDirNames = QString(qgetenv("XDG_DATA_DIRS")).split(':', QString::SkipEmptyParts);
+
+ if (!dataDirNames.isEmpty()) {
+ for (int i = 0; i < dataDirNames.count(); i++)
+ dataDirNames[i].append("/apps/quassel/");
+ }
+ else {
+ // 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;