shift-shell/components/shellsettingsplugin/mobileshellsettings.cpp
Devin Lin 037f24833c kcms/mobileshell: Remove gesture only navigation option for now
The KWin gesture currently does not work at all, so turning off the navigation panel makes it so the user cannot navigate.

See https://invent.kde.org/plasma/plasma-mobile/-/issues/300
2024-01-22 15:13:21 +00:00

187 lines
6.8 KiB
C++

/*
* SPDX-FileCopyrightText: 2022 Devin Lin <devin@kde.org>
*
* SPDX-License-Identifier: GPL-2.0-or-later
*/
#include "mobileshellsettings.h"
#include <KIO/CommandLauncherJob>
#include <KNotificationJobUiDelegate>
#include <KPluginFactory>
#include <QDBusConnection>
#include <QDBusMessage>
#include <QDBusPendingCall>
#include <QDebug>
const QString CONFIG_FILE = QStringLiteral("plasmamobilerc");
const QString GENERAL_CONFIG_GROUP = QStringLiteral("General");
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) {
Q_EMIT vibrationsEnabledChanged();
Q_EMIT vibrationDurationChanged();
Q_EMIT animationsEnabledChanged();
Q_EMIT navigationPanelEnabledChanged();
Q_EMIT alwaysShowKeyboardToggleOnNavigationPanelChanged();
Q_EMIT keyboardButtonEnabledChanged();
Q_EMIT taskSwitcherPreviewsEnabledChanged();
Q_EMIT actionDrawerTopLeftModeChanged();
Q_EMIT actionDrawerTopRightModeChanged();
Q_EMIT convergenceModeEnabledChanged();
}
});
}
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();
}
int MobileShellSettings::vibrationDuration() const
{
auto group = KConfigGroup{m_config, GENERAL_CONFIG_GROUP};
return group.readEntry("vibrationDuration", 10);
}
void MobileShellSettings::setVibrationDuration(int vibrationDuration)
{
auto group = KConfigGroup{m_config, GENERAL_CONFIG_GROUP};
group.writeEntry("vibrationDuration", vibrationDuration, KConfigGroup::Notify);
m_config->sync();
}
bool MobileShellSettings::animationsEnabled() const
{
auto group = KConfigGroup{m_config, GENERAL_CONFIG_GROUP};
return group.readEntry("animationsEnabled", true);
}
void MobileShellSettings::setAnimationsEnabled(bool animationsEnabled)
{
auto group = KConfigGroup{m_config, GENERAL_CONFIG_GROUP};
group.writeEntry("animationsEnabled", animationsEnabled, KConfigGroup::Notify);
m_config->sync();
}
bool MobileShellSettings::navigationPanelEnabled() const
{
auto group = KConfigGroup{m_config, GENERAL_CONFIG_GROUP};
return group.readEntry("navigationPanelEnabled", true);
}
void MobileShellSettings::setNavigationPanelEnabled(bool navigationPanelEnabled)
{
auto group = KConfigGroup{m_config, GENERAL_CONFIG_GROUP};
group.writeEntry("navigationPanelEnabled", navigationPanelEnabled, KConfigGroup::Notify);
m_config->sync();
// TODO: Gesture only mode setting is disabled until we get the kwin effect gesture working: https://invent.kde.org/plasma/plasma-mobile/-/issues/300
// updateNavigationBarsInPlasma(navigationPanelEnabled);
}
bool MobileShellSettings::alwaysShowKeyboardToggleOnNavigationPanel() const
{
auto group = KConfigGroup{m_config, GENERAL_CONFIG_GROUP};
return group.readEntry("alwaysShowKeyboardToggleOnNavigationPanel", false);
}
void MobileShellSettings::setAlwaysShowKeyboardToggleOnNavigationPanel(bool alwaysShowKeyboardToggleOnNavigationPanel)
{
auto group = KConfigGroup{m_config, GENERAL_CONFIG_GROUP};
group.writeEntry("alwaysShowKeyboardToggleOnNavigationPanel", alwaysShowKeyboardToggleOnNavigationPanel, KConfigGroup::Notify);
m_config->sync();
}
MobileShellSettings::ActionDrawerMode MobileShellSettings::actionDrawerTopLeftMode() const
{
auto group = KConfigGroup{m_config, GENERAL_CONFIG_GROUP};
return (ActionDrawerMode)group.readEntry("actionDrawerTopLeftMode", (int)ActionDrawerMode::Pinned);
}
void MobileShellSettings::setActionDrawerTopLeftMode(ActionDrawerMode actionDrawerMode)
{
auto group = KConfigGroup{m_config, GENERAL_CONFIG_GROUP};
group.writeEntry("actionDrawerTopLeftMode", (int)actionDrawerMode, KConfigGroup::Notify);
m_config->sync();
}
MobileShellSettings::ActionDrawerMode MobileShellSettings::actionDrawerTopRightMode() const
{
auto group = KConfigGroup{m_config, GENERAL_CONFIG_GROUP};
return (ActionDrawerMode)group.readEntry("actionDrawerTopRightMode", (int)ActionDrawerMode::Expanded);
}
void MobileShellSettings::setActionDrawerTopRightMode(ActionDrawerMode actionDrawerMode)
{
auto group = KConfigGroup{m_config, GENERAL_CONFIG_GROUP};
group.writeEntry("actionDrawerTopRightMode", (int)actionDrawerMode, KConfigGroup::Notify);
m_config->sync();
}
bool MobileShellSettings::convergenceModeEnabled() const
{
auto group = KConfigGroup{m_config, GENERAL_CONFIG_GROUP};
return group.readEntry("convergenceModeEnabled", false);
}
void MobileShellSettings::setConvergenceModeEnabled(bool enabled)
{
auto group = KConfigGroup{m_config, GENERAL_CONFIG_GROUP};
group.writeEntry("convergenceModeEnabled", enabled, KConfigGroup::Notify);
m_config->sync();
// update environment settings
auto *job = new KIO::CommandLauncherJob(QStringLiteral("plasma-mobile-envmanager --apply-settings"), {});
job->setUiDelegate(new KNotificationJobUiDelegate(KJobUiDelegate::AutoErrorHandlingEnabled));
job->setDesktopName(QStringLiteral("org.kde.plasma-mobile-envmanager"));
job->start();
}
void MobileShellSettings::updateNavigationBarsInPlasma(bool navigationPanelEnabled)
{
auto message = QDBusMessage::createMethodCall(QLatin1String("org.kde.plasmashell"),
QLatin1String("/PlasmaShell"),
QLatin1String("org.kde.PlasmaShell"),
QLatin1String("evaluateScript"));
if (navigationPanelEnabled) {
QString createNavigationPanelScript = R"(
var bottomPanel = new Panel("org.kde.plasma.mobile.taskpanel")
bottomPanel.location = "bottom";
bottomPanel.height = 2 * gridUnit;
)";
message << createNavigationPanelScript;
} else {
QString deleteNavigationPanelScript = R"(
let allPanels = panels();
for (var i = 0; i < allPanels.length; i++) {
if (allPanels[i].type === "org.kde.plasma.mobile.taskpanel") {
allPanels[i].remove();
}
}
)";
message << deleteNavigationPanelScript;
}
// TODO check for error response
QDBusConnection::sessionBus().asyncCall(message);
}