KConfig

kconfiggui.cpp
1/*
2 This file is part of the KDE libraries
3 SPDX-FileCopyrightText: 1999 Matthias Ettrich <ettrich@kde.org>
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#include "kconfig_gui_log_settings.h"
10
11#include <QGuiApplication>
12
13#include <kconfig.h>
14
15static QString configName(const QString &id, const QString &key)
16{
17 return QLatin1String("session/%1_%2_%3").arg(QGuiApplication::applicationName(), id, key);
18}
19
20static KConfig *s_sessionConfig = nullptr;
21
23{
24#ifdef QT_NO_SESSIONMANAGER
25 qCWarning(KCONFIG_GUI_LOG) << "Qt is built without session manager support";
26#else
27 if (!hasSessionConfig() && qApp->isSessionRestored()) {
28 // create the default instance specific config object
29 // from applications' -session command line parameter
30 s_sessionConfig = new KConfig(configName(qApp->sessionId(), qApp->sessionKey()), KConfig::SimpleConfig);
31 }
32#endif
33
34 return s_sessionConfig;
35}
36
37void KConfigGui::setSessionConfig(const QString &id, const QString &key)
38{
39 if (hasSessionConfig()) {
40 delete s_sessionConfig;
41 s_sessionConfig = nullptr;
42 }
43
44 // create a new instance specific config object from supplied id & key
45 s_sessionConfig = new KConfig(configName(id, key), KConfig::SimpleConfig);
46}
47
49{
50 return s_sessionConfig != nullptr;
51}
The central class of the KDE configuration data system.
Definition kconfig.h:56
@ SimpleConfig
Just a single config file.
Definition kconfig.h:85
KCONFIGGUI_EXPORT void setSessionConfig(const QString &id, const QString &key)
Replaces the current application session config object.
KCONFIGGUI_EXPORT KConfig * sessionConfig()
Returns the current application session config object.
KCONFIGGUI_EXPORT bool hasSessionConfig()
Indicates if a session config has been created for that application (i.e. if sessionConfig() got call...
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Tue Mar 26 2024 11:20:27 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.