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 "buffermodel.h"
25 #include "chatlinemodel.h"
26 #include "contextmenuactionprovider.h"
28 #include "qtuimessageprocessor.h"
29 #include "qtuisettings.h"
30 #include "qtuistyle.h"
31 #include "systemtray.h"
32 #include "toolbaractionprovider.h"
40 QPointer<QtUi> QtUi::_instance = 0;
41 QPointer<MainWin> QtUi::_mainWin = 0;
42 QList<AbstractNotificationBackend *> QtUi::_notificationBackends;
43 QList<AbstractNotificationBackend::Notification> QtUi::_notifications;
45 QtUi::QtUi() : GraphicalUi() {
47 qWarning() << "QtUi has been instantiated again!";
52 QtUiSettings uiSettings;
53 Quassel::loadTranslation(uiSettings.value("Locale", QLocale::system()).value<QLocale>());
55 setContextMenuActionProvider(new ContextMenuActionProvider(this));
56 setToolBarActionProvider(new ToolBarActionProvider(this));
58 setUiStyle(new QtUiStyle(this));
59 _mainWin = new MainWin();
61 setMainWidget(_mainWin);
63 connect(_mainWin, SIGNAL(connectToCore(const QVariantMap &)), this, SIGNAL(connectToCore(const QVariantMap &)));
64 connect(_mainWin, SIGNAL(disconnectFromCore()), this, SIGNAL(disconnectFromCore()));
68 unregisterAllNotificationBackends();
76 MessageModel *QtUi::createMessageModel(QObject *parent) {
77 return new ChatLineModel(parent);
80 AbstractMessageProcessor *QtUi::createMessageProcessor(QObject *parent) {
81 return new QtUiMessageProcessor(parent);
84 void QtUi::connectedToCore() {
85 _mainWin->connectedToCore();
88 void QtUi::disconnectedFromCore() {
89 _mainWin->disconnectedFromCore();
92 bool QtUi::haveSystemTray() {
93 #ifdef QT_NO_SYSTEMTRAYICON
96 return mainWindow()->systemTray()->isSystemTrayAvailable();
100 void QtUi::registerNotificationBackend(AbstractNotificationBackend *backend) {
101 if(!_notificationBackends.contains(backend)) {
102 _notificationBackends.append(backend);
103 instance()->connect(backend, SIGNAL(activated(uint)), SLOT(notificationActivated(uint)));
107 void QtUi::unregisterNotificationBackend(AbstractNotificationBackend *backend) {
108 _notificationBackends.removeAll(backend);
111 void QtUi::unregisterAllNotificationBackends() {
112 _notificationBackends.clear();
115 const QList<AbstractNotificationBackend *> &QtUi::notificationBackends() {
116 return _notificationBackends;
119 uint QtUi::invokeNotification(BufferId bufId, AbstractNotificationBackend::NotificationType type, const QString &sender, const QString &text) {
120 static int notificationId = 0;
122 AbstractNotificationBackend::Notification notification(++notificationId, bufId, type, sender, text);
123 _notifications.append(notification);
124 foreach(AbstractNotificationBackend *backend, _notificationBackends)
125 backend->notify(notification);
126 return notificationId;
129 void QtUi::closeNotification(uint notificationId) {
130 QList<AbstractNotificationBackend::Notification>::iterator i = _notifications.begin();
131 while(i != _notifications.end()) {
132 if(i->notificationId == notificationId) {
133 foreach(AbstractNotificationBackend *backend, _notificationBackends)
134 backend->close(notificationId);
135 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);
151 const QList<AbstractNotificationBackend::Notification> &QtUi::activeNotifications() {
152 return _notifications;
155 void QtUi::notificationActivated(uint notificationId) {
156 if(notificationId != 0) {
157 QList<AbstractNotificationBackend::Notification>::iterator i = _notifications.begin();
158 while(i != _notifications.end()) {
159 if(i->notificationId == notificationId) {
160 BufferId bufId = i->bufferId;
162 Client::bufferModel()->switchToBuffer(bufId);
168 closeNotification(notificationId);
170 mainWindow()->forceActivated();