Warning, file /plasma/plasma-mobile/components/mobileshell/mobileshellsettings.cpp was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).

0001 /*
0002  *  SPDX-FileCopyrightText: 2022 Devin Lin <devin@kde.org>
0003  *
0004  *  SPDX-License-Identifier: GPL-2.0-or-later
0005  */
0006 
0007 #include "mobileshellsettings.h"
0008 
0009 #include <QDebug>
0010 
0011 const QString CONFIG_FILE = QStringLiteral("plasmamobilerc");
0012 const QString GENERAL_CONFIG_GROUP = QStringLiteral("General");
0013 const QString QUICKSETTINGS_CONFIG_GROUP = QStringLiteral("QuickSettings");
0014 
0015 MobileShellSettings *MobileShellSettings::self()
0016 {
0017     static MobileShellSettings *singleton = new MobileShellSettings();
0018     return singleton;
0019 }
0020 
0021 MobileShellSettings::MobileShellSettings(QObject *parent)
0022     : QObject{parent}
0023     , m_config{KSharedConfig::openConfig(CONFIG_FILE, KConfig::SimpleConfig)}
0024 {
0025     m_configWatcher = KConfigWatcher::create(m_config);
0026 
0027     connect(m_configWatcher.data(), &KConfigWatcher::configChanged, this, [this](const KConfigGroup &group, const QByteArrayList &names) -> void {
0028         if (group.name() == GENERAL_CONFIG_GROUP) {
0029             Q_EMIT vibrationsEnabledChanged();
0030             Q_EMIT vibrationIntensityChanged();
0031             Q_EMIT vibrationDurationChanged();
0032             Q_EMIT animationsEnabledChanged();
0033             Q_EMIT navigationPanelEnabledChanged();
0034             Q_EMIT keyboardButtonEnabledChanged();
0035             Q_EMIT taskSwitcherPreviewsEnabledChanged();
0036             Q_EMIT actionDrawerTopLeftModeChanged();
0037             Q_EMIT actionDrawerTopRightModeChanged();
0038         } else if (group.name() == QUICKSETTINGS_CONFIG_GROUP) {
0039             Q_EMIT enabledQuickSettingsChanged();
0040             Q_EMIT disabledQuickSettingsChanged();
0041         }
0042     });
0043 }
0044 
0045 bool MobileShellSettings::vibrationsEnabled() const
0046 {
0047     auto group = KConfigGroup{m_config, GENERAL_CONFIG_GROUP};
0048     return group.readEntry("vibrationsEnabled", true);
0049 }
0050 
0051 void MobileShellSettings::setVibrationsEnabled(bool vibrationsEnabled)
0052 {
0053     auto group = KConfigGroup{m_config, GENERAL_CONFIG_GROUP};
0054     group.writeEntry("vibrationsEnabled", vibrationsEnabled, KConfigGroup::Notify);
0055     m_config->sync();
0056 }
0057 
0058 int MobileShellSettings::vibrationDuration() const
0059 {
0060     auto group = KConfigGroup{m_config, GENERAL_CONFIG_GROUP};
0061     return group.readEntry("vibrationDuration", 100);
0062 }
0063 
0064 void MobileShellSettings::setVibrationDuration(int vibrationDuration)
0065 {
0066     auto group = KConfigGroup{m_config, GENERAL_CONFIG_GROUP};
0067     group.writeEntry("vibrationDuration", vibrationDuration, KConfigGroup::Notify);
0068     m_config->sync();
0069 }
0070 
0071 qreal MobileShellSettings::vibrationIntensity() const
0072 {
0073     auto group = KConfigGroup{m_config, GENERAL_CONFIG_GROUP};
0074     return group.readEntry("vibrationIntensity", 0.5);
0075 }
0076 
0077 void MobileShellSettings::setVibrationIntensity(qreal vibrationIntensity)
0078 {
0079     auto group = KConfigGroup{m_config, GENERAL_CONFIG_GROUP};
0080     group.writeEntry("vibrationIntensity", vibrationIntensity, KConfigGroup::Notify);
0081     m_config->sync();
0082 }
0083 
0084 bool MobileShellSettings::animationsEnabled() const
0085 {
0086     auto group = KConfigGroup{m_config, GENERAL_CONFIG_GROUP};
0087     return group.readEntry("animationsEnabled", true);
0088 }
0089 
0090 void MobileShellSettings::setAnimationsEnabled(bool animationsEnabled)
0091 {
0092     auto group = KConfigGroup{m_config, GENERAL_CONFIG_GROUP};
0093     group.writeEntry("animationsEnabled", animationsEnabled, KConfigGroup::Notify);
0094     m_config->sync();
0095 }
0096 
0097 bool MobileShellSettings::navigationPanelEnabled() const
0098 {
0099     auto group = KConfigGroup{m_config, GENERAL_CONFIG_GROUP};
0100     return group.readEntry("navigationPanelEnabled", true);
0101 }
0102 
0103 void MobileShellSettings::setNavigationPanelEnabled(bool navigationPanelEnabled)
0104 {
0105     auto group = KConfigGroup{m_config, GENERAL_CONFIG_GROUP};
0106     group.writeEntry("navigationPanelEnabled", navigationPanelEnabled, KConfigGroup::Notify);
0107     m_config->sync();
0108 }
0109 
0110 bool MobileShellSettings::taskSwitcherPreviewsEnabled() const
0111 {
0112     auto group = KConfigGroup{m_config, GENERAL_CONFIG_GROUP};
0113     return group.readEntry("taskSwitcherPreviewsEnabled", true);
0114 }
0115 
0116 void MobileShellSettings::setTaskSwitcherPreviewsEnabled(bool taskSwitcherPreviewsEnabled)
0117 {
0118     auto group = KConfigGroup{m_config, GENERAL_CONFIG_GROUP};
0119     group.writeEntry("taskSwitcherPreviewsEnabled", taskSwitcherPreviewsEnabled, KConfigGroup::Notify);
0120     m_config->sync();
0121 }
0122 
0123 MobileShellSettings::ActionDrawerMode MobileShellSettings::actionDrawerTopLeftMode() const
0124 {
0125     auto group = KConfigGroup{m_config, GENERAL_CONFIG_GROUP};
0126     return (ActionDrawerMode)group.readEntry("actionDrawerTopLeftMode", (int)ActionDrawerMode::Pinned);
0127 }
0128 
0129 void MobileShellSettings::setActionDrawerTopLeftMode(ActionDrawerMode actionDrawerMode)
0130 {
0131     auto group = KConfigGroup{m_config, GENERAL_CONFIG_GROUP};
0132     group.writeEntry("actionDrawerTopLeftMode", (int)actionDrawerMode, KConfigGroup::Notify);
0133     m_config->sync();
0134 }
0135 
0136 MobileShellSettings::ActionDrawerMode MobileShellSettings::actionDrawerTopRightMode() const
0137 {
0138     auto group = KConfigGroup{m_config, GENERAL_CONFIG_GROUP};
0139     return (ActionDrawerMode)group.readEntry("actionDrawerTopRightMode", (int)ActionDrawerMode::Expanded);
0140 }
0141 
0142 void MobileShellSettings::setActionDrawerTopRightMode(ActionDrawerMode actionDrawerMode)
0143 {
0144     auto group = KConfigGroup{m_config, GENERAL_CONFIG_GROUP};
0145     group.writeEntry("actionDrawerTopRightMode", (int)actionDrawerMode, KConfigGroup::Notify);
0146     m_config->sync();
0147 }
0148 
0149 QList<QString> MobileShellSettings::enabledQuickSettings() const
0150 {
0151     auto group = KConfigGroup{m_config, QUICKSETTINGS_CONFIG_GROUP};
0152     // TODO move defaults to file
0153     // we aren't worried about quicksettings not showing up though, any that are not specified will be automatically added to the end
0154     return group.readEntry("enabledQuickSettings",
0155                            QList<QString>{QStringLiteral("org.kde.plasma.quicksetting.wifi"),
0156                                           QStringLiteral("org.kde.plasma.quicksetting.mobiledata"),
0157                                           QStringLiteral("org.kde.plasma.quicksetting.bluetooth"),
0158                                           QStringLiteral("org.kde.plasma.quicksetting.flashlight"),
0159                                           QStringLiteral("org.kde.plasma.quicksetting.screenrotation"),
0160                                           QStringLiteral("org.kde.plasma.quicksetting.settingsapp"),
0161                                           QStringLiteral("org.kde.plasma.quicksetting.airplanemode"),
0162                                           QStringLiteral("org.kde.plasma.quicksetting.audio"),
0163                                           QStringLiteral("org.kde.plasma.quicksetting.battery"),
0164                                           QStringLiteral("org.kde.plasma.quicksetting.record"),
0165                                           QStringLiteral("org.kde.plasma.quicksetting.nightcolor"),
0166                                           QStringLiteral("org.kde.plasma.quicksetting.screenshot"),
0167                                           QStringLiteral("org.kde.plasma.quicksetting.powermenu"),
0168                                           QStringLiteral("org.kde.plasma.quicksetting.donotdisturb"),
0169                                           QStringLiteral("org.kde.plasma.quicksetting.caffeine"),
0170                                           QStringLiteral("org.kde.plasma.quicksetting.keyboardtoggle")});
0171 }
0172 
0173 void MobileShellSettings::setEnabledQuickSettings(QList<QString> &list)
0174 {
0175     auto group = KConfigGroup{m_config, QUICKSETTINGS_CONFIG_GROUP};
0176     group.writeEntry("enabledQuickSettings", list, KConfigGroup::Notify);
0177     m_config->sync();
0178 }
0179 
0180 QList<QString> MobileShellSettings::disabledQuickSettings() const
0181 {
0182     auto group = KConfigGroup{m_config, QUICKSETTINGS_CONFIG_GROUP};
0183     return group.readEntry("disabledQuickSettings", QList<QString>{});
0184 }
0185 
0186 void MobileShellSettings::setDisabledQuickSettings(QList<QString> &list)
0187 {
0188     auto group = KConfigGroup{m_config, QUICKSETTINGS_CONFIG_GROUP};
0189     group.writeEntry("disabledQuickSettings", list, KConfigGroup::Notify);
0190     m_config->sync();
0191 }