Add property for detecting of application override server url is in fact a JSON array string describing multiple servers

Signed-off-by: Claudio Cambra <claudio.cambra@nextcloud.com>
This commit is contained in:
Claudio Cambra 2024-09-19 15:05:24 +08:00 коммит произвёл backportbot[bot]
Родитель f1d3d5e0be
Коммит a3fe1a7fab
2 изменённых файлов: 25 добавлений и 0 удалений

Просмотреть файл

@ -30,6 +30,8 @@
#include <QSslSocket>
#include <QSvgRenderer>
#include <QPainter>
#include <QJsonDocument>
#include <QJsonArray>
#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();
}
}

Просмотреть файл

@ -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;