@ -43,7 +43,6 @@ SettingsDialog::SettingsDialog(QWidget *parent, const IServerConfig &serverConfi
|
||||
ui->tabWidget->setCurrentIndex(0);
|
||||
|
||||
loadFromConfig();
|
||||
m_wasOriginallySystemScope = Settings::isSystemScope();
|
||||
updateControls();
|
||||
|
||||
adjustSize();
|
||||
@ -60,7 +59,7 @@ void SettingsDialog::initConnections()
|
||||
connect(Settings::instance(), &Settings::writableChanged, this, &SettingsDialog::showReadOnlyMessage);
|
||||
|
||||
connect(ui->buttonBox, &QDialogButtonBox::accepted, this, &SettingsDialog::accept);
|
||||
connect(ui->buttonBox, &QDialogButtonBox::rejected, this, &SettingsDialog::reject);
|
||||
connect(ui->buttonBox, &QDialogButtonBox::rejected, this, &QDialog::reject);
|
||||
|
||||
connect(ui->groupSecurity, &QGroupBox::toggled, this, &SettingsDialog::updateTlsControlsEnabled);
|
||||
connect(ui->cbServiceEnabled, &QCheckBox::toggled, this, &SettingsDialog::updateControls);
|
||||
@ -68,9 +67,6 @@ void SettingsDialog::initConnections()
|
||||
connect(ui->btnTlsCertPath, &QPushButton::clicked, this, &SettingsDialog::browseCertificatePath);
|
||||
connect(ui->btnBrowseLog, &QPushButton::clicked, this, &SettingsDialog::browseLogPath);
|
||||
connect(ui->cbLogToFile, &QCheckBox::toggled, this, &SettingsDialog::setLogToFile);
|
||||
|
||||
// We only need to test the System scoped Radio as they are connected
|
||||
connect(ui->rbScopeSystem, &QRadioButton::toggled, this, &SettingsDialog::setSystemScope);
|
||||
}
|
||||
|
||||
void SettingsDialog::regenCertificates()
|
||||
@ -113,17 +109,6 @@ void SettingsDialog::setLogToFile(bool logToFile)
|
||||
ui->widgetLogFilename->setEnabled(logToFile);
|
||||
}
|
||||
|
||||
void SettingsDialog::setSystemScope(bool systemScope)
|
||||
{
|
||||
Settings::setScope(systemScope);
|
||||
loadFromConfig();
|
||||
updateControls();
|
||||
|
||||
if (isVisible() && Settings::isWritable()) {
|
||||
showReadOnlyMessage();
|
||||
}
|
||||
}
|
||||
|
||||
void SettingsDialog::showEvent(QShowEvent *event)
|
||||
{
|
||||
QDialog::showEvent(event);
|
||||
@ -139,7 +124,6 @@ void SettingsDialog::showReadOnlyMessage()
|
||||
|
||||
void SettingsDialog::accept()
|
||||
{
|
||||
Settings::setScope(ui->rbScopeSystem->isChecked());
|
||||
Settings::setValue(Settings::Core::Port, ui->sbPort->value());
|
||||
Settings::setValue(Settings::Core::Interface, ui->lineInterface->text());
|
||||
Settings::setValue(Settings::Log::Level, ui->comboLogLevel->currentIndex());
|
||||
@ -168,19 +152,8 @@ void SettingsDialog::accept()
|
||||
QDialog::accept();
|
||||
}
|
||||
|
||||
void SettingsDialog::reject()
|
||||
{
|
||||
// restore original system scope value on reject.
|
||||
if (Settings::isSystemScope() != m_wasOriginallySystemScope) {
|
||||
Settings::setScope(m_wasOriginallySystemScope);
|
||||
}
|
||||
|
||||
QDialog::reject();
|
||||
}
|
||||
|
||||
void SettingsDialog::loadFromConfig()
|
||||
{
|
||||
|
||||
ui->sbPort->setValue(Settings::value(Settings::Core::Port).toInt());
|
||||
ui->lineInterface->setText(Settings::value(Settings::Core::Interface).toString());
|
||||
ui->comboLogLevel->setCurrentIndex(Settings::value(Settings::Log::Level).toInt());
|
||||
@ -194,12 +167,6 @@ void SettingsDialog::loadFromConfig()
|
||||
ui->comboElevate->setCurrentIndex(Settings::value(Settings::Core::ElevateMode).toInt());
|
||||
ui->cbAutoUpdate->setChecked(Settings::value(Settings::Gui::Autohide).toBool());
|
||||
|
||||
if (Settings::isSystemScope()) {
|
||||
ui->rbScopeSystem->setChecked(true);
|
||||
} else {
|
||||
ui->rbScopeUser->setChecked(true);
|
||||
}
|
||||
|
||||
const auto processMode = Settings::value(Settings::Core::ProcessMode).value<Settings::ProcessMode>();
|
||||
ui->cbServiceEnabled->setChecked(processMode == Settings::ProcessMode::Service);
|
||||
|
||||
|
||||
@ -39,9 +39,7 @@ private:
|
||||
void browseCertificatePath();
|
||||
void browseLogPath();
|
||||
void setLogToFile(bool logToFile);
|
||||
void setSystemScope(bool systemScope);
|
||||
void accept() override;
|
||||
void reject() override;
|
||||
void showEvent(QShowEvent *event) override;
|
||||
bool isClientMode() const;
|
||||
void updateTlsControls();
|
||||
@ -60,11 +58,6 @@ private:
|
||||
/// @brief Enables controls when they should be.
|
||||
void updateControls();
|
||||
|
||||
/// @brief Stores settings scope at start of settings dialog
|
||||
/// This is necessary to restore state if user changes
|
||||
/// the scope and doesn't save changes
|
||||
bool m_wasOriginallySystemScope = false;
|
||||
|
||||
std::unique_ptr<Ui::SettingsDialog> ui;
|
||||
const IServerConfig &m_serverConfig;
|
||||
const CoreProcess &m_coreProcess;
|
||||
|
||||
@ -656,38 +656,6 @@
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QGroupBox" name="groupScope">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Preferred" vsizetype="Maximum">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="title">
|
||||
<string>Use settings profile from</string>
|
||||
</property>
|
||||
<layout class="QHBoxLayout" name="_5">
|
||||
<item>
|
||||
<widget class="QRadioButton" name="rbScopeUser">
|
||||
<property name="text">
|
||||
<string>Current user</string>
|
||||
</property>
|
||||
<property name="checked">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QRadioButton" name="rbScopeSystem">
|
||||
<property name="text">
|
||||
<string>All users</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</widget>
|
||||
@ -728,8 +696,6 @@
|
||||
<tabstop>btnBrowseLog</tabstop>
|
||||
<tabstop>cbServiceEnabled</tabstop>
|
||||
<tabstop>comboElevate</tabstop>
|
||||
<tabstop>rbScopeUser</tabstop>
|
||||
<tabstop>rbScopeSystem</tabstop>
|
||||
</tabstops>
|
||||
<resources/>
|
||||
<connections/>
|
||||
|
||||
@ -23,21 +23,11 @@ QString getSystemSettingsBaseDir()
|
||||
// QSettingsProxy
|
||||
//
|
||||
|
||||
void QSettingsProxy::loadUser()
|
||||
{
|
||||
m_pSettings = std::make_unique<QSettings>(Settings::UserSettingFile, QSettings::IniFormat);
|
||||
}
|
||||
|
||||
void QSettingsProxy::load(const QString &fileName)
|
||||
{
|
||||
m_pSettings = std::make_unique<QSettings>(fileName, QSettings::IniFormat);
|
||||
}
|
||||
|
||||
void QSettingsProxy::loadSystem()
|
||||
{
|
||||
m_pSettings = std::make_unique<QSettings>(Settings::SystemSettingFile, QSettings::IniFormat);
|
||||
}
|
||||
|
||||
int QSettingsProxy::beginReadArray(const QString &prefix)
|
||||
{
|
||||
return m_pSettings->beginReadArray(prefix);
|
||||
|
||||
@ -15,8 +15,6 @@ class QSettingsProxy
|
||||
public:
|
||||
virtual ~QSettingsProxy() = default;
|
||||
|
||||
virtual void loadUser();
|
||||
virtual void loadSystem();
|
||||
virtual void load(const QString &fileName);
|
||||
virtual void clear()
|
||||
{
|
||||
|
||||
@ -32,15 +32,26 @@ void Settings::setSettingFile(const QString &settingsFile)
|
||||
|
||||
Settings::Settings(QObject *parent) : QObject(parent)
|
||||
{
|
||||
m_settingsProxy = std::make_shared<QSettingsProxy>();
|
||||
QString fileToLoad;
|
||||
if (QFile(m_portableSettingsFile).exists()) {
|
||||
m_settings = new QSettings(m_portableSettingsFile, QSettings::IniFormat);
|
||||
m_settingsProxy->load(m_portableSettingsFile);
|
||||
qInfo().noquote() << "settings file:" << m_settings->fileName();
|
||||
return;
|
||||
fileToLoad = m_portableSettingsFile;
|
||||
} else {
|
||||
#ifdef Q_OS_WIN
|
||||
fileToLoad = SystemSettingFile;
|
||||
#else
|
||||
if (QFile(UserSettingFile).exists())
|
||||
fileToLoad = UserSettingFile;
|
||||
else if (QFile(SystemSettingFile).exists())
|
||||
fileToLoad = SystemSettingFile;
|
||||
else
|
||||
fileToLoad = UserSettingFile;
|
||||
#endif
|
||||
}
|
||||
initSettings();
|
||||
m_settingsProxy->load(m_settings->fileName());
|
||||
|
||||
m_settings = new QSettings(fileToLoad, QSettings::IniFormat);
|
||||
m_settingsProxy = std::make_shared<QSettingsProxy>();
|
||||
m_settingsProxy->load(fileToLoad);
|
||||
qInfo().noquote() << "settings file:" << m_settings->fileName();
|
||||
}
|
||||
|
||||
bool Settings::isPortableSettings()
|
||||
@ -48,19 +59,6 @@ bool Settings::isPortableSettings()
|
||||
return (QFile(instance()->m_portableSettingsFile).exists());
|
||||
}
|
||||
|
||||
void Settings::initSettings()
|
||||
{
|
||||
|
||||
if (m_settings)
|
||||
m_settings->deleteLater();
|
||||
|
||||
const auto userScopeCheck = QSettings(UserSettingFile, QSettings::IniFormat).value(Core::Scope).toBool();
|
||||
const auto systemScopeCheck = QSettings(SystemSettingFile, QSettings::IniFormat).value(Core::Scope).toBool();
|
||||
const auto systemScope = (userScopeCheck && systemScopeCheck);
|
||||
m_settings = new QSettings(systemScope ? SystemSettingFile : UserSettingFile, QSettings::IniFormat);
|
||||
qInfo().noquote() << "settings file:" << m_settings->fileName();
|
||||
}
|
||||
|
||||
void Settings::cleanSettings()
|
||||
{
|
||||
const QStringList keys = m_settings->allKeys();
|
||||
@ -74,7 +72,7 @@ void Settings::cleanSettings()
|
||||
|
||||
QVariant Settings::defaultValue(const QString &key)
|
||||
{
|
||||
if ((key == Core::Scope) || (key == Gui::Autohide) || (key == Core::StartedBefore) || (key == Core::PreventSleep) ||
|
||||
if ((key == Gui::Autohide) || (key == Core::StartedBefore) || (key == Core::PreventSleep) ||
|
||||
(key == Server::ExternalConfig) || (key == Client::InvertScrollDirection) || (key == Log::ToFile)) {
|
||||
return false;
|
||||
}
|
||||
@ -146,43 +144,6 @@ bool Settings::isWritable()
|
||||
return instance()->m_settings->isWritable();
|
||||
}
|
||||
|
||||
bool Settings::isSystemScope()
|
||||
{
|
||||
if (isPortableSettings()) {
|
||||
return false;
|
||||
}
|
||||
return instance()->settingsFile() == SystemSettingFile;
|
||||
}
|
||||
|
||||
void Settings::setScope(bool systemScope)
|
||||
{
|
||||
if (isPortableSettings()) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (systemScope == isSystemScope())
|
||||
return;
|
||||
|
||||
const bool wasWritable = instance()->m_settings->isWritable();
|
||||
|
||||
QSettings userSettings(Settings::UserSettingFile, QSettings::IniFormat);
|
||||
userSettings.setValue(Core::Scope, systemScope);
|
||||
userSettings.sync();
|
||||
|
||||
QSettings systemSettings(Settings::SystemSettingFile, QSettings::IniFormat);
|
||||
systemSettings.setValue(Core::Scope, systemScope);
|
||||
systemSettings.sync();
|
||||
|
||||
instance()->initSettings();
|
||||
|
||||
const bool isWritable = instance()->m_settings->isWritable();
|
||||
|
||||
if (isWritable != wasWritable)
|
||||
Q_EMIT instance()->writableChanged(isWritable);
|
||||
|
||||
Q_EMIT instance()->scopeChanged(systemScope);
|
||||
}
|
||||
|
||||
const QString Settings::settingsFile()
|
||||
{
|
||||
return instance()->m_settings->fileName();
|
||||
@ -200,11 +161,8 @@ void Settings::setValue(const QString &key, const QVariant &value)
|
||||
|
||||
if (!value.isValid())
|
||||
instance()->m_settings->remove(key);
|
||||
else if (key == Core::Scope) {
|
||||
instance()->setScope(value.value<QSettings::Scope>());
|
||||
} else {
|
||||
else
|
||||
instance()->m_settings->setValue(key, value);
|
||||
}
|
||||
|
||||
instance()->m_settings->sync();
|
||||
Q_EMIT instance()->settingsChanged(key);
|
||||
|
||||
@ -47,7 +47,6 @@ public:
|
||||
inline static const auto Port = QStringLiteral("core/port");
|
||||
inline static const auto PreventSleep = QStringLiteral("core/preventSleep");
|
||||
inline static const auto ProcessMode = QStringLiteral("core/processMode");
|
||||
inline static const auto Scope = QStringLiteral("core/loadFromSystemScope");
|
||||
inline static const auto ScreenName = QStringLiteral("core/screenName");
|
||||
inline static const auto StartedBefore = QStringLiteral("core/startedBefore");
|
||||
};
|
||||
@ -133,8 +132,6 @@ public:
|
||||
static void restoreDefaultSettings();
|
||||
static QVariant defaultValue(const QString &key);
|
||||
static bool isWritable();
|
||||
static bool isSystemScope();
|
||||
static void setScope(bool systemScope);
|
||||
static const QString settingsFile();
|
||||
static const QString settingsPath();
|
||||
static const QString logLevelText();
|
||||
@ -154,7 +151,6 @@ private:
|
||||
~Settings() = default;
|
||||
static bool isPortableSettings();
|
||||
void cleanSettings();
|
||||
void initSettings();
|
||||
|
||||
QSettings *m_settings = nullptr;
|
||||
QString m_portableSettingsFile = QStringLiteral("settings/%1.conf").arg(kAppName);
|
||||
@ -180,7 +176,6 @@ private:
|
||||
, Settings::Core::Port
|
||||
, Settings::Core::PreventSleep
|
||||
, Settings::Core::ProcessMode
|
||||
, Settings::Core::Scope
|
||||
, Settings::Core::ScreenName
|
||||
, Settings::Core::StartedBefore
|
||||
, Settings::Log::File
|
||||
|
||||
Reference in New Issue
Block a user