1/*
2 SPDX-FileCopyrightText: 2017, 2018 David Edmundson <davidedmundson@kde.org>
3 SPDX-FileCopyrightText: 2020 Alexander Lohnau <alexander.lohnau@gmx.de>
4 SPDX-FileCopyrightText: 2020 Kai Uwe Broulik <kde@broulik.de>
5
6 SPDX-License-Identifier: LGPL-2.0-or-later
7*/
8
9#pragma once
10
11#include "action.h"
12#include <KRunner/QueryMatch>
13#include <QDBusArgument>
14#include <QList>
15#include <QString>
16#include <QVariantMap>
17
18struct RemoteMatch {
19 // sssida{sv}
20 QString id;
21 QString text;
22 QString iconName;
23 int categoryRelevance = qToUnderlying(e: KRunner::QueryMatch::CategoryRelevance::Lowest);
24 qreal relevance = 0;
25 QVariantMap properties;
26};
27
28typedef QList<RemoteMatch> RemoteMatches;
29
30struct RemoteImage {
31 // iiibiiay (matching notification spec image-data attribute)
32 int width = 0;
33 int height = 0;
34 int rowStride = 0;
35 bool hasAlpha = false;
36 int bitsPerSample = 0;
37 int channels = 0;
38 QByteArray data;
39};
40
41inline QDBusArgument &operator<<(QDBusArgument &argument, const RemoteMatch &match)
42{
43 argument.beginStructure();
44 argument << match.id;
45 argument << match.text;
46 argument << match.iconName;
47 argument << match.categoryRelevance;
48 argument << match.relevance;
49 argument << match.properties;
50 argument.endStructure();
51 return argument;
52}
53
54inline const QDBusArgument &operator>>(const QDBusArgument &argument, RemoteMatch &match)
55{
56 argument.beginStructure();
57 argument >> match.id;
58 argument >> match.text;
59 argument >> match.iconName;
60 argument >> match.categoryRelevance;
61 argument >> match.relevance;
62 argument >> match.properties;
63 argument.endStructure();
64
65 return argument;
66}
67
68inline QDBusArgument &operator<<(QDBusArgument &argument, const KRunner::Action &action)
69{
70 argument.beginStructure();
71 argument << action.id();
72 argument << action.text();
73 argument << action.iconSource();
74 argument.endStructure();
75 return argument;
76}
77
78inline const QDBusArgument &operator>>(const QDBusArgument &argument, KRunner::Action &action)
79{
80 QString id;
81 QString text;
82 QString iconName;
83 argument.beginStructure();
84 argument >> id;
85 argument >> text;
86 argument >> iconName;
87 argument.endStructure();
88 action = KRunner::Action(id, iconName, text);
89 return argument;
90}
91
92inline QDBusArgument &operator<<(QDBusArgument &argument, const RemoteImage &image)
93{
94 argument.beginStructure();
95 argument << image.width;
96 argument << image.height;
97 argument << image.rowStride;
98 argument << image.hasAlpha;
99 argument << image.bitsPerSample;
100 argument << image.channels;
101 argument << image.data;
102 argument.endStructure();
103 return argument;
104}
105
106inline const QDBusArgument &operator>>(const QDBusArgument &argument, RemoteImage &image)
107{
108 argument.beginStructure();
109 argument >> image.width;
110 argument >> image.height;
111 argument >> image.rowStride;
112 argument >> image.hasAlpha;
113 argument >> image.bitsPerSample;
114 argument >> image.channels;
115 argument >> image.data;
116 argument.endStructure();
117 return argument;
118}
119
120Q_DECLARE_METATYPE(QList<KRunner::Action>)
121Q_DECLARE_METATYPE(RemoteMatch)
122Q_DECLARE_METATYPE(RemoteMatches)
123Q_DECLARE_METATYPE(RemoteImage)
124

source code of krunner/src/dbusutils_p.h