Skip to content

Commit

Permalink
Fixes: #2395 - settings lost on GUI state change
Browse files Browse the repository at this point in the history
  • Loading branch information
pljones committed Aug 25, 2023
1 parent b56a7b0 commit bbde811
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 6 deletions.
4 changes: 2 additions & 2 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
27 changes: 23 additions & 4 deletions src/settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
#include <QSettings>
#include <QDir>
#ifndef HEADLESS
# include <QApplication>
# include <QMessageBox>
#endif
#include "global.h"
Expand All @@ -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<const QGuiApplication*> ( 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<QString> CommandLineOptions );
Expand Down Expand Up @@ -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 ),
Expand Down Expand Up @@ -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 );
}
Expand Down

0 comments on commit bbde811

Please sign in to comment.