Skip to content

Commit

Permalink
Use compat namespaces from KRunner API
Browse files Browse the repository at this point in the history
Those will prepare the KF6 transition
  • Loading branch information
alex1701c committed Jun 4, 2023
1 parent 897017c commit 72a9ee4
Show file tree
Hide file tree
Showing 9 changed files with 35 additions and 25 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 3.16)
project(quickwebshortcuts)

set(QT_MIN_VERSION "5.15.0")
set(KF5_MIN_VERSION "5.90.0")
set(KF5_MIN_VERSION "5.91.0")

find_package(ECM 5.12.0 REQUIRED NO_MODULE)
find_package(ECM ${KF5_MIN_VERSION} REQUIRED NO_MODULE)
Expand Down
16 changes: 8 additions & 8 deletions src/quick_web_shortcuts.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#include <searchproviders/DuckDuckGo.h>

QuickWebShortcuts::QuickWebShortcuts(QObject *parent, const KPluginMetaData &pluginMetaData, const QVariantList &args)
: Plasma::AbstractRunner(parent, pluginMetaData, args) {
: KRunner::AbstractRunner(parent, pluginMetaData, args) {
}

QuickWebShortcuts::~QuickWebShortcuts() {
Expand Down Expand Up @@ -178,7 +178,7 @@ void QuickWebShortcuts::filterHistory() {
generalKrunnerConfig.sync();
}

void QuickWebShortcuts::match(Plasma::RunnerContext &context) {
void QuickWebShortcuts::match(KRunner::RunnerContext &context) {
if (!context.isValid()) return;
wasActive = false;

Expand Down Expand Up @@ -221,7 +221,7 @@ void QuickWebShortcuts::match(Plasma::RunnerContext &context) {
}
}

void QuickWebShortcuts::run(const Plasma::RunnerContext &/*context*/, const Plasma::QueryMatch &match) {
void QuickWebShortcuts::run(const KRunner::RunnerContext &/*context*/, const KRunner::QueryMatch &match) {
const QMap<QString, QVariant> payload = match.data().toMap();
const QString url = payload.value(QStringLiteral("url")).toString();
QString launchCommand;
Expand Down Expand Up @@ -251,18 +251,18 @@ void QuickWebShortcuts::run(const Plasma::RunnerContext &/*context*/, const Plas
wasActive = true;
}

Plasma::QueryMatch QuickWebShortcuts::createMatch(const QString &text, const QMap<QString, QVariant> &data, const bool useGlobe) {
Plasma::QueryMatch match(this);
KRunner::QueryMatch QuickWebShortcuts::createMatch(const QString &text, const QMap<QString, QVariant> &data, const bool useGlobe) {
KRunner::QueryMatch match(this);
match.setIcon(useGlobe ? globeIcon : currentSearchEngine.qIcon);
match.setText(text);
match.setData(data);
match.setRelevance(1);
match.setType(Plasma::QueryMatch::ExactMatch);
match.setType(KRunner::QueryMatch::ExactMatch);
return match;
}


void QuickWebShortcuts::searchSuggest(Plasma::RunnerContext &context, const QString &term, const QString &browser) {
void QuickWebShortcuts::searchSuggest(KRunner::RunnerContext &context, const QString &term, const QString &browser) {

if (searchSuggestionChoice == Config::SearchSuggestionBing) {
QEventLoop loop;
Expand All @@ -283,7 +283,7 @@ void QuickWebShortcuts::searchSuggest(Plasma::RunnerContext &context, const QStr

}

QList<QAction *> QuickWebShortcuts::actionsForMatch(const Plasma::QueryMatch &match) {
QList<QAction *> QuickWebShortcuts::actionsForMatch(const KRunner::QueryMatch &match) {
if (match.data().toMap().contains(QStringLiteral("browser"))) {
return privateActions;
}
Expand Down
12 changes: 6 additions & 6 deletions src/quick_web_shortcuts.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#include <QRegularExpression>
#include "searchengines/SearchEngine.h"

class QuickWebShortcuts : public Plasma::AbstractRunner {
class QuickWebShortcuts : public KRunner::AbstractRunner {
Q_OBJECT

private:
Expand Down Expand Up @@ -46,16 +46,16 @@ Q_OBJECT
~QuickWebShortcuts() override;

private:
Plasma::QueryMatch createMatch(const QString &text, const QMap<QString, QVariant> &data, bool useGlobe = false);
void searchSuggest(Plasma::RunnerContext &context, const QString &term, const QString &browser = "");
KRunner::QueryMatch createMatch(const QString &text, const QMap<QString, QVariant> &data, bool useGlobe = false);
void searchSuggest(KRunner::RunnerContext &context, const QString &term, const QString &browser = "");

protected Q_SLOTS:
void init() override;
void filterHistory();
void reloadPluginConfiguration(const QString &file = QString());
void match(Plasma::RunnerContext &context) override;
QList<QAction *> actionsForMatch(const Plasma::QueryMatch &match) override;
void run(const Plasma::RunnerContext &context, const Plasma::QueryMatch &match) override;
void match(KRunner::RunnerContext &context) override;
QList<QAction *> actionsForMatch(const KRunner::QueryMatch &match) override;
void run(const KRunner::RunnerContext &context, const KRunner::QueryMatch &match) override;
};

#endif
2 changes: 2 additions & 0 deletions src/searchengines/SearchEngine.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#ifndef QUICKWEBSHORTCUTS_SEARCHENGINE_H
#define QUICKWEBSHORTCUTS_SEARCHENGINE_H

#include <QString>
#include <QIcon>

class SearchEngine {
public:
Expand Down
6 changes: 3 additions & 3 deletions src/searchproviders/Bing.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,15 @@ Q_OBJECT

private:
QNetworkAccessManager *manager;
Plasma::RunnerContext context;
KRunner::RunnerContext context;
const QString query;
const QString market;
const QString browserLaunchCommand;
RequiredData data;
QNetworkReply *reply;

public:
Bing(Plasma::RunnerContext &context, QString query, RequiredData &data, QString market = "en-us",
Bing(KRunner::RunnerContext &context, QString query, RequiredData &data, QString market = "en-us",
QString browserLaunchCommand = "")
: context(context), query(std::move(query)), market(std::move(market)),
browserLaunchCommand(std::move(browserLaunchCommand)), data(data) {
Expand Down Expand Up @@ -94,7 +94,7 @@ public Q_SLOTS:
++data.maxResults;
continue;
}
Plasma::QueryMatch match(data.runner);
KRunner::QueryMatch match(data.runner);
match.setIcon(data.icon);
match.setText(data.searchOptionTemplate.arg(suggestion));
match.setRelevance((float) (19 - i) / 20);
Expand Down
8 changes: 5 additions & 3 deletions src/searchproviders/DuckDuckGo.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,25 @@
#include <QtCore>
#include <utility>
#include <QTextDocument>
#include <QNetworkAccessManager>
#include <KNotifications/KNotification>
#include "RequiredData.h"
#include <KRunner/RunnerContext>

class DuckDuckGo : public QObject {

Q_OBJECT

private:
QNetworkAccessManager *manager;
Plasma::RunnerContext context;
KRunner::RunnerContext context;
const QString query;
const QString browserLaunchCommand;
RequiredData data;
QNetworkReply *reply;

public:
DuckDuckGo(Plasma::RunnerContext &context, QString query, RequiredData data,
DuckDuckGo(KRunner::RunnerContext &context, QString query, RequiredData data,
QString browserLaunchCommand = "") : context(context), query(std::move(query)),
browserLaunchCommand(std::move(browserLaunchCommand)), data(std::move(data)) {
manager = new QNetworkAccessManager(this);
Expand Down Expand Up @@ -83,7 +85,7 @@ public Q_SLOTS:
const int listCount = urlList.count();
for (int i = 0; i < listCount; ++i) {
const QStringList &currentList = urlList.at(i);
Plasma::QueryMatch match(data.runner);
KRunner::QueryMatch match(data.runner);
match.setIcon(data.icon);
match.setText(QString(currentList.at(1))
.remove(QLatin1String("http://"))
Expand Down
9 changes: 6 additions & 3 deletions src/searchproviders/Google.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
#include <QtCore>
#include <KNotifications/KNotification>
#include <utility>
#include <KRunner/QueryMatch>
#include <KRunner/RunnerContext>

#include "RequiredData.h"

class Google : public QObject {
Expand All @@ -13,15 +16,15 @@ Q_OBJECT

private:
QNetworkAccessManager *manager;
Plasma::RunnerContext context;
KRunner::RunnerContext context;
const QString query;
const QString language;
const QString browserLaunchCommand;
RequiredData data;
QNetworkReply *reply;

public:
Google(Plasma::RunnerContext &context,
Google(KRunner::RunnerContext &context,
QString query,
RequiredData data,
QString language = "en",
Expand Down Expand Up @@ -91,7 +94,7 @@ public Q_SLOTS:
const int suggestionCount = suggestions.count();
for (int i = 0; i < suggestionCount && i < data.maxResults; ++i) {
const QString &suggestion = suggestions.at(i);
Plasma::QueryMatch match(data.runner);
KRunner::QueryMatch match(data.runner);
match.setIcon(data.icon);
match.setText(data.searchOptionTemplate.arg(suggestion));
match.setRelevance((float) (19 - i) / 20);
Expand Down
3 changes: 2 additions & 1 deletion src/searchproviders/RequiredData.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@

#include <QNetworkAccessManager>
#include <QIcon>
#include <KRunner/AbstractRunner>

class RequiredData {
public:
QNetworkProxy *proxy = nullptr;
Plasma::AbstractRunner *runner;
KRunner::AbstractRunner *runner;
QString searchEngine;
bool isWebShortcut;
QIcon icon;
Expand Down
2 changes: 2 additions & 0 deletions src/utilities.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

#include <QtCore>
#include <QNetworkProxy>
#include <KSharedConfig>
#include <KConfigGroup>
#include "Config.h"

void initializeConfigFile() {
Expand Down

0 comments on commit 72a9ee4

Please sign in to comment.