-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsettingsjson.h
More file actions
48 lines (40 loc) · 2.65 KB
/
Copy pathsettingsjson.h
File metadata and controls
48 lines (40 loc) · 2.65 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#pragma once
#include "appsettings.h"
#include <QJsonObject>
#include <QString>
#include <QStringList>
class QSettings;
// JSON serialisation for AppSettings, shared by "export/import settings to a
// file" and by named profiles (a profile is just a stored settings object).
// Depends on Qt Core only, so it is unit-testable without a display.
// Schema version written into every exported object. Bump only for a change
// that older builds could misread; additive fields do not need it, because
// settingsFromJson() falls back to `defaults` for anything absent.
constexpr int kSettingsSchemaVersion = 1;
// Serialise every user preference. Deliberately omitted:
// * usageReporting — a privacy choice, and a file passed between machines must
// never silently re-enable reporting for someone who turned it off.
// settingsFromJson() therefore always takes it from `defaults`.
QJsonObject settingsToJson(const AppSettings& s);
// Rebuild settings from `obj`, taking any absent, malformed or out-of-range
// field from `defaults`. Never fails: a truncated or foreign file yields the
// defaults rather than a half-applied configuration. Pass the *current*
// settings as `defaults` to leave untouched anything the file does not mention.
AppSettings settingsFromJson(const QJsonObject& obj, const AppSettings& defaults);
// True if `obj` looks like a TrackClick settings export (right marker, and a
// schema version this build understands), so callers can reject an unrelated
// JSON file with a clear message instead of silently importing defaults.
bool isSettingsJson(const QJsonObject& obj);
// ── Named profiles ───────────────────────────────────────────────────────────
// All profiles live in a single QSettings key holding one JSON object keyed by
// profile name. One key rather than one group per profile keeps arbitrary
// user-entered names workable: QSettings treats '/' in a key as a group
// separator, so names would otherwise need escaping.
// The QSettings instance is passed in rather than constructed here so tests can
// point it at a temporary file instead of the user's real configuration.
QStringList settingsProfileNames(QSettings& store);
void saveSettingsProfile(QSettings& store, const QString& name, const AppSettings& s);
// Returns false (leaving `out` untouched) when no profile of that name exists.
bool loadSettingsProfile(QSettings& store, const QString& name,
const AppSettings& defaults, AppSettings& out);
void deleteSettingsProfile(QSettings& store, const QString& name);