b2b0afba7bc3e957faddb05b480242bbeb3ea7fc
[quassel.git] / src / qtui / systemtray.h
1 /***************************************************************************
2  *   Copyright (C) 2005-2010 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 #include "icon.h"
25
26 class QMenu;
27
28 class SystemTray : public QObject {
29   Q_OBJECT
30
31 public:
32   enum State {
33     Passive,
34     Active,
35     NeedsAttention
36   };
37
38   enum Mode {
39     Invalid,
40     Legacy,
41     StatusNotifier
42   };
43
44   // same as in QSystemTrayIcon
45   enum MessageIcon {
46     NoIcon,
47     Information,
48     Warning,
49     Critical
50   };
51
52   // same as in QSystemTrayIcon
53   enum ActivationReason {
54     Unknown,
55     Context,
56     DoubleClick,
57     Trigger,
58     MiddleClick
59   };
60
61   SystemTray(QObject *parent = 0);
62   virtual ~SystemTray();
63   virtual void init() {}
64
65   inline State state() const;
66   inline bool isAlerted() const;
67   virtual inline bool isSystemTrayAvailable() const;
68
69   void setAlert(bool alerted);
70   inline void setInhibitActivation();
71   inline bool isActivationInhibited() const;
72
73 public slots:
74   virtual void setState(State);
75   virtual void setVisible(bool visible = true);
76   virtual void setToolTip(const QString &title, const QString &subtitle);
77   virtual void showMessage(const QString &title, const QString &message, MessageIcon icon = Information, int millisecondsTimeoutHint = 10000);
78
79 signals:
80   void activated(SystemTray::ActivationReason);
81   void iconChanged(const Icon &);
82   void toolTipChanged(const QString &title, const QString &subtitle);
83   void messageClicked();
84
85 protected:
86   virtual void setMode(Mode mode);
87   inline Mode mode() const;
88
89   virtual Icon stateIcon() const;
90   Icon stateIcon(State state) const;
91   inline QString toolTipTitle() const;
92   inline QString toolTipSubTitle() const;
93   inline QMenu *trayMenu() const;
94   void setTrayMenu(QMenu *);
95
96   virtual bool eventFilter(QObject *obj, QEvent *event);
97
98 private slots:
99
100 private:
101   Mode _mode;
102   State _state;
103
104   bool _inhibitActivation;
105
106   QString _toolTipTitle, _toolTipSubTitle;
107   Icon _passiveIcon, _activeIcon, _needsAttentionIcon;
108
109   QMenu *_trayMenu;
110 };
111
112 // inlines
113
114 bool SystemTray::isSystemTrayAvailable() const { return false; }
115 bool SystemTray::isAlerted() const { return state() == NeedsAttention; }
116 void SystemTray::setInhibitActivation() { _inhibitActivation = true; }
117 bool SystemTray::isActivationInhibited() const { return _inhibitActivation; }
118 SystemTray::Mode SystemTray::mode() const { return _mode; }
119 SystemTray::State SystemTray::state() const { return _state; }
120 QMenu *SystemTray::trayMenu() const { return _trayMenu; }
121 QString SystemTray::toolTipTitle() const { return _toolTipTitle; }
122 QString SystemTray::toolTipSubTitle() const { return _toolTipSubTitle; }
123
124
125 #endif