diff --git a/krunner/main.cpp b/krunner/main.cpp --- a/krunner/main.cpp +++ b/krunner/main.cpp @@ -25,6 +25,8 @@ #include #include #include +#include +#include #include #include @@ -37,8 +39,6 @@ #include "view.h" -static QCommandLineParser parser; - int main(int argc, char **argv) { qunsetenv("QT_DEVICE_PIXEL_RATIO"); @@ -68,10 +68,22 @@ KAboutData::setApplicationData(aboutData); app.setQuitOnLastWindowClosed(false); - aboutData.setupCommandLine(&parser); - - parser.process(app); - aboutData.processCommandLine(&parser); + { + QCommandLineParser parser; + QCommandLineOption replaceOption({QStringLiteral("replace")}, i18n("Replace an existing instance")); + parser.addOption(replaceOption); + aboutData.setupCommandLine(&parser); + + parser.process(app); + aboutData.processCommandLine(&parser); + if (parser.isSet(replaceOption)) { + auto message = QDBusMessage::createMethodCall(QStringLiteral("org.kde.krunner"), + QStringLiteral("/MainApplication"), + QStringLiteral("org.qtproject.Qt.QCoreApplication"), + QStringLiteral("quit")); + QDBusConnection::sessionBus().call(message); //deliberately block until it's done, so we register the name after the app quits + } + } if (!KAuthorized::authorize(QStringLiteral("run_command"))) { return -1;