diff --git a/config.h.in b/config.h.in index fd2b17766..be3005502 100644 --- a/config.h.in +++ b/config.h.in @@ -23,7 +23,7 @@ #cmakedefine APPLICATION_HELP_URL "@APPLICATION_HELP_URL@" #cmakedefine APPLICATION_ICON_NAME "@APPLICATION_ICON_NAME@" #cmakedefine APPLICATION_ICON_SET "@APPLICATION_ICON_SET@" -#cmakedefine APPLICATION_SERVER_URL "@APPLICATION_SERVER_URL@" +#cmakedefine APPLICATION_SERVER_URL R"(@APPLICATION_SERVER_URL@)" #cmakedefine APPLICATION_SERVER_URL_ENFORCE "@APPLICATION_SERVER_URL_ENFORCE@" #cmakedefine LINUX_APPLICATION_ID "@LINUX_APPLICATION_ID@" #cmakedefine APPLICATION_WIZARD_HEADER_BACKGROUND_COLOR "@APPLICATION_WIZARD_HEADER_BACKGROUND_COLOR@" diff --git a/src/gui/accountmanager.cpp b/src/gui/accountmanager.cpp index 4f41267cd..57dfd097b 100644 --- a/src/gui/accountmanager.cpp +++ b/src/gui/accountmanager.cpp @@ -456,7 +456,8 @@ AccountPtr AccountManager::loadAccountHelper(QSettings &settings) const auto overrideUrl = Theme::instance()->overrideServerUrl(); const auto forceAuth = Theme::instance()->forceConfigAuthType(); - if (!forceAuth.isEmpty() && !overrideUrl.isEmpty()) { + const auto multipleOverrideServers = Theme::instance()->multipleOverrideServers(); + if (!forceAuth.isEmpty() && !overrideUrl.isEmpty() && !multipleOverrideServers) { // If forceAuth is set, this might also mean the overrideURL has changed. // See enterprise issues #1126 acc->setUrl(overrideUrl); diff --git a/src/gui/owncloudsetupwizard.cpp b/src/gui/owncloudsetupwizard.cpp index c60fd118f..40b88289a 100644 --- a/src/gui/owncloudsetupwizard.cpp +++ b/src/gui/owncloudsetupwizard.cpp @@ -103,7 +103,9 @@ void OwncloudSetupWizard::startWizard() { AccountPtr account = AccountManager::createAccount(); account->setCredentials(CredentialsFactory::create("dummy")); - account->setUrl(Theme::instance()->overrideServerUrl()); + const auto defaultUrl = + Theme::instance()->multipleOverrideServers() ? QString{} : Theme::instance()->overrideServerUrl(); + account->setUrl(defaultUrl); _ocWizard->setAccount(account); _ocWizard->setOCUrl(account->url().toString()); diff --git a/src/gui/wizard/owncloudsetupnocredspage.ui b/src/gui/wizard/owncloudsetupnocredspage.ui index d67873450..d12a9e143 100644 --- a/src/gui/wizard/owncloudsetupnocredspage.ui +++ b/src/gui/wizard/owncloudsetupnocredspage.ui @@ -199,6 +199,9 @@ + + + diff --git a/src/gui/wizard/owncloudsetuppage.cpp b/src/gui/wizard/owncloudsetuppage.cpp index a5374eb59..708949f75 100644 --- a/src/gui/wizard/owncloudsetuppage.cpp +++ b/src/gui/wizard/owncloudsetuppage.cpp @@ -25,6 +25,8 @@ #include #include #include +#include +#include #include "QProgressIndicator.h" @@ -47,14 +49,29 @@ OwncloudSetupPage::OwncloudSetupPage(QWidget *parent) setupServerAddressDescriptionLabel(); - Theme *theme = Theme::instance(); + const auto theme = Theme::instance(); if (theme->overrideServerUrl().isEmpty()) { + _ui.comboBox->hide(); _ui.leUrl->setPostfix(theme->wizardUrlPostfix()); _ui.leUrl->setPlaceholderText(theme->wizardUrlHint()); - } else if (Theme::instance()->forceOverrideServerUrl()) { - _ui.leUrl->setEnabled(false); - } + } else if (theme->multipleOverrideServers() && theme->forceOverrideServerUrl()) { + _ui.leUrl->hide(); + const auto overrideJsonUtf8 = theme->overrideServerUrl().toUtf8(); + const auto serversJsonArray = QJsonDocument::fromJson(overrideJsonUtf8).array(); + for (const auto &serverJson : serversJsonArray) { + const auto serverObject = serverJson.toObject(); + const auto serverName = serverObject.value("name").toString(); + const auto serverUrl = serverObject.value("url").toString(); + const auto serverDisplayString = QString("%1 (%2)").arg(serverName, serverUrl); + _ui.comboBox->addItem(serverDisplayString, serverUrl); + } + } else if (theme->forceOverrideServerUrl()) { + _ui.comboBox->hide(); + _ui.leUrl->setEnabled(false); + } else { + _ui.comboBox->hide(); + } registerField(QLatin1String("OCUrl*"), _ui.leUrl); @@ -165,7 +182,7 @@ void OwncloudSetupPage::slotUrlEditFinished() bool OwncloudSetupPage::isComplete() const { - return !_ui.leUrl->text().isEmpty() && !_checking; + return (!_ui.leUrl->text().isEmpty() || !_ui.comboBox->currentData().toString().isEmpty()) && !_checking; } void OwncloudSetupPage::initializePage() @@ -192,7 +209,7 @@ void OwncloudSetupPage::initializePage() if (nextButton) { nextButton->setFocus(); } - } else if (isServerUrlOverridden) { + } else if (isServerUrlOverridden && !Theme::instance()->multipleOverrideServers()) { // If the overwritten url is not empty and we force this overwritten url // we just check the server type and switch to next page // immediately. @@ -226,8 +243,12 @@ int OwncloudSetupPage::nextId() const QString OwncloudSetupPage::url() const { - QString url = _ui.leUrl->fullText().simplified(); - return url; + const auto theme = Theme::instance(); + if (theme->multipleOverrideServers() && theme->forceOverrideServerUrl()) { + return _ui.comboBox->currentData().toString(); + } else { + return _ui.leUrl->fullText().simplified(); + } } bool OwncloudSetupPage::validatePage() @@ -270,7 +291,8 @@ void OwncloudSetupPage::setErrorString(const QString &err, bool retryHTTPonly) _ui.errorLabel->setVisible(false); } else { if (retryHTTPonly) { - QUrl url(_ui.leUrl->fullText()); + const auto urlString = url(); + QUrl url(urlString); if (url.scheme() == "https") { // Ask the user how to proceed when connecting to a https:// URL fails. // It is possible that the server is secured with client-side TLS certificates, 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;