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 "qtuisettings.h"
29 #include "qtuistyle.h"
33 QHash<QString, ActionCollection *> QtUi::_actionCollections;
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!";
45 QtUiSettings uiSettings;
46 loadTranslation(uiSettings.value("Locale", QLocale::system()).value<QLocale>());
48 _mainWin = new MainWin();
49 _style = new QtUiStyle;
51 connect(_mainWin, SIGNAL(connectToCore(const QVariantMap &)), this, SIGNAL(connectToCore(const QVariantMap &)));
52 connect(_mainWin, SIGNAL(disconnectFromCore()), this, SIGNAL(disconnectFromCore()));
56 unregisterAllNotificationBackends();
65 ActionCollection *QtUi::actionCollection(const QString &category) {
66 if(_actionCollections.contains(category))
67 return _actionCollections.value(category);
68 ActionCollection *coll = new ActionCollection(mainWindow());
69 coll->addAssociatedWidget(mainWindow());
70 _actionCollections.insert(category, coll);
74 MessageModel *QtUi::createMessageModel(QObject *parent) {
75 return new ChatLineModel(parent);
78 AbstractMessageProcessor *QtUi::createMessageProcessor(QObject *parent) {
79 return new QtUiMessageProcessor(parent);
82 void QtUi::connectedToCore() {
83 _mainWin->connectedToCore();
86 void QtUi::disconnectedFromCore() {
87 _mainWin->disconnectedFromCore();
90 void QtUi::registerNotificationBackend(AbstractNotificationBackend *backend) {
91 if(!_notificationBackends.contains(backend)) {
92 _notificationBackends.append(backend);
96 void QtUi::unregisterNotificationBackend(AbstractNotificationBackend *backend) {
97 _notificationBackends.removeAll(backend);
100 void QtUi::unregisterAllNotificationBackends() {
101 _notificationBackends.clear();
104 const QList<AbstractNotificationBackend *> &QtUi::notificationBackends() {
105 return _notificationBackends;
108 uint QtUi::invokeNotification(BufferId bufId, const QString &sender, const QString &text) {
109 static int notificationId = 0;
111 AbstractNotificationBackend::Notification notification(++notificationId, bufId, sender, text);
112 _notifications.append(notification);
113 foreach(AbstractNotificationBackend *backend, _notificationBackends)
114 backend->notify(notification);
115 return notificationId;
118 void QtUi::closeNotification(uint notificationId) {
119 QList<AbstractNotificationBackend::Notification>::iterator i = _notifications.begin();
120 while(i != _notifications.end()) {
121 if((*i).notificationId == notificationId) {
122 foreach(AbstractNotificationBackend *backend, _notificationBackends)
123 backend->close(notificationId);
124 _notifications.erase(i);
131 void QtUi::closeNotifications(BufferId bufferId) {
132 QList<AbstractNotificationBackend::Notification>::iterator i = _notifications.begin();
133 while(i != _notifications.end()) {
134 if(!bufferId.isValid() || (*i).bufferId == bufferId) {
135 foreach(AbstractNotificationBackend *backend, _notificationBackends)
136 backend->close((*i).notificationId);
137 _notifications.erase(i);
143 const QList<AbstractNotificationBackend::Notification> &QtUi::activeNotifications() {
144 return _notifications;