* @brief Returns a structural summary of a snapshot file (title, counts, group titles). */
| 287 | * @brief Returns a structural summary of a snapshot file (title, counts, group titles). |
| 288 | */ |
| 289 | QVariantMap Misc::BackupManager::summarize(const QString& path) const |
| 290 | { |
| 291 | QVariantMap out; |
| 292 | if (path.isEmpty()) |
| 293 | return out; |
| 294 | |
| 295 | QFile in(path); |
| 296 | if (!in.open(QIODevice::ReadOnly)) |
| 297 | return out; |
| 298 | |
| 299 | const auto bytes = in.readAll(); |
| 300 | in.close(); |
| 301 | |
| 302 | QJsonParseError err{}; |
| 303 | const auto doc = QJsonDocument::fromJson(bytes, &err); |
| 304 | if (err.error != QJsonParseError::NoError || !doc.isObject()) |
| 305 | return out; |
| 306 | |
| 307 | const auto project = doc.object(); |
| 308 | out.insert(QStringLiteral("title"), project.value(QStringLiteral("title")).toString()); |
| 309 | |
| 310 | if (project.contains(kBackupMetaKey)) |
| 311 | out.insert(QStringLiteral("backupMeta"), |
| 312 | project.value(kBackupMetaKey).toObject().toVariantMap()); |
| 313 | |
| 314 | const auto groups = project.value(QStringLiteral("groups")).toArray(); |
| 315 | out.insert(QStringLiteral("groupCount"), groups.size()); |
| 316 | |
| 317 | int datasetCount = 0; |
| 318 | QStringList groupTitles; |
| 319 | for (const auto& gv : groups) { |
| 320 | const auto g = gv.toObject(); |
| 321 | datasetCount += g.value(QStringLiteral("datasets")).toArray().size(); |
| 322 | groupTitles.append(g.value(QStringLiteral("title")).toString()); |
| 323 | } |
| 324 | out.insert(QStringLiteral("datasetCount"), datasetCount); |
| 325 | out.insert(QStringLiteral("groupTitles"), groupTitles); |
| 326 | |
| 327 | const auto sources = project.value(QStringLiteral("sources")).toArray(); |
| 328 | out.insert(QStringLiteral("sourceCount"), sources.isEmpty() ? 1 : sources.size()); |
| 329 | out.insert(QStringLiteral("parserHash"), parserSignature(sources)); |
| 330 | return out; |
| 331 | } |
| 332 | |
| 333 | /** |
| 334 | * @brief Returns a structural summary of the current in-memory ProjectModel. |