Skip to content

Commit

Permalink
fix location of custom colors file on macOS
Browse files Browse the repository at this point in the history
  • Loading branch information
kambala-decapitator committed Nov 4, 2019
1 parent 9cabb64 commit a4ed949
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 9 deletions.
28 changes: 19 additions & 9 deletions qtbleditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include <QFileInfo>
#include <QMimeData>
#include <QDateTime>
#include <QDesktopServices>

#include <QNetworkReply>

Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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))
Expand Down Expand Up @@ -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<QAction *>(sender());
Expand Down
2 changes: 2 additions & 0 deletions qtbleditor.h
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,8 @@ private slots:

QString foldNewlines(const QString &s);
QString restoreNewlines(const QString &s);

QString customColorsFilePath() const;
};

#endif // QTBLEDITOR_H

0 comments on commit a4ed949

Please sign in to comment.