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 ***************************************************************************/
21 #include "systraynotificationbackend.h"
26 #include "clientsettings.h"
29 #include "networkmodel.h"
32 SystrayNotificationBackend::SystrayNotificationBackend(QObject *parent)
33 : AbstractNotificationBackend(parent)
35 NotificationSettings notificationSettings;
36 _showBubble = notificationSettings.value("Systray/ShowBubble", true).toBool();
37 _animate = notificationSettings.value("Systray/Animate", true).toBool();
39 notificationSettings.notify("Systray/ShowBubble", this, SLOT(showBubbleChanged(const QVariant &)));
40 notificationSettings.notify("Systray/Animate", this, SLOT(animateChanged(const QVariant &)));
43 connect(&_animationTimer, SIGNAL(timeout()), SLOT(blink()));
46 void SystrayNotificationBackend::notify(const Notification ¬ification) {
47 /* fancy stuff to be implemented later: show notifications in order
48 _notifications.append(notification);
49 if(_showBubble && _notifications.count() == 1) {
53 _notifications.clear();
54 _notifications.append(notification);
63 void SystrayNotificationBackend::close(uint notificationId) {
64 Q_UNUSED(notificationId);
65 /* fancy stuff to be implemented later
66 int idx = _notifications.indexOf(notificationId);
68 if(_notifications.isEmpty()) {
70 _notifications.clear();
75 void SystrayNotificationBackend::showBubble() {
76 // fancy stuff later: show messages in order
77 // for now, we just show the last message
78 if(_notifications.isEmpty()) return;
79 Notification n = _notifications.takeLast();
80 QString title = Client::networkModel()->networkName(n.bufferId) + " - " + Client::networkModel()->bufferName(n.bufferId);
81 QString message = QString("<%1> %2").arg(n.sender, n.message);
82 QtUi::mainWindow()->systemTrayIcon()->showMessage(title, message);
85 void SystrayNotificationBackend::closeBubble() {
86 // there really seems to be no sane way to close the bubble... :(
88 QtUi::mainWindow()->systemTrayIcon()->showMessage("", "", QSystemTrayIcon::NoIcon, 1);
92 void SystrayNotificationBackend::showBubbleChanged(const QVariant &v) {
93 _showBubble = v.toBool();
96 void SystrayNotificationBackend::startAnimation() {
97 if(!_animationTimer.isActive())
98 _animationTimer.start(500);
101 void SystrayNotificationBackend::stopAnimation() {
102 _animationTimer.stop();
103 QtUi::mainWindow()->systemTrayIcon()->setIcon(Icon("quassel"));
107 void SystrayNotificationBackend::blink() {
108 QtUi::mainWindow()->systemTrayIcon()->setIcon(_iconActive ? Icon("quassel") : Icon("quassel_newmessage"));
109 _iconActive = !_iconActive;
112 void SystrayNotificationBackend::animateChanged(const QVariant &v) {
113 _animate = v.toBool();
116 SettingsPage *SystrayNotificationBackend::createConfigWidget() const {
117 return new ConfigWidget();
120 /***************************************************************************/
122 SystrayNotificationBackend::ConfigWidget::ConfigWidget(QWidget *parent) : SettingsPage("Internal", "SystrayNotification", parent) {
123 QGroupBox *groupBox = new QGroupBox(tr("System Tray Icon"), this);
124 _animateBox = new QCheckBox(tr("Animate"));
125 connect(_animateBox, SIGNAL(toggled(bool)), this, SLOT(widgetChanged()));
126 _showBubbleBox = new QCheckBox(tr("Show bubble"));
127 connect(_showBubbleBox, SIGNAL(toggled(bool)), this, SLOT(widgetChanged()));
128 QVBoxLayout *layout = new QVBoxLayout(groupBox);
129 layout->addWidget(_animateBox);
130 layout->addWidget(_showBubbleBox);
131 layout->addStretch(1);
132 QVBoxLayout *globalLayout = new QVBoxLayout(this);
133 globalLayout->addWidget(groupBox);
137 void SystrayNotificationBackend::ConfigWidget::widgetChanged() {
138 bool changed = (_showBubble != _showBubbleBox->isChecked() || _animate != _animateBox->isChecked());
139 if(changed != hasChanged()) setChangedState(changed);
142 bool SystrayNotificationBackend::ConfigWidget::hasDefaults() const {
146 void SystrayNotificationBackend::ConfigWidget::defaults() {
147 _animateBox->setChecked(true);
148 _showBubbleBox->setChecked(false);
152 void SystrayNotificationBackend::ConfigWidget::load() {
153 NotificationSettings s;
154 _animate = s.value("Systray/Animate", true).toBool();
155 _showBubble = s.value("Systray/ShowBubble", false).toBool();
156 _animateBox->setChecked(_animate);
157 _showBubbleBox->setChecked(_showBubble);
158 setChangedState(false);
161 void SystrayNotificationBackend::ConfigWidget::save() {
162 NotificationSettings s;
163 s.setValue("Systray/Animate", _animateBox->isChecked());
164 s.setValue("Systray/ShowBubble", _showBubbleBox->isChecked());