KConfig

kconfiggui.cpp
1 /*
2  This file is part of the KDE libraries
3  SPDX-FileCopyrightText: 1999 Matthias Ettrich <[email protected]>
4 
5  SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
6 */
7 
8 #include "kconfiggui.h"
9 
10 #include <QGuiApplication>
11 
12 #include <kconfig.h>
13 
14 static QString configName(const QString &id, const QString &key)
15 {
16  return(QLatin1String("session/") + QGuiApplication::applicationName() +
17  QLatin1Char('_') + id +
18  QLatin1Char('_') + key);
19 }
20 
21 static KConfig *s_sessionConfig = nullptr;
22 
24 {
25 #ifdef QT_NO_SESSIONMANAGER
26 #error QT_NO_SESSIONMANAGER was set, this will not compile. Reconfigure Qt with Session management support.
27 #endif
28  if (!hasSessionConfig() && qApp->isSessionRestored()) {
29  // create the default instance specific config object
30  // from applications' -session command line parameter
31  s_sessionConfig = new KConfig(configName(qApp->sessionId(),
32  qApp->sessionKey()),
34  }
35 
36  return s_sessionConfig;
37 }
38 
39 void KConfigGui::setSessionConfig(const QString &id, const QString &key)
40 {
41  if (hasSessionConfig()) {
42  delete s_sessionConfig;
43  s_sessionConfig = nullptr;
44  }
45 
46  // create a new instance specific config object from supplied id & key
47  s_sessionConfig = new KConfig(configName(id, key),
49 }
50 
52 {
53  return s_sessionConfig != nullptr;
54 }
55 
56 #if KCONFIGGUI_BUILD_DEPRECATED_SINCE(5, 11)
58 {
59  if (sessionConfig()) {
60  return sessionConfig()->name();
61  } else {
62  return QString();
63  }
64 }
65 #endif
QString name() const
Returns the filename used to store the configuration.
Definition: kconfig.cpp:548
KCONFIGGUI_EXPORT void setSessionConfig(const QString &id, const QString &key)
Replaces the current application session config object.
Definition: kconfiggui.cpp:39
Just a single config file.
Definition: kconfig.h:86
The central class of the KDE configuration data system.
Definition: kconfig.h:56
KCONFIGGUI_EXPORT KConfig * sessionConfig()
Returns the current application session config object.
Definition: kconfiggui.cpp:23
KCONFIGGUI_EXPORT QString sessionConfigName()
Returns the name of the application session.
Definition: kconfiggui.cpp:57
KCONFIGGUI_EXPORT bool hasSessionConfig()
Indicates if a session config has been created for that application (i.e. if sessionConfig() got call...
Definition: kconfiggui.cpp:51
QString applicationName()
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Wed Jul 8 2020 22:46:43 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.