2022-02-13 04:23:57 +00:00
|
|
|
/*
|
|
|
|
|
* SPDX-FileCopyrightText: 2022 Devin Lin <devin@kde.org>
|
|
|
|
|
*
|
|
|
|
|
* SPDX-License-Identifier: GPL-2.0-or-later
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include "mobileshellsettings.h"
|
|
|
|
|
|
2022-03-17 19:34:27 +00:00
|
|
|
#include <QDebug>
|
|
|
|
|
|
2022-02-13 04:23:57 +00:00
|
|
|
const QString CONFIG_FILE = QStringLiteral("plasmamobilerc");
|
|
|
|
|
const QString GENERAL_CONFIG_GROUP = QStringLiteral("General");
|
2022-03-17 03:20:36 +00:00
|
|
|
const QString QUICKSETTINGS_CONFIG_GROUP = QStringLiteral("QuickSettings");
|
2022-02-13 04:23:57 +00:00
|
|
|
|
|
|
|
|
MobileShellSettings *MobileShellSettings::self()
|
|
|
|
|
{
|
|
|
|
|
static MobileShellSettings *singleton = new MobileShellSettings();
|
|
|
|
|
return singleton;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
MobileShellSettings::MobileShellSettings(QObject *parent)
|
|
|
|
|
: QObject{parent}
|
|
|
|
|
{
|
|
|
|
|
m_config = KSharedConfig::openConfig(CONFIG_FILE, KConfig::SimpleConfig);
|
|
|
|
|
m_configWatcher = KConfigWatcher::create(m_config);
|
|
|
|
|
|
|
|
|
|
connect(m_configWatcher.data(), &KConfigWatcher::configChanged, this, [this](const KConfigGroup &group, const QByteArrayList &names) -> void {
|
|
|
|
|
if (group.name() == GENERAL_CONFIG_GROUP) {
|
2022-04-29 20:15:53 +00:00
|
|
|
Q_EMIT vibrationsEnabledChanged();
|
2022-02-13 04:23:57 +00:00
|
|
|
Q_EMIT navigationPanelEnabledChanged();
|
2022-03-17 03:20:36 +00:00
|
|
|
} else if (group.name() == QUICKSETTINGS_CONFIG_GROUP) {
|
|
|
|
|
Q_EMIT enabledQuickSettingsChanged();
|
|
|
|
|
Q_EMIT disabledQuickSettingsChanged();
|
2022-02-13 04:23:57 +00:00
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2022-04-29 20:15:53 +00:00
|
|
|
bool MobileShellSettings::vibrationsEnabled() const
|
|
|
|
|
{
|
|
|
|
|
auto group = KConfigGroup{m_config, GENERAL_CONFIG_GROUP};
|
|
|
|
|
return group.readEntry("vibrationsEnabled", true);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void MobileShellSettings::setVibrationsEnabled(bool vibrationsEnabled)
|
|
|
|
|
{
|
|
|
|
|
auto group = KConfigGroup{m_config, GENERAL_CONFIG_GROUP};
|
|
|
|
|
group.writeEntry("vibrationsEnabled", vibrationsEnabled, KConfigGroup::Notify);
|
|
|
|
|
m_config->sync();
|
|
|
|
|
}
|
|
|
|
|
|
2022-02-13 04:23:57 +00:00
|
|
|
bool MobileShellSettings::navigationPanelEnabled() const
|
|
|
|
|
{
|
|
|
|
|
auto group = KConfigGroup{m_config, GENERAL_CONFIG_GROUP};
|
|
|
|
|
return group.readEntry("navigationPanelEnabled", true);
|
|
|
|
|
}
|
2022-03-17 03:20:36 +00:00
|
|
|
|
|
|
|
|
void MobileShellSettings::setNavigationPanelEnabled(bool navigationPanelEnabled)
|
|
|
|
|
{
|
|
|
|
|
auto group = KConfigGroup{m_config, GENERAL_CONFIG_GROUP};
|
|
|
|
|
group.writeEntry("navigationPanelEnabled", navigationPanelEnabled, KConfigGroup::Notify);
|
|
|
|
|
m_config->sync();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QList<QString> MobileShellSettings::enabledQuickSettings() const
|
|
|
|
|
{
|
|
|
|
|
auto group = KConfigGroup{m_config, QUICKSETTINGS_CONFIG_GROUP};
|
|
|
|
|
// TODO move defaults to file
|
|
|
|
|
// we aren't worried about quicksettings not showing up though, any that are not specified will be automatically added to the end
|
|
|
|
|
return group.readEntry("enabledQuickSettings",
|
|
|
|
|
QList<QString>{
|
2022-03-17 20:15:07 +00:00
|
|
|
QStringLiteral("org.kde.plasma.quicksetting.wifi"),
|
|
|
|
|
QStringLiteral("org.kde.plasma.quicksetting.mobiledata"),
|
|
|
|
|
QStringLiteral("org.kde.plasma.quicksetting.bluetooth"),
|
|
|
|
|
QStringLiteral("org.kde.plasma.quicksetting.flashlight"),
|
|
|
|
|
QStringLiteral("org.kde.plasma.quicksetting.screenrotation"),
|
|
|
|
|
QStringLiteral("org.kde.plasma.quicksetting.settingsapp"),
|
|
|
|
|
QStringLiteral("org.kde.plasma.quicksetting.airplanemode"),
|
|
|
|
|
QStringLiteral("org.kde.plasma.quicksetting.audio"),
|
|
|
|
|
QStringLiteral("org.kde.plasma.quicksetting.battery"),
|
|
|
|
|
QStringLiteral("org.kde.plasma.quicksetting.location"),
|
|
|
|
|
QStringLiteral("org.kde.plasma.quicksetting.nightcolor"),
|
|
|
|
|
QStringLiteral("org.kde.plasma.quicksetting.screenshot"),
|
|
|
|
|
QStringLiteral("org.kde.plasma.quicksetting.powermenu"),
|
|
|
|
|
QStringLiteral("org.kde.plasma.quicksetting.keyboardtoggle"),
|
|
|
|
|
QStringLiteral("org.kde.plasma.quicksetting.caffeine"),
|
2022-03-17 03:20:36 +00:00
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void MobileShellSettings::setEnabledQuickSettings(QList<QString> &list)
|
|
|
|
|
{
|
2022-03-17 19:34:27 +00:00
|
|
|
auto group = KConfigGroup{m_config, QUICKSETTINGS_CONFIG_GROUP};
|
2022-03-17 03:20:36 +00:00
|
|
|
group.writeEntry("enabledQuickSettings", list, KConfigGroup::Notify);
|
|
|
|
|
m_config->sync();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QList<QString> MobileShellSettings::disabledQuickSettings() const
|
|
|
|
|
{
|
|
|
|
|
auto group = KConfigGroup{m_config, QUICKSETTINGS_CONFIG_GROUP};
|
|
|
|
|
return group.readEntry("disabledQuickSettings", QList<QString>{});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void MobileShellSettings::setDisabledQuickSettings(QList<QString> &list)
|
|
|
|
|
{
|
2022-03-17 19:34:27 +00:00
|
|
|
auto group = KConfigGroup{m_config, QUICKSETTINGS_CONFIG_GROUP};
|
2022-03-17 03:20:36 +00:00
|
|
|
group.writeEntry("disabledQuickSettings", list, KConfigGroup::Notify);
|
|
|
|
|
m_config->sync();
|
|
|
|
|
}
|