Adjust krunner shortcuts update binary

Because we have changed the name of the desktop file, this also
changes the name of the kglobalaccel component. I have adjusted the program so
it checks which of the two old components is active and then sets the shortcuts
on the new one. I have opted for this because we cannot guarantee the order of
update scripts.
wilder-5.22
David Redondo 5 years ago
parent 10d647c47a
commit 6e7c616f45
  1. 79
      krunner/update/krunnerglobalshortcuts.cpp
  2. 2
      krunner/update/krunnerglobalshortcuts.upd

@ -1,5 +1,6 @@
/*************************************************************************** /***************************************************************************
* Copyright (C) 2019 by Kai Uwe Broulik <kde@broulik.de> * * Copyright (C) 2019 by Kai Uwe Broulik <kde@broulik.de> *
* Copyright (C) 2020 David Redondo <kde@david-redondo.de> *
* * * *
* This program is free software; you can redistribute it and/or modify * * This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by * * it under the terms of the GNU General Public License as published by *
@ -32,53 +33,49 @@ int main(int argc, char **argv)
{ {
QCoreApplication app(argc, argv); QCoreApplication app(argc, argv);
const auto oldRunCommand = KGlobalAccel::self()->globalShortcut(QStringLiteral("krunner"), QStringLiteral("run command")); const QString oldCompomentName = QStringLiteral("krunner");
const auto oldRunClipboard = KGlobalAccel::self()->globalShortcut(QStringLiteral("krunner"), QStringLiteral("run command on clipboard contents")); const QString oldDesktopFile = QStringLiteral("krunner.desktop");
const QString newDesktopFile = QStringLiteral("org.kde.krunner.desktop");
// Fake krunner and remove the old shortcuts // Since we need to fake those actions, read the translated names from the desktop file
{ KDesktopFile df(QStandardPaths::GenericDataLocation, QStringLiteral("kglobalaccel/") + newDesktopFile);
KActionCollection oldCollection(static_cast<QObject *>(nullptr)); QString displayName = QStringLiteral("KRunner");
oldCollection.setComponentName(QStringLiteral("krunner")); if (!df.readName().isEmpty()) {
displayName = df.readName();
QAction *oldAction = new QAction();
oldCollection.addAction(QStringLiteral("run command"), oldAction);
KGlobalAccel::self()->setDefaultShortcut(oldAction, {});
KGlobalAccel::self()->removeAllShortcuts(oldAction);
QAction *oldClipboard = new QAction();
oldCollection.addAction(QStringLiteral("run command on clipboard contents"), oldClipboard);
KGlobalAccel::self()->setDefaultShortcut(oldClipboard, {});
KGlobalAccel::self()->removeAllShortcuts(oldClipboard);
} }
const QString clipboardActionName = df.actionGroup(QStringLiteral("RunClipboard")).readEntry(QStringLiteral("Name"), QStringLiteral("Run command on clipboard contents"));
// Fake krunner.desktop launcher and transfer the shortcuts over KActionCollection shortCutActions(nullptr, oldDesktopFile);
{ shortCutActions.setComponentDisplayName(displayName);
// Since we need to fake those actions, read the translated names from the desktop file QAction runCommandAction(displayName);
KDesktopFile df(QStandardPaths::GenericDataLocation, QStringLiteral("kglobalaccel/krunner.desktop")); shortCutActions.addAction(QStringLiteral("_launch"), &runCommandAction);
QAction runClipboardAction(clipboardActionName);
QString displayName = QStringLiteral("KRunner"); shortCutActions.addAction(QStringLiteral("RunClipboard"), &runClipboardAction);
if (!df.readName().isEmpty()) {
displayName = df.readName();
}
const QString clipboardActionName = QList<QKeySequence> oldRunCommand;
df.actionGroup(QStringLiteral("RunClipboard")).readEntry(QStringLiteral("Name"), QStringLiteral("Run command on clipboard contents")); QList<QKeySequence> oldRunClipboard;
if (KGlobalAccel::isComponentActive(oldCompomentName)) {
KActionCollection shortCutActions(static_cast<QObject *>(nullptr)); oldRunCommand = KGlobalAccel::self()->globalShortcut(oldCompomentName, QStringLiteral("run command"));
shortCutActions.setComponentName(QStringLiteral("krunner.desktop")); oldRunClipboard = KGlobalAccel::self()->globalShortcut(oldCompomentName, QStringLiteral("run command on clipboard contents"));
shortCutActions.setComponentDisplayName(displayName); KGlobalAccel::self()->cleanComponent(oldCompomentName);
} else if(KGlobalAccel::isComponentActive(oldDesktopFile)) {
oldRunCommand = KGlobalAccel::self()->globalShortcut(oldDesktopFile, runCommandAction.objectName());
oldRunClipboard = KGlobalAccel::self()->globalShortcut(oldDesktopFile, runClipboardAction.objectName());
KGlobalAccel::self()->cleanComponent(oldDesktopFile);
} else {
return 0;
}
if (!oldRunCommand.isEmpty()) { shortCutActions.takeAction(&runCommandAction);
QAction *runCommandAction = new QAction(displayName); shortCutActions.takeAction(&runClipboardAction);
shortCutActions.addAction(QStringLiteral("_launch"), runCommandAction); shortCutActions.setComponentName(newDesktopFile);
KGlobalAccel::self()->setShortcut(runCommandAction, oldRunCommand, KGlobalAccel::NoAutoloading); shortCutActions.addActions({&runCommandAction, &runClipboardAction});
}
if (!oldRunClipboard.isEmpty()) { if (!oldRunCommand.isEmpty()) {
QAction *runClipboardAction = new QAction(clipboardActionName); KGlobalAccel::self()->setShortcut(&runCommandAction, oldRunCommand, KGlobalAccel::NoAutoloading);
shortCutActions.addAction(QStringLiteral("RunClipboard"), runClipboardAction); }
KGlobalAccel::self()->setShortcut(runClipboardAction, oldRunClipboard, KGlobalAccel::NoAutoloading); if (!oldRunClipboard.isEmpty()) {
} KGlobalAccel::self()->setShortcut(&runClipboardAction, oldRunClipboard, KGlobalAccel::NoAutoloading);
} }
return 0; return 0;

@ -1,3 +1,3 @@
Version=5 Version=5
Id=5.17KRunnerGlobalShortcuts Id=5.22KRunnerGlobalShortcuts
Script=krunnerglobalshortcuts Script=krunnerglobalshortcuts

Loading…
Cancel
Save