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(); diff --git a/src/libsync/account.cpp b/src/libsync/account.cpp index 9f080fdca197..872acee50feb 100644 --- a/src/libsync/account.cpp +++ b/src/libsync/account.cpp @@ -13,16 +13,16 @@ */ #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 "theme.h" #include "version.h" #include "deletejob.h" @@ -71,6 +71,7 @@ const char app_password[] = "_app-password"; Account::Account(QObject *parent) : QObject(parent) , _capabilities(QVariantMap()) + , _serverColor(Theme::defaultColor()) { qRegisterMetaType("AccountPtr"); qRegisterMetaType("Account*"); @@ -197,32 +198,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; } @@ -649,10 +648,23 @@ 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); + updateServerColors(); + emit capabilitiesChanged(); setupUserStatusConnector(); diff --git a/src/libsync/account.h b/src/libsync/account.h index 14dbc166d5ae..4cad863cf971 100644 --- a/src/libsync/account.h +++ b/src/libsync/account.h @@ -31,12 +31,13 @@ #include #endif -#include "common/utility.h" -#include #include "capabilities.h" #include "clientsideencryption.h" +#include "common/utility.h" #include "syncfileitem.h" +#include + class QSettings; class QNetworkReply; class QUrl; @@ -375,8 +376,10 @@ protected Q_SLOTS: private: Account(QObject *parent = nullptr); void setSharedThis(AccountPtr sharedThis); + void updateServerColors(); - static QString davPathBase(); + [[nodiscard]] static QString davPathBase(); + [[nodiscard]] QColor serverColor() const; bool _trustCertificates = false; @@ -406,6 +409,8 @@ protected Q_SLOTS: QSslConfiguration _sslConfiguration; Capabilities _capabilities; QString _serverVersion; + QColor _serverColor; + QColor _serverTextColor = QColorConstants::White; bool _skipE2eeMetadataChecksumValidation = false; QScopedPointer _sslErrorHandler; QSharedPointer _am;