1 /**
2  * SPDX-FileCopyrightText: 2019 Nicolas Fella <nicolas.fella@gmx.de>
3  *
4  * SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
5  */
6 
7 #include "notificationserverinfo.h"
8 
9 #include <QDBusMessage>
10 #include <QDBusPendingReply>
11 #include <QDBusPendingCallWatcher>
12 
13 #include "dbushelper.h"
14 
15 #include "core_debug.h"
16 
instance()17 NotificationServerInfo& NotificationServerInfo::instance()
18 {
19     static NotificationServerInfo instance;
20     return instance;
21 }
22 
init()23 void NotificationServerInfo::init()
24 {
25     QDBusMessage query = QDBusMessage::createMethodCall(QStringLiteral("org.freedesktop.Notifications"), QStringLiteral("/org/freedesktop/Notifications"), QStringLiteral("org.freedesktop.Notifications"), QStringLiteral("GetCapabilities"));
26 
27     QDBusPendingReply<QStringList> reply = DBusHelper::sessionBus().asyncCall(query);
28     QDBusPendingCallWatcher *watcher = new QDBusPendingCallWatcher(reply, this);
29     connect(watcher, &QDBusPendingCallWatcher::finished, this, [this, reply, watcher] {
30         watcher->deleteLater();
31 
32         if (reply.isError()) {
33             qCWarning(KDECONNECT_CORE) << "Could not query capabilities from notifications server";
34             return;
35         }
36 
37         if (reply.value().contains(QLatin1String("x-kde-display-appname"))) {
38             m_supportedHints |= X_KDE_DISPLAY_APPNAME;
39         }
40 
41         if (reply.value().contains(QLatin1String("x-kde-origin-name"))) {
42             m_supportedHints |= X_KDE_ORIGIN_NAME;
43         }
44     });
45 }
46 
supportedHints()47 NotificationServerInfo::Hints NotificationServerInfo::supportedHints()
48 {
49     return m_supportedHints;
50 }
51 
52