8 #include <QtCore/QSettings>
10 #include <QtCore/QStringBuilder>
27 static void setLegacyNames(
const QString& organizationName,
28 const QString& applicationName = {});
30 explicit Settings(QObject* parent =
nullptr);
34 Q_INVOKABLE
void setValue(
const QString& key,
const QVariant& value);
37 Q_INVOKABLE
void remove(
const QString& key);
50 Q_INVOKABLE QVariant value(
const QString& key,
const QVariant& defaultValue = {})
const;
63 T get(
const QString& key,
const T& defaultValue = {})
const
65 const auto qv = value(key);
66 return qv.isValid() && qv.canConvert<T>() ? qv.value<T>() : defaultValue;
69 Q_INVOKABLE
bool contains(
const QString& key)
const;
70 Q_INVOKABLE QStringList childGroups()
const;
73 static QString legacyOrganizationName;
74 static QString legacyApplicationName;
77 QSettings legacySettings { legacyOrganizationName, legacyApplicationName };
82 explicit SettingsGroup(QString path, QObject* parent =
nullptr)
84 , groupPath(std::move(path))
87 Q_INVOKABLE
bool contains(
const QString& key)
const;
88 Q_INVOKABLE QVariant value(
const QString& key,
const QVariant& defaultValue = {})
const;
91 T get(
const QString& key,
const T& defaultValue = {})
const
93 const auto qv = value(key);
94 return qv.isValid() && qv.canConvert<T>() ? qv.value<T>() : defaultValue;
97 Q_INVOKABLE QString group()
const;
98 Q_INVOKABLE QStringList childGroups()
const;
99 Q_INVOKABLE
void setValue(
const QString& key,
const QVariant& value);
101 Q_INVOKABLE
void remove(
const QString& key);
104 QString fullPath(QAnyStringView key)
const {
return groupPath % u'/' % key.toString(); }
109 #define QUO_DECLARE_SETTING(type, propname, setter)
110 Q_PROPERTY(type propname READ propname WRITE setter) public
112 type propname() const;
113 void setter(type newValue);
117 #define QUO_DEFINE_SETTING(classname, type, propname, qsettingname, defaultValue, setter)
118 type classname::propname() const { return get<type>(qsettingname##_L1, defaultValue); }
119 void classname::setter(type newValue) { setValue(qsettingname##_L1, std::move(newValue)); }
123 Q_PROPERTY(QString userId READ userId CONSTANT)
127 Q_PROPERTY(QByteArray encryptionAccountPickle READ encryptionAccountPickle
128 WRITE setEncryptionAccountPickle)
130 explicit AccountSettings(
const QString& accountId, QObject* parent =
nullptr)
131 : SettingsGroup(
"Accounts/"_L1 + accountId, parent)
134 QString userId()
const;
136 QUrl homeserver()
const;
137 void setHomeserver(
const QUrl& url);
139 QByteArray encryptionAccountPickle();
140 void setEncryptionAccountPickle(
const QByteArray& encryptionAccountPickle);
141 Q_INVOKABLE
void clearEncryptionAccountPickle();