File indexing completed on 2024-05-12 03:54:27

0001 /*
0002     This file is part of the KDE libraries
0003     SPDX-FileCopyrightText: 1999 Matthias Ettrich <ettrich@kde.org>
0004 
0005     SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
0006 */
0007 
0008 #include "kconfiggui.h"
0009 #include "kconfig_gui_log_settings.h"
0010 
0011 #include <QGuiApplication>
0012 
0013 #include <kconfig.h>
0014 
0015 static QString configName(const QString &id, const QString &key)
0016 {
0017     return QLatin1String("session/%1_%2_%3").arg(QGuiApplication::applicationName(), id, key);
0018 }
0019 
0020 static KConfig *s_sessionConfig = nullptr;
0021 
0022 KConfig *KConfigGui::sessionConfig()
0023 {
0024 #ifdef QT_NO_SESSIONMANAGER
0025     qCWarning(KCONFIG_GUI_LOG) << "Qt is built without session manager support";
0026 #else
0027     if (!hasSessionConfig() && qApp->isSessionRestored()) {
0028         // create the default instance specific config object
0029         // from applications' -session command line parameter
0030         s_sessionConfig = new KConfig(configName(qApp->sessionId(), qApp->sessionKey()), KConfig::SimpleConfig);
0031     }
0032 #endif
0033 
0034     return s_sessionConfig;
0035 }
0036 
0037 void KConfigGui::setSessionConfig(const QString &id, const QString &key)
0038 {
0039     if (hasSessionConfig()) {
0040         delete s_sessionConfig;
0041         s_sessionConfig = nullptr;
0042     }
0043 
0044     // create a new instance specific config object from supplied id & key
0045     s_sessionConfig = new KConfig(configName(id, key), KConfig::SimpleConfig);
0046 }
0047 
0048 bool KConfigGui::hasSessionConfig()
0049 {
0050     return s_sessionConfig != nullptr;
0051 }