diff --git a/qtbleditor.cpp b/qtbleditor.cpp index 73a6388..3526ab8 100644 --- a/qtbleditor.cpp +++ b/qtbleditor.cpp @@ -21,6 +21,7 @@ #include #include #include +#include #include @@ -1077,11 +1078,7 @@ void QTblEditor::writeSettings() // write custom colors to file - QFile f( -#ifdef Q_OS_MAC - qApp->applicationDirPath() + "/../Resources/" + -#endif - kCustomColorsFileName); + QFile f(customColorsFilePath()); if (f.open(QIODevice::WriteOnly)) { QTextStream out(&f); @@ -1140,11 +1137,11 @@ void QTblEditor::readSettings() // read custom colors from file - QFile f( -#ifdef Q_OS_MAC - qApp->applicationDirPath() + "/../Resources/" + + QFile f(customColorsFilePath()); +#ifndef Q_OS_MAC + if (!f.exists()) // fallback for older versions + f.setFileName(kCustomColorsFileName); #endif - kCustomColorsFileName); if (f.exists()) { if (f.open(QIODevice::ReadOnly)) @@ -1376,6 +1373,19 @@ QString QTblEditor::restoreNewlines(const QString &s) return QString(s).replace(QLatin1String("\\n"), QLatin1String("\n")); } +QString QTblEditor::customColorsFilePath() const +{ +#ifdef Q_OS_MAC + QString basePath = QDesktopServices::storageLocation(QDesktopServices::DataLocation); + if (basePath.isEmpty()) + basePath = QDesktopServices::storageLocation(QDesktopServices::DocumentsLocation); + QDir::current().mkpath(basePath); +#else + QString basePath = qApp->applicationDirPath(); +#endif + return basePath + '/' + kCustomColorsFileName; +} + void QTblEditor::showDifferences() { QAction *action = qobject_cast(sender()); diff --git a/qtbleditor.h b/qtbleditor.h index 10d74c0..c13c08e 100644 --- a/qtbleditor.h +++ b/qtbleditor.h @@ -118,6 +118,8 @@ private slots: QString foldNewlines(const QString &s); QString restoreNewlines(const QString &s); + + QString customColorsFilePath() const; }; #endif // QTBLEDITOR_H