From a2c818e157cfa5d0b5e6263aa744f2f73a7be517 Mon Sep 17 00:00:00 2001 From: Claudio Cambra Date: Thu, 19 Sep 2024 15:05:24 +0800 Subject: [PATCH] Add property for detecting of application override server url is in fact a JSON array string describing multiple servers Signed-off-by: Claudio Cambra --- src/libsync/theme.cpp | 16 ++++++++++++++++ src/libsync/theme.h | 9 +++++++++ 2 files changed, 25 insertions(+) diff --git a/src/libsync/theme.cpp b/src/libsync/theme.cpp index 11c8982bf..407db59ba 100644 --- a/src/libsync/theme.cpp +++ b/src/libsync/theme.cpp @@ -30,6 +30,8 @@ #include #include #include +#include +#include #include "nextcloudtheme.h" @@ -383,6 +385,7 @@ Theme::Theme() #endif #ifdef APPLICATION_SERVER_URL _overrideServerUrl = QString::fromLatin1(APPLICATION_SERVER_URL); + updateMultipleOverrideServers(); #endif } @@ -432,6 +435,18 @@ bool Theme::forceOverrideServerUrl() const return _forceOverrideServerUrl; } +void Theme::updateMultipleOverrideServers() +{ + const auto json = overrideServerUrl().toUtf8(); + const auto doc = QJsonDocument::fromJson(json); + _multipleOverrideServers = doc.isArray() && !doc.array().empty(); +} + +bool Theme::multipleOverrideServers() const +{ + return _multipleOverrideServers; +} + bool Theme::isVfsEnabled() const { return _isVfsEnabled; @@ -954,6 +969,7 @@ void Theme::setOverrideServerUrl(const QString &overrideServerUrl) { if (_overrideServerUrl != overrideServerUrl) { _overrideServerUrl = overrideServerUrl; + updateMultipleOverrideServers(); emit overrideServerUrlChanged(); } } diff --git a/src/libsync/theme.h b/src/libsync/theme.h index 0cca5484e..b414c9fa3 100644 --- a/src/libsync/theme.h +++ b/src/libsync/theme.h @@ -232,11 +232,18 @@ public: /** * Setting a value here will pre-define the server url. + * Can be a url OR a JSON array of servers description objects: {"name": "x", "url": "y"} * * The respective UI controls will be disabled only if forceOverrideServerUrl() is true */ [[nodiscard]] QString overrideServerUrl() const; + /** + * Indicates whether the override server URL is in fact a JSON array of server description + * objects. + */ + [[nodiscard]] bool multipleOverrideServers() const; + /** * Enforce a pre-defined server url. * @@ -627,6 +634,7 @@ private: Theme(Theme const &); Theme &operator=(Theme const &); + void updateMultipleOverrideServers(); void connectToPaletteSignal(); #if defined(Q_OS_WIN) QPalette reserveDarkPalette; // Windows 11 button and window dark colours @@ -638,6 +646,7 @@ private: QString _overrideServerUrl; bool _forceOverrideServerUrl = false; + bool _multipleOverrideServers = false; bool _isVfsEnabled = false; bool _startLoginFlowAutomatically = false;