Changeset View
Changeset View
Standalone View
Standalone View
src/notification.cpp
Show All 18 Lines | |||||
19 | 19 | | |||
20 | #include "notification.h" | 20 | #include "notification.h" | ||
21 | 21 | | |||
22 | #include <QDBusArgument> | 22 | #include <QDBusArgument> | ||
23 | #include <QDBusConnection> | 23 | #include <QDBusConnection> | ||
24 | #include <QDBusMessage> | 24 | #include <QDBusMessage> | ||
25 | #include <QLoggingCategory> | 25 | #include <QLoggingCategory> | ||
26 | 26 | | |||
27 | | ||||
27 | Q_LOGGING_CATEGORY(XdgDesktopPortalKdeNotification, "xdg-desktop-portal-kde-notification") | 28 | Q_LOGGING_CATEGORY(XdgDesktopPortalKdeNotification, "xdg-desktop-portal-kde-notification") | ||
28 | 29 | | |||
29 | Notification::Notification(QObject *parent) | 30 | NotificationPortal::NotificationPortal(QObject *parent) | ||
30 | : QObject(parent) | 31 | : QDBusAbstractAdaptor(parent) | ||
31 | { | 32 | { | ||
32 | } | 33 | } | ||
33 | 34 | | |||
34 | Notification::~Notification() | 35 | NotificationPortal::~NotificationPortal() | ||
35 | { | 36 | { | ||
36 | } | 37 | } | ||
37 | 38 | | |||
38 | void Notification::addNotification(const QString &app_id, | 39 | void NotificationPortal::AddNotification(const QString &app_id, | ||
39 | const QString &id, | 40 | const QString &id, | ||
40 | const QVariantMap ¬ification) | 41 | const QVariantMap ¬ification) | ||
41 | { | 42 | { | ||
42 | qCDebug(XdgDesktopPortalKdeNotification) << "AddNotification called with parameters:"; | 43 | qCDebug(XdgDesktopPortalKdeNotification) << "AddNotification called with parameters:"; | ||
43 | qCDebug(XdgDesktopPortalKdeNotification) << " app_id: " << app_id; | 44 | qCDebug(XdgDesktopPortalKdeNotification) << " app_id: " << app_id; | ||
44 | qCDebug(XdgDesktopPortalKdeNotification) << " id: " << id; | 45 | qCDebug(XdgDesktopPortalKdeNotification) << " id: " << id; | ||
45 | qCDebug(XdgDesktopPortalKdeNotification) << " notification: " << notification; | 46 | qCDebug(XdgDesktopPortalKdeNotification) << " notification: " << notification; | ||
46 | 47 | | |||
Show All 31 Lines | 68 | if (notification.contains(QLatin1String("buttons"))) { | |||
78 | 79 | | |||
79 | if (!actions.isEmpty()) { | 80 | if (!actions.isEmpty()) { | ||
80 | notify->setActions(actions); | 81 | notify->setActions(actions); | ||
81 | } | 82 | } | ||
82 | } | 83 | } | ||
83 | 84 | | |||
84 | notify->setProperty("app_id", app_id); | 85 | notify->setProperty("app_id", app_id); | ||
85 | notify->setProperty("id", id); | 86 | notify->setProperty("id", id); | ||
86 | connect(notify, static_cast<void (KNotification::*)(uint)>(&KNotification::activated), this, &Notification::notificationActivated); | 87 | connect(notify, static_cast<void (KNotification::*)(uint)>(&KNotification::activated), this, &NotificationPortal::notificationActivated); | ||
87 | connect(notify, &KNotification::closed, this, &Notification::notificationClosed); | 88 | connect(notify, &KNotification::closed, this, &NotificationPortal::notificationClosed); | ||
88 | notify->sendEvent(); | 89 | notify->sendEvent(); | ||
89 | 90 | | |||
90 | m_notifications.insert(QString("%1:%2").arg(app_id, id), notify); | 91 | m_notifications.insert(QString("%1:%2").arg(app_id, id), notify); | ||
91 | } | 92 | } | ||
92 | 93 | | |||
93 | void Notification::notificationActivated(uint action) | 94 | void NotificationPortal::notificationActivated(uint action) | ||
94 | { | 95 | { | ||
95 | KNotification *notify = qobject_cast<KNotification*>(sender()); | 96 | KNotification *notify = qobject_cast<KNotification*>(sender()); | ||
96 | 97 | | |||
97 | if (!notify) { | 98 | if (!notify) { | ||
98 | return; | 99 | return; | ||
99 | } | 100 | } | ||
100 | 101 | | |||
101 | const QString appId = notify->property("app_id").toString(); | 102 | const QString appId = notify->property("app_id").toString(); | ||
102 | const QString id = notify->property("id").toString(); | 103 | const QString id = notify->property("id").toString(); | ||
103 | 104 | | |||
104 | qCDebug(XdgDesktopPortalKdeNotification) << "Notification activated:"; | 105 | qCDebug(XdgDesktopPortalKdeNotification) << "Notification activated:"; | ||
105 | qCDebug(XdgDesktopPortalKdeNotification) << " app_id: " << appId; | 106 | qCDebug(XdgDesktopPortalKdeNotification) << " app_id: " << appId; | ||
106 | qCDebug(XdgDesktopPortalKdeNotification) << " id: " << id; | 107 | qCDebug(XdgDesktopPortalKdeNotification) << " id: " << id; | ||
107 | qCDebug(XdgDesktopPortalKdeNotification) << " action: " << action; | 108 | qCDebug(XdgDesktopPortalKdeNotification) << " action: " << action; | ||
108 | 109 | | |||
109 | QDBusMessage message = QDBusMessage::createSignal(QLatin1String("/org/freedesktop/portal/desktop"), | 110 | QDBusMessage message = QDBusMessage::createSignal(QLatin1String("/org/freedesktop/portal/desktop"), | ||
110 | QLatin1String("org.freedesktop.impl.portal.Notification"), | 111 | QLatin1String("org.freedesktop.impl.portal.Notification"), | ||
111 | QLatin1String("ActionInvoked")); | 112 | QLatin1String("ActionInvoked")); | ||
112 | message << appId << id << QString::number(action) << QVariantList(); | 113 | message << appId << id << QString::number(action) << QVariantList(); | ||
113 | QDBusConnection::sessionBus().send(message); | 114 | QDBusConnection::sessionBus().send(message); | ||
114 | } | 115 | } | ||
115 | 116 | | |||
116 | void Notification::removeNotification(const QString &app_id, | 117 | void NotificationPortal::RemoveNotification(const QString &app_id, | ||
117 | const QString &id) | 118 | const QString &id) | ||
118 | { | 119 | { | ||
119 | qCDebug(XdgDesktopPortalKdeNotification) << "RemoveNotification called with parameters:"; | 120 | qCDebug(XdgDesktopPortalKdeNotification) << "RemoveNotification called with parameters:"; | ||
120 | qCDebug(XdgDesktopPortalKdeNotification) << " app_id: " << app_id; | 121 | qCDebug(XdgDesktopPortalKdeNotification) << " app_id: " << app_id; | ||
121 | qCDebug(XdgDesktopPortalKdeNotification) << " id: " << id; | 122 | qCDebug(XdgDesktopPortalKdeNotification) << " id: " << id; | ||
122 | 123 | | |||
123 | KNotification *notify = m_notifications.take(QString("%1:%2").arg(app_id, id)); | 124 | KNotification *notify = m_notifications.take(QString("%1:%2").arg(app_id, id)); | ||
124 | if (notify) { | 125 | if (notify) { | ||
125 | notify->close(); | 126 | notify->close(); | ||
126 | notify->deleteLater(); | 127 | notify->deleteLater(); | ||
127 | } | 128 | } | ||
128 | } | 129 | } | ||
129 | 130 | | |||
130 | void Notification::notificationClosed() | 131 | void NotificationPortal::notificationClosed() | ||
131 | { | 132 | { | ||
132 | KNotification *notify = qobject_cast<KNotification*>(sender()); | 133 | KNotification *notify = qobject_cast<KNotification*>(sender()); | ||
133 | 134 | | |||
134 | if (!notify) { | 135 | if (!notify) { | ||
135 | return; | 136 | return; | ||
136 | } | 137 | } | ||
137 | 138 | | |||
138 | const QString appId = notify->property("app_id").toString(); | 139 | const QString appId = notify->property("app_id").toString(); | ||
139 | const QString id = notify->property("id").toString(); | 140 | const QString id = notify->property("id").toString(); | ||
140 | 141 | | |||
141 | m_notifications.remove(QString("%1:%2").arg(appId, id)); | 142 | m_notifications.remove(QString("%1:%2").arg(appId, id)); | ||
142 | notify->deleteLater(); | 143 | notify->deleteLater(); | ||
143 | } | 144 | } |