Changeset View
Changeset View
Standalone View
Standalone View
globalaccel.cpp
Show All 20 Lines | |||||
21 | #include <QAction> | 21 | #include <QAction> | ||
22 | #include <QFile> | 22 | #include <QFile> | ||
23 | #include <QStandardPaths> | 23 | #include <QStandardPaths> | ||
24 | 24 | | |||
25 | #include <KGlobalAccel> | 25 | #include <KGlobalAccel> | ||
26 | #include <KLocalizedString> | 26 | #include <KLocalizedString> | ||
27 | #include <KService> | 27 | #include <KService> | ||
28 | 28 | | |||
29 | void GlobalAccel::changeMenuEntryShortcut(const QString &storageId, const QKeySequence &shortcut) | 29 | void GlobalAccel::changeMenuEntryShortcut(const KService::Ptr service, const QKeySequence &shortcut) | ||
30 | { | 30 | { | ||
31 | const KService::Ptr service = KService::serviceByStorageId(storageId); | | |||
32 | const QString desktopFile = QStringLiteral("%1.desktop").arg(service->desktopEntryName()); | 31 | const QString desktopFile = QStringLiteral("%1.desktop").arg(service->desktopEntryName()); | ||
33 | 32 | | |||
34 | if (!KGlobalAccel::isComponentActive(desktopFile)) { | 33 | if (!KGlobalAccel::isComponentActive(desktopFile)) { | ||
35 | const QString destination = QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation) | 34 | const QString destination = QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation) | ||
36 | + QStringLiteral("/kglobalaccel/") + desktopFile; | 35 | + QStringLiteral("/kglobalaccel/") + desktopFile; | ||
37 | QFile::copy(service->entryPath(), destination); | 36 | QFile::copy(service->entryPath(), destination); | ||
38 | } | 37 | } | ||
39 | QAction action(i18n("Launch %1", service->name())); | 38 | QAction action(i18n("Launch %1", service->name())); | ||
40 | action.setProperty("componentName", desktopFile); | 39 | action.setProperty("componentName", desktopFile); | ||
41 | action.setProperty("componentDisplayName", service->name()); | 40 | action.setProperty("componentDisplayName", service->name()); | ||
42 | action.setObjectName(QStringLiteral("_launch")); | 41 | action.setObjectName(QStringLiteral("_launch")); | ||
43 | //Make sure that the action is marked active | 42 | //Make sure that the action is marked active | ||
44 | KGlobalAccel::self()->setShortcut(&action, {shortcut}); | 43 | KGlobalAccel::self()->setShortcut(&action, {shortcut}); | ||
45 | action.setProperty("isConfigurationAction", true); | 44 | action.setProperty("isConfigurationAction", true); | ||
46 | KGlobalAccel::self()->setShortcut(&action, {shortcut}, KGlobalAccel::NoAutoloading); | 45 | KGlobalAccel::self()->setShortcut(&action, {shortcut}, KGlobalAccel::NoAutoloading); | ||
47 | 46 | | |||
48 | } | 47 | } | ||
49 | 48 | | |||
50 | QKeySequence GlobalAccel::getMenuEntryShortcut(const QString &storageId) | 49 | QKeySequence GlobalAccel::getMenuEntryShortcut(const KService::Ptr service) | ||
51 | { | 50 | { | ||
52 | const KService::Ptr service = KService::serviceByStorageId(storageId); | | |||
53 | const QString desktopFile = QStringLiteral("%1.desktop").arg(service->desktopEntryName()); | 51 | const QString desktopFile = QStringLiteral("%1.desktop").arg(service->desktopEntryName()); | ||
54 | const QList<QKeySequence> shortcut = KGlobalAccel::self()->globalShortcut(desktopFile, QStringLiteral("_launch")); | 52 | const QList<QKeySequence> shortcut = KGlobalAccel::self()->globalShortcut(desktopFile, QStringLiteral("_launch")); | ||
55 | if (!shortcut.isEmpty()) { | 53 | if (!shortcut.isEmpty()) { | ||
56 | return shortcut[0]; | 54 | return shortcut[0]; | ||
57 | } | 55 | } | ||
58 | return QKeySequence(); | 56 | return QKeySequence(); | ||
59 | } | 57 | } | ||
60 | 58 | | |||
61 | 59 | |