File indexing completed on 2024-10-13 13:11:42
0001 /* 0002 * SPDX-FileCopyrightText: 2019 David Redondo <kde@david-redondo.de> 0003 * 0004 * SPDX-License-Identifier: GPL-2.0-or-later 0005 */ 0006 0007 #include <QAction> 0008 #include <QCoreApplication> 0009 #include <QDBusInterface> 0010 0011 #include <KConfig> 0012 #include <KConfigGroup> 0013 #include <KGlobalAccel> 0014 0015 #include "../globalaccel.h" 0016 0017 int main(int argc, char **argv) 0018 { 0019 QCoreApplication app(argc, argv); 0020 QDBusInterface khotkeys(QStringLiteral("org.kde.kded5"), QStringLiteral("/modules/khotkeys"), QStringLiteral("org.kde.khotkeys")); 0021 khotkeys.call(QStringLiteral("declareConfigOutDated")); 0022 KConfig khotkeysrc(QStringLiteral("khotkeysrc"), KConfig::SimpleConfig); 0023 const int dataCount = KConfigGroup(&khotkeysrc, "Data").readEntry("DataCount", 0); 0024 bool foundKmenuedit = false; 0025 int kmenueditIndex; 0026 KConfigGroup kmenueditGroup; 0027 for (int i = 1; i <= dataCount; ++i) { 0028 kmenueditGroup = KConfigGroup(&khotkeysrc, QStringLiteral("Data_%1").arg(i)); 0029 if (kmenueditGroup.readEntry("Name", QString()) == QLatin1String("KMenuEdit")) { 0030 foundKmenuedit = true; 0031 kmenueditIndex = i; 0032 break; 0033 } 0034 } 0035 if (!foundKmenuedit) { 0036 return 0; 0037 } 0038 const int numShortcuts = kmenueditGroup.readEntry("DataCount", 0); 0039 for (int i = 1; i <= numShortcuts; ++i) { 0040 const QString groupName = QStringLiteral("Data_%1_%2").arg(kmenueditIndex).arg(i); 0041 // only migrate the launch actions for now, not the default search action 0042 if (KConfigGroup(&khotkeysrc, groupName).readEntry("Type") != QLatin1String("MENUENTRY_SHORTCUT_ACTION_DATA")) { 0043 continue; 0044 } 0045 const QString storageId = KConfigGroup(&khotkeysrc, groupName + QStringLiteral("Actions0")).readEntry("CommandURL"); 0046 const QString id = KConfigGroup(&khotkeysrc, groupName + QStringLiteral("Triggers0")).readEntry("Uuid"); 0047 // ask globalaccel about the current shortcut rather than parsing it ourselves 0048 const QList<QKeySequence> shortcut = KGlobalAccel::self()->globalShortcut(QStringLiteral("khotkeys"), id); 0049 QAction action; 0050 action.setObjectName(id); 0051 action.setProperty("componentName", QStringLiteral("khotkeys")); 0052 KGlobalAccel::self()->setShortcut(&action, {}); 0053 KGlobalAccel::self()->removeAllShortcuts(&action); 0054 if (!shortcut.isEmpty() && !shortcut[0].isEmpty()) { 0055 GlobalAccel::changeMenuEntryShortcut(KService::serviceByStorageId(storageId), shortcut[0]); 0056 } 0057 khotkeysrc.deleteGroup(groupName); 0058 khotkeysrc.deleteGroup(groupName + QStringLiteral("Actions")); 0059 khotkeysrc.deleteGroup(groupName + QStringLiteral("Actions0")); 0060 khotkeysrc.deleteGroup(groupName + QStringLiteral("Conditions")); 0061 khotkeysrc.deleteGroup(groupName + QStringLiteral("Triggers")); 0062 khotkeysrc.deleteGroup(groupName + QStringLiteral("Triggers0")); 0063 } 0064 khotkeysrc.sync(); 0065 khotkeys.call(QStringLiteral("reread_configuration")); 0066 }