Commit 42b1039e authored by David Redondo's avatar David Redondo 🏎 Committed by Nate Graham
Browse files

krunnerglobalshortcuts: Prevent actions from becoming inactive

If a QAction is destroyed, KGlobalAccel will automaticaly set it
to inactive. To prevent this put them on the heap and intentionally
leak them as it did before.
CCBUG:437364


(cherry picked from commit 6502f798)
parent f90d4d55
......@@ -49,10 +49,12 @@ int main(int argc, char **argv)
KActionCollection shortCutActions(nullptr, oldDesktopFile);
shortCutActions.setComponentDisplayName(displayName);
QAction runCommandAction(displayName);
shortCutActions.addAction(QStringLiteral("_launch"), &runCommandAction);
QAction runClipboardAction(clipboardActionName);
shortCutActions.addAction(QStringLiteral("RunClipboard"), &runClipboardAction);
// The actions are intentionally allocated and never cleaned up, because otherwise KGlobalAccel
// will mark them as inactive
auto runCommandAction = new QAction(displayName);
shortCutActions.addAction(QStringLiteral("_launch"), runCommandAction);
auto runClipboardAction = new QAction(clipboardActionName);
shortCutActions.addAction(QStringLiteral("RunClipboard"), runClipboardAction);
QList<QKeySequence> oldRunCommand;
QList<QKeySequence> oldRunClipboard;
......@@ -61,23 +63,23 @@ int main(int argc, char **argv)
oldRunClipboard = KGlobalAccel::self()->globalShortcut(oldCompomentName, QStringLiteral("run command on clipboard contents"));
KGlobalAccel::self()->cleanComponent(oldCompomentName);
} else if (KGlobalAccel::isComponentActive(oldDesktopFile)) {
oldRunCommand = KGlobalAccel::self()->globalShortcut(oldDesktopFile, runCommandAction.objectName());
oldRunClipboard = KGlobalAccel::self()->globalShortcut(oldDesktopFile, runClipboardAction.objectName());
oldRunCommand = KGlobalAccel::self()->globalShortcut(oldDesktopFile, runCommandAction->objectName());
oldRunClipboard = KGlobalAccel::self()->globalShortcut(oldDesktopFile, runClipboardAction->objectName());
KGlobalAccel::self()->cleanComponent(oldDesktopFile);
} else {
return 0;
}
shortCutActions.takeAction(&runCommandAction);
shortCutActions.takeAction(&runClipboardAction);
shortCutActions.takeAction(runCommandAction);
shortCutActions.takeAction(runClipboardAction);
shortCutActions.setComponentName(newDesktopFile);
shortCutActions.addActions({&runCommandAction, &runClipboardAction});
shortCutActions.addActions({runCommandAction, runClipboardAction});
if (!oldRunCommand.isEmpty()) {
KGlobalAccel::self()->setShortcut(&runCommandAction, oldRunCommand, KGlobalAccel::NoAutoloading);
KGlobalAccel::self()->setShortcut(runCommandAction, oldRunCommand, KGlobalAccel::NoAutoloading);
}
if (!oldRunClipboard.isEmpty()) {
KGlobalAccel::self()->setShortcut(&runClipboardAction, oldRunClipboard, KGlobalAccel::NoAutoloading);
KGlobalAccel::self()->setShortcut(runClipboardAction, oldRunClipboard, KGlobalAccel::NoAutoloading);
}
return 0;
......
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