Quassel IRC  Pre-Release
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros
systraynotificationbackend.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  * Copyright (C) 2005-2015 by the Quassel Project *
3  * devel@quassel-irc.org *
4  * *
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. *
9  * *
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. *
14  * *
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  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
19  ***************************************************************************/
20 
21 #include <QApplication>
22 #include <QCheckBox>
23 #include <QGroupBox>
24 #include <QIcon>
25 #include <QHBoxLayout>
26 
28 
29 #include "client.h"
30 #include "clientsettings.h"
31 #include "mainwin.h"
32 #include "networkmodel.h"
33 #include "qtui.h"
34 #include "systemtray.h"
35 
38  _blockActivation(false)
39 {
40  NotificationSettings notificationSettings;
41  notificationSettings.initAndNotify("Systray/ShowBubble", this, SLOT(showBubbleChanged(QVariant)), true);
42  notificationSettings.initAndNotify("Systray/Animate", this, SLOT(animateChanged(QVariant)), true);
43 
44  connect(QtUi::mainWindow()->systemTray(), SIGNAL(messageClicked(uint)), SLOT(notificationActivated(uint)));
45  connect(QtUi::mainWindow()->systemTray(), SIGNAL(activated(SystemTray::ActivationReason)),
47 
48  QApplication::instance()->installEventFilter(this);
49 
50  updateToolTip();
51 }
52 
53 
55 {
56  if (n.type != Highlight && n.type != PrivMsg)
57  return;
58 
59  _notifications.append(n);
60  if (_showBubble) {
62  QString message = QString("<%1> %2").arg(n.sender, n.message);
64  }
65 
66  if (_animate)
68 
69  updateToolTip();
70 }
71 
72 
73 void SystrayNotificationBackend::close(uint notificationId)
74 {
75  QList<Notification>::iterator i = _notifications.begin();
76  while (i != _notifications.end()) {
77  if (i->notificationId == notificationId)
78  i = _notifications.erase(i);
79  else
80  ++i;
81  }
82 
83  QtUi::mainWindow()->systemTray()->closeMessage(notificationId);
84 
85  //if(!_notifications.count()) //FIXME make configurable
87 
88  updateToolTip();
89 }
90 
91 
93 {
94  if (!_blockActivation) {
95  if (_notifications.count()) {
97  _blockActivation = true; // prevent double activation because both tray icon and bubble might send a signal
98  if (!notificationId)
99  notificationId = _notifications.count() ? _notifications.last().notificationId : 0;
100  emit activated(notificationId);
101  }
102  else
104  }
105 }
106 
107 
109 {
110  if (reason == SystemTray::Trigger) {
112  }
113 }
114 
115 
116 // moving the mouse or releasing the button means that we're not dealing with a double activation
117 bool SystrayNotificationBackend::eventFilter(QObject *obj, QEvent *event)
118 {
119  if (event->type() == QEvent::MouseMove || event->type() == QEvent::MouseButtonRelease) {
120  _blockActivation = false;
121  }
122  return AbstractNotificationBackend::eventFilter(obj, event);
123 }
124 
125 
127 {
128  _showBubble = v.toBool();
129 }
130 
131 
133 {
134  _animate = v.toBool();
135 }
136 
137 
139 {
140  QtUi::mainWindow()->systemTray()->setToolTip("Quassel IRC",
141  _notifications.count() ? tr("%n pending highlight(s)", "", _notifications.count()) : QString());
142 }
143 
144 
146 {
147  return new ConfigWidget();
148 }
149 
150 
151 /***************************************************************************/
152 
153 SystrayNotificationBackend::ConfigWidget::ConfigWidget(QWidget *parent) : SettingsPage("Internal", "SystrayNotification", parent)
154 {
155  _showBubbleBox = new QCheckBox(tr("Show a message in a popup"));
156  _showBubbleBox->setIcon(QIcon::fromTheme("dialog-information"));
157  connect(_showBubbleBox, SIGNAL(toggled(bool)), this, SLOT(widgetChanged()));
158  QHBoxLayout *layout = new QHBoxLayout(this);
159  layout->addWidget(_showBubbleBox);
160 }
161 
162 
164 {
165  bool changed = (_showBubble != _showBubbleBox->isChecked());
166  if (changed != hasChanged())
167  setChangedState(changed);
168 }
169 
170 
172 {
173  return true;
174 }
175 
176 
178 {
179  _showBubbleBox->setChecked(false);
180  widgetChanged();
181 }
182 
183 
185 {
187  _showBubble = s.value("Systray/ShowBubble", false).toBool();
188  _showBubbleBox->setChecked(_showBubble);
189  setChangedState(false);
190 }
191 
192 
194 {
196  s.setValue("Systray/ShowBubble", _showBubbleBox->isChecked());
197  load();
198 }