dc31edc7e7996b62a0257e1fd2ae79f7c0ef8fd9
[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   Q_ENUMS(State Mode MessageIcon ActivationReason)
31
32 public:
33   enum State {
34     Passive,
35     Active,
36     NeedsAttention
37   };
38
39   enum Mode {
40     Invalid,
41     Legacy,
42     StatusNotifier
43   };
44
45   // same as in QSystemTrayIcon
46   enum MessageIcon {
47     NoIcon,
48     Information,
49     Warning,
50     Critical
51   };
52
53   // same as in QSystemTrayIcon
54   enum ActivationReason {
55     Unknown,
56     Context,
57     DoubleClick,
58     Trigger,
59     MiddleClick
60   };
61
62   explicit SystemTray(QWidget *parent);
63   virtual ~SystemTray();
64   virtual void init() {}
65
66   inline State state() const;
67   inline bool isAlerted() const;
68   virtual inline bool isSystemTrayAvailable() const;
69
70   void setAlert(bool alerted);
71   virtual inline bool isVisible() const { return false; }
72
73   QWidget *associatedWidget() const;
74
75 public slots:
76   virtual void setState(State);
77   virtual void setVisible(bool visible = true);
78   virtual void setToolTip(const QString &title, const QString &subtitle);
79   virtual void showMessage(const QString &title, const QString &message, MessageIcon icon = Information, int millisecondsTimeoutHint = 10000);
80
81 signals:
82   void activated(SystemTray::ActivationReason);
83   void iconChanged(const Icon &);
84   void toolTipChanged(const QString &title, const QString &subtitle);
85   void messageClicked();
86
87 protected slots:
88   virtual void activate(SystemTray::ActivationReason = Trigger);
89
90 protected:
91   virtual void setMode(Mode mode);
92   inline Mode mode() const;
93
94   virtual Icon stateIcon() const;
95   Icon stateIcon(State state) const;
96   inline QString toolTipTitle() const;
97   inline QString toolTipSubTitle() const;
98   inline QMenu *trayMenu() const;
99   void setTrayMenu(QMenu *);
100
101 private slots:
102
103 private:
104   Mode _mode;
105   State _state;
106
107   QString _toolTipTitle, _toolTipSubTitle;
108   Icon _passiveIcon, _activeIcon, _needsAttentionIcon;
109
110   QMenu *_trayMenu;
111   QWidget *_associatedWidget;
112 };
113
114 // inlines
115
116 bool SystemTray::isSystemTrayAvailable() const { return false; }
117 bool SystemTray::isAlerted() const { return state() == NeedsAttention; }
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