1 /***************************************************************************
2 * Copyright (C) 2005-08 by the Quassel Project *
3 * devel@quassel-irc.org *
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. *
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. *
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 ***************************************************************************/
23 #include "abstractnotificationbackend.h"
24 #include "actioncollection.h"
25 #include "chatlinemodel.h"
27 #include "networkmodelactionprovider.h"
28 #include "qtuimessageprocessor.h"
29 #include "qtuisettings.h"
30 #include "qtuistyle.h"
34 QHash<QString, ActionCollection *> QtUi::_actionCollections;
35 QPointer<MainWin> QtUi::_mainWin = 0;
36 QList<AbstractNotificationBackend *> QtUi::_notificationBackends;
37 QList<AbstractNotificationBackend::Notification> QtUi::_notifications;
38 QtUiStyle *QtUi::_style = 0;
40 QtUi::QtUi() : AbstractUi() {
42 qWarning() << "QtUi has been instantiated again!";
46 _actionProvider = new NetworkModelActionProvider(this);
48 QtUiSettings uiSettings;
49 loadTranslation(uiSettings.value("Locale", QLocale::system()).value<QLocale>());
51 _mainWin = new MainWin();
52 _style = new QtUiStyle;
54 connect(_mainWin, SIGNAL(connectToCore(const QVariantMap &)), this, SIGNAL(connectToCore(const QVariantMap &)));
55 connect(_mainWin, SIGNAL(disconnectFromCore()), this, SIGNAL(disconnectFromCore()));
59 unregisterAllNotificationBackends();
68 ActionCollection *QtUi::actionCollection(const QString &category) {
69 if(_actionCollections.contains(category))
70 return _actionCollections.value(category);
71 ActionCollection *coll = new ActionCollection(mainWindow());
72 coll->addAssociatedWidget(mainWindow());
73 _actionCollections.insert(category, coll);
77 MessageModel *QtUi::createMessageModel(QObject *parent) {
78 return new ChatLineModel(parent);
81 AbstractMessageProcessor *QtUi::createMessageProcessor(QObject *parent) {
82 return new QtUiMessageProcessor(parent);
85 void QtUi::connectedToCore() {
86 _mainWin->connectedToCore();
89 void QtUi::disconnectedFromCore() {
90 _mainWin->disconnectedFromCore();
93 void QtUi::registerNotificationBackend(AbstractNotificationBackend *backend) {
94 if(!_notificationBackends.contains(backend)) {
95 _notificationBackends.append(backend);
99 void QtUi::unregisterNotificationBackend(AbstractNotificationBackend *backend) {
100 _notificationBackends.removeAll(backend);
103 void QtUi::unregisterAllNotificationBackends() {
104 _notificationBackends.clear();
107 const QList<AbstractNotificationBackend *> &QtUi::notificationBackends() {
108 return _notificationBackends;
111 uint QtUi::invokeNotification(BufferId bufId, const QString &sender, const QString &text) {
112 static int notificationId = 0;
114 AbstractNotificationBackend::Notification notification(++notificationId, bufId, sender, text);
115 _notifications.append(notification);
116 foreach(AbstractNotificationBackend *backend, _notificationBackends)
117 backend->notify(notification);
118 return notificationId;
121 void QtUi::closeNotification(uint notificationId) {
122 QList<AbstractNotificationBackend::Notification>::iterator i = _notifications.begin();
123 while(i != _notifications.end()) {
124 if((*i).notificationId == notificationId) {
125 foreach(AbstractNotificationBackend *backend, _notificationBackends)
126 backend->close(notificationId);
127 _notifications.erase(i);
134 void QtUi::closeNotifications(BufferId bufferId) {
135 QList<AbstractNotificationBackend::Notification>::iterator i = _notifications.begin();
136 while(i != _notifications.end()) {
137 if(!bufferId.isValid() || (*i).bufferId == bufferId) {
138 foreach(AbstractNotificationBackend *backend, _notificationBackends)
139 backend->close((*i).notificationId);
140 _notifications.erase(i);
146 const QList<AbstractNotificationBackend::Notification> &QtUi::activeNotifications() {
147 return _notifications;