Quassel IRC  Pre-Release
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros
taskbarnotificationbackend.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 <QHBoxLayout>
24 #include <QIcon>
25 #include <QSpinBox>
26 
28 
29 #include "clientsettings.h"
30 #include "mainwin.h"
31 #include "qtui.h"
32 
35 {
36  NotificationSettings notificationSettings;
37  _enabled = notificationSettings.value("Taskbar/Enabled", true).toBool();
38  _timeout = notificationSettings.value("Taskbar/Timeout", 0).toInt();
39 
40  notificationSettings.notify("Taskbar/Enabled", this, SLOT(enabledChanged(const QVariant &)));
41  notificationSettings.notify("Taskbar/Timeout", this, SLOT(timeoutChanged(const QVariant &)));
42 }
43 
44 
46 {
47  if (_enabled && (notification.type == Highlight || notification.type == PrivMsg)) {
48  QApplication::alert(QtUi::mainWindow(), _timeout);
49  }
50 }
51 
52 
53 void TaskbarNotificationBackend::close(uint notificationId)
54 {
55  Q_UNUSED(notificationId);
56 }
57 
58 
60 {
61  _enabled = v.toBool();
62 }
63 
64 
66 {
67  _timeout = v.toInt();
68 }
69 
70 
72 {
73  return new ConfigWidget();
74 }
75 
76 
77 /***************************************************************************/
78 
79 TaskbarNotificationBackend::ConfigWidget::ConfigWidget(QWidget *parent) : SettingsPage("Internal", "TaskbarNotification", parent)
80 {
81  QHBoxLayout *layout = new QHBoxLayout(this);
82 #ifdef Q_OS_MAC
83  layout->addWidget(enabledBox = new QCheckBox(tr("Activate dock entry, timeout:"), this));
84 #else
85  layout->addWidget(enabledBox = new QCheckBox(tr("Mark taskbar entry, timeout:"), this));
86 #endif
87  enabledBox->setIcon(QIcon::fromTheme("flag-blue"));
88  enabledBox->setEnabled(true);
89 
90  timeoutBox = new QSpinBox(this);
91  timeoutBox->setMinimum(0);
92  timeoutBox->setMaximum(99);
93  timeoutBox->setSpecialValueText(tr("Unlimited"));
94  timeoutBox->setSuffix(tr(" seconds"));
95  layout->addWidget(timeoutBox);
96  layout->addStretch(20);
97 
98  connect(enabledBox, SIGNAL(toggled(bool)), SLOT(widgetChanged()));
99  connect(enabledBox, SIGNAL(toggled(bool)), timeoutBox, SLOT(setEnabled(bool)));
100  connect(timeoutBox, SIGNAL(valueChanged(int)), SLOT(widgetChanged()));
101 }
102 
103 
105 {
106  bool changed = (enabled != enabledBox->isChecked() || timeout/1000 != timeoutBox->value());
107  if (changed != hasChanged()) setChangedState(changed);
108 }
109 
110 
112 {
113  return true;
114 }
115 
116 
118 {
119  enabledBox->setChecked(true);
120  timeoutBox->setValue(0);
121  widgetChanged();
122 }
123 
124 
126 {
128  enabled = s.value("Taskbar/Enabled", true).toBool();
129  timeout = s.value("Taskbar/Timeout", 0).toInt();
130 
131  enabledBox->setChecked(enabled);
132  timeoutBox->setValue(timeout/1000);
133 
134  setChangedState(false);
135 }
136 
137 
139 {
141  s.setValue("Taskbar/Enabled", enabledBox->isChecked());
142  s.setValue("Taskbar/Timeout", timeoutBox->value() * 1000);
143  load();
144 }