File indexing completed on 2024-05-12 05:29:27
0001 // SPDX-FileCopyrightText: 2019, 2022 Mikhail Zolotukhin <zomial@protonmail.com> 0002 // SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL 0003 0004 #include "settings_ini.h" 0005 0006 #include <KConfigGroup> 0007 #include <KSharedConfig> 0008 0009 #include <QStandardPaths> 0010 0011 #include "config_editor/utils.h" 0012 0013 namespace SettingsIniEditor 0014 { 0015 0016 namespace 0017 { 0018 0019 KConfigGroup gtkConfigGroup(int gtkVersion) 0020 { 0021 QString configLocation = QStandardPaths::writableLocation(QStandardPaths::GenericConfigLocation); 0022 auto gtkConfigPath = QStringLiteral("%1/gtk-%2.0/settings.ini").arg(configLocation).arg(gtkVersion); 0023 0024 KSharedConfig::Ptr gtkConfig = KSharedConfig::openConfig(gtkConfigPath, KConfig::NoGlobals); 0025 return gtkConfig->group(QStringLiteral("Settings")); 0026 } 0027 } 0028 0029 void setValue(const QString ¶mName, const QVariant ¶mValue, int gtkVersion) 0030 { 0031 auto setValueForVersion = [&](int version) { 0032 auto group = gtkConfigGroup(version); 0033 group.writeEntry(paramName, paramValue); 0034 group.sync(); 0035 }; 0036 0037 if (gtkVersion != -1) { 0038 setValueForVersion(gtkVersion); 0039 return; 0040 } 0041 0042 for (auto version : Utils::s_gtkVersions) { 0043 setValueForVersion(version); 0044 } 0045 } 0046 0047 void unsetValue(const QString ¶mName, int gtkVersion) 0048 { 0049 auto unsetValueForVersion = [&](int version) { 0050 auto group = gtkConfigGroup(version); 0051 group.deleteEntry(paramName); 0052 group.sync(); 0053 }; 0054 0055 if (gtkVersion != -1) { 0056 unsetValueForVersion(gtkVersion); 0057 return; 0058 } 0059 0060 for (auto version : Utils::s_gtkVersions) { 0061 unsetValueForVersion(version); 0062 } 0063 } 0064 0065 QString value(const QString ¶mName, int gtkVersion) 0066 { 0067 if (gtkVersion == -1) { 0068 gtkVersion = *Utils::s_gtkVersions.begin(); 0069 } 0070 0071 auto group = gtkConfigGroup(gtkVersion); 0072 return group.readEntry(paramName); 0073 } 0074 0075 }