From bbde811c7737571c50cf57993ebfc3fc105be2d8 Mon Sep 17 00:00:00 2001 From: Peter L Jones Date: Sat, 12 Aug 2023 14:54:42 +0100 Subject: [PATCH] Fixes: #2395 - settings lost on GUI state change --- src/main.cpp | 4 ++-- src/settings.h | 27 +++++++++++++++++++++++---- 2 files changed, 25 insertions(+), 6 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index e030306cd6..53e4b02198 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -948,7 +948,7 @@ int main ( int argc, char** argv ) bMuteMeInPersonalMix ); // load settings from init-file (command line options override) - CClientSettings Settings ( &Client, strIniFileName ); + CClientSettings Settings ( &Client, strIniFileName, pApp, bUseGUI ); Settings.Load ( CommandLineOptions ); // load translation @@ -1029,7 +1029,7 @@ int main ( int argc, char** argv ) if ( bUseGUI ) { // load settings from init-file (command line options override) - CServerSettings Settings ( &Server, strIniFileName ); + CServerSettings Settings ( &Server, strIniFileName, pApp, bUseGUI ); Settings.Load ( CommandLineOptions ); // load translation diff --git a/src/settings.h b/src/settings.h index 6e3bd758c2..994119035d 100644 --- a/src/settings.h +++ b/src/settings.h @@ -29,6 +29,7 @@ #include #include #ifndef HEADLESS +# include # include #endif #include "global.h" @@ -44,12 +45,28 @@ class CSettings : public QObject Q_OBJECT public: - CSettings() : + CSettings ( const QCoreApplication* pApp, const bool bUseGUI ) : vecWindowPosMain(), // empty array strLanguage ( "" ), strFileName ( "" ) { QObject::connect ( QCoreApplication::instance(), &QCoreApplication::aboutToQuit, this, &CSettings::OnAboutToQuit ); + +#ifndef HEADLESS + if ( bUseGUI ) + { + const QGuiApplication* pGApp = static_cast ( pApp ); + + QObject::connect ( pGApp, &QGuiApplication::saveStateRequest, this, [=] ( QSessionManager& ) { Save(); } ); + + QObject::connect ( pGApp, &QGuiApplication::applicationStateChanged, this, [=] ( Qt::ApplicationState state ) { + if ( Qt::ApplicationActive != state ) + { + Save(); + } + } ); + } +#endif } void Load ( const QList CommandLineOptions ); @@ -112,8 +129,8 @@ public slots: class CClientSettings : public CSettings { public: - CClientSettings ( CClient* pNCliP, const QString& sNFiName ) : - CSettings(), + CClientSettings ( CClient* pNCliP, const QString& sNFiName, const QCoreApplication* pApp, const bool bUseGUI ) : + CSettings ( pApp, bUseGUI ), vecStoredFaderTags ( MAX_NUM_STORED_FADER_SETTINGS, "" ), vecStoredFaderLevels ( MAX_NUM_STORED_FADER_SETTINGS, AUD_MIX_FADER_MAX ), vecStoredPanValues ( MAX_NUM_STORED_FADER_SETTINGS, AUD_MIX_PAN_MAX / 2 ), @@ -193,7 +210,9 @@ class CClientSettings : public CSettings class CServerSettings : public CSettings { public: - CServerSettings ( CServer* pNSerP, const QString& sNFiName ) : CSettings(), pServer ( pNSerP ) + CServerSettings ( CServer* pNSerP, const QString& sNFiName, const QCoreApplication* pApp, const bool bUseGUI ) : + CSettings ( pApp, bUseGUI ), + pServer ( pNSerP ) { SetFileName ( sNFiName, DEFAULT_INI_FILE_NAME_SERVER ); }