-void Quassel::handleCrash() {
-#ifdef BUILD_CRASHHANDLER
- void* callstack[128];
- int i, frames = backtrace(callstack, 128);
-
- QFile dumpFile(QString("Quassel-Crash-%1").arg(QDateTime::currentDateTime().toString("yyyyMMdd-hhmm.log")));
- dumpFile.open(QIODevice::WriteOnly);
- QTextStream dumpStream(&dumpFile);
-
- for (i = 0; i < frames; ++i) {
- Dl_info info;
- dladdr (callstack[i], &info);
- // as a reference:
- // typedef struct
- // {
- // __const char *dli_fname; /* File name of defining object. */
- // void *dli_fbase; /* Load address of that object. */
- // __const char *dli_sname; /* Name of nearest symbol. */
- // void *dli_saddr; /* Exact value of nearest symbol. */
- // } Dl_info;
-
- #if __LP64__
- int addrSize = 16;
- #else
- int addrSize = 8;
- #endif
-
- QString funcName;
- if(info.dli_sname) {
- char *func = abi::__cxa_demangle(info.dli_sname, 0, 0, 0);
- if(func) {
- funcName = QString(func);
- free(func);
- } else {
- funcName = QString(info.dli_sname);
- }
- } else {
- funcName = QString("0x%1").arg((long)info.dli_saddr, addrSize, QLatin1Char('0'));
+
+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;
+
+ // Disable DCC until it is ready
+ feats &= ~Feature::DccFileTransfer;
+
+ 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;