File indexing completed on 2024-09-08 05:00:58
0001 /* 0002 * SPDX-FileCopyrightText: 2022 Devin Lin <devin@kde.org> 0003 * 0004 * SPDX-License-Identifier: GPL-2.0-or-later 0005 */ 0006 0007 #include "quicksettingsconfig.h" 0008 0009 #include <QDebug> 0010 0011 const QString CONFIG_FILE = QStringLiteral("plasmamobilerc"); 0012 const QString QUICKSETTINGS_CONFIG_GROUP = QStringLiteral("QuickSettings"); 0013 0014 QuickSettingsConfig::QuickSettingsConfig(QObject *parent) 0015 : QObject{parent} 0016 , m_config{KSharedConfig::openConfig(CONFIG_FILE, KConfig::SimpleConfig)} 0017 { 0018 m_configWatcher = KConfigWatcher::create(m_config); 0019 0020 connect(m_configWatcher.data(), &KConfigWatcher::configChanged, this, [this](const KConfigGroup &group, const QByteArrayList &names) -> void { 0021 if (group.name() == QUICKSETTINGS_CONFIG_GROUP) { 0022 Q_EMIT enabledQuickSettingsChanged(); 0023 Q_EMIT disabledQuickSettingsChanged(); 0024 } 0025 }); 0026 } 0027 0028 QList<QString> QuickSettingsConfig::enabledQuickSettings() const 0029 { 0030 auto group = KConfigGroup{m_config, QUICKSETTINGS_CONFIG_GROUP}; 0031 // TODO move defaults to file 0032 // we aren't worried about quicksettings not showing up though, any that are not specified will be automatically added to the end 0033 return group.readEntry("enabledQuickSettings", 0034 QList<QString>{QStringLiteral("org.kde.plasma.quicksetting.wifi"), 0035 QStringLiteral("org.kde.plasma.quicksetting.mobiledata"), 0036 QStringLiteral("org.kde.plasma.quicksetting.bluetooth"), 0037 QStringLiteral("org.kde.plasma.quicksetting.flashlight"), 0038 QStringLiteral("org.kde.plasma.quicksetting.screenrotation"), 0039 QStringLiteral("org.kde.plasma.quicksetting.settingsapp"), 0040 QStringLiteral("org.kde.plasma.quicksetting.airplanemode"), 0041 QStringLiteral("org.kde.plasma.quicksetting.audio"), 0042 QStringLiteral("org.kde.plasma.quicksetting.battery"), 0043 QStringLiteral("org.kde.plasma.quicksetting.record"), 0044 QStringLiteral("org.kde.plasma.quicksetting.nightcolor"), 0045 QStringLiteral("org.kde.plasma.quicksetting.screenshot"), 0046 QStringLiteral("org.kde.plasma.quicksetting.powermenu"), 0047 QStringLiteral("org.kde.plasma.quicksetting.donotdisturb"), 0048 QStringLiteral("org.kde.plasma.quicksetting.caffeine"), 0049 QStringLiteral("org.kde.plasma.quicksetting.keyboardtoggle"), 0050 QStringLiteral("org.kde.plasma.quicksetting.hotspot")}); 0051 } 0052 0053 void QuickSettingsConfig::setEnabledQuickSettings(QList<QString> &list) 0054 { 0055 auto group = KConfigGroup{m_config, QUICKSETTINGS_CONFIG_GROUP}; 0056 group.writeEntry("enabledQuickSettings", list, KConfigGroup::Notify); 0057 m_config->sync(); 0058 } 0059 0060 QList<QString> QuickSettingsConfig::disabledQuickSettings() const 0061 { 0062 auto group = KConfigGroup{m_config, QUICKSETTINGS_CONFIG_GROUP}; 0063 return group.readEntry("disabledQuickSettings", QList<QString>{}); 0064 } 0065 0066 void QuickSettingsConfig::setDisabledQuickSettings(QList<QString> &list) 0067 { 0068 auto group = KConfigGroup{m_config, QUICKSETTINGS_CONFIG_GROUP}; 0069 group.writeEntry("disabledQuickSettings", list, KConfigGroup::Notify); 0070 m_config->sync(); 0071 }