File indexing completed on 2025-01-19 08:09:46
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 if (!service) { 0019 return; 0020 } 0021 0022 const QString desktopFile = QStringLiteral("%1.desktop").arg(service->desktopEntryName()); 0023 0024 if (!KGlobalAccel::isComponentActive(desktopFile)) { 0025 const QString destination = QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation) + QStringLiteral("/kglobalaccel/") + desktopFile; 0026 QFile::copy(service->entryPath(), destination); 0027 } 0028 QAction action(i18n("Launch %1", service->name())); 0029 action.setProperty("componentName", desktopFile); 0030 action.setProperty("componentDisplayName", service->name()); 0031 action.setObjectName(QStringLiteral("_launch")); 0032 // Make sure that the action is marked active 0033 KGlobalAccel::self()->setShortcut(&action, {shortcut}); 0034 action.setProperty("isConfigurationAction", true); 0035 KGlobalAccel::self()->setShortcut(&action, {shortcut}, KGlobalAccel::NoAutoloading); 0036 } 0037 0038 QKeySequence GlobalAccel::getMenuEntryShortcut(const KService::Ptr &service) 0039 { 0040 const QString desktopFile = QStringLiteral("%1.desktop").arg(service->desktopEntryName()); 0041 const QList<QKeySequence> shortcut = KGlobalAccel::self()->globalShortcut(desktopFile, QStringLiteral("_launch")); 0042 if (!shortcut.isEmpty()) { 0043 return shortcut[0]; 0044 } 0045 return QKeySequence(); 0046 }