1/*
2 SPDX-FileCopyrightText: 2005-2006 Olivier Goffart <ogoffart at kde.org>
3 SPDX-FileCopyrightText: 2008 Dmitry Suzdalev <dimsuz@gmail.com>
4 SPDX-FileCopyrightText: 2014 Martin Klapetek <mklapetek@kde.org>
5
6 SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
7*/
8
9#ifndef NOTIFYBYPOPUP_H
10#define NOTIFYBYPOPUP_H
11
12#include "knotificationplugin.h"
13
14#include "knotifyconfig.h"
15#include <QStringList>
16
17#include "notifications_interface.h"
18
19class KNotification;
20class QDBusPendingCallWatcher;
21
22class NotifyByPopup : public KNotificationPlugin
23{
24 Q_OBJECT
25public:
26 explicit NotifyByPopup(QObject *parent = nullptr);
27 ~NotifyByPopup() override;
28
29 QString optionName() override
30 {
31 return QStringLiteral("Popup");
32 }
33 void notify(KNotification *notification, const KNotifyConfig &notifyConfig) override;
34 void close(KNotification *notification) override;
35 void update(KNotification *notification, const KNotifyConfig &notifyConfig) override;
36
37private Q_SLOTS:
38 // slot which gets called when DBus signals that some notification action was invoked
39 void onNotificationActionInvoked(uint notificationId, const QString &actionKey);
40 void onNotificationActionTokenReceived(uint notificationId, const QString &xdgActionToken);
41 // slot which gets called when DBus signals that some notification was closed
42 void onNotificationClosed(uint, uint);
43 void onNotificationReplied(uint notificationId, const QString &text);
44
45private:
46 /*
47 * Sends notification to DBus "org.freedesktop.notifications" interface.
48 * id knotify-sid identifier of notification
49 * config notification data
50 * update If true, will request the DBus service to update
51 the notification with new data from \c notification
52 * Otherwise will put new notification on screen
53 * Returns true for success or false if there was an error.
54 */
55 bool sendNotificationToServer(KNotification *notification, const KNotifyConfig &config, bool update = false);
56
57 /*
58 * Find the caption and the icon name of the application
59 */
60 void getAppCaptionAndIconName(const KNotifyConfig &config, QString *appCaption, QString *iconName);
61 /*
62 * Query the dbus server for notification capabilities
63 */
64 void queryPopupServerCapabilities();
65
66 /*
67 * DBus notification daemon capabilities cache.
68 */
69 QStringList m_popupServerCapabilities;
70
71 /*!
72 * In case we still don't know notification server capabilities,
73 * we need to query those first. That's done in an async way
74 * so we queue all notifications while waiting for the capabilities
75 * to return, then process them from this queue
76 */
77 QList<QPair<KNotification *, KNotifyConfig>> m_notificationQueue;
78 /*
79 * Whether the DBus notification daemon capability cache is up-to-date.
80 */
81 bool m_dbusServiceCapCacheDirty;
82
83 /*
84 * As we communicate with the notification server over dbus
85 * we use only ids, this is for fast KNotifications lookup
86 */
87 QHash<uint, QPointer<KNotification>> m_notifications;
88
89 org::freedesktop::Notifications m_dbusInterface;
90
91 Q_DISABLE_COPY_MOVE(NotifyByPopup)
92};
93
94#endif
95

source code of knotifications/src/notifybypopup.h