From aacc4bcb4a487871daae6717f77605aaba444341 Mon Sep 17 00:00:00 2001 From: Marc Deop Date: Sat, 2 Mar 2019 12:26:57 +0100 Subject: style: apply .clang-format to all .cpp and .h files --- lib/settings.h | 206 +++++++++++++++++++++++++++++---------------------------- 1 file changed, 104 insertions(+), 102 deletions(-) (limited to 'lib/settings.h') diff --git a/lib/settings.h b/lib/settings.h index 0b3ecaff..0cde47a3 100644 --- a/lib/settings.h +++ b/lib/settings.h @@ -13,140 +13,142 @@ * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ #pragma once #include -#include #include +#include class QVariant; -namespace QMatrixClient -{ - class Settings: public QSettings +namespace QMatrixClient { + class Settings : public QSettings { - Q_OBJECT + Q_OBJECT public: - /** - * Use this function before creating any Settings objects in order - * to setup a read-only location where configuration has previously - * been stored. This will provide an additional fallback in case of - * renaming the organisation/application. - */ - static void setLegacyNames(const QString& organizationName, - const QString& applicationName = {}); + /** + * Use this function before creating any Settings objects in order + * to setup a read-only location where configuration has previously + * been stored. This will provide an additional fallback in case of + * renaming the organisation/application. + */ + static void setLegacyNames(const QString& organizationName, + const QString& applicationName = {}); #if defined(_MSC_VER) && _MSC_VER < 1900 - // VS 2013 (and probably older) aren't friends with 'using' statements - // that involve private constructors - explicit Settings(QObject* parent = 0) : QSettings(parent) { } + // VS 2013 (and probably older) aren't friends with 'using' statements + // that involve private constructors + explicit Settings(QObject* parent = 0) : QSettings(parent) {} #else - using QSettings::QSettings; + using QSettings::QSettings; #endif - Q_INVOKABLE void setValue(const QString &key, - const QVariant &value); - Q_INVOKABLE QVariant value(const QString &key, - const QVariant &defaultValue = {}) const; + Q_INVOKABLE void setValue(const QString& key, const QVariant& value); + Q_INVOKABLE QVariant value(const QString& key, + const QVariant& defaultValue = {}) const; - template - T get(const QString& key, const T& defaultValue = {}) const - { - const auto qv = value(key, QVariant()); - return qv.isValid() && qv.canConvert() ? qv.value() - : defaultValue; - } + template + T get(const QString& key, const T& defaultValue = {}) const + { + const auto qv = value(key, QVariant()); + return qv.isValid() && qv.canConvert() ? qv.value() + : defaultValue; + } - Q_INVOKABLE bool contains(const QString& key) const; - Q_INVOKABLE QStringList childGroups() const; + Q_INVOKABLE bool contains(const QString& key) const; + Q_INVOKABLE QStringList childGroups() const; private: - static QString legacyOrganizationName; - static QString legacyApplicationName; + static QString legacyOrganizationName; + static QString legacyApplicationName; protected: - QSettings legacySettings { legacyOrganizationName, - legacyApplicationName }; + QSettings legacySettings { legacyOrganizationName, + legacyApplicationName }; }; - class SettingsGroup: public Settings + class SettingsGroup : public Settings { public: - template - explicit SettingsGroup(QString path, ArgTs&&... qsettingsArgs) - : Settings(std::forward(qsettingsArgs)...) - , groupPath(std::move(path)) - { } - - Q_INVOKABLE bool contains(const QString& key) const; - Q_INVOKABLE QVariant value(const QString &key, - const QVariant &defaultValue = {}) const; - - template - T get(const QString& key, const T& defaultValue = {}) const - { - const auto qv = value(key, QVariant()); - return qv.isValid() && qv.canConvert() ? qv.value() - : defaultValue; - } - - Q_INVOKABLE QString group() const; - Q_INVOKABLE QStringList childGroups() const; - Q_INVOKABLE void setValue(const QString &key, - const QVariant &value); - - Q_INVOKABLE void remove(const QString& key); + template + explicit SettingsGroup(QString path, ArgTs&&... qsettingsArgs) + : Settings(std::forward(qsettingsArgs)...), + groupPath(std::move(path)) + { + } + + Q_INVOKABLE bool contains(const QString& key) const; + Q_INVOKABLE QVariant value(const QString& key, + const QVariant& defaultValue = {}) const; + + template + T get(const QString& key, const T& defaultValue = {}) const + { + const auto qv = value(key, QVariant()); + return qv.isValid() && qv.canConvert() ? qv.value() + : defaultValue; + } + + Q_INVOKABLE QString group() const; + Q_INVOKABLE QStringList childGroups() const; + Q_INVOKABLE void setValue(const QString& key, const QVariant& value); + + Q_INVOKABLE void remove(const QString& key); private: - QString groupPath; + QString groupPath; }; -#define QMC_DECLARE_SETTING(type, propname, setter) \ - Q_PROPERTY(type propname READ propname WRITE setter) \ - public: \ - type propname() const; \ - void setter(type newValue); \ +#define QMC_DECLARE_SETTING(type, propname, setter) \ + Q_PROPERTY(type propname READ propname WRITE setter) \ + public: \ + type propname() const; \ + void setter(type newValue); \ + \ private: -#define QMC_DEFINE_SETTING(classname, type, propname, qsettingname, defaultValue, setter) \ -type classname::propname() const \ -{ \ - return get(QStringLiteral(qsettingname), defaultValue); \ -} \ -\ -void classname::setter(type newValue) \ -{ \ - setValue(QStringLiteral(qsettingname), newValue); \ -} \ - - class AccountSettings: public SettingsGroup +#define QMC_DEFINE_SETTING(classname, type, propname, qsettingname, \ + defaultValue, setter) \ + type classname::propname() const \ + { \ + return get(QStringLiteral(qsettingname), defaultValue); \ + } \ + \ + void classname::setter(type newValue) \ + { \ + setValue(QStringLiteral(qsettingname), newValue); \ + } + + class AccountSettings : public SettingsGroup { - Q_OBJECT - Q_PROPERTY(QString userId READ userId CONSTANT) - QMC_DECLARE_SETTING(QString, deviceId, setDeviceId) - QMC_DECLARE_SETTING(QString, deviceName, setDeviceName) - QMC_DECLARE_SETTING(bool, keepLoggedIn, setKeepLoggedIn) - /** \deprecated \sa setAccessToken */ - Q_PROPERTY(QString accessToken READ accessToken WRITE setAccessToken) + Q_OBJECT + Q_PROPERTY(QString userId READ userId CONSTANT) + QMC_DECLARE_SETTING(QString, deviceId, setDeviceId) + QMC_DECLARE_SETTING(QString, deviceName, setDeviceName) + QMC_DECLARE_SETTING(bool, keepLoggedIn, setKeepLoggedIn) + /** \deprecated \sa setAccessToken */ + Q_PROPERTY(QString accessToken READ accessToken WRITE setAccessToken) public: - template - explicit AccountSettings(const QString& accountId, ArgTs... qsettingsArgs) - : SettingsGroup("Accounts/" + accountId, qsettingsArgs...) - { } - - QString userId() const; - - QUrl homeserver() const; - void setHomeserver(const QUrl& url); - - /** \deprecated \sa setToken */ - QString accessToken() const; - /** \deprecated Storing accessToken in QSettings is unsafe, - * see QMatrixClient/Quaternion#181 */ - void setAccessToken(const QString& accessToken); - Q_INVOKABLE void clearAccessToken(); + template + explicit AccountSettings(const QString& accountId, + ArgTs... qsettingsArgs) + : SettingsGroup("Accounts/" + accountId, qsettingsArgs...) + { + } + + QString userId() const; + + QUrl homeserver() const; + void setHomeserver(const QUrl& url); + + /** \deprecated \sa setToken */ + QString accessToken() const; + /** \deprecated Storing accessToken in QSettings is unsafe, + * see QMatrixClient/Quaternion#181 */ + void setAccessToken(const QString& accessToken); + Q_INVOKABLE void clearAccessToken(); }; -} // namespace QMatrixClient +} // namespace QMatrixClient -- cgit v1.2.3 From 432e7fd7107d8260e0016a1adcd8d94263dc1044 Mon Sep 17 00:00:00 2001 From: Kitsune Ral Date: Thu, 4 Apr 2019 21:27:38 +0900 Subject: Clean up on clang-tidy/clazy analysis --- lib/settings.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib/settings.h') diff --git a/lib/settings.h b/lib/settings.h index 0b3ecaff..759bda35 100644 --- a/lib/settings.h +++ b/lib/settings.h @@ -119,7 +119,7 @@ type classname::propname() const \ \ void classname::setter(type newValue) \ { \ - setValue(QStringLiteral(qsettingname), newValue); \ + setValue(QStringLiteral(qsettingname), std::move(newValue)); \ } \ class AccountSettings: public SettingsGroup -- cgit v1.2.3 From 69ba71cca36b4a90328d169c845195f39c041a3a Mon Sep 17 00:00:00 2001 From: Alexey Andreyev Date: Sat, 22 Jun 2019 19:57:18 +0300 Subject: Add EncryptionManager class. Add AccountSettings::encryptionAccountPickle logic. --- lib/settings.h | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'lib/settings.h') diff --git a/lib/settings.h b/lib/settings.h index 759bda35..61e5232a 100644 --- a/lib/settings.h +++ b/lib/settings.h @@ -131,6 +131,7 @@ void classname::setter(type newValue) \ QMC_DECLARE_SETTING(bool, keepLoggedIn, setKeepLoggedIn) /** \deprecated \sa setAccessToken */ Q_PROPERTY(QString accessToken READ accessToken WRITE setAccessToken) + Q_PROPERTY(QByteArray encryptionAccountPickle READ encryptionAccountPickle WRITE setEncryptionAccountPickle) public: template explicit AccountSettings(const QString& accountId, ArgTs... qsettingsArgs) @@ -148,5 +149,9 @@ void classname::setter(type newValue) \ * see QMatrixClient/Quaternion#181 */ void setAccessToken(const QString& accessToken); Q_INVOKABLE void clearAccessToken(); + + QByteArray encryptionAccountPickle(); + void setEncryptionAccountPickle(const QByteArray& encryptionAccountPickle); + Q_INVOKABLE void clearEncryptionAccountPickle(); }; } // namespace QMatrixClient -- cgit v1.2.3 From c05ade838f0fce81f2bbe80a3295618a8a26ff52 Mon Sep 17 00:00:00 2001 From: Kitsune Ral Date: Fri, 2 Aug 2019 19:59:40 +0900 Subject: Apply the new brace wrapping to source files --- lib/settings.h | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) (limited to 'lib/settings.h') diff --git a/lib/settings.h b/lib/settings.h index e1ca0866..6747631e 100644 --- a/lib/settings.h +++ b/lib/settings.h @@ -24,10 +24,8 @@ class QVariant; -namespace QMatrixClient -{ -class Settings : public QSettings -{ +namespace QMatrixClient { +class Settings : public QSettings { Q_OBJECT public: /** @@ -42,9 +40,7 @@ public: #if defined(_MSC_VER) && _MSC_VER < 1900 // VS 2013 (and probably older) aren't friends with 'using' statements // that involve private constructors - explicit Settings(QObject* parent = 0) - : QSettings(parent) - {} + explicit Settings(QObject* parent = 0) : QSettings(parent) {} #else using QSettings::QSettings; #endif @@ -71,8 +67,7 @@ protected: QSettings legacySettings { legacyOrganizationName, legacyApplicationName }; }; -class SettingsGroup : public Settings -{ +class SettingsGroup : public Settings { public: template explicit SettingsGroup(QString path, ArgTs&&... qsettingsArgs) @@ -121,8 +116,7 @@ private: setValue(QStringLiteral(qsettingname), std::move(newValue)); \ } -class AccountSettings : public SettingsGroup -{ +class AccountSettings : public SettingsGroup { Q_OBJECT Q_PROPERTY(QString userId READ userId CONSTANT) QMC_DECLARE_SETTING(QString, deviceId, setDeviceId) -- cgit v1.2.3 From 7a5b359b8823646ce97cbaf05c251cb04c291466 Mon Sep 17 00:00:00 2001 From: Kitsune Ral Date: Sun, 7 Jul 2019 18:16:30 +0900 Subject: Rename zero-impact strings --- lib/settings.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib/settings.h') diff --git a/lib/settings.h b/lib/settings.h index 6747631e..427f5494 100644 --- a/lib/settings.h +++ b/lib/settings.h @@ -140,7 +140,7 @@ public: /** \deprecated \sa setToken */ QString accessToken() const; /** \deprecated Storing accessToken in QSettings is unsafe, - * see QMatrixClient/Quaternion#181 */ + * see quotient-im/Quaternion#181 */ void setAccessToken(const QString& accessToken); Q_INVOKABLE void clearAccessToken(); -- cgit v1.2.3 From 27ca32a1e5a56e09b9cc1d94224d2831004dcf3d Mon Sep 17 00:00:00 2001 From: Kitsune Ral Date: Sun, 7 Jul 2019 19:32:34 +0900 Subject: Namespace: QMatrixClient -> Quotient (with back comp alias) --- lib/settings.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'lib/settings.h') diff --git a/lib/settings.h b/lib/settings.h index 427f5494..4dcbbea0 100644 --- a/lib/settings.h +++ b/lib/settings.h @@ -24,7 +24,7 @@ class QVariant; -namespace QMatrixClient { +namespace Quotient { class Settings : public QSettings { Q_OBJECT public: @@ -148,4 +148,4 @@ public: void setEncryptionAccountPickle(const QByteArray& encryptionAccountPickle); Q_INVOKABLE void clearEncryptionAccountPickle(); }; -} // namespace QMatrixClient +} // namespace Quotient -- cgit v1.2.3 From cf19c87f6561afee7aba5591d3c81b7a158449ea Mon Sep 17 00:00:00 2001 From: Kitsune Ral Date: Mon, 12 Aug 2019 15:37:52 +0900 Subject: Make Settings::remove() to clear the legacy; more doc-comments --- lib/settings.h | 43 +++++++++++++++++++++++++++++++++---------- 1 file changed, 33 insertions(+), 10 deletions(-) (limited to 'lib/settings.h') diff --git a/lib/settings.h b/lib/settings.h index 4dcbbea0..d317ec2a 100644 --- a/lib/settings.h +++ b/lib/settings.h @@ -28,27 +28,50 @@ namespace Quotient { class Settings : public QSettings { Q_OBJECT public: - /** + /// Add a legacy organisation/application name to migrate settings from + /*! * Use this function before creating any Settings objects in order - * to setup a read-only location where configuration has previously - * been stored. This will provide an additional fallback in case of - * renaming the organisation/application. + * to set a legacy location where configuration has previously been stored. + * This will provide an additional fallback in case of renaming + * the organisation/application. Values in legacy locations are _removed_ + * when setValue() or remove() is called. */ static void setLegacyNames(const QString& organizationName, const QString& applicationName = {}); -#if defined(_MSC_VER) && _MSC_VER < 1900 - // VS 2013 (and probably older) aren't friends with 'using' statements - // that involve private constructors - explicit Settings(QObject* parent = 0) : QSettings(parent) {} -#else using QSettings::QSettings; -#endif + /// Set the value for a given key + /*! If the key exists in the legacy location, it is removed. */ Q_INVOKABLE void setValue(const QString& key, const QVariant& value); + + /// Remove the value from both the primary and legacy locations + Q_INVOKABLE void remove(const QString& key); + + /// Obtain a value for a given key + /*! + * If the key doesn't exist in the primary settings location, the legacy + * location is checked. If neither location has the key, + * \p defaultValue is returned. + * + * This function returns a QVariant; use get<>() to get the unwrapped + * value if you know the type upfront. + * + * \sa setLegacyNames, get + */ Q_INVOKABLE QVariant value(const QString& key, const QVariant& defaultValue = {}) const; + /// Obtain a value for a given key, coerced to the given type + /*! + * On top of value(), this function unwraps the QVariant and returns + * its contents assuming the type passed as the template parameter. + * If the type is different from the one stored inside the QVariant, + * \p defaultValue is returned. In presence of legacy settings, + * only the first found value is checked; if its type does not match, + * further checks through legacy settings are not performed and + * \p defaultValue is returned. + */ template T get(const QString& key, const T& defaultValue = {}) const { -- cgit v1.2.3 From be53652eb30edd6e096c172a97609070d1e74746 Mon Sep 17 00:00:00 2001 From: Kitsune Ral Date: Sun, 29 Sep 2019 17:50:28 +0900 Subject: Settings: childGroups() should merge legacy and current groups; QMC->QTNT in macros Because otherwise migrating one group to the current location leads to all other groups suddenly disappearing from Settings view. --- lib/settings.h | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'lib/settings.h') diff --git a/lib/settings.h b/lib/settings.h index d317ec2a..79ebba6c 100644 --- a/lib/settings.h +++ b/lib/settings.h @@ -119,7 +119,7 @@ private: QString groupPath; }; -#define QMC_DECLARE_SETTING(type, propname, setter) \ +#define QTNT_DECLARE_SETTING(type, propname, setter) \ Q_PROPERTY(type propname READ propname WRITE setter) \ public: \ type propname() const; \ @@ -127,7 +127,7 @@ public: \ \ private: -#define QMC_DEFINE_SETTING(classname, type, propname, qsettingname, \ +#define QTNT_DEFINE_SETTING(classname, type, propname, qsettingname, \ defaultValue, setter) \ type classname::propname() const \ { \ @@ -142,9 +142,9 @@ private: class AccountSettings : public SettingsGroup { Q_OBJECT Q_PROPERTY(QString userId READ userId CONSTANT) - QMC_DECLARE_SETTING(QString, deviceId, setDeviceId) - QMC_DECLARE_SETTING(QString, deviceName, setDeviceName) - QMC_DECLARE_SETTING(bool, keepLoggedIn, setKeepLoggedIn) + QTNT_DECLARE_SETTING(QString, deviceId, setDeviceId) + QTNT_DECLARE_SETTING(QString, deviceName, setDeviceName) + QTNT_DECLARE_SETTING(bool, keepLoggedIn, setKeepLoggedIn) /** \deprecated \sa setAccessToken */ Q_PROPERTY(QString accessToken READ accessToken WRITE setAccessToken) Q_PROPERTY(QByteArray encryptionAccountPickle READ encryptionAccountPickle -- cgit v1.2.3 From 04a277dbb6c15e79be8623f3c36edd465d4b80a7 Mon Sep 17 00:00:00 2001 From: Kitsune Ral Date: Tue, 14 Apr 2020 07:14:28 +0200 Subject: Settings: use UTF-8 encoding Fixes #403. --- lib/settings.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib/settings.h') diff --git a/lib/settings.h b/lib/settings.h index 79ebba6c..5a097285 100644 --- a/lib/settings.h +++ b/lib/settings.h @@ -39,7 +39,7 @@ public: static void setLegacyNames(const QString& organizationName, const QString& applicationName = {}); - using QSettings::QSettings; + explicit Settings(QObject* parent = nullptr); /// Set the value for a given key /*! If the key exists in the legacy location, it is removed. */ -- cgit v1.2.3 From f6faea5971d94627da67dc1442504da07374958d Mon Sep 17 00:00:00 2001 From: Kitsune Ral Date: Sun, 7 Jun 2020 13:54:23 +0200 Subject: AccountSettins: use perfect forwarding --- lib/settings.h | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'lib/settings.h') diff --git a/lib/settings.h b/lib/settings.h index 5a097285..c45764a6 100644 --- a/lib/settings.h +++ b/lib/settings.h @@ -25,6 +25,7 @@ class QVariant; namespace Quotient { + class Settings : public QSettings { Q_OBJECT public: @@ -151,8 +152,9 @@ class AccountSettings : public SettingsGroup { WRITE setEncryptionAccountPickle) public: template - explicit AccountSettings(const QString& accountId, ArgTs... qsettingsArgs) - : SettingsGroup("Accounts/" + accountId, qsettingsArgs...) + explicit AccountSettings(const QString& accountId, ArgTs&&... qsettingsArgs) + : SettingsGroup("Accounts/" + accountId, + std::forward(qsettingsArgs)...) {} QString userId() const; -- cgit v1.2.3 From cd9c9296bb1ac7af7ebbbf66931e731dbf581bc8 Mon Sep 17 00:00:00 2001 From: Carl Schwan Date: Sat, 26 Dec 2020 14:54:31 +0100 Subject: Port existing copyright statement to reuse using licensedigger --- lib/settings.h | 16 ++-------------- 1 file changed, 2 insertions(+), 14 deletions(-) (limited to 'lib/settings.h') diff --git a/lib/settings.h b/lib/settings.h index c45764a6..badabec2 100644 --- a/lib/settings.h +++ b/lib/settings.h @@ -1,19 +1,7 @@ /****************************************************************************** - * Copyright (C) 2016 Kitsune Ral + * SPDX-FileCopyrightText: 2016 Kitsune Ral * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * SPDX-License-Identifier: LGPL-2.1-or-later */ #pragma once -- cgit v1.2.3 From 0a775d9b3209be15dea8b8915fc0a1c8e0046ba6 Mon Sep 17 00:00:00 2001 From: Kitsune Ral Date: Sat, 16 Jan 2021 18:19:45 +0100 Subject: Updated copyright statements upon Git audit After going through all the files and the history of commits on them it was clear that some copyright statements are obsolete (the code has been overwritten since) and some are missing. This commit tries best to remedy that, along with adding SPDX tags where they were still not used. Also, a minimal SPDX convention is documented for further contributions. Closes #426. --- lib/settings.h | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) (limited to 'lib/settings.h') diff --git a/lib/settings.h b/lib/settings.h index badabec2..84c54802 100644 --- a/lib/settings.h +++ b/lib/settings.h @@ -1,8 +1,5 @@ -/****************************************************************************** - * SPDX-FileCopyrightText: 2016 Kitsune Ral - * - * SPDX-License-Identifier: LGPL-2.1-or-later - */ +// SPDX-FileCopyrightText: 2016 Kitsune Ral +// SPDX-License-Identifier: LGPL-2.1-or-later #pragma once -- cgit v1.2.3 From 395f3758e810fed6cd276a356fd5f0e955c5477e Mon Sep 17 00:00:00 2001 From: Alexey Rusakov Date: Sun, 22 Aug 2021 20:22:36 +0200 Subject: Settings: no more setToken() and accessToken(); deprecate clearAccessToken() Access tokens should be stored with Qt Keychain that's about to come; and these methods were deprecated since before 0.5. --- lib/settings.h | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) (limited to 'lib/settings.h') diff --git a/lib/settings.h b/lib/settings.h index 84c54802..3f4dc123 100644 --- a/lib/settings.h +++ b/lib/settings.h @@ -131,8 +131,6 @@ class AccountSettings : public SettingsGroup { QTNT_DECLARE_SETTING(QString, deviceId, setDeviceId) QTNT_DECLARE_SETTING(QString, deviceName, setDeviceName) QTNT_DECLARE_SETTING(bool, keepLoggedIn, setKeepLoggedIn) - /** \deprecated \sa setAccessToken */ - Q_PROPERTY(QString accessToken READ accessToken WRITE setAccessToken) Q_PROPERTY(QByteArray encryptionAccountPickle READ encryptionAccountPickle WRITE setEncryptionAccountPickle) public: @@ -147,11 +145,7 @@ public: QUrl homeserver() const; void setHomeserver(const QUrl& url); - /** \deprecated \sa setToken */ - QString accessToken() const; - /** \deprecated Storing accessToken in QSettings is unsafe, - * see quotient-im/Quaternion#181 */ - void setAccessToken(const QString& accessToken); + Q_DECL_DEPRECATED_X("Access tokens are not stored in QSettings any more") Q_INVOKABLE void clearAccessToken(); QByteArray encryptionAccountPickle(); -- cgit v1.2.3 From f005f3b69651bd6d6f58879804e1281f6c08177a Mon Sep 17 00:00:00 2001 From: Alexey Rusakov Date: Mon, 30 Aug 2021 12:33:56 +0200 Subject: SettingsGroup, AccountSettings: simplify constructors The parameter packs intended to pass organisation/application names to QSettings never worked that way since Quotient::Settings didn't have that parameter pack in its constructor. On the other hand, setting organisation/application name using static methods before constructing the first settings object has been working just fine so far. If someone needs to create a settings object with customised org/app name for some reason (sneaking settings from other apps?), those can be brought back in a working manner and without breaking API/ABI even. --- lib/settings.h | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) (limited to 'lib/settings.h') diff --git a/lib/settings.h b/lib/settings.h index 3f4dc123..efd0d714 100644 --- a/lib/settings.h +++ b/lib/settings.h @@ -78,9 +78,8 @@ protected: class SettingsGroup : public Settings { public: - template - explicit SettingsGroup(QString path, ArgTs&&... qsettingsArgs) - : Settings(std::forward(qsettingsArgs)...) + explicit SettingsGroup(QString path, QObject* parent = nullptr) + : Settings(parent) , groupPath(std::move(path)) {} @@ -134,10 +133,8 @@ class AccountSettings : public SettingsGroup { Q_PROPERTY(QByteArray encryptionAccountPickle READ encryptionAccountPickle WRITE setEncryptionAccountPickle) public: - template - explicit AccountSettings(const QString& accountId, ArgTs&&... qsettingsArgs) - : SettingsGroup("Accounts/" + accountId, - std::forward(qsettingsArgs)...) + explicit AccountSettings(const QString& accountId, QObject* parent = nullptr) + : SettingsGroup("Accounts/" + accountId, parent) {} QString userId() const; -- cgit v1.2.3 From 0d9428bfbd997ac2073a470e59749cda81e0b213 Mon Sep 17 00:00:00 2001 From: Alexey Rusakov Date: Tue, 28 Dec 2021 09:01:37 +0100 Subject: Settings classes: unify on QUO_ macro prefix At some point macros were prepended with QTNT (pronounced "cute-n't", "Quotient" with vowels dropped) but that didn't go very far. Having forgotten about this, I introduced QUO prefix in a few places. Being initial letters of "Quotient", QUO feels more understandable (and coincidentally is a well-known Latin word); so let's unify on this. --- lib/settings.h | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'lib/settings.h') diff --git a/lib/settings.h b/lib/settings.h index efd0d714..3cab8958 100644 --- a/lib/settings.h +++ b/lib/settings.h @@ -104,7 +104,7 @@ private: QString groupPath; }; -#define QTNT_DECLARE_SETTING(type, propname, setter) \ +#define QUO_DECLARE_SETTING(type, propname, setter) \ Q_PROPERTY(type propname READ propname WRITE setter) \ public: \ type propname() const; \ @@ -112,7 +112,7 @@ public: \ \ private: -#define QTNT_DEFINE_SETTING(classname, type, propname, qsettingname, \ +#define QUO_DEFINE_SETTING(classname, type, propname, qsettingname, \ defaultValue, setter) \ type classname::propname() const \ { \ @@ -127,9 +127,9 @@ private: class AccountSettings : public SettingsGroup { Q_OBJECT Q_PROPERTY(QString userId READ userId CONSTANT) - QTNT_DECLARE_SETTING(QString, deviceId, setDeviceId) - QTNT_DECLARE_SETTING(QString, deviceName, setDeviceName) - QTNT_DECLARE_SETTING(bool, keepLoggedIn, setKeepLoggedIn) + QUO_DECLARE_SETTING(QString, deviceId, setDeviceId) + QUO_DECLARE_SETTING(QString, deviceName, setDeviceName) + QUO_DECLARE_SETTING(bool, keepLoggedIn, setKeepLoggedIn) Q_PROPERTY(QByteArray encryptionAccountPickle READ encryptionAccountPickle WRITE setEncryptionAccountPickle) public: -- cgit v1.2.3 From 7350fe82953cf6274b8845a890eafb21a09b9931 Mon Sep 17 00:00:00 2001 From: Alexey Rusakov Date: Wed, 29 Dec 2021 15:59:58 +0100 Subject: Add QUOTIENT_API throughout non-generated code This include all (hopefully) classes/structures and functions that have non-inline definitions, as well as namespaces with Q_NAMESPACE since those have non-inline (as of Qt 5.15) QMetaObject - for that a new macro, QUO_NAMESPACE, has been devised to accommodate the lack of Q_NAMESPACE_EXPORT in Qt before 5.14. --- lib/settings.h | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'lib/settings.h') diff --git a/lib/settings.h b/lib/settings.h index efd0d714..b66879c5 100644 --- a/lib/settings.h +++ b/lib/settings.h @@ -3,6 +3,8 @@ #pragma once +#include "quotient_export.h" + #include #include #include @@ -11,7 +13,7 @@ class QVariant; namespace Quotient { -class Settings : public QSettings { +class QUOTIENT_API Settings : public QSettings { Q_OBJECT public: /// Add a legacy organisation/application name to migrate settings from @@ -76,7 +78,7 @@ protected: QSettings legacySettings { legacyOrganizationName, legacyApplicationName }; }; -class SettingsGroup : public Settings { +class QUOTIENT_API SettingsGroup : public Settings { public: explicit SettingsGroup(QString path, QObject* parent = nullptr) : Settings(parent) @@ -124,7 +126,7 @@ private: setValue(QStringLiteral(qsettingname), std::move(newValue)); \ } -class AccountSettings : public SettingsGroup { +class QUOTIENT_API AccountSettings : public SettingsGroup { Q_OBJECT Q_PROPERTY(QString userId READ userId CONSTANT) QTNT_DECLARE_SETTING(QString, deviceId, setDeviceId) -- cgit v1.2.3