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<QtUi> QtUi::_instance = 0;
36 QPointer<MainWin> QtUi::_mainWin = 0;
37 QList<AbstractNotificationBackend *> QtUi::_notificationBackends;
38 QList<AbstractNotificationBackend::Notification> QtUi::_notifications;
39 QtUiStyle *QtUi::_style = 0;
41 QtUi::QtUi() : AbstractUi() {
43 qWarning() << "QtUi has been instantiated again!";
48 _actionProvider = new NetworkModelActionProvider(this);
50 QtUiSettings uiSettings;
51 loadTranslation(uiSettings.value("Locale", QLocale::system()).value<QLocale>());
53 _mainWin = new MainWin();
54 _style = new QtUiStyle;
56 connect(_mainWin, SIGNAL(connectToCore(const QVariantMap &)), this, SIGNAL(connectToCore(const QVariantMap &)));
57 connect(_mainWin, SIGNAL(disconnectFromCore()), this, SIGNAL(disconnectFromCore()));
61 unregisterAllNotificationBackends();
70 ActionCollection *QtUi::actionCollection(const QString &category) {
71 if(_actionCollections.contains(category))
72 return _actionCollections.value(category);
73 ActionCollection *coll = new ActionCollection(mainWindow());
74 coll->addAssociatedWidget(mainWindow());
75 _actionCollections.insert(category, coll);
79 MessageModel *QtUi::createMessageModel(QObject *parent) {
80 return new ChatLineModel(parent);
83 AbstractMessageProcessor *QtUi::createMessageProcessor(QObject *parent) {
84 return new QtUiMessageProcessor(parent);
87 void QtUi::connectedToCore() {
88 _mainWin->connectedToCore();
91 void QtUi::disconnectedFromCore() {
92 _mainWin->disconnectedFromCore();
95 void QtUi::registerNotificationBackend(AbstractNotificationBackend *backend) {
96 if(!_notificationBackends.contains(backend)) {
97 _notificationBackends.append(backend);
98 instance()->connect(backend, SIGNAL(activated()), SLOT(notificationActivated()));
102 void QtUi::unregisterNotificationBackend(AbstractNotificationBackend *backend) {
103 _notificationBackends.removeAll(backend);
106 void QtUi::unregisterAllNotificationBackends() {
107 _notificationBackends.clear();
110 const QList<AbstractNotificationBackend *> &QtUi::notificationBackends() {
111 return _notificationBackends;
114 uint QtUi::invokeNotification(BufferId bufId, const QString &sender, const QString &text) {
115 static int notificationId = 0;
117 AbstractNotificationBackend::Notification notification(++notificationId, bufId, sender, text);
118 _notifications.append(notification);
119 foreach(AbstractNotificationBackend *backend, _notificationBackends)
120 backend->notify(notification);
121 return notificationId;
124 void QtUi::closeNotification(uint notificationId) {
125 QList<AbstractNotificationBackend::Notification>::iterator i = _notifications.begin();
126 while(i != _notifications.end()) {
127 if((*i).notificationId == notificationId) {
128 foreach(AbstractNotificationBackend *backend, _notificationBackends)
129 backend->close(notificationId);
130 _notifications.erase(i);
137 void QtUi::closeNotifications(BufferId bufferId) {
138 QList<AbstractNotificationBackend::Notification>::iterator i = _notifications.begin();
139 while(i != _notifications.end()) {
140 if(!bufferId.isValid() || (*i).bufferId == bufferId) {
141 foreach(AbstractNotificationBackend *backend, _notificationBackends)
142 backend->close((*i).notificationId);
143 _notifications.erase(i);
149 const QList<AbstractNotificationBackend::Notification> &QtUi::activeNotifications() {
150 return _notifications;
153 void QtUi::notificationActivated() {
154 // this might not work with some window managers
156 _mainWin->activateWindow();