1eb038f2f85591ca123b1fbfca9068c73dac90c9
[quassel.git] / src / qtui / qtui.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 QTUI_H
22 #define QTUI_H
23
24 #include "graphicalui.h"
25
26 #include "abstractnotificationbackend.h"
27 #include "mainwin.h"
28 #include "qtuistyle.h"
29
30 class MainWin;
31 class MessageModel;
32 class QtUiMessageProcessor;
33
34 //! This class encapsulates Quassel's Qt-based GUI.
35 /** This is basically a wrapper around MainWin, which is necessary because we cannot derive MainWin
36  *  from both QMainWindow and AbstractUi (because of multiple inheritance of QObject).
37  */
38 class QtUi : public GraphicalUi {
39   Q_OBJECT
40
41 public:
42   QtUi();
43   ~QtUi();
44
45   MessageModel *createMessageModel(QObject *parent);
46   AbstractMessageProcessor *createMessageProcessor(QObject *parent);
47
48   inline static QtUi *instance();
49   inline static QtUiStyle *style();
50   inline static MainWin *mainWindow();
51
52   static bool haveSystemTray();
53
54   /* Notifications */
55
56   static void registerNotificationBackend(AbstractNotificationBackend *);
57   static void unregisterNotificationBackend(AbstractNotificationBackend *);
58   static void unregisterAllNotificationBackends();
59   static const QList<AbstractNotificationBackend *> &notificationBackends();
60   static uint invokeNotification(BufferId bufId, AbstractNotificationBackend::NotificationType type, const QString &sender, const QString &text);
61   static void closeNotification(uint notificationId);
62   static void closeNotifications(BufferId bufferId = BufferId());
63   static const QList<AbstractNotificationBackend::Notification> &activeNotifications();
64
65 public slots:
66   virtual void init();
67
68 protected slots:
69   void connectedToCore();
70   void disconnectedFromCore();
71   void notificationActivated(uint notificationId);
72
73 protected:
74   virtual void minimizeRestore(bool show);
75   virtual bool isHidingMainWidgetAllowed() const;
76
77 private slots:
78   void useSystemTrayChanged(const QVariant &);
79
80 private:
81   static QPointer<QtUi> _instance;
82   static QPointer<MainWin> _mainWin;
83   static QList<AbstractNotificationBackend *> _notificationBackends;
84   static QList<AbstractNotificationBackend::Notification> _notifications;
85
86   bool _useSystemTray;
87 };
88
89 QtUi *QtUi::instance() { return _instance ? _instance.data() : new QtUi(); }
90 QtUiStyle *QtUi::style() { return qobject_cast<QtUiStyle*>(uiStyle()); }
91 MainWin *QtUi::mainWindow() { return _mainWin; }
92
93 #endif