| 144 | } |
| 145 | |
| 146 | QString ThemeRepository::importThemeFromFile(const QString &filePath, QString *errorMessage) |
| 147 | { |
| 148 | QJsonObject json = readJsonFile(filePath); |
| 149 | if (json.isEmpty()) { |
| 150 | if (errorMessage) |
| 151 | *errorMessage = QObject::tr("The file could not be read or is not valid JSON."); |
| 152 | return { }; |
| 153 | } |
| 154 | |
| 155 | // Check that the theme targets the correct application |
| 156 | const auto metaIn = json["meta"].toObject(); |
| 157 | const QString themeTargetApp = metaIn["targetApp"].toString(); |
| 158 | if (!themeTargetApp.isEmpty() && themeTargetApp != targetApp) { |
| 159 | if (errorMessage) |
| 160 | *errorMessage = QObject::tr("This theme is for %1, not %2.").arg(themeTargetApp, targetApp); |
| 161 | return { }; |
| 162 | } |
| 163 | |
| 164 | // Force a new user id regardless of what the file contains |
| 165 | auto metaObj = json["meta"].toObject(); |
| 166 | const QString uuid = QUuid::createUuid().toString(QUuid::WithoutBraces); |
| 167 | const QString id = "user/" + uuid; |
| 168 | metaObj["id"] = id; |
| 169 | json["meta"] = metaObj; |
| 170 | |
| 171 | return saveUserTheme(json); |
| 172 | } |
| 173 | |
| 174 | void ThemeRepository::refresh() |
| 175 | { |
no test coverage detected