parent
6056e5850b
commit
0e3cee6287
7 changed files with 21 additions and 154 deletions
|
|
@ -43,7 +43,6 @@ SettingsDialog::SettingsDialog(QWidget *parent, const IServerConfig &serverConfi
|
||||||
ui->tabWidget->setCurrentIndex(0);
|
ui->tabWidget->setCurrentIndex(0);
|
||||||
|
|
||||||
loadFromConfig();
|
loadFromConfig();
|
||||||
m_wasOriginallySystemScope = Settings::isSystemScope();
|
|
||||||
updateControls();
|
updateControls();
|
||||||
|
|
||||||
adjustSize();
|
adjustSize();
|
||||||
|
|
@ -60,7 +59,7 @@ void SettingsDialog::initConnections()
|
||||||
connect(Settings::instance(), &Settings::writableChanged, this, &SettingsDialog::showReadOnlyMessage);
|
connect(Settings::instance(), &Settings::writableChanged, this, &SettingsDialog::showReadOnlyMessage);
|
||||||
|
|
||||||
connect(ui->buttonBox, &QDialogButtonBox::accepted, this, &SettingsDialog::accept);
|
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->groupSecurity, &QGroupBox::toggled, this, &SettingsDialog::updateTlsControlsEnabled);
|
||||||
connect(ui->cbServiceEnabled, &QCheckBox::toggled, this, &SettingsDialog::updateControls);
|
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->btnTlsCertPath, &QPushButton::clicked, this, &SettingsDialog::browseCertificatePath);
|
||||||
connect(ui->btnBrowseLog, &QPushButton::clicked, this, &SettingsDialog::browseLogPath);
|
connect(ui->btnBrowseLog, &QPushButton::clicked, this, &SettingsDialog::browseLogPath);
|
||||||
connect(ui->cbLogToFile, &QCheckBox::toggled, this, &SettingsDialog::setLogToFile);
|
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()
|
void SettingsDialog::regenCertificates()
|
||||||
|
|
@ -113,17 +109,6 @@ void SettingsDialog::setLogToFile(bool logToFile)
|
||||||
ui->widgetLogFilename->setEnabled(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)
|
void SettingsDialog::showEvent(QShowEvent *event)
|
||||||
{
|
{
|
||||||
QDialog::showEvent(event);
|
QDialog::showEvent(event);
|
||||||
|
|
@ -139,7 +124,6 @@ void SettingsDialog::showReadOnlyMessage()
|
||||||
|
|
||||||
void SettingsDialog::accept()
|
void SettingsDialog::accept()
|
||||||
{
|
{
|
||||||
Settings::setScope(ui->rbScopeSystem->isChecked());
|
|
||||||
Settings::setValue(Settings::Core::Port, ui->sbPort->value());
|
Settings::setValue(Settings::Core::Port, ui->sbPort->value());
|
||||||
Settings::setValue(Settings::Core::Interface, ui->lineInterface->text());
|
Settings::setValue(Settings::Core::Interface, ui->lineInterface->text());
|
||||||
Settings::setValue(Settings::Log::Level, ui->comboLogLevel->currentIndex());
|
Settings::setValue(Settings::Log::Level, ui->comboLogLevel->currentIndex());
|
||||||
|
|
@ -168,19 +152,8 @@ void SettingsDialog::accept()
|
||||||
QDialog::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()
|
void SettingsDialog::loadFromConfig()
|
||||||
{
|
{
|
||||||
|
|
||||||
ui->sbPort->setValue(Settings::value(Settings::Core::Port).toInt());
|
ui->sbPort->setValue(Settings::value(Settings::Core::Port).toInt());
|
||||||
ui->lineInterface->setText(Settings::value(Settings::Core::Interface).toString());
|
ui->lineInterface->setText(Settings::value(Settings::Core::Interface).toString());
|
||||||
ui->comboLogLevel->setCurrentIndex(Settings::value(Settings::Log::Level).toInt());
|
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->comboElevate->setCurrentIndex(Settings::value(Settings::Core::ElevateMode).toInt());
|
||||||
ui->cbAutoUpdate->setChecked(Settings::value(Settings::Gui::Autohide).toBool());
|
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>();
|
const auto processMode = Settings::value(Settings::Core::ProcessMode).value<Settings::ProcessMode>();
|
||||||
ui->cbServiceEnabled->setChecked(processMode == Settings::ProcessMode::Service);
|
ui->cbServiceEnabled->setChecked(processMode == Settings::ProcessMode::Service);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -39,9 +39,7 @@ private:
|
||||||
void browseCertificatePath();
|
void browseCertificatePath();
|
||||||
void browseLogPath();
|
void browseLogPath();
|
||||||
void setLogToFile(bool logToFile);
|
void setLogToFile(bool logToFile);
|
||||||
void setSystemScope(bool systemScope);
|
|
||||||
void accept() override;
|
void accept() override;
|
||||||
void reject() override;
|
|
||||||
void showEvent(QShowEvent *event) override;
|
void showEvent(QShowEvent *event) override;
|
||||||
bool isClientMode() const;
|
bool isClientMode() const;
|
||||||
void updateTlsControls();
|
void updateTlsControls();
|
||||||
|
|
@ -60,11 +58,6 @@ private:
|
||||||
/// @brief Enables controls when they should be.
|
/// @brief Enables controls when they should be.
|
||||||
void updateControls();
|
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;
|
std::unique_ptr<Ui::SettingsDialog> ui;
|
||||||
const IServerConfig &m_serverConfig;
|
const IServerConfig &m_serverConfig;
|
||||||
const CoreProcess &m_coreProcess;
|
const CoreProcess &m_coreProcess;
|
||||||
|
|
|
||||||
|
|
@ -656,38 +656,6 @@
|
||||||
</layout>
|
</layout>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</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>
|
</layout>
|
||||||
</widget>
|
</widget>
|
||||||
</widget>
|
</widget>
|
||||||
|
|
@ -728,8 +696,6 @@
|
||||||
<tabstop>btnBrowseLog</tabstop>
|
<tabstop>btnBrowseLog</tabstop>
|
||||||
<tabstop>cbServiceEnabled</tabstop>
|
<tabstop>cbServiceEnabled</tabstop>
|
||||||
<tabstop>comboElevate</tabstop>
|
<tabstop>comboElevate</tabstop>
|
||||||
<tabstop>rbScopeUser</tabstop>
|
|
||||||
<tabstop>rbScopeSystem</tabstop>
|
|
||||||
</tabstops>
|
</tabstops>
|
||||||
<resources/>
|
<resources/>
|
||||||
<connections/>
|
<connections/>
|
||||||
|
|
|
||||||
|
|
@ -23,21 +23,11 @@ QString getSystemSettingsBaseDir()
|
||||||
// QSettingsProxy
|
// QSettingsProxy
|
||||||
//
|
//
|
||||||
|
|
||||||
void QSettingsProxy::loadUser()
|
|
||||||
{
|
|
||||||
m_pSettings = std::make_unique<QSettings>(Settings::UserSettingFile, QSettings::IniFormat);
|
|
||||||
}
|
|
||||||
|
|
||||||
void QSettingsProxy::load(const QString &fileName)
|
void QSettingsProxy::load(const QString &fileName)
|
||||||
{
|
{
|
||||||
m_pSettings = std::make_unique<QSettings>(fileName, QSettings::IniFormat);
|
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)
|
int QSettingsProxy::beginReadArray(const QString &prefix)
|
||||||
{
|
{
|
||||||
return m_pSettings->beginReadArray(prefix);
|
return m_pSettings->beginReadArray(prefix);
|
||||||
|
|
|
||||||
|
|
@ -15,8 +15,6 @@ class QSettingsProxy
|
||||||
public:
|
public:
|
||||||
virtual ~QSettingsProxy() = default;
|
virtual ~QSettingsProxy() = default;
|
||||||
|
|
||||||
virtual void loadUser();
|
|
||||||
virtual void loadSystem();
|
|
||||||
virtual void load(const QString &fileName);
|
virtual void load(const QString &fileName);
|
||||||
virtual void clear()
|
virtual void clear()
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -32,15 +32,26 @@ void Settings::setSettingFile(const QString &settingsFile)
|
||||||
|
|
||||||
Settings::Settings(QObject *parent) : QObject(parent)
|
Settings::Settings(QObject *parent) : QObject(parent)
|
||||||
{
|
{
|
||||||
m_settingsProxy = std::make_shared<QSettingsProxy>();
|
QString fileToLoad;
|
||||||
if (QFile(m_portableSettingsFile).exists()) {
|
if (QFile(m_portableSettingsFile).exists()) {
|
||||||
m_settings = new QSettings(m_portableSettingsFile, QSettings::IniFormat);
|
fileToLoad = m_portableSettingsFile;
|
||||||
m_settingsProxy->load(m_portableSettingsFile);
|
} else {
|
||||||
qInfo().noquote() << "settings file:" << m_settings->fileName();
|
#ifdef Q_OS_WIN
|
||||||
return;
|
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()
|
bool Settings::isPortableSettings()
|
||||||
|
|
@ -48,19 +59,6 @@ bool Settings::isPortableSettings()
|
||||||
return (QFile(instance()->m_portableSettingsFile).exists());
|
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()
|
void Settings::cleanSettings()
|
||||||
{
|
{
|
||||||
const QStringList keys = m_settings->allKeys();
|
const QStringList keys = m_settings->allKeys();
|
||||||
|
|
@ -74,7 +72,7 @@ void Settings::cleanSettings()
|
||||||
|
|
||||||
QVariant Settings::defaultValue(const QString &key)
|
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)) {
|
(key == Server::ExternalConfig) || (key == Client::InvertScrollDirection) || (key == Log::ToFile)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
@ -146,43 +144,6 @@ bool Settings::isWritable()
|
||||||
return instance()->m_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()
|
const QString Settings::settingsFile()
|
||||||
{
|
{
|
||||||
return instance()->m_settings->fileName();
|
return instance()->m_settings->fileName();
|
||||||
|
|
@ -200,11 +161,8 @@ void Settings::setValue(const QString &key, const QVariant &value)
|
||||||
|
|
||||||
if (!value.isValid())
|
if (!value.isValid())
|
||||||
instance()->m_settings->remove(key);
|
instance()->m_settings->remove(key);
|
||||||
else if (key == Core::Scope) {
|
else
|
||||||
instance()->setScope(value.value<QSettings::Scope>());
|
|
||||||
} else {
|
|
||||||
instance()->m_settings->setValue(key, value);
|
instance()->m_settings->setValue(key, value);
|
||||||
}
|
|
||||||
|
|
||||||
instance()->m_settings->sync();
|
instance()->m_settings->sync();
|
||||||
Q_EMIT instance()->settingsChanged(key);
|
Q_EMIT instance()->settingsChanged(key);
|
||||||
|
|
|
||||||
|
|
@ -47,7 +47,6 @@ public:
|
||||||
inline static const auto Port = QStringLiteral("core/port");
|
inline static const auto Port = QStringLiteral("core/port");
|
||||||
inline static const auto PreventSleep = QStringLiteral("core/preventSleep");
|
inline static const auto PreventSleep = QStringLiteral("core/preventSleep");
|
||||||
inline static const auto ProcessMode = QStringLiteral("core/processMode");
|
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 ScreenName = QStringLiteral("core/screenName");
|
||||||
inline static const auto StartedBefore = QStringLiteral("core/startedBefore");
|
inline static const auto StartedBefore = QStringLiteral("core/startedBefore");
|
||||||
};
|
};
|
||||||
|
|
@ -133,8 +132,6 @@ public:
|
||||||
static void restoreDefaultSettings();
|
static void restoreDefaultSettings();
|
||||||
static QVariant defaultValue(const QString &key);
|
static QVariant defaultValue(const QString &key);
|
||||||
static bool isWritable();
|
static bool isWritable();
|
||||||
static bool isSystemScope();
|
|
||||||
static void setScope(bool systemScope);
|
|
||||||
static const QString settingsFile();
|
static const QString settingsFile();
|
||||||
static const QString settingsPath();
|
static const QString settingsPath();
|
||||||
static const QString logLevelText();
|
static const QString logLevelText();
|
||||||
|
|
@ -154,7 +151,6 @@ private:
|
||||||
~Settings() = default;
|
~Settings() = default;
|
||||||
static bool isPortableSettings();
|
static bool isPortableSettings();
|
||||||
void cleanSettings();
|
void cleanSettings();
|
||||||
void initSettings();
|
|
||||||
|
|
||||||
QSettings *m_settings = nullptr;
|
QSettings *m_settings = nullptr;
|
||||||
QString m_portableSettingsFile = QStringLiteral("settings/%1.conf").arg(kAppName);
|
QString m_portableSettingsFile = QStringLiteral("settings/%1.conf").arg(kAppName);
|
||||||
|
|
@ -180,7 +176,6 @@ private:
|
||||||
, Settings::Core::Port
|
, Settings::Core::Port
|
||||||
, Settings::Core::PreventSleep
|
, Settings::Core::PreventSleep
|
||||||
, Settings::Core::ProcessMode
|
, Settings::Core::ProcessMode
|
||||||
, Settings::Core::Scope
|
|
||||||
, Settings::Core::ScreenName
|
, Settings::Core::ScreenName
|
||||||
, Settings::Core::StartedBefore
|
, Settings::Core::StartedBefore
|
||||||
, Settings::Log::File
|
, Settings::Log::File
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue