diff options
| author | Stefan Becker <chemobejk@gmail.com> | 2015-05-09 17:16:27 +0300 | 
|---|---|---|
| committer | Rex Dieter <rdieter@math.unl.edu> | 2015-05-11 15:37:13 -0500 | 
| commit | 9978cfd5ccd18509dd514b3a7ada8c158c209de1 (patch) | |
| tree | 9ec5fc21c41796153ad477db8da1efa30651d14d /src/gui/kconfiggui.cpp | |
| parent | a9d71364dc59cb49688518c10648e7555d6fdc67 (diff) | |
| download | kconfig-9978cfd5ccd18509dd514b3a7ada8c158c209de1.tar.gz kconfig-9978cfd5ccd18509dd514b3a7ada8c158c209de1.tar.bz2 | |
Add KConfigGui::setSessionConfig()
When the application receives a saveState signal it needs to replace the
current KConfig object with a new one based on the QSessionManager
information. Add a new interface that accepts the new session id and key.
BUG: 346768
REVIEW: 123705
Diffstat (limited to 'src/gui/kconfiggui.cpp')
| -rw-r--r-- | src/gui/kconfiggui.cpp | 41 | 
1 files changed, 32 insertions, 9 deletions
| diff --git a/src/gui/kconfiggui.cpp b/src/gui/kconfiggui.cpp index 0048c60a..67b6009a 100644 --- a/src/gui/kconfiggui.cpp +++ b/src/gui/kconfiggui.cpp @@ -25,28 +25,51 @@  #include <kconfig.h> +static QString configName(const QString &id, const QString &key) +{ +    return(QLatin1String("session/") + QGuiApplication::applicationName() + +           QLatin1Char('_')          + id                                 + +           QLatin1Char('_')          + key); +} +  static KConfig *s_sessionConfig = Q_NULLPTR;  KConfig *KConfigGui::sessionConfig()  { -    if (!s_sessionConfig) { // create an instance specific config object -        s_sessionConfig = new KConfig(sessionConfigName(), KConfig::SimpleConfig); +#ifdef QT_NO_SESSIONMANAGER +#error QT_NO_SESSIONMANAGER was set, this will not compile. Reconfigure Qt with Session management support. +#endif +    if (!hasSessionConfig()) { +        // create the default instance specific config object +        // from applications' -session command line parameter +        s_sessionConfig = new KConfig(configName(qApp->sessionId(), +                                                 qApp->sessionKey()), +                                      KConfig::SimpleConfig);      } +      return s_sessionConfig;  } +void KConfigGui::setSessionConfig(const QString &id, const QString &key) +{ +    if (hasSessionConfig()) { +        delete s_sessionConfig; +        s_sessionConfig = Q_NULLPTR; +    } + +    // create a new instance specific config object from supplied id & key +    s_sessionConfig = new KConfig(configName(id, key), +                                  KConfig::SimpleConfig); +} +  bool KConfigGui::hasSessionConfig()  {      return s_sessionConfig != Q_NULLPTR;  } +#ifndef KDE_NO_DEPRECATED  QString KConfigGui::sessionConfigName()  { -#ifdef QT_NO_SESSIONMANAGER -#error QT_NO_SESSIONMANAGER was set, this will not compile. Reconfigure Qt with Session management support. -#endif -    const QString sessionKey = qApp->sessionKey(); -    const QString sessionId = qApp->sessionId(); -    return QString(QLatin1String("session/%1_%2_%3")).arg(QGuiApplication::applicationName()).arg(sessionId).arg(sessionKey); +    return sessionConfig()->name();  } - +#endif | 
