SYNERGY-821 The system doesn't recognize old settings (#6947)

* SYNERGY-821 The system doesn't recognize old settings

* SYNERGY-821 Update ChangeLog
This commit is contained in:
SerhiiGadzhilov 2021-02-10 21:49:29 +03:00 committed by GitHub
parent 0d3ac899d0
commit 8b26dd3495
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 51 additions and 36 deletions

View file

@ -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:

View file

@ -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) {

View file

@ -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<class T> static inline void destroy(T*& p) { delete p; p = 0; }
};