Changeset View
Changeset View
Standalone View
Standalone View
src/desktopportal.cpp
Show All 23 Lines | |||||
24 | #include <QDBusArgument> | 24 | #include <QDBusArgument> | ||
25 | #include <QDBusMessage> | 25 | #include <QDBusMessage> | ||
26 | #include <QDBusConnection> | 26 | #include <QDBusConnection> | ||
27 | #include <QLoggingCategory> | 27 | #include <QLoggingCategory> | ||
28 | 28 | | |||
29 | Q_LOGGING_CATEGORY(XdgDesktopPortalKdeDesktopPortal, "xdg-desktop-portal-kde-desktop-portal") | 29 | Q_LOGGING_CATEGORY(XdgDesktopPortalKdeDesktopPortal, "xdg-desktop-portal-kde-desktop-portal") | ||
30 | 30 | | |||
31 | DesktopPortal::DesktopPortal(QObject *parent) | 31 | DesktopPortal::DesktopPortal(QObject *parent) | ||
32 | : QDBusVirtualObject(parent) | 32 | : QObject(parent) | ||
33 | , m_access(new Access()) | 33 | , m_access(new AccessPortal(this)) | ||
34 | , m_appChooser(new AppChooser()) | 34 | , m_appChooser(new AppChooserPortal(this)) | ||
35 | , m_email(new Email()) | 35 | , m_email(new EmailPortal(this)) | ||
36 | , m_fileChooser(new FileChooser()) | 36 | , m_fileChooser(new FileChooserPortal(this)) | ||
37 | , m_inhibit(new Inhibit()) | 37 | , m_inhibit(new InhibitPortal(this)) | ||
38 | , m_notification(new Notification()) | 38 | , m_notification(new NotificationPortal(this)) | ||
39 | , m_print(new Print()) | 39 | , m_print(new PrintPortal(this)) | ||
40 | { | 40 | { | ||
41 | } | 41 | } | ||
42 | 42 | | |||
43 | DesktopPortal::~DesktopPortal() | 43 | DesktopPortal::~DesktopPortal() | ||
44 | { | 44 | { | ||
45 | delete m_access; | | |||
46 | delete m_appChooser; | | |||
47 | delete m_email; | | |||
48 | delete m_fileChooser; | | |||
49 | delete m_inhibit; | | |||
50 | delete m_notification; | | |||
51 | delete m_print; | | |||
52 | } | | |||
53 | | ||||
54 | bool DesktopPortal::handleMessage(const QDBusMessage &message, const QDBusConnection &connection) | | |||
55 | { | | |||
56 | /* Check to make sure we're getting properties on our interface */ | | |||
57 | if (message.type() != QDBusMessage::MessageType::MethodCallMessage) { | | |||
58 | return false; | | |||
59 | } | | |||
60 | | ||||
61 | qCDebug(XdgDesktopPortalKdeDesktopPortal) << message.interface(); | | |||
62 | qCDebug(XdgDesktopPortalKdeDesktopPortal) << message.member(); | | |||
63 | qCDebug(XdgDesktopPortalKdeDesktopPortal) << message.path(); | | |||
64 | | ||||
65 | QList<QVariant> arguments; | | |||
66 | if (message.interface() == QLatin1String("org.freedesktop.impl.portal.Access")) { | | |||
67 | if (message.member() == QLatin1String("AccessDialog")) { | | |||
68 | QVariantMap results; | | |||
69 | QVariantMap options; | | |||
70 | | ||||
71 | QDBusArgument dbusArgument = message.arguments().at(6).value<QDBusArgument>(); | | |||
72 | dbusArgument >> options; | | |||
73 | | ||||
74 | uint response = m_access->accessDialog(qvariant_cast<QDBusObjectPath>(message.arguments().at(0)), // handle | | |||
75 | message.arguments().at(1).toString(), // app_id | | |||
76 | message.arguments().at(2).toString(), // parent_window | | |||
77 | message.arguments().at(3).toString(), // title | | |||
78 | message.arguments().at(4).toString(), // subtitle | | |||
79 | message.arguments().at(5).toString(), // body | | |||
80 | options, // options | | |||
81 | results); | | |||
82 | arguments << response; | | |||
83 | arguments << results; | | |||
84 | } | | |||
85 | } else if (message.interface() == QLatin1String("org.freedesktop.impl.portal.AppChooser")) { | | |||
86 | if (message.member() == QLatin1String("ChooseApplication")) { | | |||
87 | QVariantMap results; | | |||
88 | QVariantMap choices; | | |||
89 | | ||||
90 | QDBusArgument dbusArgument = message.arguments().at(4).value<QDBusArgument>(); | | |||
91 | dbusArgument >> choices; | | |||
92 | | ||||
93 | uint response = m_appChooser->chooseApplication(qvariant_cast<QDBusObjectPath>(message.arguments().at(0)), // handle | | |||
94 | message.arguments().at(1).toString(), // app_id | | |||
95 | message.arguments().at(2).toString(), // parent_window | | |||
96 | message.arguments().at(3).toStringList(), // choices | | |||
97 | choices, // options | | |||
98 | results); | | |||
99 | arguments << response; | | |||
100 | arguments << results; | | |||
101 | } | | |||
102 | } else if (message.interface() == QLatin1String("org.freedesktop.impl.portal.Email")) { | | |||
103 | uint response = 2; | | |||
104 | QVariantMap results; | | |||
105 | QVariantMap options; | | |||
106 | | ||||
107 | QDBusArgument dbusArgument = message.arguments().at(3).value<QDBusArgument>(); | | |||
108 | dbusArgument >> options; | | |||
109 | | ||||
110 | if (message.member() == QLatin1String("ComposeEmail")) { | | |||
111 | response = m_email->composeEmail(qvariant_cast<QDBusObjectPath>(message.arguments().at(0)), // handle | | |||
112 | message.arguments().at(1).toString(), // app_id | | |||
113 | message.arguments().at(2).toString(), // parent_window | | |||
114 | options, // options | | |||
115 | results); | | |||
116 | } | | |||
117 | | ||||
118 | arguments << response; | | |||
119 | arguments << results; | | |||
120 | } else if (message.interface() == QLatin1String("org.freedesktop.impl.portal.FileChooser")) { | | |||
121 | uint response = 2; | | |||
122 | QVariantMap results; | | |||
123 | QVariantMap choices; | | |||
124 | | ||||
125 | QDBusArgument dbusArgument = message.arguments().at(4).value<QDBusArgument>(); | | |||
126 | dbusArgument >> choices; | | |||
127 | | ||||
128 | if (message.member() == QLatin1String("OpenFile")) { | | |||
129 | response = m_fileChooser->openFile(qvariant_cast<QDBusObjectPath>(message.arguments().at(0)), // handle | | |||
130 | message.arguments().at(1).toString(), // app_id | | |||
131 | message.arguments().at(2).toString(), // parent_window | | |||
132 | message.arguments().at(3).toString(), // title | | |||
133 | choices, // options | | |||
134 | results); | | |||
135 | } else if (message.member() == QLatin1String("SaveFile")) { | | |||
136 | response = m_fileChooser->saveFile(qvariant_cast<QDBusObjectPath>(message.arguments().at(0)), // handle | | |||
137 | message.arguments().at(1).toString(), // app_id | | |||
138 | message.arguments().at(2).toString(), // parent_window | | |||
139 | message.arguments().at(3).toString(), // title | | |||
140 | choices, // options | | |||
141 | results); | | |||
142 | } | | |||
143 | | ||||
144 | arguments << response; | | |||
145 | arguments << results; | | |||
146 | | ||||
147 | } else if (message.interface() == QLatin1String("org.freedesktop.impl.portal.Inhibit")) { | | |||
148 | if (message.member() == QLatin1String("Inhibit")) { | | |||
149 | QVariantMap options; | | |||
150 | | ||||
151 | QDBusArgument dbusArgument = message.arguments().at(4).value<QDBusArgument>(); | | |||
152 | dbusArgument >> options; | | |||
153 | | ||||
154 | m_inhibit->inhibit(qvariant_cast<QDBusObjectPath>(message.arguments().at(0)), // handle | | |||
155 | message.arguments().at(1).toString(), // app_id | | |||
156 | message.arguments().at(2).toString(), // window | | |||
157 | message.arguments().at(3).toUInt(), // flags | | |||
158 | options); // options | | |||
159 | } | | |||
160 | } else if (message.interface() == QLatin1String("org.freedesktop.impl.portal.Notification")) { | | |||
161 | if (message.member() == QLatin1String("AddNotification")) { | | |||
162 | QVariantMap notificationParams; | | |||
163 | | ||||
164 | QDBusArgument dbusArgument = message.arguments().at(2).value<QDBusArgument>(); | | |||
165 | dbusArgument >> notificationParams; | | |||
166 | | ||||
167 | m_notification->addNotification(message.arguments().at(0).toString(), // app_id | | |||
168 | message.arguments().at(1).toString(), // id | | |||
169 | notificationParams); // notification | | |||
170 | } else if (message.member() == QLatin1String("RemoveNotification")) { | | |||
171 | m_notification->removeNotification(message.arguments().at(0).toString(), // app_id | | |||
172 | message.arguments().at(1).toString()); // id | | |||
173 | } | | |||
174 | } else if (message.interface() == QLatin1String("org.freedesktop.impl.portal.Print")) { | | |||
175 | uint response = 2; | | |||
176 | QVariantMap results; | | |||
177 | | ||||
178 | if (message.member() == QLatin1String("Print")) { | | |||
179 | QVariantMap options; | | |||
180 | | ||||
181 | QDBusArgument dbusArgument = message.arguments().at(5).value<QDBusArgument>(); | | |||
182 | dbusArgument >> options; | | |||
183 | | ||||
184 | response = m_print->print(qvariant_cast<QDBusObjectPath>(message.arguments().at(0)), // handle | | |||
185 | message.arguments().at(1).toString(), // app_id | | |||
186 | message.arguments().at(2).toString(), // parent_window | | |||
187 | message.arguments().at(3).toString(), // title | | |||
188 | qvariant_cast<QDBusUnixFileDescriptor>(message.arguments().at(4)), // fd | | |||
189 | options, // options | | |||
190 | results); | | |||
191 | } else if (message.member() == QLatin1String("PreparePrint")) { | | |||
192 | QVariantMap settings; | | |||
193 | QVariantMap pageSetup; | | |||
194 | QVariantMap options; | | |||
195 | | ||||
196 | QDBusArgument dbusArgument = message.arguments().at(4).value<QDBusArgument>(); | | |||
197 | dbusArgument >> settings; | | |||
198 | | ||||
199 | QDBusArgument dbusArgument1 = message.arguments().at(5).value<QDBusArgument>(); | | |||
200 | dbusArgument1 >> pageSetup; | | |||
201 | | ||||
202 | QDBusArgument dbusArgument2 = message.arguments().at(6).value<QDBusArgument>(); | | |||
203 | dbusArgument2 >> options; | | |||
204 | | ||||
205 | response = m_print->preparePrint(qvariant_cast<QDBusObjectPath>(message.arguments().at(0)), // handle | | |||
206 | message.arguments().at(1).toString(), // app_id | | |||
207 | message.arguments().at(2).toString(), // parent_window | | |||
208 | message.arguments().at(3).toString(), // title | | |||
209 | settings, // settings | | |||
210 | pageSetup, // page_setup | | |||
211 | options, // options | | |||
212 | results); | | |||
213 | } | | |||
214 | | ||||
215 | arguments << response; | | |||
216 | arguments << results; | | |||
217 | } | | |||
218 | | ||||
219 | QDBusMessage reply = message.createReply(); | | |||
220 | reply.setArguments(arguments); | | |||
221 | return connection.send(reply); | | |||
222 | } | | |||
223 | | ||||
224 | QString DesktopPortal::introspect(const QString &path) const | | |||
225 | { | | |||
226 | QString nodes; | | |||
227 | | ||||
228 | if (path == QLatin1String("/org/freedesktop/portal/desktop/") || path == QLatin1String("/org/freedesktop/portal/desktop")) { | | |||
229 | nodes = QStringLiteral( | | |||
230 | "<interface name=\"org.freedesktop.impl.portal.Access\">" | | |||
231 | " <method name=\"AccessDialog\">" | | |||
232 | " <arg type=\"o\" name=\"handle\" direction=\"in\"/>" | | |||
233 | " <arg type=\"s\" name=\"app_id\" direction=\"in\"/>" | | |||
234 | " <arg type=\"s\" name=\"parent_window\" direction=\"in\"/>" | | |||
235 | " <arg type=\"s\" name=\"title\" direction=\"in\"/>" | | |||
236 | " <arg type=\"s\" name=\"subtitle\" direction=\"in\"/>" | | |||
237 | " <arg type=\"s\" name=\"body\" direction=\"in\"/>" | | |||
238 | " <arg type=\"a{sv}\" name=\"options\" direction=\"in\"/>" | | |||
239 | " <arg type=\"u\" name=\"response\" direction=\"out\"/>" | | |||
240 | " <arg type=\"a{sv}\" name=\"results\" direction=\"out\"/>" | | |||
241 | " </method>" | | |||
242 | "</interface>" | | |||
243 | "<interface name=\"org.freedesktop.impl.portal.AppChooser\">" | | |||
244 | " <method name=\"ChooseApplication\">" | | |||
245 | " <arg type=\"o\" name=\"handle\" direction=\"in\"/>" | | |||
246 | " <arg type=\"s\" name=\"app_id\" direction=\"in\"/>" | | |||
247 | " <arg type=\"s\" name=\"parent_window\" direction=\"in\"/>" | | |||
248 | " <arg type=\"as\" name=\"choices\" direction=\"in\"/>" | | |||
249 | " <arg type=\"a{sv}\" name=\"options\" direction=\"in\"/>" | | |||
250 | " <arg type=\"u\" name=\"response\" direction=\"out\"/>" | | |||
251 | " <arg type=\"a{sv}\" name=\"results\" direction=\"out\"/>" | | |||
252 | " </method>" | | |||
253 | "</interface>" | | |||
254 | "<interface name=\"org.freedesktop.impl.portal.Email\">" | | |||
255 | " <method name=\"ComposeEmail\">" | | |||
256 | " <arg type=\"o\" name=\"handle\" direction=\"in\"/>" | | |||
257 | " <arg type=\"s\" name=\"app_id\" direction=\"in\"/>" | | |||
258 | " <arg type=\"s\" name=\"window\" direction=\"in\"/>" | | |||
259 | " <arg type=\"a{sv}\" name=\"options\" direction=\"in\"/>" | | |||
260 | " <arg type=\"u\" name=\"response\" direction=\"out\"/>" | | |||
261 | " <arg type=\"a{sv}\" name=\"results\" direction=\"out\"/>" | | |||
262 | " </method>" | | |||
263 | "</interface>" | | |||
264 | "<interface name=\"org.freedesktop.impl.portal.FileChooser\">" | | |||
265 | " <method name=\"OpenFile\">" | | |||
266 | " <arg type=\"o\" name=\"handle\" direction=\"in\"/>" | | |||
267 | " <arg type=\"s\" name=\"app_id\" direction=\"in\"/>" | | |||
268 | " <arg type=\"s\" name=\"parent_window\" direction=\"in\"/>" | | |||
269 | " <arg type=\"s\" name=\"title\" direction=\"in\"/>" | | |||
270 | " <arg type=\"a{sv}\" name=\"options\" direction=\"in\"/>" | | |||
271 | " <arg type=\"u\" name=\"response\" direction=\"out\"/>" | | |||
272 | " <arg type=\"a{sv}\" name=\"results\" direction=\"out\"/>" | | |||
273 | " </method>" | | |||
274 | " <method name=\"SaveFile\">" | | |||
275 | " <arg type=\"o\" name=\"handle\" direction=\"in\"/>" | | |||
276 | " <arg type=\"s\" name=\"app_id\" direction=\"in\"/>" | | |||
277 | " <arg type=\"s\" name=\"parent_window\" direction=\"in\"/>" | | |||
278 | " <arg type=\"s\" name=\"title\" direction=\"in\"/>" | | |||
279 | " <arg type=\"a{sv}\" name=\"options\" direction=\"in\"/>" | | |||
280 | " <arg type=\"u\" name=\"response\" direction=\"out\"/>" | | |||
281 | " <arg type=\"a{sv}\" name=\"results\" direction=\"out\"/>" | | |||
282 | " </method>" | | |||
283 | "</interface>" | | |||
284 | "<interface name=\"org.freedesktop.impl.portal.Inhibit\">" | | |||
285 | " <method name=\"Inhibit\">" | | |||
286 | " <arg type=\"o\" name=\"handle\" direction=\"in\"/>" | | |||
287 | " <arg type=\"s\" name=\"app_id\" direction=\"in\"/>" | | |||
288 | " <arg type=\"s\" name=\"window\" direction=\"in\"/>" | | |||
289 | " <arg type=\"u\" name=\"flags\" direction=\"in\"/>" | | |||
290 | " <arg type=\"a{sv}\" name=\"options\" direction=\"in\"/>" | | |||
291 | " </method>" | | |||
292 | "</interface>" | | |||
293 | "<interface name=\"org.freedesktop.impl.portal.Notification\">" | | |||
294 | " <method name=\"AddNotification\">" | | |||
295 | " <arg type=\"s\" name=\"app_id\" direction=\"in\"/>" | | |||
296 | " <arg type=\"s\" name=\"id\" direction=\"in\"/>" | | |||
297 | " <arg type=\"a{sv}\" name=\"notification\" direction=\"in\"/>" | | |||
298 | " </method>" | | |||
299 | " <method name=\"RemoveNotification\">" | | |||
300 | " <arg type=\"s\" name=\"app_id\" direction=\"in\"/>" | | |||
301 | " <arg type=\"s\" name=\"id\" direction=\"in\"/>" | | |||
302 | " </method>" | | |||
303 | " <signal name=\"ActionInvoked\">" | | |||
304 | " <arg type=\"s\" name=\"app_id\"/>" | | |||
305 | " <arg type=\"s\" name=\"id\"/>" | | |||
306 | " <arg type=\"s\" name=\"action\"/>" | | |||
307 | " <arg type=\"av\" name=\"parameter\"/>" | | |||
308 | " </signal>" | | |||
309 | "</interface>" | | |||
310 | "<interface name=\"org.freedesktop.impl.portal.Print\">" | | |||
311 | " <method name=\"Print\">" | | |||
312 | " <arg type=\"o\" name=\"handle\" direction=\"in\"/>" | | |||
313 | " <arg type=\"s\" name=\"app_id\" direction=\"in\"/>" | | |||
314 | " <arg type=\"s\" name=\"parent_window\" direction=\"in\"/>" | | |||
315 | " <arg type=\"s\" name=\"title\" direction=\"in\"/>" | | |||
316 | " <arg type=\"h\" name=\"fd\" direction=\"in\"/>" | | |||
317 | " <arg type=\"a{sv}\" name=\"options\" direction=\"in\"/>" | | |||
318 | " <arg type=\"u\" name=\"response\" direction=\"out\"/>" | | |||
319 | " <arg type=\"a{sv}\" name=\"results\" direction=\"out\"/>" | | |||
320 | " </method>" | | |||
321 | " <method name=\"PreparePrint\">" | | |||
322 | " <arg type=\"o\" name=\"handle\" direction=\"in\"/>" | | |||
323 | " <arg type=\"s\" name=\"app_id\" direction=\"in\"/>" | | |||
324 | " <arg type=\"s\" name=\"parent_window\" direction=\"in\"/>" | | |||
325 | " <arg type=\"s\" name=\"title\" direction=\"in\"/>" | | |||
326 | " <arg type=\"a{sv}\" name=\"settings\" direction=\"in\"/>" | | |||
327 | " <arg type=\"a{sv}\" name=\"page_setup\" direction=\"in\"/>" | | |||
328 | " <arg type=\"a{sv}\" name=\"options\" direction=\"in\"/>" | | |||
329 | " <arg type=\"u\" name=\"response\" direction=\"out\"/>" | | |||
330 | " <arg type=\"a{sv}\" name=\"results\" direction=\"out\"/>" | | |||
331 | " </method>" | | |||
332 | "</interface>"); | | |||
333 | } | | |||
334 | | ||||
335 | qCDebug(XdgDesktopPortalKdeDesktopPortal) << nodes; | | |||
336 | | ||||
337 | return nodes; | | |||
338 | } | 45 | } |