modernize: Reformat ALL the source... again!
[quassel.git] / src / qtui / statusnotifieritem.h
index aa35635..2973919 100644 (file)
@@ -1,5 +1,5 @@
 /***************************************************************************
- *   Copyright (C) 2005-2014 by the Quassel Project                        *
+ *   Copyright (C) 2005-2018 by the Quassel Project                        *
  *   devel@quassel-irc.org                                                 *
  *                                                                         *
  *   This contains code from KStatusNotifierItem, part of the KDE libs     *
  *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.         *
  ***************************************************************************/
 
-#ifndef STATUSNOTIFIERITEM_H_
-#define STATUSNOTIFIERITEM_H_
+#pragma once
 
 #ifdef HAVE_DBUS
 
-#include "notificationsclient.h"
-#include "systemtray.h"
-#include "statusnotifierwatcher.h"
+#    include <QDBusError>
+#    include <QHash>
+#    include <QString>
+#    include <QTemporaryDir>
 
-#ifdef QT_NO_SYSTEMTRAYICON
-#  define StatusNotifierItemParent SystemTray
-#else
-#  define StatusNotifierItemParent LegacySystemTray
-#  include "legacysystemtray.h"
-#endif
+#    include "notificationsclient.h"
+#    include "statusnotifierwatcher.h"
+#    include "systemtray.h"
+
+#    ifdef QT_NO_SYSTEMTRAYICON
+#        define StatusNotifierItemParent SystemTray
+#    else
+#        define StatusNotifierItemParent LegacySystemTray
+#        include "legacysystemtray.h"
+#    endif
+
+class QDBusServiceWatcher;
 
 class StatusNotifierItemDBus;
 
@@ -44,22 +50,19 @@ class StatusNotifierItem : public StatusNotifierItemParent
     Q_OBJECT
 
 public:
-    explicit StatusNotifierItem(QWidget *parent);
-    virtual ~StatusNotifierItem();
+    explicit StatusNotifierItem(QWidget* parent);
 
-    virtual bool isSystemTrayAvailable() const;
-    virtual bool isVisible() const;
+    bool isSystemTrayAvailable() const override;
 
 public slots:
-    virtual void setState(State state);
-    virtual void setVisible(bool visible);
-    virtual void showMessage(const QString &title, const QString &message, MessageIcon icon = Information, int msTimeout = 10000, uint notificationId = 0);
-    virtual void closeMessage(uint notificationId);
+    void showMessage(const QString& title,
+                     const QString& message,
+                     MessageIcon icon = Information,
+                     int msTimeout = 10000,
+                     uint notificationId = 0) override;
+    void closeMessage(uint notificationId) override;
 
 protected:
-    virtual void init();
-    virtual void setMode(Mode mode);
-
     QString title() const;
     QString iconName() const;
     QString attentionIconName() const;
@@ -67,36 +70,41 @@ protected:
     QString iconThemePath() const;
     QString menuObjectPath() const;
 
-    virtual bool eventFilter(QObject *watched, QEvent *event);
+    bool eventFilter(QObject* watched, QEvent* event) override;
 
 private slots:
-    void activated(const QPoint &pos);
-    void serviceChange(const QString &name, const QString &oldOwner, const QString &newOwner);
+    void activated(const QPointpos);
+    void serviceChange(const QString& name, const QString& oldOwner, const QString& newOwner);
     void checkForRegisteredHosts();
+    void onDBusError(const QDBusError& error);
 
     void notificationClosed(uint id, uint reason);
-    void notificationInvoked(uint id, const QString &action);
+    void notificationInvoked(uint id, const QStringaction);
 
-private:
-    void registerToDaemon();
+    void refreshIcons();
 
-    static const int _protocolVersion;
-    static const QString _statusNotifierWatcherServiceName;
-    StatusNotifierItemDBus *_statusNotifierItemDBus;
+    void onModeChanged(Mode mode);
+    void onStateChanged(State state);
+    void onVisibilityChanged(bool isVisible);
 
-    org::kde::StatusNotifierWatcher *_statusNotifierWatcher;
-    org::freedesktop::Notifications *_notificationsClient;
-    bool _notificationsClientSupportsMarkup;
-    bool _notificationsClientSupportsActions;
-    quint32 _lastNotificationsDBusId;
-    QHash<uint, uint> _notificationsIdMap; ///< Maps our own notification ID to the D-Bus one
+private:
+    void registerToWatcher();
+
+    QDBusServiceWatcher* _serviceWatcher{nullptr};
+    StatusNotifierItemDBus* _statusNotifierItemDBus{nullptr};
+    org::kde::StatusNotifierWatcher* _statusNotifierWatcher{nullptr};
+    org::freedesktop::Notifications* _notificationsClient{nullptr};
+    bool _notificationsClientSupportsMarkup{false};
+    bool _notificationsClientSupportsActions{false};
+    quint32 _lastNotificationsDBusId{0};
+    QHash<uint, uint> _notificationsIdMap;  ///< Maps our own notification ID to the D-Bus one
 
     QString _iconThemePath;
     QString _menuObjectPath;
 
+    QTemporaryDir _iconThemeDir;
+
     friend class StatusNotifierItemDBus;
 };
 
-
 #endif /* HAVE_DBUS */
-#endif /* STATUSNOTIFIERITEM_H_ */