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 "chatlinemodel.h"
25 #include "contextmenuactionprovider.h"
27 #include "qtuimessageprocessor.h"
28 #include "qtuisettings.h"
29 #include "qtuistyle.h"
30 #include "toolbaractionprovider.h"
34 QPointer<QtUi> QtUi::_instance = 0;
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() : GraphicalUi() {
42 qWarning() << "QtUi has been instantiated again!";
47 setContextMenuActionProvider(new ContextMenuActionProvider(this));
48 setToolBarActionProvider(new ToolBarActionProvider(this));
50 QtUiSettings uiSettings;
51 Quassel::loadTranslation(uiSettings.value("Locale", QLocale::system()).value<QLocale>());
53 _mainWin = new MainWin();
54 _style = new QtUiStyle;
56 setMainWidget(_mainWin);
58 connect(_mainWin, SIGNAL(connectToCore(const QVariantMap &)), this, SIGNAL(connectToCore(const QVariantMap &)));
59 connect(_mainWin, SIGNAL(disconnectFromCore()), this, SIGNAL(disconnectFromCore()));
63 unregisterAllNotificationBackends();
72 MessageModel *QtUi::createMessageModel(QObject *parent) {
73 return new ChatLineModel(parent);
76 AbstractMessageProcessor *QtUi::createMessageProcessor(QObject *parent) {
77 return new QtUiMessageProcessor(parent);
80 void QtUi::connectedToCore() {
81 _mainWin->connectedToCore();
84 void QtUi::disconnectedFromCore() {
85 _mainWin->disconnectedFromCore();
88 void QtUi::registerNotificationBackend(AbstractNotificationBackend *backend) {
89 if(!_notificationBackends.contains(backend)) {
90 _notificationBackends.append(backend);
91 instance()->connect(backend, SIGNAL(activated()), SLOT(notificationActivated()));
95 void QtUi::unregisterNotificationBackend(AbstractNotificationBackend *backend) {
96 _notificationBackends.removeAll(backend);
99 void QtUi::unregisterAllNotificationBackends() {
100 _notificationBackends.clear();
103 const QList<AbstractNotificationBackend *> &QtUi::notificationBackends() {
104 return _notificationBackends;
107 uint QtUi::invokeNotification(BufferId bufId, const QString &sender, const QString &text) {
108 static int notificationId = 0;
110 AbstractNotificationBackend::Notification notification(++notificationId, bufId, sender, text);
111 _notifications.append(notification);
112 foreach(AbstractNotificationBackend *backend, _notificationBackends)
113 backend->notify(notification);
114 return notificationId;
117 void QtUi::closeNotification(uint notificationId) {
118 QList<AbstractNotificationBackend::Notification>::iterator i = _notifications.begin();
119 while(i != _notifications.end()) {
120 if((*i).notificationId == notificationId) {
121 foreach(AbstractNotificationBackend *backend, _notificationBackends)
122 backend->close(notificationId);
123 i = _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 i = _notifications.erase(i);
144 const QList<AbstractNotificationBackend::Notification> &QtUi::activeNotifications() {
145 return _notifications;
148 void QtUi::notificationActivated() {
149 // this might not work with some window managers
151 _mainWin->activateWindow();