From ac7054366dc5e8ad637d6bce5a7f440d5fdf1202 Mon Sep 17 00:00:00 2001 From: Alexander Lohnau Date: Thu, 15 Apr 2021 20:37:09 +0200 Subject: [PATCH] runners: Set urls for matches This saves us the custom implementation of mimeDataForMatch and allows us to get the urls for example in milou, just like we already can with the DBus runners. --- runners/bookmarks/bookmarkmatch.cpp | 1 + runners/bookmarks/bookmarksrunner.cpp | 12 ------------ runners/bookmarks/bookmarksrunner.h | 2 -- runners/locations/locationrunner.cpp | 8 +------- runners/locations/locationrunner.h | 3 --- runners/places/placesrunner.cpp | 12 +----------- runners/places/placesrunner.h | 1 - runners/recentdocuments/recentdocuments.cpp | 8 +------- runners/recentdocuments/recentdocuments.h | 3 --- 9 files changed, 4 insertions(+), 46 deletions(-) diff --git a/runners/bookmarks/bookmarkmatch.cpp b/runners/bookmarks/bookmarkmatch.cpp index 665d48026..35d8fe8f3 100644 --- a/runners/bookmarks/bookmarkmatch.cpp +++ b/runners/bookmarks/bookmarkmatch.cpp @@ -68,6 +68,7 @@ Plasma::QueryMatch BookmarkMatch::asQueryMatch(Plasma::AbstractRunner *runner) match.setText(isNameEmpty ? (!isDescriptionEmpty ? m_description : m_bookmarkURL) : m_bookmarkTitle); match.setData(m_bookmarkURL); + match.setUrls({QUrl(m_bookmarkURL)}); return match; } diff --git a/runners/bookmarks/bookmarksrunner.cpp b/runners/bookmarks/bookmarksrunner.cpp index 0b4fd58f8..f94317be6 100644 --- a/runners/bookmarks/bookmarksrunner.cpp +++ b/runners/bookmarks/bookmarksrunner.cpp @@ -124,16 +124,4 @@ void BookmarksRunner::run(const Plasma::RunnerContext &context, const Plasma::Qu QDesktopServices::openUrl(url); } -QMimeData *BookmarksRunner::mimeDataForMatch(const Plasma::QueryMatch &match) -{ - QMimeData *result = new QMimeData(); - QList urls; - urls << QUrl(match.data().toString()); - result->setUrls(urls); - - result->setText(match.data().toString()); - - return result; -} - #include "bookmarksrunner.moc" diff --git a/runners/bookmarks/bookmarksrunner.h b/runners/bookmarks/bookmarksrunner.h index e6596e60d..f5beef9b0 100644 --- a/runners/bookmarks/bookmarksrunner.h +++ b/runners/bookmarks/bookmarksrunner.h @@ -48,8 +48,6 @@ private: private: Browser *m_browser; BrowserFactory *const m_browserFactory; -protected Q_SLOTS: - QMimeData *mimeDataForMatch(const Plasma::QueryMatch &match) override; private Q_SLOTS: void prep(); diff --git a/runners/locations/locationrunner.cpp b/runners/locations/locationrunner.cpp index d2651f3e7..cc910c33b 100644 --- a/runners/locations/locationrunner.cpp +++ b/runners/locations/locationrunner.cpp @@ -80,6 +80,7 @@ void LocationsRunner::match(Plasma::RunnerContext &context) const QString protocol = url.scheme(); Plasma::QueryMatch match(this); match.setData(url); + match.setUrls({url}); if (!KProtocolInfo::isKnownProtocol(protocol) || KProtocolInfo::isHelperProtocol(protocol)) { const KService::Ptr service = KApplicationTrader::preferredService(QLatin1String("x-scheme-handler/") + protocol); @@ -115,11 +116,4 @@ void LocationsRunner::run(const Plasma::RunnerContext &context, const Plasma::Qu job->start(); } -QMimeData *LocationsRunner::mimeDataForMatch(const Plasma::QueryMatch &match) -{ - QMimeData *result = new QMimeData(); - result->setUrls({match.data().toUrl()}); - return result; -} - #include "locationrunner.moc" diff --git a/runners/locations/locationrunner.h b/runners/locations/locationrunner.h index ed7a8aee3..855e2c09a 100644 --- a/runners/locations/locationrunner.h +++ b/runners/locations/locationrunner.h @@ -31,9 +31,6 @@ public: void match(Plasma::RunnerContext &context) override; void run(const Plasma::RunnerContext &context, const Plasma::QueryMatch &action) override; - -protected Q_SLOTS: - QMimeData *mimeDataForMatch(const Plasma::QueryMatch &match) override; }; #endif diff --git a/runners/places/placesrunner.cpp b/runners/places/placesrunner.cpp index ba0397229..c664a372c 100644 --- a/runners/places/placesrunner.cpp +++ b/runners/places/placesrunner.cpp @@ -130,6 +130,7 @@ void PlacesRunnerHelper::match(Plasma::RunnerContext *c) } else { const QUrl url = KFilePlacesModel::convertedUrl(m_places.url(current_index)); match.setData(url); + match.setUrls({url}); match.setId(url.toDisplayString()); } @@ -169,15 +170,4 @@ void PlacesRunner::run(const Plasma::RunnerContext &context, const Plasma::Query } } -QMimeData *PlacesRunner::mimeDataForMatch(const Plasma::QueryMatch &match) -{ - if (match.data().type() == QVariant::Url) { - QMimeData *result = new QMimeData(); - result->setUrls({match.data().toUrl()}); - return result; - } - - return nullptr; -} - #include "placesrunner.moc" diff --git a/runners/places/placesrunner.h b/runners/places/placesrunner.h index cfa59f71e..b6db56265 100644 --- a/runners/places/placesrunner.h +++ b/runners/places/placesrunner.h @@ -51,7 +51,6 @@ public: void match(Plasma::RunnerContext &context) override; void run(const Plasma::RunnerContext &context, const Plasma::QueryMatch &action) override; - QMimeData *mimeDataForMatch(const Plasma::QueryMatch &match) override; Q_SIGNALS: void doMatch(Plasma::RunnerContext *context); diff --git a/runners/recentdocuments/recentdocuments.cpp b/runners/recentdocuments/recentdocuments.cpp index d23241d6b..f6f0b3513 100644 --- a/runners/recentdocuments/recentdocuments.cpp +++ b/runners/recentdocuments/recentdocuments.cpp @@ -96,6 +96,7 @@ void RecentDocuments::match(Plasma::RunnerContext &context) match.setIconName(KIO::iconNameForUrl(url)); match.setRelevance(relevance); match.setData(QVariant(url)); + match.setUrls({url}); if (url.isLocalFile()) { match.setActions(actions().values()); } @@ -125,11 +126,4 @@ void RecentDocuments::run(const Plasma::RunnerContext &context, const Plasma::Qu job->start(); } -QMimeData *RecentDocuments::mimeDataForMatch(const Plasma::QueryMatch &match) -{ - QMimeData *result = new QMimeData(); - result->setUrls({match.data().toUrl()}); - return result; -} - #include "recentdocuments.moc" diff --git a/runners/recentdocuments/recentdocuments.h b/runners/recentdocuments/recentdocuments.h index a2580ad6d..500031009 100644 --- a/runners/recentdocuments/recentdocuments.h +++ b/runners/recentdocuments/recentdocuments.h @@ -34,9 +34,6 @@ public: void match(Plasma::RunnerContext &context) override; void run(const Plasma::RunnerContext &context, const Plasma::QueryMatch &match) override; - -private Q_SLOTS: - QMimeData *mimeDataForMatch(const Plasma::QueryMatch &match) override; }; #endif