Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Display correct server colour prior to acquiring server capabilities #5946

Merged
merged 5 commits into from
Aug 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/gui/accountmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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<QColor>();
acc->_serverTextColor = settings.value(QLatin1String(serverTextColorC)).value<QColor>();
acc->_skipE2eeMetadataChecksumValidation = settings.value(QLatin1String(skipE2eeMetadataChecksumValidationC), {}).toBool();
acc->_davUser = settings.value(QLatin1String(davUserC), "").toString();

Expand Down
48 changes: 30 additions & 18 deletions src/libsync/account.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -71,6 +71,7 @@ const char app_password[] = "_app-password";
Account::Account(QObject *parent)
: QObject(parent)
, _capabilities(QVariantMap())
, _serverColor(Theme::defaultColor())
{
qRegisterMetaType<AccountPtr>("AccountPtr");
qRegisterMetaType<Account *>("Account*");
Expand Down Expand Up @@ -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<int>((1 - Theme::getColorDarkness(serverColor)) * effectMultiplier);
auto darknessAdjustment = static_cast<int>((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;
}

Expand Down Expand Up @@ -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();
Expand Down
11 changes: 8 additions & 3 deletions src/libsync/account.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,13 @@
#include <QPixmap>
#endif

#include "common/utility.h"
#include <memory>
#include "capabilities.h"
#include "clientsideencryption.h"
#include "common/utility.h"
#include "syncfileitem.h"

#include <memory>

class QSettings;
class QNetworkReply;
class QUrl;
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -406,6 +409,8 @@ protected Q_SLOTS:
QSslConfiguration _sslConfiguration;
Capabilities _capabilities;
QString _serverVersion;
QColor _serverColor;
QColor _serverTextColor = QColorConstants::White;
bool _skipE2eeMetadataChecksumValidation = false;
QScopedPointer<AbstractSslErrorHandler> _sslErrorHandler;
QSharedPointer<QNetworkAccessManager> _am;
Expand Down
Loading