#6538 Moved settings from main window to appconfig

This commit is contained in:
Jamie Newbon 2020-03-31 11:09:50 +01:00
parent ab92492d65
commit 2bff3807f8
3 changed files with 131 additions and 24 deletions

View file

@ -29,11 +29,13 @@
const char AppConfig::m_SynergysName[] = "synergys.exe";
const char AppConfig::m_SynergycName[] = "synergyc.exe";
const char AppConfig::m_SynergyLogDir[] = "log/";
const char AppConfig::synergyConfigName[] = "synergy.sgc";
#define DEFAULT_PROCESS_MODE Service
#else
const char AppConfig::m_SynergysName[] = "synergys";
const char AppConfig::m_SynergycName[] = "synergyc";
const char AppConfig::m_SynergyLogDir[] = "/var/log/";
const char AppConfig::synergyConfigName[] = "synergy.conf";
#define DEFAULT_PROCESS_MODE Desktop
#endif
@ -62,7 +64,13 @@ const char* AppConfig::m_SynergySettingsName[] = {
"activationHasRun",
"minimizeToTray",
"ActivateEmail",
"loadFromSystemScope"
"loadFromSystemScope",
"groupServerChecked",
"useExternalConfig",
"configFile",
"useInternalConfig",
"groupClientChecked",
"serverHostname",
};
static const char* logLevelNames[] =
@ -213,6 +221,12 @@ void AppConfig::loadSettings(bool ignoreSystem)
m_ActivationHasRun = loadSetting(ActivationHasRun, false).toBool();
m_MinimizeToTray = loadSetting(MinimizeToTray, false).toBool();
m_LoadFromSystemScope = loadSetting(LoadSystemSettings, false).toBool();
m_ServerGroupChecked = loadSetting(GroupServerCheck, false).toBool();
m_UseExternalConfig = loadSetting(UseExternalConfig, false).toBool();
m_ConfigFile = loadSetting(ConfigFile, QDir::homePath() + "/" + synergyConfigName).toString();
m_UseInternalConfig = loadSetting(UseInternalConfig, false).toBool();
m_ClientGroupChecked = loadSetting(GroupClientCheck, true).toBool();
m_ServerHostname = loadSetting(ServerHostname).toString();
//If this is user scope and the user chose switch to global but ignoreSystem is not set.
if (settings().scope() == QSettings::UserScope &&
@ -251,6 +265,12 @@ void AppConfig::saveSettings()
setSetting(ActivationHasRun, m_ActivationHasRun);
setSetting(MinimizeToTray, m_MinimizeToTray);
setSetting(LoadSystemSettings, m_LoadFromSystemScope);
setSetting(GroupServerCheck, m_ServerGroupChecked);
setSetting(UseExternalConfig, m_UseExternalConfig);
setSetting(ConfigFile, m_ConfigFile);
setSetting(UseInternalConfig, m_UseInternalConfig);
setSetting(GroupClientCheck, m_ClientGroupChecked);
setSetting(ServerHostname, m_ServerHostname);
settings().sync();
}
@ -442,3 +462,55 @@ void AppConfig::setLoadFromSystemScope(bool value) {
bool AppConfig::isSystemScoped() const {
return m_pSettings->scope() == QSettings::SystemScope;
}
bool AppConfig::unsavedChanges() {
return m_SettingModified;
}
bool AppConfig::getServerGroupChecked() const {
return m_ServerGroupChecked;
}
bool AppConfig::getUseExternalConfig() const {
return m_UseExternalConfig;
}
QString AppConfig::getConfigFile() const {
return m_ConfigFile;
}
bool AppConfig::getUseInternalConfig() const {
return m_UseInternalConfig;
}
bool AppConfig::getClientGroupChecked() const {
return m_ClientGroupChecked;
}
QString AppConfig::getServerHostname() const {
return m_ServerHostname;
}
void AppConfig::setServerGroupChecked(bool newValue) {
m_ServerGroupChecked = newValue;
}
void AppConfig::setUseExternalConfig(bool newValue) {
m_UseExternalConfig = newValue;
}
void AppConfig::setConfigFile(const QString& newValue) {
m_ConfigFile = newValue;
}
void AppConfig::setUseInternalConfig(bool newValue) {
m_UseInternalConfig = newValue;
}
void AppConfig::setClientGroupChecked(bool newValue) {
m_ClientGroupChecked = newValue;
}
void AppConfig::setServerHostname(const QString& newValue) {
m_ServerHostname = newValue;
}

View file

@ -130,6 +130,21 @@ class AppConfig: public QObject
/// @brief Returns true if the setting should be set to global scope. Only useful if current scope is UserScope
bool getLoadFromSystemScope() const;
bool getServerGroupChecked() const;
bool getUseExternalConfig() const;
QString getConfigFile() const;
bool getUseInternalConfig() const;
bool getClientGroupChecked() const;
QString getServerHostname() const;
void setServerGroupChecked(bool);
void setUseExternalConfig(bool) ;
void setConfigFile(const QString&);
void setUseInternalConfig(bool) ;
void setClientGroupChecked(bool) ;
void setServerHostname(const QString&);
QString lastVersion() const;
void setMinimizeToTray(bool b);
@ -179,6 +194,12 @@ protected:
MinimizeToTray,
ActivateEmail,
LoadSystemSettings,
GroupServerCheck,
UseExternalConfig,
ConfigFile,
UseInternalConfig,
GroupClientCheck,
ServerHostname,
};
void setScreenName(const QString& s);
@ -223,6 +244,14 @@ protected:
int m_LastExpiringWarningTime;
bool m_ActivationHasRun;
bool m_MinimizeToTray;
bool m_ServerGroupChecked;
bool m_UseExternalConfig;
QString m_ConfigFile;
bool m_UseInternalConfig;
bool m_ClientGroupChecked;
QString m_ServerHostname;
bool m_LoadFromSystemScope; /// @brief should the setting be loaded from SystemScope
/// If the user has settings but this is true then
/// system settings will be loaded instead of the users
@ -234,6 +263,9 @@ protected:
/// @brief Contains the string values of the settings names that will be saved
static const char* m_SynergySettingsName[];
/// @brief Contains the name of the default configuration filename
static const char synergyConfigName[];
/// @brief Sets the value of a setting
/// @param [in] name The Setting to be saved
/// @param [in] value The Value to be saved

View file

@ -323,13 +323,13 @@ void MainWindow::loadSettings()
{
// the next two must come BEFORE loading groupServerChecked and groupClientChecked or
// disabling and/or enabling the right widgets won't automatically work
m_pRadioExternalConfig->setChecked(settings().value("useExternalConfig", false).toBool());
m_pRadioInternalConfig->setChecked(settings().value("useInternalConfig", true).toBool());
m_pRadioExternalConfig->setChecked(appConfig().getUseExternalConfig());
m_pRadioInternalConfig->setChecked(appConfig().getUseInternalConfig());
m_pGroupServer->setChecked(settings().value("groupServerChecked", false).toBool());
m_pLineEditConfigFile->setText(settings().value("configFile", QDir::homePath() + "/" + synergyConfigName).toString());
m_pGroupClient->setChecked(settings().value("groupClientChecked", true).toBool());
m_pLineEditHostname->setText(settings().value("serverHostname").toString());
m_pGroupServer->setChecked(appConfig().getServerGroupChecked()));
m_pLineEditConfigFile->setText(appConfig().getConfigFile());
m_pGroupClient->setChecked(appConfig().getClientGroupChecked());
m_pLineEditHostname->setText(appConfig().getServerHostname());
}
void MainWindow::initConnections()
@ -345,25 +345,28 @@ void MainWindow::initConnections()
void MainWindow::saveSettings()
{
// program settings
settings().setValue("groupServerChecked", m_pGroupServer->isChecked());
settings().setValue("useExternalConfig", m_pRadioExternalConfig->isChecked());
settings().setValue("configFile", m_pLineEditConfigFile->text());
settings().setValue("useInternalConfig", m_pRadioInternalConfig->isChecked());
settings().setValue("groupClientChecked", m_pGroupClient->isChecked());
settings().setValue("serverHostname", m_pLineEditHostname->text());
appConfig().setServerGroupChecked(m_pGroupServer->isChecked());
appConfig().setClientGroupChecked(m_pGroupClient->isChecked());
appConfig().setUseExternalConfig(m_pRadioExternalConfig->isChecked());
appConfig().setUseInternalConfig(m_pRadioInternalConfig->isChecked());
appConfig().setConfigFile(m_pLineEditConfigFile->text());
appConfig().setServerHostname(m_pLineEditHostname->text());
auto choice = appConfig().checkGlobalSave();
switch (choice)
{
case AppConfig::SaveToUser:
//Switch to local and overrun into the save case
appConfig().switchToGlobal(false);
case AppConfig::Save:
settings().sync();
break;
default:
break;
//Save if there are any unsaved changes otherwise skip
if (appConfig().unsavedChanges()) {
auto choice = appConfig().checkGlobalSave();
switch (choice) {
case AppConfig::SaveToUser:
//Switch to local and overrun into the save case
appConfig().switchToGlobal(false);
case AppConfig::Save:
settings().sync();
break;
default:
break;
}
}
}