|
3 | 3 | #include "ConfigIO.h" |
4 | 4 | #include "utils/Common.h" |
5 | 5 |
|
| 6 | +#include <QStandardPaths> |
| 7 | + |
6 | 8 | #define ENCLOSE_QUOTES(x) "\"" + x + "\"" |
7 | 9 |
|
8 | 10 | #define DEFINE_KEY(name, defaultValue) \ |
@@ -85,28 +87,39 @@ bool AppConfig::isAppBlocked(const QString &name) const |
85 | 87 |
|
86 | 88 | QString AppConfig::getDspConfPath() |
87 | 89 | { |
88 | | - return QString("%1/.config/jamesdsp/audio.conf").arg(QDir::homePath()); |
| 90 | + return getPath("audio.conf"); |
89 | 91 | } |
90 | 92 |
|
91 | 93 | QString AppConfig::getPath(QString subdir) |
92 | 94 | { |
93 | | - return QString("%1/.config/jamesdsp/%2").arg(QDir::homePath()).arg(subdir); |
| 95 | + QString path = QStandardPaths::writableLocation(QStandardPaths::GenericConfigLocation); |
| 96 | + if(path.isEmpty()) |
| 97 | + { |
| 98 | + path = QString("%1/.config/").arg(QDir::homePath()); |
| 99 | + } |
| 100 | + |
| 101 | + return QString("%1/jamesdsp/%2").arg(path).arg(subdir); |
94 | 102 | } |
95 | 103 |
|
96 | 104 | QString AppConfig::getCachePath(QString subdir) |
97 | 105 | { |
98 | | - return QString("%1/.cache/jamesdsp/%2").arg(QDir::homePath()).arg(subdir); |
| 106 | + QString path = QStandardPaths::writableLocation(QStandardPaths::GenericCacheLocation); |
| 107 | + if(path.isEmpty()) |
| 108 | + { |
| 109 | + path = QString("%1/.cache/").arg(QDir::homePath()); |
| 110 | + } |
| 111 | + return QString("%1/jamesdsp/%2").arg(path).arg(subdir); |
99 | 112 | } |
100 | 113 |
|
101 | 114 | void AppConfig::save() |
102 | 115 | { |
103 | | - auto file = QString("%1/.config/jamesdsp/application.conf").arg(QDir::homePath()); |
| 116 | + auto file = getPath("application.conf"); |
104 | 117 | ConfigIO::writeFile(file, _appconf->getConfigMap()); |
105 | 118 | } |
106 | 119 |
|
107 | 120 | void AppConfig::load() |
108 | 121 | { |
109 | | - auto map = ConfigIO::readFile(QString("%1/.config/jamesdsp/application.conf").arg(QDir::homePath())); |
| 122 | + auto map = ConfigIO::readFile(getPath("application.conf")); |
110 | 123 | _appconf->setConfigMap(map); |
111 | 124 |
|
112 | 125 | for(const auto& key : map.keys()) |
|
0 commit comments