File indexing completed on 2024-05-12 17:07:30

0001 /*
0002     SPDX-FileCopyrightText: 2013 Alexander Mezin <mezin.alexander@gmail.com>
0003 
0004     SPDX-License-Identifier: GPL-2.0-or-later
0005 */
0006 
0007 #include "actions.h"
0008 
0009 #include <KGlobalAccel>
0010 #include <KLocalizedString>
0011 #include <QAction>
0012 #include <QDebug>
0013 
0014 TouchpadGlobalActions::TouchpadGlobalActions(bool isConfiguration, QObject *parent)
0015     : KActionCollection(parent)
0016 {
0017     // setComponentName(TouchpadPluginFactory::componentData());
0018     setComponentName("kcm_touchpad");
0019     setComponentDisplayName(i18n("Touchpad"));
0020 
0021     QAction *enable = addAction("Enable Touchpad");
0022     enable->setText(i18n("Enable Touchpad"));
0023     connect(enable, SIGNAL(triggered()), SIGNAL(enableTriggered()));
0024     bool okEnable = KGlobalAccel::setGlobalShortcut(enable, QKeySequence(Qt::Key_TouchpadOn));
0025     if (!okEnable) {
0026         qWarning() << "Couldn't set global shortcut to Qt::Key_TouchpadOn. There's another program using it, otherwise file a bug against kcm_touchpad";
0027     }
0028 
0029     QAction *disable = addAction("Disable Touchpad");
0030     disable->setText(i18n("Disable Touchpad"));
0031     connect(disable, SIGNAL(triggered()), SIGNAL(disableTriggered()));
0032     bool okDisable = KGlobalAccel::setGlobalShortcut(disable, QKeySequence(Qt::Key_TouchpadOff));
0033     if (!okDisable) {
0034         qWarning() << "Couldn't set global shortcut to Qt::Key_TouchpadOff. There's another program using it, otherwise file a bug against kcm_touchpad";
0035     }
0036 
0037     QAction *toggle = addAction("Toggle Touchpad");
0038     toggle->setText(i18n("Toggle Touchpad"));
0039     connect(toggle, SIGNAL(triggered()), SIGNAL(toggleTriggered()));
0040     bool okToggle = KGlobalAccel::setGlobalShortcut(toggle, QKeySequence(Qt::Key_TouchpadToggle));
0041     if (!okToggle) {
0042         qWarning() << "Couldn't set global shortcut to Qt::Key_TouchpadToggle. There's another program using it, otherwise file a bug against kcm_touchpad";
0043     }
0044 
0045     const auto actionsList = actions();
0046     for (QAction *act : actionsList) {
0047         KActionCollection::setShortcutsConfigurable(act, true);
0048         if (isConfiguration) {
0049             act->setProperty("isConfigurationAction", true);
0050         }
0051     }
0052 }