1 /* BEGIN_COMMON_COPYRIGHT_HEADER
2  * (c)LGPL2+
3  *
4  * LXQt - a lightweight, Qt based, desktop toolset
5  * https://lxqt.org
6  *
7  * Copyright: 2015 LXQt team
8  * Authors:
9  *  Balázs Béla <balazsbela[at]gmail.com>
10  *  Paulo Lieuthier <paulolieuthier@gmail.com>
11  *
12  * This program or library is free software; you can redistribute it
13  * and/or modify it under the terms of the GNU Lesser General Public
14  * License as published by the Free Software Foundation; either
15  * version 2.1 of the License, or (at your option) any later version.
16  *
17  * This library is distributed in the hope that it will be useful,
18  * but WITHOUT ANY WARRANTY; without even the implied warranty of
19  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
20  * Lesser General Public License for more details.
21  *
22  * You should have received a copy of the GNU Lesser General
23  * Public License along with this library; if not, write to the
24  * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
25  * Boston, MA 02110-1301 USA
26  *
27  * END_COMMON_COPYRIGHT_HEADER */
28 
29 #ifndef STATUSNOTIFIERWATCHER_H
30 #define STATUSNOTIFIERWATCHER_H
31 
32 #include <QDBusConnection>
33 #include <QDBusContext>
34 #include <QDBusMessage>
35 #include <QDBusMetaType>
36 #include <QDBusServiceWatcher>
37 
38 #include "dbustypes.h"
39 
40 class StatusNotifierWatcher : public QObject, protected QDBusContext
41 {
42     Q_OBJECT
43     Q_CLASSINFO("D-Bus Interface", "org.kde.StatusNotifierWatcher")
44     Q_SCRIPTABLE Q_PROPERTY(bool IsStatusNotifierHostRegistered READ isStatusNotifierHostRegistered)
45     Q_SCRIPTABLE Q_PROPERTY(int ProtocolVersion READ protocolVersion)
46     Q_SCRIPTABLE Q_PROPERTY(QStringList RegisteredStatusNotifierItems READ RegisteredStatusNotifierItems)
47 
48 public:
49     explicit StatusNotifierWatcher(QObject *parent = nullptr);
50     ~StatusNotifierWatcher();
51 
isStatusNotifierHostRegistered()52     bool isStatusNotifierHostRegistered() { return mHosts.count() > 0; }
protocolVersion()53     int protocolVersion() const { return 0; }
RegisteredStatusNotifierItems()54     QStringList RegisteredStatusNotifierItems() const { return mServices; }
55 
56 signals:
57     Q_SCRIPTABLE void StatusNotifierItemRegistered(const QString &service);
58     Q_SCRIPTABLE void StatusNotifierItemUnregistered(const QString &service);
59     Q_SCRIPTABLE void StatusNotifierHostRegistered();
60 
61 public slots:
62     Q_SCRIPTABLE void RegisterStatusNotifierItem(const QString &serviceOrPath);
63     Q_SCRIPTABLE void RegisterStatusNotifierHost(const QString &service);
64 
65     void serviceUnregistered(const QString &service);
66 
67 private:
68     QStringList mServices;
69     QStringList mHosts;
70     QDBusServiceWatcher *mWatcher;
71 };
72 
73 #endif // STATUSNOTIFIERWATCHER_H
74