File indexing completed on 2024-05-12 05:38:23

0001 /*
0002     SPDX-FileCopyrightText: 2023 Marco Martin <mart@kde.org>
0003 
0004     SPDX-License-Identifier: GPL-2.0-or-later
0005 */
0006 
0007 #include <KConfigGroup>
0008 #include <KGlobalAccel>
0009 #include <KSharedConfig>
0010 #include <cstdlib>
0011 
0012 #include <QAction>
0013 #include <QGuiApplication>
0014 
0015 /**
0016  * In plasma5, every single contextual action was registered as a global shortcut, with
0017  * Often confusing and duplicated names. Now this capability has been dropped in Plasma6
0018  * and applets that want global shortcuts will have to do that explicitly
0019  *
0020  * @since 6.0
0021  */
0022 int main(int argc, char **argv)
0023 {
0024     QGuiApplication app(argc, argv);
0025     const KSharedConfigPtr configPtr = KSharedConfig::openConfig(QString::fromLatin1("kglobalshortcutsrc"), KConfig::FullConfig);
0026     KConfigGroup plasmaGroup(configPtr, QStringLiteral("plasmashell"));
0027 
0028     // All of those actions
0029     // TODO: maybe they should eventually all be renamed to have applet plugin id prefix?
0030     const QSet<QString> allowedActionNames({QStringLiteral("clipboard_action"),
0031                                             QStringLiteral("cycle-panels"),
0032                                             QStringLiteral("cycleNextAction"),
0033                                             QStringLiteral("cyclePrevAction"),
0034                                             QStringLiteral("edit_clipboard"),
0035                                             QStringLiteral("clear-history"),
0036                                             QStringLiteral("manage activities"),
0037                                             QStringLiteral("repeat_action"),
0038                                             QStringLiteral("show dashboard"),
0039                                             QStringLiteral("show-barcode"),
0040                                             QStringLiteral("show-on-mouse-pos"),
0041                                             QStringLiteral("stop current activity"),
0042                                             QStringLiteral("switch to next activity"),
0043                                             QStringLiteral("switch to previous activity"),
0044                                             QStringLiteral("toggle do not disturb")});
0045 
0046     QStringList filteredActionNames = plasmaGroup.keyList();
0047 
0048     filteredActionNames.erase(std::remove_if(filteredActionNames.begin(),
0049                                              filteredActionNames.end(),
0050                                              [allowedActionNames](const QString &str) {
0051                                                  return str == QStringLiteral("_k_friendly_name")
0052                                                      || str.startsWith(QStringLiteral("activate task manager entry"))
0053                                                      || str.startsWith(QStringLiteral("activate widget")) || allowedActionNames.contains(str);
0054                                              }),
0055                               filteredActionNames.end());
0056 
0057     for (const QString &actionName : filteredActionNames) {
0058         QAction action;
0059         qWarning() << actionName;
0060         action.setObjectName(actionName);
0061         action.setProperty("componentName", QStringLiteral("plasmashell"));
0062         KGlobalAccel::self()->setShortcut(&action, {QKeySequence()}, KGlobalAccel::NoAutoloading);
0063         KGlobalAccel::self()->removeAllShortcuts(&action);
0064     }
0065 
0066     return EXIT_SUCCESS;
0067 }