1 /***************************************************************************
2 * Copyright (C) 2005-09 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"
26 #include "contextmenuactionprovider.h"
28 #include "qtuimessageprocessor.h"
29 #include "qtuisettings.h"
30 #include "qtuistyle.h"
31 #include "toolbaractionprovider.h"
35 QHash<QString, ActionCollection *> QtUi::_actionCollections;
36 QPointer<QtUi> QtUi::_instance = 0;
37 QPointer<MainWin> QtUi::_mainWin = 0;
38 QList<AbstractNotificationBackend *> QtUi::_notificationBackends;
39 QList<AbstractNotificationBackend::Notification> QtUi::_notifications;
40 QtUiStyle *QtUi::_style = 0;
42 QtUi::QtUi() : GraphicalUi() {
44 qWarning() << "QtUi has been instantiated again!";
49 setContextMenuActionProvider(new ContextMenuActionProvider(this));
50 setToolBarActionProvider(new ToolBarActionProvider(this));
52 QtUiSettings uiSettings;
53 Quassel::loadTranslation(uiSettings.value("Locale", QLocale::system()).value<QLocale>());
55 _mainWin = new MainWin();
56 _style = new QtUiStyle;
58 connect(_mainWin, SIGNAL(connectToCore(const QVariantMap &)), this, SIGNAL(connectToCore(const QVariantMap &)));
59 connect(_mainWin, SIGNAL(disconnectFromCore()), this, SIGNAL(disconnectFromCore()));
63 unregisterAllNotificationBackends();
72 ActionCollection *QtUi::actionCollection(const QString &category) {
73 if(_actionCollections.contains(category))
74 return _actionCollections.value(category);
75 ActionCollection *coll = new ActionCollection(mainWindow());
76 coll->addAssociatedWidget(mainWindow());
77 _actionCollections.insert(category, coll);
81 MessageModel *QtUi::createMessageModel(QObject *parent) {
82 return new ChatLineModel(parent);
85 AbstractMessageProcessor *QtUi::createMessageProcessor(QObject *parent) {
86 return new QtUiMessageProcessor(parent);
89 void QtUi::connectedToCore() {
90 _mainWin->connectedToCore();
93 void QtUi::disconnectedFromCore() {
94 _mainWin->disconnectedFromCore();
97 void QtUi::registerNotificationBackend(AbstractNotificationBackend *backend) {
98 if(!_notificationBackends.contains(backend)) {
99 _notificationBackends.append(backend);
100 instance()->connect(backend, SIGNAL(activated()), SLOT(notificationActivated()));
104 void QtUi::unregisterNotificationBackend(AbstractNotificationBackend *backend) {
105 _notificationBackends.removeAll(backend);
108 void QtUi::unregisterAllNotificationBackends() {
109 _notificationBackends.clear();
112 const QList<AbstractNotificationBackend *> &QtUi::notificationBackends() {
113 return _notificationBackends;
116 uint QtUi::invokeNotification(BufferId bufId, const QString &sender, const QString &text) {
117 static int notificationId = 0;
119 AbstractNotificationBackend::Notification notification(++notificationId, bufId, sender, text);
120 _notifications.append(notification);
121 foreach(AbstractNotificationBackend *backend, _notificationBackends)
122 backend->notify(notification);
123 return notificationId;
126 void QtUi::closeNotification(uint notificationId) {
127 QList<AbstractNotificationBackend::Notification>::iterator i = _notifications.begin();
128 while(i != _notifications.end()) {
129 if((*i).notificationId == notificationId) {
130 foreach(AbstractNotificationBackend *backend, _notificationBackends)
131 backend->close(notificationId);
132 i = _notifications.erase(i);
140 void QtUi::closeNotifications(BufferId bufferId) {
141 QList<AbstractNotificationBackend::Notification>::iterator i = _notifications.begin();
142 while(i != _notifications.end()) {
143 if(!bufferId.isValid() || (*i).bufferId == bufferId) {
144 foreach(AbstractNotificationBackend *backend, _notificationBackends)
145 backend->close((*i).notificationId);
146 i = _notifications.erase(i);
153 const QList<AbstractNotificationBackend::Notification> &QtUi::activeNotifications() {
154 return _notifications;
157 void QtUi::notificationActivated() {
158 // this might not work with some window managers
160 _mainWin->activateWindow();