1/****************************************************************************
2**
3** Copyright (C) 2016 The Qt Company Ltd.
4** Contact: https://www.qt.io/licensing/
5**
6** This file is part of the QtGui module of the Qt Toolkit.
7**
8** $QT_BEGIN_LICENSE:LGPL$
9** Commercial License Usage
10** Licensees holding valid commercial Qt licenses may use this file in
11** accordance with the commercial license agreement provided with the
12** Software or, alternatively, in accordance with the terms contained in
13** a written agreement between you and The Qt Company. For licensing terms
14** and conditions see https://www.qt.io/terms-conditions. For further
15** information use the contact form at https://www.qt.io/contact-us.
16**
17** GNU Lesser General Public License Usage
18** Alternatively, this file may be used under the terms of the GNU Lesser
19** General Public License version 3 as published by the Free Software
20** Foundation and appearing in the file LICENSE.LGPL3 included in the
21** packaging of this file. Please review the following information to
22** ensure the GNU Lesser General Public License version 3 requirements
23** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
24**
25** GNU General Public License Usage
26** Alternatively, this file may be used under the terms of the GNU
27** General Public License version 2.0 or (at your option) the GNU General
28** Public license version 3 or any later version approved by the KDE Free
29** Qt Foundation. The licenses are as published by the Free Software
30** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
31** included in the packaging of this file. Please review the following
32** information to ensure the GNU General Public License requirements will
33** be met: https://www.gnu.org/licenses/gpl-2.0.html and
34** https://www.gnu.org/licenses/gpl-3.0.html.
35**
36** $QT_END_LICENSE$
37**
38****************************************************************************/
39
40
41#ifndef QDBUSTRAYICON_H
42#define QDBUSTRAYICON_H
43
44//
45// W A R N I N G
46// -------------
47//
48// This file is not part of the Qt API. It exists purely as an
49// implementation detail. This header file may change from version to
50// version without notice, or even be removed.
51//
52// We mean it.
53//
54
55#include <QtGui/private/qtguiglobal_p.h>
56
57QT_REQUIRE_CONFIG(systemtrayicon);
58
59#include <QIcon>
60#include <QTemporaryFile>
61#include <QTimer>
62#include "QtGui/qpa/qplatformsystemtrayicon.h"
63#include "private/qdbusmenuconnection_p.h"
64
65QT_BEGIN_NAMESPACE
66
67class QStatusNotifierItemAdaptor;
68class QDBusMenuAdaptor;
69class QDBusPlatformMenu;
70class QXdgNotificationInterface;
71
72class QDBusTrayIcon: public QPlatformSystemTrayIcon
73{
74 Q_OBJECT
75 Q_PROPERTY(QString category READ category NOTIFY categoryChanged)
76 Q_PROPERTY(QString status READ status NOTIFY statusChanged)
77 Q_PROPERTY(QString tooltip READ tooltip NOTIFY tooltipChanged)
78 Q_PROPERTY(QString iconName READ iconName NOTIFY iconChanged)
79 Q_PROPERTY(QIcon icon READ icon NOTIFY iconChanged)
80 Q_PROPERTY(bool isRequestingAttention READ isRequestingAttention NOTIFY attention)
81 Q_PROPERTY(QString attentionTitle READ attentionTitle NOTIFY attention)
82 Q_PROPERTY(QString attentionMessage READ attentionMessage NOTIFY attention)
83 Q_PROPERTY(QString attentionIconName READ attentionIconName NOTIFY attention)
84 Q_PROPERTY(QIcon attentionIcon READ attentionIcon NOTIFY attention)
85 Q_PROPERTY(QDBusPlatformMenu *menu READ menu NOTIFY menuChanged)
86
87public:
88 QDBusTrayIcon();
89
90 virtual ~QDBusTrayIcon();
91
92 QDBusMenuConnection * dBusConnection();
93
94 void init() override;
95 void cleanup() override;
96 void updateIcon(const QIcon &icon) override;
97 void updateToolTip(const QString &tooltip) override;
98 void updateMenu(QPlatformMenu *menu) override;
99 QPlatformMenu *createMenu() const override;
100 void showMessage(const QString &title, const QString &msg,
101 const QIcon &icon, MessageIcon iconType, int msecs) override;
102
103 bool isSystemTrayAvailable() const override;
104 bool supportsMessages() const override { return true; }
105 QRect geometry() const override { return QRect(); }
106
107 QString category() const { return m_category; }
108 QString status() const { return m_status; }
109 QString tooltip() const { return m_tooltip; }
110
111 QString iconName() const { return m_iconName; }
112 const QIcon & icon() const { return m_icon; }
113
114 bool isRequestingAttention() const { return m_attentionTimer.isActive(); }
115 QString attentionTitle() const { return m_messageTitle; }
116 QString attentionMessage() const { return m_message; }
117 QString attentionIconName() const { return m_attentionIconName; }
118 const QIcon & attentionIcon() const { return m_attentionIcon; }
119
120 QString instanceId() const { return m_instanceId; }
121
122 QDBusPlatformMenu *menu() { return m_menu; }
123
124signals:
125 void categoryChanged();
126 void statusChanged(QString arg);
127 void tooltipChanged();
128 void iconChanged();
129 void attention();
130 void menuChanged();
131
132private Q_SLOTS:
133 void attentionTimerExpired();
134 void actionInvoked(uint id, const QString &action);
135 void notificationClosed(uint id, uint reason);
136 void watcherServiceRegistered(const QString &serviceName);
137
138private:
139 void setStatus(const QString &status);
140 QTemporaryFile *tempIcon(const QIcon &icon);
141
142private:
143 QDBusMenuConnection* m_dbusConnection;
144 QStatusNotifierItemAdaptor *m_adaptor;
145 QDBusMenuAdaptor *m_menuAdaptor;
146 QDBusPlatformMenu *m_menu;
147 QXdgNotificationInterface *m_notifier;
148 QString m_instanceId;
149 QString m_category;
150 QString m_defaultStatus;
151 QString m_status;
152 QString m_tooltip;
153 QString m_messageTitle;
154 QString m_message;
155 QIcon m_icon;
156 QTemporaryFile *m_tempIcon;
157 QString m_iconName;
158 QIcon m_attentionIcon;
159 QTemporaryFile *m_tempAttentionIcon;
160 QString m_attentionIconName;
161 QTimer m_attentionTimer;
162 bool m_registered;
163};
164
165QT_END_NAMESPACE
166
167#endif // QDBUSTRAYICON_H
168

source code of qtbase/src/platformsupport/themes/genericunix/dbustray/qdbustrayicon_p.h