From 73b9f40a44728c9ce7822c0b1f8a0422bbb35c27 Mon Sep 17 00:00:00 2001 From: Jamie Newbon Date: Mon, 27 Apr 2020 12:59:37 +0100 Subject: [PATCH] #6538 Added save to ConfigWriter, updated system config pathing and, set initial scope --- src/gui/src/ConfigWriter.cpp | 26 +++++++++++++++++++------- src/gui/src/ConfigWriter.h | 10 ++++++++++ 2 files changed, 29 insertions(+), 7 deletions(-) diff --git a/src/gui/src/ConfigWriter.cpp b/src/gui/src/ConfigWriter.cpp index e0c562aa1..8e77dab4b 100644 --- a/src/gui/src/ConfigWriter.cpp +++ b/src/gui/src/ConfigWriter.cpp @@ -42,6 +42,8 @@ namespace GUI { QCoreApplication::organizationName(), QCoreApplication::applicationName()); + //Set scope to user for initially + m_pSettingsCurrent = m_pSettingsUser; } @@ -98,9 +100,6 @@ namespace GUI { //setScope should never be kCurrent assert(scope); } - - //Notify registered classes to reload - globalLoad(); } } @@ -129,6 +128,7 @@ namespace GUI { for (auto &i : m_pCallerList) { i->saveSettings(); } + save(); break; default: break; @@ -153,10 +153,11 @@ namespace GUI { #elif defined(Q_OS_DARWIN) //Global preferances dir // Would be nice to use /library, but QT has no elevate system in place - path = "/usr/local/etc/symless/synergy/"; + path = "/usr/local/etc/symless/"; #elif defined(Q_OS_LINUX) - // /usr/local/etc/synergy - path = "/usr/local/etc/symless/synergy/"; + // QT adds application and filename to the end of the path already on linux + path = "/usr/local/etc/symless/"; + return path; #else assert("OS not supported"); #endif @@ -164,6 +165,10 @@ namespace GUI { } bool ConfigWriter::unsavedChanges() const { + if (m_unsavedChanges) { + return true; + } + for (const auto &i : m_pCallerList) { if (i->modified()){ //If any class returns true there is no point checking more @@ -174,6 +179,10 @@ namespace GUI { return false; } + void ConfigWriter::markUnsaved() { + m_unsavedChanges = true; + } + ConfigWriter::SaveChoice ConfigWriter::checkSystemSave() const { if (m_CurrentScope == kSystem) { @@ -201,6 +210,9 @@ namespace GUI { return kSave; } - + void ConfigWriter::save() { + m_pSettingsCurrent->sync(); + m_unsavedChanges = false; + } } } \ No newline at end of file diff --git a/src/gui/src/ConfigWriter.h b/src/gui/src/ConfigWriter.h index 79ba87c02..f7817ef18 100644 --- a/src/gui/src/ConfigWriter.h +++ b/src/gui/src/ConfigWriter.h @@ -81,12 +81,18 @@ namespace GUI { /// @brief trigger a config save across all registered classes void globalSave(); + /// @brief Saves the settings to file + void save(); + /// @brief Returns the current scopes settings object /// If more specialize control into the settings is needed this can provide /// direct access to the settings file handler /// @return QSettings The Settings object as a reference QSettings& settings(); + /// @brief This marks the settings as unsaved if the settings() was used to directly affect the config file + void markUnsaved(); + /// @brief Register a class to receives globalLoad and globalSave events /// @param [in] ConfigBase The class that will receive the events void registerClass(ConfigBase* receiver); @@ -116,6 +122,9 @@ namespace GUI { /// on a save and reload by any other class std::list m_pCallerList; + /// @brief if this class modified settings then set the flag + bool m_unsavedChanges = false; + /// @brief The constructor, as this is a singolton we want to control who can call the constructor ConfigWriter(); @@ -145,6 +154,7 @@ namespace GUI { m_pSettingsCurrent->setValue(name, value); break; } + m_unsavedChanges = true; } } }