diff --git a/src/gui/newaccountwizard/urlpagecontroller.cpp b/src/gui/newaccountwizard/urlpagecontroller.cpp index 290c56a6bf1..3af2c024ef2 100644 --- a/src/gui/newaccountwizard/urlpagecontroller.cpp +++ b/src/gui/newaccountwizard/urlpagecontroller.cpp @@ -14,9 +14,11 @@ #include "urlpagecontroller.h" #include "accessmanager.h" +#include "configfile.h" #include "networkadapters/determineauthtypeadapter.h" #include "networkadapters/discoverwebfingerserviceadapter.h" #include "networkadapters/resolveurladapter.h" +#include "systemconfig.h" #include "theme.h" #include @@ -34,10 +36,26 @@ UrlPageController::UrlPageController(QWizardPage *page, AccessManager *accessMan { buildPage(); - QString themeUrl = Theme::instance()->overrideServerUrlV2(); - if (_urlField && !themeUrl.isEmpty()) { - setUrl(themeUrl); - // The theme provides the url, don't let the user change it! + if (_urlField == nullptr) { + return; + } + + // a theme can provide a hardcoded url which is not subject of change by definition + bool allowServerUrlChange = true; + QString serverUrl = Theme::instance()->overrideServerUrlV2(); + if (serverUrl.isEmpty()) { + // respect global pre-configuration + allowServerUrlChange = SystemConfig::allowServerUrlChange(); + serverUrl = SystemConfig::serverUrl(); + } + + // no server url was given by any means, so the user has to provide one + if (serverUrl.isEmpty()) { + return; + } + setUrl(serverUrl); + // The system admin provides the url, don't let the user change it! + if (!allowServerUrlChange) { _urlField->setEnabled(false); _instructionLabel->setText(tr("Your web browser will be opened to complete sign in.")); } diff --git a/src/gui/newaccountwizard/urlpagecontroller.h b/src/gui/newaccountwizard/urlpagecontroller.h index d944881056e..71e0cc60266 100644 --- a/src/gui/newaccountwizard/urlpagecontroller.h +++ b/src/gui/newaccountwizard/urlpagecontroller.h @@ -95,9 +95,9 @@ class UrlPageController : public QObject, public WizardPageValidator QPointer _page; QPointer _accessManager; - QLabel *_instructionLabel; - QLineEdit *_urlField; - QLabel *_errorField; + QLabel *_instructionLabel = nullptr; + QLineEdit *_urlField = nullptr; + QLabel *_errorField = nullptr; UrlPageResults _results; bool _urlValidated = false; diff --git a/src/libsync/CMakeLists.txt b/src/libsync/CMakeLists.txt index af3d72041cb..e13a2cf6e82 100644 --- a/src/libsync/CMakeLists.txt +++ b/src/libsync/CMakeLists.txt @@ -52,6 +52,7 @@ set(libsync_SRCS abstractcorejob.cpp appprovider.cpp + systemconfig.cpp ) if(WIN32) diff --git a/src/libsync/systemconfig.cpp b/src/libsync/systemconfig.cpp new file mode 100644 index 00000000000..ab407fbc92a --- /dev/null +++ b/src/libsync/systemconfig.cpp @@ -0,0 +1,43 @@ + +#include "common/asserts.h" +#include "common/utility.h" +#include "systemconfig.h" +#include "theme.h" + +#include +#include +#include + +namespace OCC { + +namespace chrono = std::chrono; + +QVariant SystemConfig::value(QAnyStringView key, const QVariant &defaultValue) +{ + auto format = Utility::isWindows() ? QSettings::NativeFormat : QSettings::IniFormat; + QSettings system(configPath(QOperatingSystemVersion::currentType(), *Theme::instance()), format); + + return system.value(key, defaultValue); +} +QString SystemConfig::configPath(const QOperatingSystemVersion::OSType& os, const Theme& theme) +{ + if (os == QOperatingSystemVersion::Windows) { + return QString("HKEY_LOCAL_MACHINE\\Software\\%1\\%2").arg(theme.vendor(), theme.appNameGUI()); + } + if (os == QOperatingSystemVersion::MacOS) { + return QString("/Library/Preferences/%1/%2.ini").arg(theme.orgDomainName(), theme.appName()); + } + + return QString("/etc/%1/%1.ini").arg(theme.appName()); +} + +bool SystemConfig::allowServerUrlChange() +{ + return value("Setup/AllowServerUrlChange", true).toBool(); +} + +QString SystemConfig::serverUrl() +{ + return value("Setup/ServerUrl", QString()).toString(); +} +} diff --git a/src/libsync/systemconfig.h b/src/libsync/systemconfig.h new file mode 100644 index 00000000000..1db4c473f48 --- /dev/null +++ b/src/libsync/systemconfig.h @@ -0,0 +1,30 @@ + +#pragma once + +#include "owncloudlib.h" +#include "theme.h" + +#include +#include +#include + + +namespace OCC { + +/** + * @brief The SystemConfig class + * @ingroup libsync + */ +class OWNCLOUDSYNC_EXPORT SystemConfig +{ +public: + // Access system configuration + static bool allowServerUrlChange(); + static QString serverUrl(); + + // General purpose function + static QVariant value(QAnyStringView key, const QVariant &defaultValue); + static QString configPath(const QOperatingSystemVersion::OSType& os, const Theme& theme); + +}; +} diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 685efd9d7f7..3bbbe5a571f 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -22,6 +22,7 @@ endif() owncloud_add_test(ExcludedFiles) owncloud_add_test(Utility) +owncloud_add_test(SystemConfig ../src/libsync/owncloudtheme.cpp) owncloud_add_test(SyncEngine) owncloud_add_test(SyncMove) diff --git a/test/testsystemconfig.cpp b/test/testsystemconfig.cpp new file mode 100644 index 00000000000..0eff2b1d7d0 --- /dev/null +++ b/test/testsystemconfig.cpp @@ -0,0 +1,25 @@ +// SPDX-License-Identifier: GPL-2.0-or-later + +#include + +#include "testutils/testutils.h" + +#include "libsync/owncloudtheme.h" +#include "libsync/systemconfig.h" + +class TestSystemConfig : public QObject +{ + Q_OBJECT + +private Q_SLOTS: + void testConfigPath() + { + auto t = OCC::ownCloudTheme(); + QCOMPARE(OCC::SystemConfig::configPath(QOperatingSystemVersion::Windows, t), QString("HKEY_LOCAL_MACHINE\\Software\\ownCloud\\ownCloud")); + QCOMPARE(OCC::SystemConfig::configPath(QOperatingSystemVersion::MacOS, t), QString("/Library/Preferences/com.owncloud.desktopclient/ownCloud.ini")); + QCOMPARE(OCC::SystemConfig::configPath(QOperatingSystemVersion::Unknown, t), QString("/etc/ownCloud/ownCloud.ini")); + } +}; + +QTEST_GUILESS_MAIN(TestSystemConfig) +#include "testsystemconfig.moc"