File indexing completed on 2024-04-28 03:56:48
0001 /* 0002 SPDX-FileCopyrightText: 2021 Alexander Lohnau <alexander.lohnau@gmx.de> 0003 SPDX-License-Identifier: LGPL-2.0-or-later 0004 */ 0005 0006 #include <KRunner/AbstractRunner> 0007 #include <KRunner/Action> 0008 #include <QEventLoop> 0009 #include <QThread> 0010 #include <QTimer> 0011 0012 using namespace KRunner; 0013 0014 class FakeRunner : public AbstractRunner 0015 { 0016 public: 0017 explicit FakeRunner(QObject *parent, const KPluginMetaData &metadata) 0018 : AbstractRunner(parent, metadata) 0019 , m_action("someid", "sometext", "dialog-ok") 0020 { 0021 } 0022 ~FakeRunner() 0023 { 0024 // qWarning() << Q_FUNC_INFO; 0025 } 0026 0027 void match(RunnerContext &context) override 0028 { 0029 // Do not use nested event loop, because that would be quit when quitting the QThread's event loop 0030 QThread::msleep(50); 0031 if (context.query().startsWith(QLatin1String("foo"))) { 0032 context.addMatch(createDummyMatch(QStringLiteral("foo"), 0.1)); 0033 context.addMatch(createDummyMatch(QStringLiteral("bar"), 0.2)); 0034 } 0035 } 0036 0037 private: 0038 QueryMatch createDummyMatch(const QString &text, qreal relevance) 0039 { 0040 QueryMatch queryMatch(this); 0041 queryMatch.setId(text); 0042 queryMatch.setText(text); 0043 queryMatch.setRelevance(relevance); 0044 queryMatch.setActions({m_action}); 0045 return queryMatch; 0046 } 0047 KRunner::Action m_action; 0048 };