qtui: Clean up SystemTray
[quassel.git] / src / qtui / systemtray.cpp
index bb80eeb..36b7047 100644 (file)
@@ -1,11 +1,11 @@
 /***************************************************************************
- *   Copyright (C) 2005-2013 by the Quassel Project                        *
+ *   Copyright (C) 2005-2018 by the Quassel Project                        *
  *   devel@quassel-irc.org                                                 *
  *                                                                         *
- *   This program is free software; you can redistribute it and/or modify  *
- *   it under the terms of the GNU General Public License as published by  *
- *   the Free Software Foundation; either version 2 of the License, or     *
- *   (at your option) version 3.                                           *
+ *   This file is free software; you can redistribute it and/or modify     *
+ *   it under the terms of the GNU Library General Public License (LGPL)   *
+ *   as published by the Free Software Foundation; either version 2 of the *
+ *   License, or (at your option) any later version.                       *
  *                                                                         *
  *   This program is distributed in the hope that it will be useful,       *
  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
 #include "action.h"
 #include "actioncollection.h"
 #include "client.h"
-#include "iconloader.h"
 #include "qtui.h"
 
-#ifdef HAVE_KDE
+#ifdef HAVE_KDE4
 #  include <KMenu>
 #  include <KWindowInfo>
 #  include <KWindowSystem>
 
 SystemTray::SystemTray(QWidget *parent)
     : QObject(parent),
-    _mode(Invalid),
-    _state(Passive),
-    _shouldBeVisible(true),
-    _passiveIcon(DesktopIcon("quassel-inactive")),
-    _activeIcon(DesktopIcon("quassel")),
-    _needsAttentionIcon(DesktopIcon("quassel-message")),
-    _trayMenu(0),
+    _passiveIcon(QIcon::fromTheme("inactive-quassel", QIcon(":/icons/inactive-quassel.png"))),
+    _activeIcon(QIcon::fromTheme("quassel", QIcon(":/icons/quassel.png"))),
+    _needsAttentionIcon(QIcon::fromTheme("message-quassel", QIcon(":/icons/message-quassel.png"))),
     _associatedWidget(parent)
 {
     Q_ASSERT(parent);
@@ -56,18 +51,12 @@ SystemTray::~SystemTray()
 }
 
 
-QWidget *SystemTray::associatedWidget() const
-{
-    return _associatedWidget;
-}
-
-
 void SystemTray::init()
 {
     ActionCollection *coll = QtUi::actionCollection("General");
     _minimizeRestoreAction = new Action(tr("&Minimize"), this, this, SLOT(minimizeRestore()));
 
-#ifdef HAVE_KDE
+#ifdef HAVE_KDE4
     KMenu *kmenu;
     _trayMenu = kmenu = new KMenu();
     kmenu->addTitle(_activeIcon, "Quassel IRC");
@@ -77,7 +66,7 @@ void SystemTray::init()
 
     _trayMenu->setTitle("Quassel IRC");
 
-#ifndef HAVE_KDE
+#ifndef HAVE_KDE4
     _trayMenu->setAttribute(Qt::WA_Hover);
 #endif
 
@@ -95,12 +84,39 @@ void SystemTray::init()
 }
 
 
-void SystemTray::trayMenuAboutToShow()
+QWidget *SystemTray::associatedWidget() const
 {
-    if (GraphicalUi::isMainWidgetVisible())
-        _minimizeRestoreAction->setText(tr("&Minimize"));
-    else
-        _minimizeRestoreAction->setText(tr("&Restore"));
+    return _associatedWidget;
+}
+
+
+bool SystemTray::isSystemTrayAvailable() const
+{
+    return false;
+}
+
+
+bool SystemTray::isVisible() const
+{
+    return false;
+}
+
+
+bool SystemTray::shouldBeVisible() const
+{
+    return _shouldBeVisible;
+}
+
+
+void SystemTray::setVisible(bool visible)
+{
+    _shouldBeVisible = visible;
+}
+
+
+SystemTray::Mode SystemTray::mode() const
+{
+    return _mode;
 }
 
 
@@ -108,7 +124,7 @@ void SystemTray::setMode(Mode mode_)
 {
     if (mode_ != _mode) {
         _mode = mode_;
-#ifdef HAVE_KDE
+#ifdef HAVE_KDE4
         if (_trayMenu) {
             if (_mode == Legacy) {
                 _trayMenu->setWindowFlags(Qt::Popup);
@@ -122,13 +138,27 @@ void SystemTray::setMode(Mode mode_)
 }
 
 
-Icon SystemTray::stateIcon() const
+SystemTray::State SystemTray::state() const
+{
+    return _state;
+}
+
+
+void SystemTray::setState(State state)
+{
+    if (_state != state) {
+        _state = state;
+    }
+}
+
+
+QIcon SystemTray::stateIcon() const
 {
     return stateIcon(state());
 }
 
 
-Icon SystemTray::stateIcon(State state) const
+QIcon SystemTray::stateIcon(State state) const
 {
     switch (state) {
     case Passive:
@@ -138,15 +168,13 @@ Icon SystemTray::stateIcon(State state) const
     case NeedsAttention:
         return _needsAttentionIcon;
     }
-    return Icon();
+    return QIcon();
 }
 
 
-void SystemTray::setState(State state)
+bool SystemTray::isAlerted() const
 {
-    if (_state != state) {
-        _state = state;
-    }
+    return state() == State::NeedsAttention;
 }
 
 
@@ -159,9 +187,43 @@ void SystemTray::setAlert(bool alerted)
 }
 
 
-void SystemTray::setVisible(bool visible)
+QMenu *SystemTray::trayMenu() const
 {
-    _shouldBeVisible = visible;
+    return _trayMenu;
+}
+
+
+void SystemTray::trayMenuAboutToShow()
+{
+    if (GraphicalUi::isMainWidgetVisible())
+        _minimizeRestoreAction->setText(tr("&Minimize"));
+    else
+        _minimizeRestoreAction->setText(tr("&Restore"));
+}
+
+
+bool SystemTray::animationEnabled() const
+{
+    return _animationEnabled;
+}
+
+
+void SystemTray::enableAnimationChanged(const QVariant &v)
+{
+    _animationEnabled = v.toBool();
+    emit animationEnabledChanged(v.toBool());
+}
+
+
+QString SystemTray::toolTipTitle() const
+{
+    return _toolTipTitle;
+}
+
+
+QString SystemTray::toolTipSubTitle() const
+{
+    return _toolTipSubTitle;
 }
 
 
@@ -183,20 +245,19 @@ void SystemTray::showMessage(const QString &title, const QString &message, Messa
 }
 
 
-void SystemTray::activate(SystemTray::ActivationReason reason)
+void SystemTray::closeMessage(uint notificationId)
 {
-    emit activated(reason);
+    Q_UNUSED(notificationId)
 }
 
 
-void SystemTray::minimizeRestore()
+void SystemTray::activate(SystemTray::ActivationReason reason)
 {
-    GraphicalUi::toggleMainWidget();
+    emit activated(reason);
 }
 
 
-void SystemTray::enableAnimationChanged(const QVariant &v)
+void SystemTray::minimizeRestore()
 {
-    _animationEnabled = v.toBool();
-    emit animationEnabledChanged(v.toBool());
+    GraphicalUi::toggleMainWidget();
 }