Changeset View
Changeset View
Standalone View
Standalone View
src/session.cpp
- This file was added.
1 | /* | ||||
---|---|---|---|---|---|
2 | * Copyright © 2018 Red Hat, Inc | ||||
3 | * | ||||
4 | * This program is free software; you can redistribute it and/or | ||||
5 | * modify it under the terms of the GNU Lesser General Public | ||||
6 | * License as published by the Free Software Foundation; either | ||||
7 | * version 2 of the License, or (at your option) any later version. | ||||
8 | * | ||||
9 | * This library is distributed in the hope that it will be useful, | ||||
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||||
12 | * Lesser General Public License for more details. | ||||
13 | * | ||||
14 | * You should have received a copy of the GNU Lesser General Public | ||||
15 | * License along with this library. If not, see <http://www.gnu.org/licenses/>. | ||||
16 | * | ||||
17 | * Authors: | ||||
18 | * Jan Grulich <jgrulich@redhat.com> | ||||
19 | */ | ||||
20 | | ||||
21 | #include "desktopportal.h" | ||||
22 | #include "session.h" | ||||
23 | | ||||
24 | #include <QDBusArgument> | ||||
25 | #include <QDBusConnection> | ||||
26 | #include <QDBusMessage> | ||||
27 | #include <QDBusPendingCall> | ||||
28 | #include <QDBusPendingReply> | ||||
29 | #include <QDBusPendingCallWatcher> | ||||
30 | #include <QLoggingCategory> | ||||
31 | | ||||
32 | Q_LOGGING_CATEGORY(XdgSessionKdeSession, "xdp-kde-session") | ||||
33 | | ||||
34 | Session::Session(QObject *parent, const QString &appId, const QString &path) | ||||
35 | : QDBusVirtualObject(parent) | ||||
36 | , m_multipleSources(false) | ||||
37 | , m_appId(appId) | ||||
38 | , m_path(path) | ||||
39 | { | ||||
40 | } | ||||
41 | | ||||
42 | Session::~Session() | ||||
43 | { | ||||
44 | } | ||||
45 | | ||||
46 | bool Session::handleMessage(const QDBusMessage &message, const QDBusConnection &connection) | ||||
47 | { | ||||
48 | Q_UNUSED(connection); | ||||
49 | | ||||
50 | if (message.path() != m_path) { | ||||
51 | return false; | ||||
52 | } | ||||
53 | | ||||
54 | /* Check to make sure we're getting properties on our interface */ | ||||
55 | if (message.type() != QDBusMessage::MessageType::MethodCallMessage) { | ||||
56 | return false; | ||||
57 | } | ||||
58 | | ||||
59 | qCDebug(XdgSessionKdeSession) << message.interface(); | ||||
60 | qCDebug(XdgSessionKdeSession) << message.member(); | ||||
61 | qCDebug(XdgSessionKdeSession) << message.path(); | ||||
62 | | ||||
63 | if (message.interface() == QLatin1String("org.freedesktop.impl.portal.Session")) { | ||||
64 | if (message.member() == QLatin1String("Close")) { | ||||
65 | Q_EMIT closed(); | ||||
66 | QDBusMessage reply = message.createReply(); | ||||
67 | return connection.send(reply); | ||||
68 | } | ||||
69 | } else if (message.interface() == QLatin1String("org.freedesktop.DBus.Properties")) { | ||||
70 | if (message.member() == QLatin1String("Get")) { | ||||
71 | if (message.arguments().count() == 2) { | ||||
72 | const QString interface = message.arguments().at(0).toString(); | ||||
73 | const QString property = message.arguments().at(1).toString(); | ||||
74 | | ||||
75 | if (interface == QLatin1String("org.freedesktop.impl.portal.Session") && | ||||
76 | property == QLatin1String("version")) { | ||||
77 | QList<QVariant> arguments; | ||||
78 | arguments << 1; | ||||
79 | | ||||
80 | QDBusMessage reply = message.createReply(); | ||||
81 | reply.setArguments(arguments); | ||||
82 | return connection.send(reply); | ||||
83 | } | ||||
84 | } | ||||
85 | } | ||||
86 | } | ||||
87 | | ||||
88 | return false; | ||||
89 | } | ||||
90 | | ||||
91 | QString Session::introspect(const QString &path) const | ||||
92 | { | ||||
93 | QString nodes; | ||||
94 | | ||||
95 | if (path.startsWith(QLatin1String("/org/freedesktop/portal/desktop/session/"))) { | ||||
96 | nodes = QStringLiteral( | ||||
97 | "<interface name=\"org.freedesktop.impl.portal.Session\">" | ||||
98 | " <method name=\"Close\">" | ||||
99 | " </method>" | ||||
100 | "<signal name=\"Closed\">" | ||||
101 | "</signal>" | ||||
102 | "<property name=\"version\" type=\"u\" access=\"read\"/>" | ||||
103 | "</interface>"); | ||||
104 | } | ||||
105 | | ||||
106 | qCDebug(XdgSessionKdeSession) << nodes; | ||||
107 | | ||||
108 | return nodes; | ||||
109 | } | ||||
110 | | ||||
111 | bool Session::multipleSources() const | ||||
112 | { | ||||
113 | return m_multipleSources; | ||||
114 | } | ||||
115 | | ||||
116 | void Session::setMultipleSources(bool multipleSources) | ||||
117 | { | ||||
118 | m_multipleSources = multipleSources; | ||||
119 | } | ||||
120 | | ||||
121 | bool Session::close() | ||||
122 | { | ||||
123 | QDBusMessage reply = QDBusMessage::createSignal(m_path, QLatin1String("org.freedesktop.impl.portal.Session"), QLatin1String("Closed")); | ||||
124 | return QDBusConnection::sessionBus().send(reply); | ||||
125 | } | ||||
126 | |