1// Copyright (C) 2016 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
4
5#ifndef QDBUSTRAYICON_H
6#define QDBUSTRAYICON_H
7
8//
9// W A R N I N G
10// -------------
11//
12// This file is not part of the Qt API. It exists purely as an
13// implementation detail. This header file may change from version to
14// version without notice, or even be removed.
15//
16// We mean it.
17//
18
19#include <QtGui/private/qtguiglobal_p.h>
20
21QT_REQUIRE_CONFIG(systemtrayicon);
22
23#include <QIcon>
24#include <QTemporaryFile>
25#include <QTimer>
26#include "QtGui/qpa/qplatformsystemtrayicon.h"
27#include "private/qdbusmenuconnection_p.h"
28
29QT_BEGIN_NAMESPACE
30
31class QStatusNotifierItemAdaptor;
32class QDBusMenuAdaptor;
33class QDBusPlatformMenu;
34class QXdgNotificationInterface;
35
36class QDBusTrayIcon: public QPlatformSystemTrayIcon
37{
38 Q_OBJECT
39 Q_PROPERTY(QString category READ category NOTIFY categoryChanged)
40 Q_PROPERTY(QString status READ status NOTIFY statusChanged)
41 Q_PROPERTY(QString tooltip READ tooltip NOTIFY tooltipChanged)
42 Q_PROPERTY(QString iconName READ iconName NOTIFY iconChanged)
43 Q_PROPERTY(QIcon icon READ icon NOTIFY iconChanged)
44 Q_PROPERTY(bool isRequestingAttention READ isRequestingAttention NOTIFY attention)
45 Q_PROPERTY(QString attentionTitle READ attentionTitle NOTIFY attention)
46 Q_PROPERTY(QString attentionMessage READ attentionMessage NOTIFY attention)
47 Q_PROPERTY(QString attentionIconName READ attentionIconName NOTIFY attention)
48 Q_PROPERTY(QIcon attentionIcon READ attentionIcon NOTIFY attention)
49 Q_PROPERTY(QDBusPlatformMenu *menu READ menu NOTIFY menuChanged)
50 Q_MOC_INCLUDE(<private/qdbusplatformmenu_p.h>)
51
52public:
53 QDBusTrayIcon();
54
55 virtual ~QDBusTrayIcon();
56
57 QDBusMenuConnection * dBusConnection();
58
59 void init() override;
60 void cleanup() override;
61 void updateIcon(const QIcon &icon) override;
62 void updateToolTip(const QString &tooltip) override;
63 void updateMenu(QPlatformMenu *menu) override;
64 QPlatformMenu *createMenu() const override;
65 void showMessage(const QString &title, const QString &msg,
66 const QIcon &icon, MessageIcon iconType, int msecs) override;
67
68 bool isSystemTrayAvailable() const override;
69 bool supportsMessages() const override { return true; }
70 QRect geometry() const override { return QRect(); }
71
72 QString category() const { return m_category; }
73 QString status() const { return m_status; }
74 QString tooltip() const { return m_tooltip; }
75
76 QString iconName() const { return m_iconName; }
77 const QIcon & icon() const { return m_icon; }
78
79 bool isRequestingAttention() const { return m_attentionTimer.isActive(); }
80 QString attentionTitle() const { return m_messageTitle; }
81 QString attentionMessage() const { return m_message; }
82 QString attentionIconName() const { return m_attentionIconName; }
83 const QIcon & attentionIcon() const { return m_attentionIcon; }
84
85 QString instanceId() const { return m_instanceId; }
86
87 QDBusPlatformMenu *menu() { return m_menu; }
88
89signals:
90 void categoryChanged();
91 void statusChanged(QString arg);
92 void tooltipChanged();
93 void iconChanged();
94 void attention();
95 void menuChanged();
96
97private Q_SLOTS:
98 void attentionTimerExpired();
99 void actionInvoked(uint id, const QString &action);
100 void notificationClosed(uint id, uint reason);
101 void watcherServiceRegistered(const QString &serviceName);
102
103private:
104 void setStatus(const QString &status);
105 QTemporaryFile *tempIcon(const QIcon &icon);
106
107private:
108 QDBusMenuConnection* m_dbusConnection;
109 QStatusNotifierItemAdaptor *m_adaptor;
110 QDBusMenuAdaptor *m_menuAdaptor;
111 QDBusPlatformMenu *m_menu;
112 QXdgNotificationInterface *m_notifier;
113 QString m_instanceId;
114 QString m_category;
115 QString m_defaultStatus;
116 QString m_status;
117 QString m_tooltip;
118 QString m_messageTitle;
119 QString m_message;
120 QIcon m_icon;
121 QTemporaryFile *m_tempIcon;
122 QString m_iconName;
123 QIcon m_attentionIcon;
124 QTemporaryFile *m_tempAttentionIcon;
125 QString m_attentionIconName;
126 QTimer m_attentionTimer;
127 bool m_registered;
128};
129
130QT_END_NAMESPACE
131
132#endif // QDBUSTRAYICON_H
133

source code of qtbase/src/gui/platform/unix/dbustray/qdbustrayicon_p.h