MCPcopy Create free account
hub / github.com/YACReader/yacreader / importThemeFromFile

Method importThemeFromFile

common/themes/theme_repository.cpp:146–172  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

144}
145
146QString 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
174void ThemeRepository::refresh()
175{

Callers 1

importThemeMethod · 0.80

Calls 2

isEmptyMethod · 0.80
toStringMethod · 0.80

Tested by

no test coverage detected