From 8b26dd3495c7e60f74a5fd24e323c839670057b1 Mon Sep 17 00:00:00 2001 From: SerhiiGadzhilov <71632867+SerhiiGadzhilov@users.noreply.github.com> Date: Wed, 10 Feb 2021 21:49:29 +0300 Subject: [PATCH] SYNERGY-821 The system doesn't recognize old settings (#6947) * SYNERGY-821 The system doesn't recognize old settings * SYNERGY-821 Update ChangeLog --- ChangeLog | 1 + src/gui/src/ConfigWriter.cpp | 82 ++++++++++++++++++++++-------------- src/gui/src/ConfigWriter.h | 4 -- 3 files changed, 51 insertions(+), 36 deletions(-) diff --git a/ChangeLog b/ChangeLog index 70b0c5f71..265acc48a 100644 --- a/ChangeLog +++ b/ChangeLog @@ -14,6 +14,7 @@ Bug fixes: - #6939 Update pipelines to use correct credentials - #6942 All the text in all the windows should have the same font and size - #6944 Systray icon is incorrect for macOS Big Sur +- #6941 The application doesn't recognize old settings - #6945 Fix build for Raspberry Pi Enhancements: diff --git a/src/gui/src/ConfigWriter.cpp b/src/gui/src/ConfigWriter.cpp index 2ceed673e..752c8276f 100644 --- a/src/gui/src/ConfigWriter.cpp +++ b/src/gui/src/ConfigWriter.cpp @@ -23,6 +23,53 @@ #include "ConfigWriter.h" #include "ConfigBase.h" +namespace { + +QString getSystemSettingPath() +{ + const QString settingFilename("SystemConfig.ini"); + QString path; +#if defined(Q_OS_WIN) + // Program file + path = QCoreApplication::applicationDirPath() + "\\"; +#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/"; +#elif defined(Q_OS_LINUX) + // 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 + return path + settingFilename; +} + +#if defined(Q_OS_WIN) +void loadOldSystemSettings(QSettings& settings) +{ + if (!QFile(settings.fileName()).exists()) { + QSettings::setPath(QSettings::IniFormat, QSettings::SystemScope, "SystemConfig.ini"); + QSettings oldSystemSettings (QSettings::IniFormat, + QSettings::SystemScope, + QCoreApplication::organizationName(), + QCoreApplication::applicationName()); + + if (QFile(oldSystemSettings.fileName()).exists()) { + for (const auto& key : oldSystemSettings.allKeys()) { + settings.setValue(key, oldSystemSettings.value(key)); + } + } + + //Restore system settings path + QSettings::setPath(QSettings::IniFormat, QSettings::SystemScope, getSystemSettingPath()); + } +} +#endif + +} + namespace GUI { namespace Config { //Assignment of static variable @@ -37,19 +84,6 @@ namespace GUI { return s_pConfiguration; } - void loadOldSystemSettings(QSettings& settings) - { - if (!QFile(settings.fileName()).exists()) { - QFile oldSystemSettings("SystemConfig.ini"); - if (oldSystemSettings.exists()) { - QSettings oldSettings(oldSystemSettings.fileName(), QSettings::Format::IniFormat); - for (const auto& key : oldSettings.allKeys()) { - settings.setValue(key, oldSettings.value(key)); - } - } - } - } - ConfigWriter::ConfigWriter() { QSettings::setPath(QSettings::Format::IniFormat, QSettings::Scope::SystemScope, @@ -62,8 +96,10 @@ namespace GUI { QCoreApplication::organizationName(), QCoreApplication::applicationName()); + #if defined(Q_OS_WIN) //This call is needed for backwardcapability with old settings. loadOldSystemSettings(*m_pSettingsSystem); + #endif //defaults to user scope, if we set the scope specifically then we also have to set // the application name and the organisation name which breaks backwards compatibility @@ -162,25 +198,7 @@ namespace GUI { m_pCallerList.push_back(receiver); } - QString ConfigWriter::getSystemSettingPath() { - const QString settingFilename("SystemConfig.ini"); - QString path; -#if defined(Q_OS_WIN) - // Program file - path = QCoreApplication::applicationDirPath() + "\\"; -#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/"; -#elif defined(Q_OS_LINUX) - // 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 - return path + settingFilename; - } + bool ConfigWriter::unsavedChanges() const { if (m_unsavedChanges) { diff --git a/src/gui/src/ConfigWriter.h b/src/gui/src/ConfigWriter.h index 8eae8e73b..da70942d3 100644 --- a/src/gui/src/ConfigWriter.h +++ b/src/gui/src/ConfigWriter.h @@ -123,10 +123,6 @@ namespace GUI { /// @brief the pointer of the ConfigWriter for singolton use static ConfigWriter* s_pConfiguration; - /// @brief Returns the OS specific settings ini file location - static QString getSystemSettingPath(); - - /// @brief deletes pointers and sets the value to null template static inline void destroy(T*& p) { delete p; p = 0; } };