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 * @param id knotify-sid identifier of notification
49 * @param config notification data
50 * @param 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 * @return 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 * Do not use this variable. Use #popupServerCapabilities() instead.
69 * @see popupServerCapabilities
70 */
71 QStringList m_popupServerCapabilities;
72
73 /**
74 * In case we still don't know notification server capabilities,
75 * we need to query those first. That's done in an async way
76 * so we queue all notifications while waiting for the capabilities
77 * to return, then process them from this queue
78 */
79 QList<QPair<KNotification *, KNotifyConfig>> m_notificationQueue;
80 /**
81 * Whether the DBus notification daemon capability cache is up-to-date.
82 */
83 bool m_dbusServiceCapCacheDirty;
84
85 /*
86 * As we communicate with the notification server over dbus
87 * we use only ids, this is for fast KNotifications lookup
88 */
89 QHash<uint, QPointer<KNotification>> m_notifications;
90
91 org::freedesktop::Notifications m_dbusInterface;
92
93 Q_DISABLE_COPY_MOVE(NotifyByPopup)
94};
95
96#endif
97

source code of knotifications/src/notifybypopup.h