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(args: QGuiApplication::applicationName(), args: id, args: key);
18}
19
20static KConfig *s_sessionConfig = nullptr;
21
22KConfig *KConfigGui::sessionConfig()
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
48bool KConfigGui::hasSessionConfig()
49{
50 return s_sessionConfig != nullptr;
51}
52

source code of kconfig/src/gui/kconfiggui.cpp