7192b3fe38c88d76260063a19c161a45c748f3ce
[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 void setInhibitActivation();
72   virtual inline bool isVisible() const { return false; }
73   inline bool isActivationInhibited() const;
74
75   QWidget *associatedWidget() const;
76
77 public slots:
78   virtual void setState(State);
79   virtual void setVisible(bool visible = true);
80   virtual void setToolTip(const QString &title, const QString &subtitle);
81   virtual void showMessage(const QString &title, const QString &message, MessageIcon icon = Information, int millisecondsTimeoutHint = 10000);
82
83 signals:
84   void activated(SystemTray::ActivationReason);
85   void iconChanged(const Icon &);
86   void toolTipChanged(const QString &title, const QString &subtitle);
87   void messageClicked();
88
89 protected slots:
90   virtual void activate(SystemTray::ActivationReason = Trigger);
91
92 protected:
93   virtual void setMode(Mode mode);
94   inline Mode mode() const;
95
96   virtual Icon stateIcon() const;
97   Icon stateIcon(State state) const;
98   inline QString toolTipTitle() const;
99   inline QString toolTipSubTitle() const;
100   inline QMenu *trayMenu() const;
101   void setTrayMenu(QMenu *);
102
103   virtual bool eventFilter(QObject *obj, QEvent *event);
104
105 private slots:
106
107 private:
108   Mode _mode;
109   State _state;
110
111   bool _inhibitActivation;
112
113   QString _toolTipTitle, _toolTipSubTitle;
114   Icon _passiveIcon, _activeIcon, _needsAttentionIcon;
115
116   QMenu *_trayMenu;
117   QWidget *_associatedWidget;
118 };
119
120 // inlines
121
122 bool SystemTray::isSystemTrayAvailable() const { return false; }
123 bool SystemTray::isAlerted() const { return state() == NeedsAttention; }
124 void SystemTray::setInhibitActivation() { _inhibitActivation = true; }
125 bool SystemTray::isActivationInhibited() const { return _inhibitActivation; }
126 SystemTray::Mode SystemTray::mode() const { return _mode; }
127 SystemTray::State SystemTray::state() const { return _state; }
128 QMenu *SystemTray::trayMenu() const { return _trayMenu; }
129 QString SystemTray::toolTipTitle() const { return _toolTipTitle; }
130 QString SystemTray::toolTipSubTitle() const { return _toolTipSubTitle; }
131
132
133 #endif