kdeui: setup the session config instance for saving

comes with a warning, session management is tricky but it works like a
charm now

Signed-off-by: Ivailo Monev <xakepa10@gmail.com>
This commit is contained in:
Ivailo Monev 2024-05-10 06:23:55 +03:00
parent 753b39282c
commit a8080b7dde
3 changed files with 23 additions and 3 deletions

View file

@ -134,6 +134,11 @@ static void kRegisterSessionClient(const bool enable, const QString &serviceName
}
}
static QString kSessionConfigName()
{
return QString::fromLatin1("%1_%2").arg(QCoreApplication::applicationName()).arg(QCoreApplication::applicationPid());
}
/*
Private data
*/
@ -456,7 +461,7 @@ KConfig* KApplication::sessionConfig()
// create an instance specific config object
QString configName = d->sessionKey;
if (configName.isEmpty()) {
configName = QString::fromLatin1("%1_%2").arg(QCoreApplication::applicationName()).arg(QCoreApplication::applicationPid());
configName = kSessionConfigName();
}
d->pSessionConfig = new KConfig(
QString::fromLatin1("session/%1").arg(configName),
@ -482,6 +487,15 @@ bool KApplication::saveSession()
s_asked.append(topwidget);
}
if (d->pSessionConfig) {
// the config is used for restoring and saving, set it up for saving
delete d->pSessionConfig;
d->pSessionConfig = new KConfig(
QString::fromLatin1("session/%1").arg(kSessionConfigName()),
KConfig::SimpleConfig
);
}
d->session_save = true;
KConfig* config = KApplication::kApplication()->sessionConfig();
if ( KMainWindow::memberList().count() ){

View file

@ -257,8 +257,11 @@ public Q_SLOTS:
*/
void updateUserTimestamp(int time = 0);
/**
* Saves the state of the application for the current session, the state will be restored on the
* Saves the state of the application for the current session, the state may be restored on the
* next login
*
* @warning when reimplementing call this method first! also sessionSaving() will not return true
* outside the scope of the implementation
*/
virtual bool saveSession();
void reparseConfiguration();

View file

@ -471,7 +471,10 @@ void KMainWindow::closeEvent ( QCloseEvent *e )
if (queryClose()) {
e->accept();
} else e->ignore(); //if the window should not be closed, don't close it
} else {
// if the window should not be closed, don't close it
e->ignore();
}
}
bool KMainWindow::queryClose()