From 9253016d00e57b61694d8546965053d5d6ffe13a Mon Sep 17 00:00:00 2001 From: Claudio Cambra Date: Tue, 1 Aug 2023 15:55:41 +0800 Subject: [PATCH 1/5] Store server color in private member of account when capabilities fetched Signed-off-by: Claudio Cambra --- src/libsync/account.cpp | 35 +++++++++++++++++------------------ src/libsync/account.h | 10 +++++++--- 2 files changed, 24 insertions(+), 21 deletions(-) diff --git a/src/libsync/account.cpp b/src/libsync/account.cpp index 9f080fdca197..e30965c98514 100644 --- a/src/libsync/account.cpp +++ b/src/libsync/account.cpp @@ -13,15 +13,14 @@ */ #include "account.h" +#include "accessmanager.h" #include "accountfwd.h" +#include "capabilities.h" #include "clientsideencryptionjobs.h" -#include "cookiejar.h" -#include "networkjobs.h" #include "configfile.h" -#include "accessmanager.h" +#include "cookiejar.h" #include "creds/abstractcredentials.h" -#include "capabilities.h" -#include "theme.h" +#include "networkjobs.h" #include "pushnotifications.h" #include "version.h" @@ -197,32 +196,30 @@ QString Account::prettyName() const return name; } +QColor Account::serverColor() const +{ + return _serverColor; +} + QColor Account::headerColor() const { - const auto serverColor = capabilities().serverColor(); - return serverColor.isValid() ? serverColor : Theme::defaultColor(); + return serverColor(); } QColor Account::headerTextColor() const { - const auto headerTextColor = capabilities().serverTextColor(); - return headerTextColor.isValid() ? headerTextColor : QColor(255,255,255); + return _serverTextColor; } QColor Account::accentColor() const { - // This will need adjusting when dark theme is a thing - auto serverColor = capabilities().serverColor(); - - if(!serverColor.isValid()) { - serverColor = Theme::defaultColor(); - } + const auto accentColor = serverColor(); + constexpr auto effectMultiplier = 8; - const auto effectMultiplier = 8; - auto darknessAdjustment = static_cast((1 - Theme::getColorDarkness(serverColor)) * effectMultiplier); + auto darknessAdjustment = static_cast((1 - Theme::getColorDarkness(accentColor)) * effectMultiplier); darknessAdjustment *= darknessAdjustment; // Square the value to pronounce the darkness more in lighter colours const auto baseAdjustment = 125; - const auto adjusted = Theme::isDarkColor(serverColor) ? serverColor : serverColor.darker(baseAdjustment + darknessAdjustment); + const auto adjusted = Theme::isDarkColor(accentColor) ? accentColor : accentColor.darker(baseAdjustment + darknessAdjustment); return adjusted; } @@ -652,6 +649,8 @@ const Capabilities &Account::capabilities() const void Account::setCapabilities(const QVariantMap &caps) { _capabilities = Capabilities(caps); + _serverColor = _capabilities.serverColor(); + _serverTextColor = _capabilities.serverTextColor(); emit capabilitiesChanged(); diff --git a/src/libsync/account.h b/src/libsync/account.h index 14dbc166d5ae..97e7835dd0ef 100644 --- a/src/libsync/account.h +++ b/src/libsync/account.h @@ -31,11 +31,12 @@ #include #endif -#include "common/utility.h" -#include #include "capabilities.h" #include "clientsideencryption.h" +#include "common/utility.h" #include "syncfileitem.h" +#include "theme.h" +#include class QSettings; class QNetworkReply; @@ -376,7 +377,8 @@ protected Q_SLOTS: Account(QObject *parent = nullptr); void setSharedThis(AccountPtr sharedThis); - static QString davPathBase(); + [[nodiscard]] static QString davPathBase(); + [[nodiscard]] QColor serverColor() const; bool _trustCertificates = false; @@ -406,6 +408,8 @@ protected Q_SLOTS: QSslConfiguration _sslConfiguration; Capabilities _capabilities; QString _serverVersion; + QColor _serverColor = Theme::defaultColor(); + QColor _serverTextColor = QColor(255, 255, 255); bool _skipE2eeMetadataChecksumValidation = false; QScopedPointer _sslErrorHandler; QSharedPointer _am; From 135b23556820f186266c1ed84b912066fb104e08 Mon Sep 17 00:00:00 2001 From: Claudio Cambra Date: Tue, 1 Aug 2023 16:00:17 +0800 Subject: [PATCH 2/5] Only update private colors if received capabilities colors are valid Signed-off-by: Claudio Cambra --- src/libsync/account.cpp | 15 +++++++++++++-- src/libsync/account.h | 1 + 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/src/libsync/account.cpp b/src/libsync/account.cpp index e30965c98514..da3a80a29ccd 100644 --- a/src/libsync/account.cpp +++ b/src/libsync/account.cpp @@ -646,11 +646,22 @@ const Capabilities &Account::capabilities() const return _capabilities; } +void Account::updateServerColors() +{ + if (const auto capServerColor = _capabilities.serverColor(); capServerColor.isValid()) { + _serverColor = capServerColor; + } + + if (const auto capServerTextColor = _capabilities.serverTextColor(); capServerTextColor.isValid()) { + _serverTextColor = capServerTextColor; + } +} + void Account::setCapabilities(const QVariantMap &caps) { _capabilities = Capabilities(caps); - _serverColor = _capabilities.serverColor(); - _serverTextColor = _capabilities.serverTextColor(); + + updateServerColors(); emit capabilitiesChanged(); diff --git a/src/libsync/account.h b/src/libsync/account.h index 97e7835dd0ef..7a2655151f9b 100644 --- a/src/libsync/account.h +++ b/src/libsync/account.h @@ -376,6 +376,7 @@ protected Q_SLOTS: private: Account(QObject *parent = nullptr); void setSharedThis(AccountPtr sharedThis); + void updateServerColors(); [[nodiscard]] static QString davPathBase(); [[nodiscard]] QColor serverColor() const; From f260bbf9f40ad080ed3351a048e93ffcaf24a8e4 Mon Sep 17 00:00:00 2001 From: Claudio Cambra Date: Tue, 1 Aug 2023 16:00:39 +0800 Subject: [PATCH 3/5] Remember server colors across restarts, enabling correct color before capabilities fetched Signed-off-by: Claudio Cambra --- src/gui/accountmanager.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/gui/accountmanager.cpp b/src/gui/accountmanager.cpp index 205a8007c98f..98b250b3f1f0 100644 --- a/src/gui/accountmanager.cpp +++ b/src/gui/accountmanager.cpp @@ -42,6 +42,8 @@ constexpr auto caCertsKeyC = "CaCertificates"; constexpr auto accountsC = "Accounts"; constexpr auto versionC = "version"; constexpr auto serverVersionC = "serverVersion"; +constexpr auto serverColorC = "serverColor"; +constexpr auto serverTextColorC = "serverTextColor"; constexpr auto skipE2eeMetadataChecksumValidationC = "skipE2eeMetadataChecksumValidation"; constexpr auto generalC = "General"; @@ -306,6 +308,8 @@ void AccountManager::saveAccountHelper(Account *acc, QSettings &settings, bool s settings.setValue(QLatin1String(davUserC), acc->_davUser); settings.setValue(QLatin1String(displayNameC), acc->_displayName); settings.setValue(QLatin1String(serverVersionC), acc->_serverVersion); + settings.setValue(QLatin1String(serverColorC), acc->_serverColor); + settings.setValue(QLatin1String(serverTextColorC), acc->_serverTextColor); if (!acc->_skipE2eeMetadataChecksumValidation) { settings.remove(QLatin1String(skipE2eeMetadataChecksumValidationC)); } else { @@ -412,6 +416,8 @@ AccountPtr AccountManager::loadAccountHelper(QSettings &settings) qCInfo(lcAccountManager) << "Account for" << acc->url() << "using auth type" << authType; acc->_serverVersion = settings.value(QLatin1String(serverVersionC)).toString(); + acc->_serverColor = settings.value(QLatin1String(serverColorC)).value(); + acc->_serverTextColor = settings.value(QLatin1String(serverTextColorC)).value(); acc->_skipE2eeMetadataChecksumValidation = settings.value(QLatin1String(skipE2eeMetadataChecksumValidationC), {}).toBool(); acc->_davUser = settings.value(QLatin1String(davUserC), "").toString(); From 362118eafc3845bc57db286c1af1bd5e9d494672 Mon Sep 17 00:00:00 2001 From: Claudio Cambra Date: Wed, 23 Aug 2023 09:25:54 +0800 Subject: [PATCH 4/5] Use QColorConstants for white instead of manually creating QColor Signed-off-by: Claudio Cambra --- src/libsync/account.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libsync/account.h b/src/libsync/account.h index 7a2655151f9b..1c44b7144326 100644 --- a/src/libsync/account.h +++ b/src/libsync/account.h @@ -410,7 +410,7 @@ protected Q_SLOTS: Capabilities _capabilities; QString _serverVersion; QColor _serverColor = Theme::defaultColor(); - QColor _serverTextColor = QColor(255, 255, 255); + QColor _serverTextColor = QColorConstants::White; bool _skipE2eeMetadataChecksumValidation = false; QScopedPointer _sslErrorHandler; QSharedPointer _am; From 01cb5d7e222a7b783d2540aa21437825c0c0d1e8 Mon Sep 17 00:00:00 2001 From: Claudio Cambra Date: Wed, 23 Aug 2023 09:26:31 +0800 Subject: [PATCH 5/5] Do not include theme header in account header Signed-off-by: Claudio Cambra --- src/libsync/account.cpp | 2 ++ src/libsync/account.h | 4 ++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/libsync/account.cpp b/src/libsync/account.cpp index da3a80a29ccd..872acee50feb 100644 --- a/src/libsync/account.cpp +++ b/src/libsync/account.cpp @@ -22,6 +22,7 @@ #include "creds/abstractcredentials.h" #include "networkjobs.h" #include "pushnotifications.h" +#include "theme.h" #include "version.h" #include "deletejob.h" @@ -70,6 +71,7 @@ const char app_password[] = "_app-password"; Account::Account(QObject *parent) : QObject(parent) , _capabilities(QVariantMap()) + , _serverColor(Theme::defaultColor()) { qRegisterMetaType("AccountPtr"); qRegisterMetaType("Account*"); diff --git a/src/libsync/account.h b/src/libsync/account.h index 1c44b7144326..4cad863cf971 100644 --- a/src/libsync/account.h +++ b/src/libsync/account.h @@ -35,7 +35,7 @@ #include "clientsideencryption.h" #include "common/utility.h" #include "syncfileitem.h" -#include "theme.h" + #include class QSettings; @@ -409,7 +409,7 @@ protected Q_SLOTS: QSslConfiguration _sslConfiguration; Capabilities _capabilities; QString _serverVersion; - QColor _serverColor = Theme::defaultColor(); + QColor _serverColor; QColor _serverTextColor = QColorConstants::White; bool _skipE2eeMetadataChecksumValidation = false; QScopedPointer _sslErrorHandler;