~ubuntu-branches/ubuntu/vivid/quassel/vivid-updates

« back to all changes in this revision

Viewing changes to src/qtui/taskbarnotificationbackend.cpp

  • Committer: Package Import Robot
  • Author(s): Scott Kitterman
  • Date: 2013-03-06 15:07:41 UTC
  • mfrom: (1.1.49)
  • Revision ID: package-import@ubuntu.com-20130306150741-pys1igw1g8uhja38
Tags: 0.9~beta1-0ubuntu1
* New upstream beta release
  - Remove debian/patches/0001-Support-intermediate-CA-certificates.patch,
    incorporated upstream
  - Remove 0002-Allow-the-core-to-use-expired-certificates.patch,
    incorporated upstream
  - Update kubuntu_02_enable_message_indicator.diff for 0.9

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/***************************************************************************
2
 
*   Copyright (C) 2005-09 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
 
*   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
19
 
***************************************************************************/
 
2
 *   Copyright (C) 2005-2013 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 <QSpinBox>
20
25
 
21
26
#include "taskbarnotificationbackend.h"
22
27
 
23
 
#include <QtGui>
24
 
 
25
28
#include "clientsettings.h"
26
29
#include "iconloader.h"
27
30
#include "mainwin.h"
28
31
#include "qtui.h"
29
32
 
30
33
TaskbarNotificationBackend::TaskbarNotificationBackend(QObject *parent)
31
 
  : AbstractNotificationBackend(parent)
32
 
{
33
 
  NotificationSettings notificationSettings;
34
 
  _enabled = notificationSettings.value("Taskbar/Enabled", true).toBool();
35
 
  _timeout = notificationSettings.value("Taskbar/Timeout", 0).toInt();
36
 
 
37
 
  notificationSettings.notify("Taskbar/Enabled", this, SLOT(enabledChanged(const QVariant &)));
38
 
  notificationSettings.notify("Taskbar/Timeout", this, SLOT(timeoutChanged(const QVariant &)));
39
 
}
40
 
 
41
 
void TaskbarNotificationBackend::notify(const Notification &notification) {
42
 
  if(_enabled && (notification.type == Highlight || notification.type == PrivMsg)) {
43
 
    QApplication::alert(QtUi::mainWindow(), _timeout);
44
 
  }
45
 
}
46
 
 
47
 
void TaskbarNotificationBackend::close(uint notificationId) {
48
 
  Q_UNUSED(notificationId);
49
 
}
50
 
 
51
 
void TaskbarNotificationBackend::enabledChanged(const QVariant &v) {
52
 
  _enabled = v.toBool();
53
 
}
54
 
 
55
 
void TaskbarNotificationBackend::timeoutChanged(const QVariant &v) {
56
 
  _timeout = v.toInt();
57
 
}
58
 
 
59
 
SettingsPage *TaskbarNotificationBackend::createConfigWidget() const {
60
 
  return new ConfigWidget();
61
 
}
 
34
    : AbstractNotificationBackend(parent)
 
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
 
 
45
void TaskbarNotificationBackend::notify(const Notification &notification)
 
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
 
 
59
void TaskbarNotificationBackend::enabledChanged(const QVariant &v)
 
60
{
 
61
    _enabled = v.toBool();
 
62
}
 
63
 
 
64
 
 
65
void TaskbarNotificationBackend::timeoutChanged(const QVariant &v)
 
66
{
 
67
    _timeout = v.toInt();
 
68
}
 
69
 
 
70
 
 
71
SettingsPage *TaskbarNotificationBackend::createConfigWidget() const
 
72
{
 
73
    return new ConfigWidget();
 
74
}
 
75
 
62
76
 
63
77
/***************************************************************************/
64
78
 
65
 
TaskbarNotificationBackend::ConfigWidget::ConfigWidget(QWidget *parent) : SettingsPage("Internal", "TaskbarNotification", parent) {
66
 
  QHBoxLayout *layout = new QHBoxLayout(this);
 
79
TaskbarNotificationBackend::ConfigWidget::ConfigWidget(QWidget *parent) : SettingsPage("Internal", "TaskbarNotification", parent)
 
80
{
 
81
    QHBoxLayout *layout = new QHBoxLayout(this);
67
82
#ifdef Q_WS_MAC
68
 
  layout->addWidget(enabledBox = new QCheckBox(tr("Activate dock entry, timeout:"), this));
 
83
    layout->addWidget(enabledBox = new QCheckBox(tr("Activate dock entry, timeout:"), this));
69
84
#else
70
 
  layout->addWidget(enabledBox = new QCheckBox(tr("Mark taskbar entry, timeout:"), this));
 
85
    layout->addWidget(enabledBox = new QCheckBox(tr("Mark taskbar entry, timeout:"), this));
71
86
#endif
72
 
  enabledBox->setIcon(SmallIcon("flag-blue"));
73
 
  enabledBox->setEnabled(true);
74
 
 
75
 
  timeoutBox = new QSpinBox(this);
76
 
  timeoutBox->setMinimum(1);
77
 
  timeoutBox->setMaximum(99);
78
 
  timeoutBox->setSpecialValueText(tr("Unlimited"));
79
 
  timeoutBox->setSuffix(tr(" seconds"));
80
 
  layout->addWidget(timeoutBox);
81
 
  layout->addStretch(20);
82
 
 
83
 
  connect(enabledBox, SIGNAL(toggled(bool)), SLOT(widgetChanged()));
84
 
  connect(enabledBox, SIGNAL(toggled(bool)), timeoutBox, SLOT(setEnabled(bool)));
85
 
  connect(timeoutBox, SIGNAL(valueChanged(int)), SLOT(widgetChanged()));
86
 
}
87
 
 
88
 
void TaskbarNotificationBackend::ConfigWidget::widgetChanged() {
89
 
  bool changed = (enabled != enabledBox->isChecked() || timeout/1000 != timeoutBox->value());
90
 
  if(changed != hasChanged()) setChangedState(changed);
91
 
}
92
 
 
93
 
bool TaskbarNotificationBackend::ConfigWidget::hasDefaults() const {
94
 
  return true;
95
 
}
96
 
 
97
 
void TaskbarNotificationBackend::ConfigWidget::defaults() {
98
 
  enabledBox->setChecked(true);
99
 
  timeoutBox->setValue(0);
100
 
  widgetChanged();
101
 
}
102
 
 
103
 
void TaskbarNotificationBackend::ConfigWidget::load() {
104
 
  NotificationSettings s;
105
 
  enabled = s.value("Taskbar/Enabled", true).toBool();
106
 
  timeout = s.value("Taskbar/Timeout", 0).toInt();
107
 
 
108
 
  enabledBox->setChecked(enabled);
109
 
  timeoutBox->setValue(timeout/1000);
110
 
 
111
 
  setChangedState(false);
112
 
}
113
 
 
114
 
void TaskbarNotificationBackend::ConfigWidget::save() {
115
 
  NotificationSettings s;
116
 
  s.setValue("Taskbar/Enabled", enabledBox->isChecked());
117
 
  s.setValue("Taskbar/Timeout", timeoutBox->value() * 1000);
118
 
  load();
 
87
    enabledBox->setIcon(SmallIcon("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
 
 
104
void TaskbarNotificationBackend::ConfigWidget::widgetChanged()
 
105
{
 
106
    bool changed = (enabled != enabledBox->isChecked() || timeout/1000 != timeoutBox->value());
 
107
    if (changed != hasChanged()) setChangedState(changed);
 
108
}
 
109
 
 
110
 
 
111
bool TaskbarNotificationBackend::ConfigWidget::hasDefaults() const
 
112
{
 
113
    return true;
 
114
}
 
115
 
 
116
 
 
117
void TaskbarNotificationBackend::ConfigWidget::defaults()
 
118
{
 
119
    enabledBox->setChecked(true);
 
120
    timeoutBox->setValue(0);
 
121
    widgetChanged();
 
122
}
 
123
 
 
124
 
 
125
void TaskbarNotificationBackend::ConfigWidget::load()
 
126
{
 
127
    NotificationSettings s;
 
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
 
 
138
void TaskbarNotificationBackend::ConfigWidget::save()
 
139
{
 
140
    NotificationSettings s;
 
141
    s.setValue("Taskbar/Enabled", enabledBox->isChecked());
 
142
    s.setValue("Taskbar/Timeout", timeoutBox->value() * 1000);
 
143
    load();
119
144
}