Allow compilation without QSystemTrayIcon
[quassel.git] / src / qtui / systemtray.h
1 /***************************************************************************
2 *   Copyright (C) 2005-09 by the Quassel Project                          *
3 *   devel@quassel-irc.org                                                 *
4 *                                                                         *
5 *   This program is free software; you can redistribute it and/or modify  *
6 *   it under the terms of the GNU General Public License as published by  *
7 *   the Free Software Foundation; either version 2 of the License, or     *
8 *   (at your option) version 3.                                           *
9 *                                                                         *
10 *   This program is distributed in the hope that it will be useful,       *
11 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
12 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
13 *   GNU General Public License for more details.                          *
14 *                                                                         *
15 *   You should have received a copy of the GNU General Public License     *
16 *   along with this program; if not, write to the                         *
17 *   Free Software Foundation, Inc.,                                       *
18 *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
19 ***************************************************************************/
20
21 #ifndef SYSTEMTRAY_H_
22 #define SYSTEMTRAY_H_
23
24 #ifndef QT_NO_SYSTEMTRAYICON
25
26 #ifdef HAVE_KDE
27 #  include <KSystemTrayIcon>
28 #else
29 #  include <QSystemTrayIcon>
30 #endif
31
32 #include <QTimer>
33
34 #include "icon.h"
35
36 class SystemTray : public QObject {
37   Q_OBJECT
38
39 public:
40   enum State {
41     Inactive,
42     Active
43   };
44
45   SystemTray(QObject *parent = 0);
46   ~SystemTray();
47
48   inline bool isSystemTrayAvailable() const;
49   inline bool isAlerted() const;
50
51   inline void setInhibitActivation();
52
53 public slots:
54   void setState(State);
55   void setAlert(bool alert = true);
56   void setIconVisible(bool visible = true);
57   void setToolTip(const QString &tip);
58   void showMessage(const QString &title, const QString &message,
59                    QSystemTrayIcon::MessageIcon icon = QSystemTrayIcon::Information, int millisecondsTimeoutHint = 10000);
60
61 signals:
62   void activated(QSystemTrayIcon::ActivationReason);
63   void iconChanged(const Icon &);
64   void messageClicked();
65
66 protected:
67   bool eventFilter(QObject *obj, QEvent *event);
68
69 private slots:
70   void nextPhase();
71   void on_activated(QSystemTrayIcon::ActivationReason);
72
73 private:
74   void loadAnimations();
75
76 #ifdef HAVE_KDE
77   KSystemTrayIcon *_trayIcon;
78 #else
79   QSystemTrayIcon *_trayIcon;
80 #endif
81
82   QMenu *_trayMenu;
83   State _state;
84   bool _alert;
85   bool _inhibitActivation;
86
87   int _idxOffStart, _idxOffEnd, _idxOnStart, _idxOnEnd, _idxAlertStart;
88   int _currentIdx;
89   QTimer _animationTimer;
90
91   QList<QPixmap> _phases;
92 };
93
94 // inlines
95
96 bool SystemTray::isSystemTrayAvailable() const { return QSystemTrayIcon::isSystemTrayAvailable(); }
97 bool SystemTray::isAlerted() const { return _alert; }
98 void SystemTray::setInhibitActivation() { _inhibitActivation = true; }
99
100 #endif /* QT_NO_SYSTEMTRAYICON */
101
102 #endif