diff --git a/CMakeLists.txt b/CMakeLists.txt --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -25,7 +25,7 @@ include(KDEPackageAppTemplates) find_package(KF5 ${KF5_MIN_VERSION} REQUIRED COMPONENTS - Plasma DocTools Runner JsEmbed NotifyConfig Su NewStuff Wallet + Plasma DocTools DBusRunner Runner JsEmbed NotifyConfig Su NewStuff Wallet IdleTime Declarative TextWidgets KDELibs4Support Crash GlobalAccel DBusAddons Wayland CoreAddons) find_package(KF5NetworkManagerQt ${KF5_MIN_VERSION}) diff --git a/runners/baloo/CMakeLists.txt b/runners/baloo/CMakeLists.txt --- a/runners/baloo/CMakeLists.txt +++ b/runners/baloo/CMakeLists.txt @@ -4,15 +4,13 @@ set(baloosearchrunner_SRCS baloosearchrunner.cpp) -qt5_add_dbus_adaptor(baloosearchrunner_SRCS "org.kde.krunner1.xml" baloosearchrunner.h SearchRunner) add_executable(baloorunner ${baloosearchrunner_SRCS}) target_link_libraries(baloorunner - KF5::Runner + KF5::DBusRunner KF5::KIOWidgets KF5::I18n KF5::Baloo - Qt5::DBus ) configure_file(org.kde.baloorunner.service.in diff --git a/runners/baloo/baloosearchrunner.h b/runners/baloo/baloosearchrunner.h --- a/runners/baloo/baloosearchrunner.h +++ b/runners/baloo/baloosearchrunner.h @@ -22,34 +22,27 @@ #ifndef _BALOO_SEARCH_RUNNER_H_ #define _BALOO_SEARCH_RUNNER_H_ -#include -#include -#include - -#include -#include "dbusutils_p.h" +#include class QTimer; -class SearchRunner : public QObject, protected QDBusContext +class SearchRunner : public KDBusRunner::AbstractRunner { Q_OBJECT public: explicit SearchRunner(QObject* parent=nullptr); ~SearchRunner() override; - RemoteActions Actions(); - RemoteMatches Match(const QString &searchTerm); - void Run(const QString &id, const QString &actionId); + KDBusRunner::Actions actions() const override; + void handleMatchRequest(const KDBusRunner::MatchReply::Ptr &matchReply) override; + void run(const QString &matchId, const QString &actionId) override; private: void performMatch(); - RemoteMatches matchInternal(const QString &searchTerm, const QString& type, - const QString& category); + void matchInternal(const QString &type, const QString &category); - QDBusMessage m_lastRequest; - QString m_searchTerm; + KDBusRunner::MatchReply::Ptr m_matchReply; QTimer *m_timer = nullptr; }; diff --git a/runners/baloo/baloosearchrunner.cpp b/runners/baloo/baloosearchrunner.cpp --- a/runners/baloo/baloosearchrunner.cpp +++ b/runners/baloo/baloosearchrunner.cpp @@ -25,23 +25,18 @@ #include #include #include -#include #include #include #include #include #include -#include #include #include #include #include -#include "dbusutils_p.h" -#include "krunner1adaptor.h" - static const QString s_openParentDirId = QStringLiteral("openParentDir"); int main (int argc, char **argv) @@ -53,49 +48,38 @@ QApplication::setQuitOnLastWindowClosed(false); QApplication app(argc, argv); //KRun needs widgets for error message boxes SearchRunner r; + r.setEnabled(); return app.exec(); } SearchRunner::SearchRunner(QObject* parent) - : QObject(parent), + : KDBusRunner::AbstractRunner(QStringLiteral("/runner"), QStringLiteral("org.kde.runners.baloo"), parent), m_timer(new QTimer(this)) { m_timer->setSingleShot(true); connect(m_timer, &QTimer::timeout, this, &SearchRunner::performMatch); - - new Krunner1Adaptor(this); - qDBusRegisterMetaType(); - qDBusRegisterMetaType(); - qDBusRegisterMetaType(); - qDBusRegisterMetaType(); - QDBusConnection::sessionBus().registerObject(QStringLiteral("/runner"), this); - QDBusConnection::sessionBus().registerService(QStringLiteral("org.kde.runners.baloo")); } SearchRunner::~SearchRunner() { } -RemoteActions SearchRunner::Actions() +KDBusRunner::Actions SearchRunner::actions() const { - return RemoteActions({RemoteAction{ + return {{ s_openParentDirId, i18n("Open Containing Folder"), QStringLiteral("document-open-folder") - }}); + }}; } -RemoteMatches SearchRunner::Match(const QString& searchTerm) +void SearchRunner::handleMatchRequest(const KDBusRunner::MatchReply::Ptr &matchReply) { - setDelayedReply(true); - - if (m_lastRequest.type() != QDBusMessage::InvalidMessage) { - QDBusConnection::sessionBus().send(m_lastRequest.createReply(QVariantList())); - } - - m_lastRequest = message(); - m_searchTerm = searchTerm; + // discard any still to-do reply by dropping its reference here (-> auto-submit as empty reply) + // assuming for now there is only one instance asking so quickly in a row and + // which also currently has no option to repull outdated requests + m_matchReply = matchReply; // Baloo (as of 2014-11-20) is single threaded. It has an internal mutex which results in // queries being queued one after another. Also, Baloo is really really slow for small queries @@ -106,41 +90,38 @@ // int waitTimeMs = 0; - if (searchTerm.length() <= 3) { + if (m_matchReply->query().length() <= 3) { waitTimeMs = 100; } + //we're still using the event delayed call even when the length is < 3 so that if we have multiple Match() calls in our DBus queue, we only process the last one m_timer->start(waitTimeMs); - - return RemoteMatches(); } void SearchRunner::performMatch() { - RemoteMatches matches; - matches << matchInternal(m_searchTerm, QStringLiteral("Audio"), i18n("Audio")); - matches << matchInternal(m_searchTerm, QStringLiteral("Image"), i18n("Image")); - matches << matchInternal(m_searchTerm, QStringLiteral("Document"), i18n("Document")); - matches << matchInternal(m_searchTerm, QStringLiteral("Video"), i18n("Video")); - matches << matchInternal(m_searchTerm, QStringLiteral("Folder"), i18n("Folder")); - matches << matchInternal(m_searchTerm, QStringLiteral("Archive"), i18n("Archive")); - matches << matchInternal(m_searchTerm, QStringLiteral("Spreadsheet"), i18n("Spreadsheet")); - matches << matchInternal(m_searchTerm, QStringLiteral("Presentation"), i18n("Presentation")); - - QDBusConnection::sessionBus().send(m_lastRequest.createReply(QVariant::fromValue(matches))); - m_lastRequest = QDBusMessage(); + matchInternal(QStringLiteral("Audio"), i18n("Audio")); + matchInternal(QStringLiteral("Image"), i18n("Image")); + matchInternal(QStringLiteral("Document"), i18n("Document")); + matchInternal(QStringLiteral("Video"), i18n("Video")); + matchInternal(QStringLiteral("Folder"), i18n("Folder")); + matchInternal(QStringLiteral("Archive"), i18n("Archive")); + matchInternal(QStringLiteral("Spreadsheet"), i18n("Spreadsheet")); + matchInternal(QStringLiteral("Presentation"), i18n("Presentation")); + m_matchReply->submit(); + m_matchReply.reset(); } -RemoteMatches SearchRunner::matchInternal(const QString& searchTerm, const QString &type, const QString &category) +void SearchRunner::matchInternal(const QString &type, const QString &category) { Baloo::Query query; - query.setSearchString(searchTerm); + query.setSearchString(m_matchReply->query()); query.setType(type); query.setLimit(10); Baloo::ResultIterator it = query.exec(); - RemoteMatches matches; + KDBusRunner::QueryMatches matches; QMimeDatabase mimeDb; @@ -152,14 +133,14 @@ // Anyway, that's why we're starting with .75 float relevance = .75; while (it.next()) { - RemoteMatch match; + KDBusRunner::QueryMatch match; QString localUrl = it.filePath(); const QUrl url = QUrl::fromLocalFile(localUrl); match.id = it.filePath(); match.text = url.fileName(); match.iconName = mimeDb.mimeTypeForFile(localUrl).iconName(); match.relevance = relevance; - match.type = Plasma::QueryMatch::PossibleMatch; + match.type = KDBusRunner::QueryMatch::PossibleMatch; QVariantMap properties; QString folderPath = url.adjusted(QUrl::RemoveFilename | QUrl::StripTrailingSlash).toLocalFile(); @@ -177,12 +158,12 @@ matches << match; } - return matches; + m_matchReply->addMatches(matches); } -void SearchRunner::Run(const QString& id, const QString& actionId) +void SearchRunner::run(const QString& matchId, const QString& actionId) { - const QUrl url = QUrl::fromLocalFile(id); + const QUrl url = QUrl::fromLocalFile(matchId); if (actionId == s_openParentDirId) { KIO::highlightInFileManager({url}); return; diff --git a/runners/baloo/dbusutils_p.h b/runners/baloo/dbusutils_p.h deleted file mode 100644 --- a/runners/baloo/dbusutils_p.h +++ /dev/null @@ -1,81 +0,0 @@ -#pragma once - -#include -#include -#include -#include -#include - -struct RemoteMatch -{ - //sssuda{sv} - QString id; - QString text; - QString iconName; - Plasma::QueryMatch::Type type = Plasma::QueryMatch::NoMatch; - qreal relevance = 0; - QVariantMap properties; -}; - -typedef QList RemoteMatches; - -struct RemoteAction -{ - QString id; - QString text; - QString iconName; -}; - -typedef QList RemoteActions; - -inline QDBusArgument &operator<< (QDBusArgument &argument, const RemoteMatch &match) { - argument.beginStructure(); - argument << match.id; - argument << match.text; - argument << match.iconName; - argument << match.type; - argument << match.relevance; - argument << match.properties; - argument.endStructure(); - return argument; -} - -inline const QDBusArgument &operator>>(const QDBusArgument &argument, RemoteMatch &match) { - argument.beginStructure(); - argument >> match.id; - argument >> match.text; - argument >> match.iconName; - uint type; - argument >> type; - match.type = (Plasma::QueryMatch::Type)type; - argument >> match.relevance; - argument >> match.properties; - argument.endStructure(); - - return argument; -} - -inline QDBusArgument &operator<< (QDBusArgument &argument, const RemoteAction &action) -{ - argument.beginStructure(); - argument << action.id; - argument << action.text; - argument << action.iconName; - argument.endStructure(); - return argument; -} - -inline const QDBusArgument &operator>>(const QDBusArgument &argument, RemoteAction &action) { - argument.beginStructure(); - argument >> action.id; - argument >> action.text; - argument >> action.iconName; - argument.endStructure(); - return argument; -} - -Q_DECLARE_METATYPE(RemoteMatch) -Q_DECLARE_METATYPE(RemoteMatches) -Q_DECLARE_METATYPE(RemoteAction) -Q_DECLARE_METATYPE(RemoteActions) - diff --git a/runners/baloo/org.kde.krunner1.xml b/runners/baloo/org.kde.krunner1.xml deleted file mode 100644 --- a/runners/baloo/org.kde.krunner1.xml +++ /dev/null @@ -1,55 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - -