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 "actioncollection.h"
24 #include "chatlinemodel.h"
26 #include "abstractnotificationbackend.h"
27 #include "qtuimessageprocessor.h"
28 #include "qtuistyle.h"
30 #include "uisettings.h"
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;
39 QtUi::QtUi() : AbstractUi() {
41 qWarning() << "QtUi has been instantiated again!";
44 _actionCollection = new ActionCollection(this);
46 UiSettings uiSettings;
47 loadTranslation(uiSettings.value("Locale", QLocale::system()).value<QLocale>());
49 _mainWin = new MainWin();
50 _style = new QtUiStyle;
52 connect(_mainWin, SIGNAL(connectToCore(const QVariantMap &)), this, SIGNAL(connectToCore(const QVariantMap &)));
53 connect(_mainWin, SIGNAL(disconnectFromCore()), this, SIGNAL(disconnectFromCore()));
57 unregisterAllNotificationBackends();
66 MessageModel *QtUi::createMessageModel(QObject *parent) {
67 return new ChatLineModel(parent);
70 AbstractMessageProcessor *QtUi::createMessageProcessor(QObject *parent) {
71 return new QtUiMessageProcessor(parent);
74 void QtUi::connectedToCore() {
75 _mainWin->connectedToCore();
78 void QtUi::disconnectedFromCore() {
79 _mainWin->disconnectedFromCore();
82 void QtUi::registerNotificationBackend(AbstractNotificationBackend *backend) {
83 if(!_notificationBackends.contains(backend)) {
84 _notificationBackends.append(backend);
88 void QtUi::unregisterNotificationBackend(AbstractNotificationBackend *backend) {
89 _notificationBackends.removeAll(backend);
92 void QtUi::unregisterAllNotificationBackends() {
93 _notificationBackends.clear();
96 const QList<AbstractNotificationBackend *> &QtUi::notificationBackends() {
97 return _notificationBackends;
100 uint QtUi::invokeNotification(BufferId bufId, const QString &sender, const QString &text) {
101 static int notificationId = 0;
103 AbstractNotificationBackend::Notification notification(++notificationId, bufId, sender, text);
104 _notifications.append(notification);
105 foreach(AbstractNotificationBackend *backend, _notificationBackends)
106 backend->notify(notification);
107 return notificationId;
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);
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);
135 const QList<AbstractNotificationBackend::Notification> &QtUi::activeNotifications() {
136 return _notifications;