Make position hints configurable again
[quassel.git] / src / qtui / qtui.cpp
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 #include "qtui.h"
22
23 #include "actioncollection.h"
24 #include "chatlinemodel.h"
25 #include "mainwin.h"
26 #include "abstractnotificationbackend.h"
27 #include "qtuimessageprocessor.h"
28 #include "qtuistyle.h"
29 #include "types.h"
30 #include "uisettings.h"
31 #include "util.h"
32
33 ActionCollection *QtUi::_actionCollection = 0;
34 MainWin *QtUi::_mainWin = 0;
35 QList<AbstractNotificationBackend *> QtUi::_notificationBackends;
36 QList<AbstractNotificationBackend::Notification> QtUi::_notifications;
37 QtUiStyle *QtUi::_style = 0;
38
39 QtUi::QtUi() : AbstractUi() {
40   if(_style != 0) {
41     qWarning() << "QtUi has been instantiated again!";
42     return;
43   }
44   _actionCollection = new ActionCollection(this);
45
46   UiSettings uiSettings;
47   loadTranslation(uiSettings.value("Locale", QLocale::system()).value<QLocale>());
48
49   _mainWin = new MainWin();
50   _style = new QtUiStyle;
51
52   connect(_mainWin, SIGNAL(connectToCore(const QVariantMap &)), this, SIGNAL(connectToCore(const QVariantMap &)));
53   connect(_mainWin, SIGNAL(disconnectFromCore()), this, SIGNAL(disconnectFromCore()));
54 }
55
56 QtUi::~QtUi() {
57   unregisterAllNotificationBackends();
58   delete _style;
59   delete _mainWin;
60 }
61
62 void QtUi::init() {
63   _mainWin->init();
64 }
65
66 MessageModel *QtUi::createMessageModel(QObject *parent) {
67   return new ChatLineModel(parent);
68 }
69
70 AbstractMessageProcessor *QtUi::createMessageProcessor(QObject *parent) {
71   return new QtUiMessageProcessor(parent);
72 }
73
74 void QtUi::connectedToCore() {
75   _mainWin->connectedToCore();
76 }
77
78 void QtUi::disconnectedFromCore() {
79   _mainWin->disconnectedFromCore();
80 }
81
82 void QtUi::registerNotificationBackend(AbstractNotificationBackend *backend) {
83   if(!_notificationBackends.contains(backend)) {
84     _notificationBackends.append(backend);
85   }
86 }
87
88 void QtUi::unregisterNotificationBackend(AbstractNotificationBackend *backend) {
89   _notificationBackends.removeAll(backend);
90 }
91
92 void QtUi::unregisterAllNotificationBackends() {
93   _notificationBackends.clear();
94 }
95
96 const QList<AbstractNotificationBackend *> &QtUi::notificationBackends() {
97   return _notificationBackends;
98 }
99
100 uint QtUi::invokeNotification(BufferId bufId, const QString &sender, const QString &text) {
101   static int notificationId = 0;
102   //notificationId++;
103   AbstractNotificationBackend::Notification notification(++notificationId, bufId, sender, text);
104   _notifications.append(notification);
105   foreach(AbstractNotificationBackend *backend, _notificationBackends)
106     backend->notify(notification);
107   return notificationId;
108 }
109
110 void QtUi::closeNotification(uint notificationId) {
111   QList<AbstractNotificationBackend::Notification>::iterator i = _notifications.begin();
112   while(i != _notifications.end()) {
113     if((*i).notificationId == notificationId) {
114       foreach(AbstractNotificationBackend *backend, _notificationBackends)
115         backend->close(notificationId);
116       _notifications.erase(i);
117       break;
118     }
119     ++i;
120   }
121 }
122
123 void QtUi::closeNotifications(BufferId bufferId) {
124   QList<AbstractNotificationBackend::Notification>::iterator i = _notifications.begin();
125   while(i != _notifications.end()) {
126     if(!bufferId.isValid() || (*i).bufferId == bufferId) {
127       foreach(AbstractNotificationBackend *backend, _notificationBackends)
128         backend->close((*i).notificationId);
129       _notifications.erase(i);
130     }
131     ++i;
132   }
133 }
134
135 const QList<AbstractNotificationBackend::Notification> &QtUi::activeNotifications() {
136   return _notifications;
137 }
138