Skip to content
Draft
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
26 changes: 22 additions & 4 deletions src/gui/newaccountwizard/urlpagecontroller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 <QLabel>
Expand All @@ -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."));
}
Expand Down
6 changes: 3 additions & 3 deletions src/gui/newaccountwizard/urlpagecontroller.h
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,9 @@ class UrlPageController : public QObject, public WizardPageValidator
QPointer<QWizardPage> _page;
QPointer<AccessManager> _accessManager;

QLabel *_instructionLabel;
QLineEdit *_urlField;
QLabel *_errorField;
QLabel *_instructionLabel = nullptr;
QLineEdit *_urlField = nullptr;
QLabel *_errorField = nullptr;

UrlPageResults _results;
bool _urlValidated = false;
Expand Down
1 change: 1 addition & 0 deletions src/libsync/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ set(libsync_SRCS
abstractcorejob.cpp

appprovider.cpp
systemconfig.cpp
)

if(WIN32)
Expand Down
43 changes: 43 additions & 0 deletions src/libsync/systemconfig.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@

#include "common/asserts.h"
#include "common/utility.h"
#include "systemconfig.h"
#include "theme.h"

#include <QFile>
#include <QSettings>
#include <QOperatingSystemVersion>

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();
}
}
30 changes: 30 additions & 0 deletions src/libsync/systemconfig.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@

#pragma once

#include "owncloudlib.h"
#include "theme.h"

#include <QOperatingSystemVersion>
#include <QString>
#include <QVariant>


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

};
}
1 change: 1 addition & 0 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
25 changes: 25 additions & 0 deletions test/testsystemconfig.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// SPDX-License-Identifier: GPL-2.0-or-later

#include <QtTest>

#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"