Changeset View
Changeset View
Standalone View
Standalone View
autotests/testremoterunner.cpp
Show All 11 Lines | |||||
12 | * | 12 | * | ||
13 | * You should have received a copy of the GNU Library General Public | 13 | * You should have received a copy of the GNU Library General Public | ||
14 | * License along with this program; if not, write to the | 14 | * License along with this program; if not, write to the | ||
15 | * Free Software Foundation, Inc., | 15 | * Free Software Foundation, Inc., | ||
16 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | 16 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | ||
17 | */ | 17 | */ | ||
18 | 18 | | |||
19 | #include <QCoreApplication> | 19 | #include <QCoreApplication> | ||
20 | #include <QDBusConnection> | | |||
21 | | ||||
22 | #include <iostream> | 20 | #include <iostream> | ||
23 | 21 | | |||
24 | #include "testremoterunner.h" | 22 | #include "testremoterunner.h" | ||
25 | #include "krunner1adaptor.h" | | |||
26 | 23 | | |||
27 | //Test DBus runner, if the search term contains "foo" it returns a match, otherwise nothing | 24 | //Test DBus runner, if the search term contains "foo" it returns a match, otherwise nothing | ||
28 | //Run prints a line to stdout | 25 | //Run prints a line to stdout | ||
29 | 26 | | |||
30 | TestRemoteRunner::TestRemoteRunner(const QString &serviceName) | 27 | TestRemoteRunner::TestRemoteRunner(const QString &serviceName) | ||
28 | : KDBusRunner::AbstractRunner(QStringLiteral("/dave"), serviceName) | ||||
31 | { | 29 | { | ||
32 | new Krunner1Adaptor(this); | | |||
33 | qDBusRegisterMetaType<RemoteMatch>(); | | |||
34 | qDBusRegisterMetaType<RemoteMatches>(); | | |||
35 | qDBusRegisterMetaType<RemoteAction>(); | | |||
36 | qDBusRegisterMetaType<RemoteActions>(); | | |||
37 | QDBusConnection::sessionBus().registerService(serviceName); | | |||
38 | QDBusConnection::sessionBus().registerObject(QStringLiteral("/dave"), this); | | |||
39 | } | 30 | } | ||
40 | 31 | | |||
41 | RemoteMatches TestRemoteRunner::Match(const QString& searchTerm) | 32 | void TestRemoteRunner::handleMatchRequest(const KDBusRunner::MatchReply::Ptr &matchReply) | ||
42 | { | 33 | { | ||
43 | RemoteMatches ms; | 34 | if (matchReply->query().contains(QLatin1String("foo"))) { | ||
44 | if (searchTerm.contains(QLatin1String("foo"))) { | 35 | matchReply->addMatches({{ | ||
45 | RemoteMatch m; | 36 | QStringLiteral("id1"), | ||
46 | m.id = QStringLiteral("id1"); | 37 | QStringLiteral("Match 1"), | ||
47 | m.text = QStringLiteral("Match 1"); | 38 | QStringLiteral("icon1"), | ||
48 | m.iconName = QStringLiteral("icon1"); | 39 | KDBusRunner::QueryMatch::ExactMatch, | ||
49 | m.type = Plasma::QueryMatch::ExactMatch; | 40 | 0.8, | ||
50 | m.relevance = 0.8; | 41 | {} | ||
51 | ms << m; | 42 | }}); | ||
52 | } | 43 | } | ||
53 | return ms; | | |||
54 | | ||||
55 | } | 44 | } | ||
56 | 45 | | |||
57 | RemoteActions TestRemoteRunner::Actions() | 46 | KDBusRunner::Actions TestRemoteRunner::actions() const | ||
58 | { | 47 | { | ||
59 | RemoteAction action; | 48 | return {{ | ||
60 | action.id = QStringLiteral("action1"); | 49 | QStringLiteral("action1"), | ||
61 | action.text = QStringLiteral("Action 1"); | 50 | QStringLiteral("Action 1"), | ||
62 | action.iconName = QStringLiteral("document-browser"); | 51 | QStringLiteral("document-browser") | ||
63 | 52 | }}; | |||
64 | return RemoteActions({action}); | | |||
65 | } | 53 | } | ||
66 | 54 | | |||
67 | void TestRemoteRunner::Run(const QString &id, const QString &actionId) | 55 | void TestRemoteRunner::run(const QString &matchId, const QString &actionId) | ||
68 | { | 56 | { | ||
69 | std::cout << "Running:" << qPrintable(id) << ":" << qPrintable(actionId) << std::endl; | 57 | std::cout << "Running:" << qPrintable(matchId) << ":" << qPrintable(actionId) << std::endl; | ||
70 | std::cout.flush(); | 58 | std::cout.flush(); | ||
71 | } | 59 | } | ||
72 | 60 | | |||
73 | int main(int argc, char ** argv) | 61 | int main(int argc, char ** argv) | ||
74 | { | 62 | { | ||
75 | QCoreApplication app(argc, argv); | 63 | QCoreApplication app(argc, argv); | ||
76 | Q_ASSERT(app.arguments().count() == 2); | 64 | Q_ASSERT(app.arguments().count() == 2); | ||
77 | TestRemoteRunner r(app.arguments()[1]); | 65 | TestRemoteRunner r(app.arguments()[1]); | ||
66 | r.setEnabled(); | ||||
78 | app.exec(); | 67 | app.exec(); | ||
79 | } | 68 | } |