qtui: Set proper icon for "About Quassel" menu option
[quassel.git] / src / qtui / systrayanimationnotificationbackend.cpp
1 /***************************************************************************
2  *   Copyright (C) 2005-2016 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
27 #include "systrayanimationnotificationbackend.h"
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
36 SystrayAnimationNotificationBackend::SystrayAnimationNotificationBackend(QObject *parent)
37     : AbstractNotificationBackend(parent)
38 {
39     NotificationSettings notificationSettings;
40     notificationSettings.initAndNotify("Systray/Animate", this, SLOT(animateChanged(QVariant)), true);
41 }
42
43
44 void SystrayAnimationNotificationBackend::notify(const Notification &n)
45 {
46     if (n.type != Highlight && n.type != PrivMsg)
47         return;
48
49     if (_animate)
50         QtUi::mainWindow()->systemTray()->setAlert(true);
51 }
52
53
54 void SystrayAnimationNotificationBackend::close(uint notificationId)
55 {
56     QtUi::mainWindow()->systemTray()->setAlert(false);
57 }
58
59
60 void SystrayAnimationNotificationBackend::animateChanged(const QVariant &v)
61 {
62     _animate = v.toBool();
63 }
64
65
66 SettingsPage *SystrayAnimationNotificationBackend::createConfigWidget() const
67 {
68     return new ConfigWidget();
69 }
70
71
72 /***************************************************************************/
73
74 SystrayAnimationNotificationBackend::ConfigWidget::ConfigWidget(QWidget *parent) : SettingsPage("Internal", "SystrayNotification", parent)
75 {
76     _animateBox = new QCheckBox(tr("Animate system tray icon"));
77     _animateBox->setIcon(QIcon::fromTheme("dialog-information"));
78     connect(_animateBox, SIGNAL(toggled(bool)), this, SLOT(widgetChanged()));
79     QHBoxLayout *layout = new QHBoxLayout(this);
80     layout->addWidget(_animateBox);
81 }
82
83
84 void SystrayAnimationNotificationBackend::ConfigWidget::widgetChanged()
85 {
86     bool changed = (_animate != _animateBox->isChecked());
87     if (changed != hasChanged())
88         setChangedState(changed);
89 }
90
91
92 bool SystrayAnimationNotificationBackend::ConfigWidget::hasDefaults() const
93 {
94     return true;
95 }
96
97
98 void SystrayAnimationNotificationBackend::ConfigWidget::defaults()
99 {
100     _animateBox->setChecked(false);
101     widgetChanged();
102 }
103
104
105 void SystrayAnimationNotificationBackend::ConfigWidget::load()
106 {
107     NotificationSettings s;
108     _animate = s.value("Systray/Animate", true).toBool();
109     _animateBox->setChecked(_animate);
110     setChangedState(false);
111 }
112
113
114 void SystrayAnimationNotificationBackend::ConfigWidget::save()
115 {
116     NotificationSettings s;
117     s.setValue("Systray/Animate", _animateBox->isChecked());
118     load();
119 }