Make _mainWin a QPointer, to avoid problems with double deletion in case we use KDE
[quassel.git] / src / qtui / qtui.h
1 /***************************************************************************
2  *   Copyright (C) 2005-08 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 "quasselui.h"
25
26 #include "abstractnotificationbackend.h"
27 #include "mainwin.h"
28
29 class ActionCollection;
30 class MainWin;
31 class MessageModel;
32 class QtUiMessageProcessor;
33 class QtUiStyle;
34
35 //! This class encapsulates Quassel's Qt-based GUI.
36 /** This is basically a wrapper around MainWin, which is necessary because we cannot derive MainWin
37  *  from both QMainWindow and AbstractUi (because of multiple inheritance of QObject).
38  */
39 class QtUi : public AbstractUi {
40   Q_OBJECT
41
42 public:
43   QtUi();
44   ~QtUi();
45
46   MessageModel *createMessageModel(QObject *parent);
47   AbstractMessageProcessor *createMessageProcessor(QObject *parent);
48
49   inline static QtUiStyle *style();
50   inline static MainWin *mainWindow();
51
52   //! Access global ActionCollections.
53   /** These ActionCollections are associated with the main window, i.e. they contain global
54    *  actions (and thus, shortcuts). Widgets providing application-wide shortcuts should
55    *  create appropriate Action objects using QtUi::actionCollection(cat)->add\<Action\>().
56    *  @param category The category (default: "General")
57    */
58   static ActionCollection *actionCollection(const QString &category = "General");
59   inline AbstractActionProvider *actionProvider() const;
60
61   /* Notifications */
62
63   static void registerNotificationBackend(AbstractNotificationBackend *);
64   static void unregisterNotificationBackend(AbstractNotificationBackend *);
65   static void unregisterAllNotificationBackends();
66   static const QList<AbstractNotificationBackend *> &notificationBackends();
67   static uint invokeNotification(BufferId bufId, const QString &sender, const QString &text);
68   static void closeNotification(uint notificationId);
69   static void closeNotifications(BufferId bufferId = BufferId());
70   static const QList<AbstractNotificationBackend::Notification> &activeNotifications();
71
72 public slots:
73   void init();
74
75 protected slots:
76   void connectedToCore();
77   void disconnectedFromCore();
78
79 private:
80   AbstractActionProvider *_actionProvider;
81
82   static QPointer<MainWin> _mainWin;
83   static QHash<QString, ActionCollection *> _actionCollections;
84   static QtUiStyle *_style;
85   static QList<AbstractNotificationBackend *> _notificationBackends;
86   static QList<AbstractNotificationBackend::Notification> _notifications;
87 };
88
89 QtUiStyle *QtUi::style() { return _style; }
90 MainWin *QtUi::mainWindow() { return _mainWin; }
91 AbstractActionProvider *QtUi::actionProvider() const { return _actionProvider; }
92
93 #endif