diff --git a/krunner/CMakeLists.txt b/krunner/CMakeLists.txt --- a/krunner/CMakeLists.txt +++ b/krunner/CMakeLists.txt @@ -18,7 +18,6 @@ KF5::Declarative KF5::I18n KF5::PlasmaQuick - KF5::GlobalAccel KF5::DBusAddons KF5::Crash KF5::WaylandClient @@ -29,7 +28,7 @@ install(TARGETS krunner ${KDE_INSTALL_TARGETS_DEFAULT_ARGS}) install(FILES ${krunner_dbusAppXML} DESTINATION ${KDE_INSTALL_DBUSINTERFACEDIR} ) -install(FILES krunner.desktop DESTINATION ${KDE_INSTALL_AUTOSTARTDIR}) +install(FILES krunner.desktop DESTINATION ${DATA_INSTALL_DIR}/kglobalaccel) set(CMAKECONFIG_INSTALL_DIR "${KDE_INSTALL_CMAKEPACKAGEDIR}/KRunnerAppDBusInterface") configure_package_config_file(KRunnerAppDBusInterfaceConfig.cmake.in diff --git a/krunner/krunner.desktop b/krunner/krunner.desktop --- a/krunner/krunner.desktop +++ b/krunner/krunner.desktop @@ -49,4 +49,11 @@ X-DBUS-StartupType=Unique X-DBUS-ServiceName=org.kde.krunner X-KDE-StartupNotify=false -X-KDE-autostart-phase=0 +X-KDE-Shortcuts=Alt+Space,Alt+F2,Search +Actions=RunClipboard + +[Desktop Action RunClipboard] +Exec=krunner -c +Name=Run command on clipboard contents +X-KDE-Shortcuts=Alt+Shift+F2 + diff --git a/krunner/main.cpp b/krunner/main.cpp --- a/krunner/main.cpp +++ b/krunner/main.cpp @@ -25,6 +25,7 @@ #include #include #include +#include #include #include @@ -37,11 +38,10 @@ #include "view.h" -static QCommandLineParser parser; - int main(int argc, char **argv) { qunsetenv("QT_DEVICE_PIXEL_RATIO"); + QCommandLineParser parser; QCoreApplication::setAttribute(Qt::AA_DisableHighDpiScaling); const bool qpaVariable = qEnvironmentVariableIsSet("QT_QPA_PLATFORM"); @@ -68,7 +68,16 @@ KAboutData::setApplicationData(aboutData); app.setQuitOnLastWindowClosed(false); + QCommandLineOption clipboardOption({QStringLiteral("c"), QStringLiteral("clipboard")}, + i18n("Use the clipboard contents as query for KRunner")); + QCommandLineOption daemonOption({QStringLiteral("d"), QStringLiteral("daemon")}, + i18n("Start KRunner in the background, don't show it.")); + parser.addOption(clipboardOption); + parser.addOption(daemonOption); + parser.addPositionalArgument(QStringLiteral("query"), i18n("The query to run, only used if -c is not provided")); + aboutData.setupCommandLine(&parser); + parser.addHelpOption(); parser.addVersionOption(); @@ -90,9 +99,30 @@ QObject::connect(&app, &QGuiApplication::saveStateRequest, disableSessionManagement); View view; - view.setVisible(false); - QObject::connect(&service, &KDBusService::activateRequested, &view, &View::display); + auto updateVisibility = [&view, &parser, &clipboardOption]() { + const QString query = parser.positionalArguments().value(0); + + if (parser.isSet(clipboardOption)) { + view.displayWithClipboardContents(); + } else if (!query.isEmpty()) { + view.query(query); + } else { + view.display(); + } + }; + + if (parser.isSet(daemonOption)) { + view.setVisible(false); + } else { + QTimer::singleShot(100, updateVisibility); + } + + QObject::connect(&service, &KDBusService::activateRequested, &view, [&view, &parser, &clipboardOption, updateVisibility](const QStringList &arguments, const QString &workingDirectory) { + Q_UNUSED(workingDirectory) + parser.parse(arguments); + updateVisibility(); + }); return app.exec(); } diff --git a/krunner/update/CMakeLists.txt b/krunner/update/CMakeLists.txt --- a/krunner/update/CMakeLists.txt +++ b/krunner/update/CMakeLists.txt @@ -1,5 +1,5 @@ set(krunnerplugins_SRCS - main.cpp + krunnerplugins.cpp ) add_executable(krunnerplugins ${krunnerplugins_SRCS}) @@ -10,3 +10,14 @@ install(FILES krunnerplugins.upd DESTINATION ${KDE_INSTALL_KCONFUPDATEDIR}) +set(krunnerglobalshortcuts_SRCS + krunnerglobalshortcuts.cpp + ) + +add_executable(krunnerglobalshortcuts ${krunnerglobalshortcuts_SRCS}) + +target_link_libraries(krunnerglobalshortcuts KF5::CoreAddons KF5::Service KF5::Runner KF5::ConfigCore) + +install(TARGETS krunnerglobalshortcuts DESTINATION ${KDE_INSTALL_LIBDIR}/kconf_update_bin/) +install(FILES krunnerglobalshortcuts.upd DESTINATION ${KDE_INSTALL_KCONFUPDATEDIR}) + diff --git a/krunner/update/main.cpp b/krunner/update/krunnerglobalshortcuts.cpp rename from krunner/update/main.cpp rename to krunner/update/krunnerglobalshortcuts.cpp --- a/krunner/update/main.cpp +++ b/krunner/update/krunnerglobalshortcuts.cpp @@ -1,5 +1,5 @@ /*************************************************************************** - * Copyright (C) 2016 by Marco Martin * + * Copyright (C) 2018 by Marco Martin * * * * 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 * @@ -18,50 +18,22 @@ ***************************************************************************/ #include -#include #include -#include -#include #include #include #include -#include -#include -void migrateEnabledPlugins() -{ - KSharedConfig::Ptr config = KSharedConfig::openConfig("krunnerrc"); - KConfigGroup runnerManagerGroup(config, "PlasmaRunnerManager"); - KConfigGroup pluginsGroup(config, "Plugins"); - - QStringList enabledCategories = runnerManagerGroup.readEntry("enabledCategories", QStringList()); - - if (enabledCategories.isEmpty()) { - return; - } - Plasma::RunnerManager *manager = new Plasma::RunnerManager(); - manager->reloadConfiguration(); - for (Plasma::AbstractRunner *runner : manager->runners()) { - pluginsGroup.writeEntry(runner->metadata().pluginName() + QStringLiteral("Enabled"), false); - for (auto category : runner->categories()) { - if (enabledCategories.contains(category)) { - pluginsGroup.writeEntry(runner->metadata().pluginName() + QStringLiteral("Enabled"), true); - break; - } - } - } - - runnerManagerGroup.deleteEntry("enabledCategories"); -} int main(int argc, char **argv) { QCoreApplication app(argc, argv); - migrateEnabledPlugins(); + KSharedConfig::Ptr config = KSharedConfig::openConfig("kglobalshortcutsrc"); + KConfigGroup runnergroup(config, "krunner"); + runnergroup.deleteGroup(); return 0; } diff --git a/krunner/update/krunnerglobalshortcuts.upd b/krunner/update/krunnerglobalshortcuts.upd new file mode 100644 --- /dev/null +++ b/krunner/update/krunnerglobalshortcuts.upd @@ -0,0 +1,3 @@ +Version=5 +Id=5.13KRunnerGlobalShortcuts +Script=krunnerglobalshortcuts diff --git a/krunner/update/main.cpp b/krunner/update/krunnerplugins.cpp rename from krunner/update/main.cpp rename to krunner/update/krunnerplugins.cpp diff --git a/krunner/view.cpp b/krunner/view.cpp --- a/krunner/view.cpp +++ b/krunner/view.cpp @@ -32,7 +32,6 @@ #include #include #include -#include #include #include #include @@ -70,22 +69,6 @@ new AppAdaptor(this); QDBusConnection::sessionBus().registerObject(QStringLiteral("/App"), this); - QAction *a = new QAction(nullptr); - QObject::connect(a, &QAction::triggered, this, &View::displayOrHide); - a->setText(i18n("Run Command")); - a->setObjectName(QStringLiteral("run command")); - a->setProperty("componentDisplayName", i18nc("Name for krunner shortcuts category", "Run Command")); - KGlobalAccel::self()->setDefaultShortcut(a, QList() << QKeySequence(Qt::ALT + Qt::Key_Space), KGlobalAccel::NoAutoloading); - KGlobalAccel::self()->setShortcut(a, QList() << QKeySequence(Qt::ALT + Qt::Key_Space) << QKeySequence(Qt::ALT + Qt::Key_F2) << Qt::Key_Search); - - a = new QAction(nullptr); - QObject::connect(a, &QAction::triggered, this, &View::displayWithClipboardContents); - a->setText(i18n("Run Command on clipboard contents")); - a->setObjectName(QStringLiteral("run command on clipboard contents")); - a->setProperty("componentDisplayName", i18nc("Name for krunner shortcuts category", "Run Command")); - KGlobalAccel::self()->setDefaultShortcut(a, QList() << QKeySequence(Qt::ALT+Qt::SHIFT+Qt::Key_F2)); - KGlobalAccel::self()->setShortcut(a, QList() << QKeySequence(Qt::ALT+Qt::SHIFT+Qt::Key_F2)); - m_qmlObj = new KDeclarative::QmlObject(this); m_qmlObj->setInitializationDelayed(true); connect(m_qmlObj, &KDeclarative::QmlObject::finished, this, &View::objectIncubated); @@ -135,6 +118,7 @@ } connect(qGuiApp, &QGuiApplication::focusWindowChanged, this, &View::slotFocusWindowChanged); + // QTimer::singleShot(100, this, [this]() {display();}); } View::~View()