File indexing completed on 2024-12-01 13:34:34
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 "globalaccel.h" 0008 0009 #include <QAction> 0010 #include <QFile> 0011 #include <QStandardPaths> 0012 0013 #include <KGlobalAccel> 0014 #include <KLocalizedString> 0015 0016 void GlobalAccel::changeMenuEntryShortcut(const KService::Ptr &service, const QKeySequence &shortcut) 0017 { 0018 const QString desktopFile = QStringLiteral("%1.desktop").arg(service->desktopEntryName()); 0019 0020 if (!KGlobalAccel::isComponentActive(desktopFile)) { 0021 const QString destination = QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation) + QStringLiteral("/kglobalaccel/") + desktopFile; 0022 QFile::copy(service->entryPath(), destination); 0023 } 0024 QAction action(i18n("Launch %1", service->name())); 0025 action.setProperty("componentName", desktopFile); 0026 action.setProperty("componentDisplayName", service->name()); 0027 action.setObjectName(QStringLiteral("_launch")); 0028 // Make sure that the action is marked active 0029 KGlobalAccel::self()->setShortcut(&action, {shortcut}); 0030 action.setProperty("isConfigurationAction", true); 0031 KGlobalAccel::self()->setShortcut(&action, {shortcut}, KGlobalAccel::NoAutoloading); 0032 } 0033 0034 QKeySequence GlobalAccel::getMenuEntryShortcut(const KService::Ptr &service) 0035 { 0036 const QString desktopFile = QStringLiteral("%1.desktop").arg(service->desktopEntryName()); 0037 const QList<QKeySequence> shortcut = KGlobalAccel::self()->globalShortcut(desktopFile, QStringLiteral("_launch")); 0038 if (!shortcut.isEmpty()) { 0039 return shortcut[0]; 0040 } 0041 return QKeySequence(); 0042 }