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

Add ability to provide multiple hardcoded server URLs via CMake define #7160

Merged
merged 11 commits into from
Sep 24, 2024
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
2 changes: 1 addition & 1 deletion config.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -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@"
Expand Down
3 changes: 2 additions & 1 deletion src/gui/accountmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
4 changes: 3 additions & 1 deletion src/gui/owncloudsetupwizard.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*

Check notice on line 1 in src/gui/owncloudsetupwizard.cpp

View workflow job for this annotation

GitHub Actions / build

Run clang-format on src/gui/owncloudsetupwizard.cpp

File src/gui/owncloudsetupwizard.cpp does not conform to Custom style guidelines. (lines 106)
* Copyright (C) by Klaas Freitag <[email protected]>
* Copyright (C) by Krzesimir Nowak <[email protected]>
*
Expand All @@ -13,7 +13,7 @@
* for more details.
*/

#include <QAbstractButton>

Check failure on line 16 in src/gui/owncloudsetupwizard.cpp

View workflow job for this annotation

GitHub Actions / build

src/gui/owncloudsetupwizard.cpp:16:10 [clang-diagnostic-error]

'QAbstractButton' file not found
#include <QtCore>
#include <QProcess>
#include <QMessageBox>
Expand Down Expand Up @@ -103,7 +103,9 @@
{
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());

Expand Down
3 changes: 3 additions & 0 deletions src/gui/wizard/owncloudsetupnocredspage.ui
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,9 @@
</item>
</layout>
</item>
<item>
<widget class="QComboBox" name="comboBox"/>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_5">
<property name="topMargin">
Expand Down
38 changes: 30 additions & 8 deletions src/gui/wizard/owncloudsetuppage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* for more details.
*/

#include <QDir>

Check failure on line 16 in src/gui/wizard/owncloudsetuppage.cpp

View workflow job for this annotation

GitHub Actions / build

src/gui/wizard/owncloudsetuppage.cpp:16:10 [clang-diagnostic-error]

'QDir' file not found
#include <QFileDialog>
#include <QUrl>
#include <QTimer>
Expand All @@ -25,6 +25,8 @@
#include <QPropertyAnimation>
#include <QGraphicsPixmapItem>
#include <QBuffer>
#include <QJsonArray>
#include <QJsonDocument>

#include "QProgressIndicator.h"

Expand All @@ -47,15 +49,30 @@

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()) {
} 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);

auto sizePolicy = _progressIndi->sizePolicy();
Expand Down Expand Up @@ -165,7 +182,7 @@

bool OwncloudSetupPage::isComplete() const
{
return !_ui.leUrl->text().isEmpty() && !_checking;
return (!_ui.leUrl->text().isEmpty() || !_ui.comboBox->currentData().toString().isEmpty()) && !_checking;
}

void OwncloudSetupPage::initializePage()
Expand All @@ -192,7 +209,7 @@
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.
Expand Down Expand Up @@ -226,8 +243,12 @@

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()
Expand Down Expand Up @@ -270,7 +291,8 @@
_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,
Expand Down
16 changes: 16 additions & 0 deletions src/libsync/theme.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@
#include <QSslSocket>
#include <QSvgRenderer>
#include <QPainter>
#include <QJsonDocument>
#include <QJsonArray>

#include "nextcloudtheme.h"

Expand Down Expand Up @@ -383,6 +385,7 @@ Theme::Theme()
#endif
#ifdef APPLICATION_SERVER_URL
_overrideServerUrl = QString::fromLatin1(APPLICATION_SERVER_URL);
updateMultipleOverrideServers();
#endif
}

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -954,6 +969,7 @@ void Theme::setOverrideServerUrl(const QString &overrideServerUrl)
{
if (_overrideServerUrl != overrideServerUrl) {
_overrideServerUrl = overrideServerUrl;
updateMultipleOverrideServers();
emit overrideServerUrlChanged();
}
}
Expand Down
9 changes: 9 additions & 0 deletions src/libsync/theme.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
#ifndef _THEME_H
#define _THEME_H

#include <QIcon>

Check failure on line 18 in src/libsync/theme.h

View workflow job for this annotation

GitHub Actions / build

src/libsync/theme.h:18:10 [clang-diagnostic-error]

'QIcon' file not found
#include <QObject>
#include <QPalette>
#include <QGuiApplication>
Expand Down Expand Up @@ -232,11 +232,18 @@

/**
* 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.
*
Expand Down Expand Up @@ -627,6 +634,7 @@
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
Expand All @@ -638,6 +646,7 @@

QString _overrideServerUrl;
bool _forceOverrideServerUrl = false;
bool _multipleOverrideServers = false;
bool _isVfsEnabled = false;
bool _startLoginFlowAutomatically = false;

Expand Down
Loading