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