Repository navigation
Expand file tree
/
Copy pathglobalaccel.cpp
More file actions
51 lines (43 loc) · 1.81 KB
/
Copy pathglobalaccel.cpp
File metadata and controls
51 lines (43 loc) · 1.81 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
/*
* SPDX-FileCopyrightText: 2019 David Redondo <kde@david-redondo.de>
*
* SPDX-License-Identifier: GPL-2.0-or-later
*/
#include "globalaccel.h"
#include <QAction>
#include <QFile>
#include <QStandardPaths>
#include <KGlobalAccel>
#include <KLocalizedString>
void GlobalAccel::changeMenuEntryShortcut(const KService::Ptr &service, const QKeySequence &shortcut)
{
if (!service) {
return;
}
const QString desktopFile = QStringLiteral("%1.desktop").arg(service->desktopEntryName());
// if the component doesn't exist already, and we don't want any shortcuts, don't create one
if (!KGlobalAccel::isComponentActive(desktopFile) && shortcut.isEmpty()) {
return;
}
if (!KGlobalAccel::isComponentActive(desktopFile)) {
const QString destination = QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation) + QStringLiteral("/kglobalaccel/") + desktopFile;
QFile::copy(service->entryPath(), destination);
}
QAction action(i18n("Launch %1", service->name()));
action.setProperty("componentName", desktopFile);
action.setProperty("componentDisplayName", service->name());
action.setObjectName(QStringLiteral("_launch"));
// Make sure that the action is marked active
KGlobalAccel::self()->setShortcut(&action, {shortcut});
action.setProperty("isConfigurationAction", true);
KGlobalAccel::self()->setShortcut(&action, {shortcut}, KGlobalAccel::NoAutoloading);
}
QKeySequence GlobalAccel::getMenuEntryShortcut(const KService::Ptr &service)
{
const QString desktopFile = QStringLiteral("%1.desktop").arg(service->desktopEntryName());
const QList<QKeySequence> shortcut = KGlobalAccel::self()->globalShortcut(desktopFile, QStringLiteral("_launch"));
if (!shortcut.isEmpty()) {
return shortcut[0];
}
return QKeySequence();
}