Commit 92bbc473 authored by David Redondo's avatar David Redondo 🏎
Browse files

Correctly save shortcuts of new Items

Summary:
When saving first all changes are saved before updating syscoca. This lead to a
crash because serviceByStorageId failed. We can just change the API to directly to
take KService::Ptr's.
BUG: 415699
FIXED-IN: 5.18.0

Test Plan: Correctly created a new item and set a shortcut for it

Reviewers: #plasma, rikmills, davidedmundson

Reviewed By: #plasma, davidedmundson

Subscribers: plasma-devel

Tags: #plasma

Differential Revision: https://phabricator.kde.org/D26765
parent 4ae11e6f
......@@ -26,9 +26,8 @@
#include <KLocalizedString>
#include <KService>
void GlobalAccel::changeMenuEntryShortcut(const QString &storageId, const QKeySequence &shortcut)
void GlobalAccel::changeMenuEntryShortcut(const KService::Ptr service, const QKeySequence &shortcut)
{
const KService::Ptr service = KService::serviceByStorageId(storageId);
const QString desktopFile = QStringLiteral("%1.desktop").arg(service->desktopEntryName());
if (!KGlobalAccel::isComponentActive(desktopFile)) {
......@@ -47,9 +46,8 @@ void GlobalAccel::changeMenuEntryShortcut(const QString &storageId, const QKeySe
}
QKeySequence GlobalAccel::getMenuEntryShortcut(const QString &storageId)
QKeySequence GlobalAccel::getMenuEntryShortcut(const KService::Ptr service)
{
const KService::Ptr service = KService::serviceByStorageId(storageId);
const QString desktopFile = QStringLiteral("%1.desktop").arg(service->desktopEntryName());
const QList<QKeySequence> shortcut = KGlobalAccel::self()->globalShortcut(desktopFile, QStringLiteral("_launch"));
if (!shortcut.isEmpty()) {
......
......@@ -18,14 +18,14 @@
#ifndef GLOBALACCEL_H
#define GLOBALACCEL_H
#include <QString>
#include <KService>
#include <QKeySequence>
class GlobalAccel
{
public:
static QKeySequence getMenuEntryShortcut(const QString &storageId);
static void changeMenuEntryShortcut(const QString &storageId, const QKeySequence &shortcut);
static QKeySequence getMenuEntryShortcut(const KService::Ptr service);
static void changeMenuEntryShortcut(const KService::Ptr service, const QKeySequence &shortcut);
};
#endif // GLOBALACCEL_H
......@@ -65,7 +65,7 @@ int main(int argc, char **argv)
KGlobalAccel::self()->setShortcut(&action, {});
KGlobalAccel::self()->removeAllShortcuts(&action);
if (!shortcut.isEmpty() && !shortcut[0].isEmpty()) {
GlobalAccel::changeMenuEntryShortcut(storageId, shortcut[0]);
GlobalAccel::changeMenuEntryShortcut(KService::serviceByStorageId(storageId), shortcut[0]);
}
khotkeysrc.deleteGroup(groupName);
khotkeysrc.deleteGroup(groupName + QStringLiteral("Actions"));
......
......@@ -181,7 +181,7 @@ void MenuFolderInfo::save(MenuFile *menuFile)
for (QStringList::ConstIterator it = s_deletedApps->constBegin();
it != s_deletedApps->constEnd(); ++it) {
// The shorcut is deleted if we set a empty sequence
GlobalAccel::changeMenuEntryShortcut(*it, QKeySequence());
GlobalAccel::changeMenuEntryShortcut(KService::serviceByStorageId(*it), QKeySequence());
}
delete s_deletedApps;
s_deletedApps = nullptr;
......@@ -324,7 +324,7 @@ void MenuEntryInfo::save()
dirty = false;
}
if (shortcutDirty) {
GlobalAccel::changeMenuEntryShortcut(service->storageId(), shortCut);
GlobalAccel::changeMenuEntryShortcut(service, shortCut);
shortcutDirty = false;
}
}
......@@ -364,7 +364,7 @@ QKeySequence MenuEntryInfo::shortcut()
{
if (!shortcutLoaded) {
shortcutLoaded = true;
shortCut = GlobalAccel::getMenuEntryShortcut(service->storageId());
shortCut = GlobalAccel::getMenuEntryShortcut(service);
}
return shortCut;
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment