4af9109904f84d2edca4ba9dd7b5d64ed42f9368
[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 <QIcon>
22
23 #include "systrayanimationnotificationbackend.h"
24
25 #include "clientsettings.h"
26 #include "mainwin.h"
27 #include "qtui.h"
28 #include "systemtray.h"
29
30 SystrayAnimationNotificationBackend::SystrayAnimationNotificationBackend(QObject *parent)
31     : AbstractNotificationBackend(parent)
32 {
33     NotificationSettings notificationSettings;
34     notificationSettings.initAndNotify("Systray/Alert", this, SLOT(alertChanged(QVariant)), true);
35 }
36
37
38 void SystrayAnimationNotificationBackend::notify(const Notification &n)
39 {
40     if (n.type != Highlight && n.type != PrivMsg)
41         return;
42
43     if (_alert)
44         QtUi::mainWindow()->systemTray()->setAlert(true);
45 }
46
47
48 void SystrayAnimationNotificationBackend::close(uint notificationId)
49 {
50     Q_UNUSED(notificationId)
51     QtUi::mainWindow()->systemTray()->setAlert(false);
52 }
53
54
55 void SystrayAnimationNotificationBackend::alertChanged(const QVariant &v)
56 {
57     _alert = v.toBool();
58 }
59
60
61 SettingsPage *SystrayAnimationNotificationBackend::createConfigWidget() const
62 {
63     return new ConfigWidget();
64 }
65
66
67 /***************************************************************************/
68
69 SystrayAnimationNotificationBackend::ConfigWidget::ConfigWidget(QWidget *parent) : SettingsPage("Internal", "SystrayAnimation", parent)
70 {
71     ui.setupUi(this);
72     ui.enableAlert->setIcon(QIcon::fromTheme("dialog-information"));
73
74     ui.attentionBehavior->setEnabled(ui.enableAlert->isChecked());
75
76     initAutoWidgets();
77 }
78
79
80 QString SystrayAnimationNotificationBackend::ConfigWidget::settingsKey() const
81 {
82     return "Notification";
83 }
84
85
86 QVariant SystrayAnimationNotificationBackend::ConfigWidget::loadAutoWidgetValue(const QString &widgetName)
87 {
88     if (widgetName == "attentionBehavior") {
89         NotificationSettings s;
90         if (s.value("Systray/Animate", false).toBool()) {
91             return 2;
92         }
93         if (s.value("Systray/ChangeColor", true).toBool()) {
94             return 1;
95         }
96         return 0;
97     }
98
99     return SettingsPage::loadAutoWidgetValue(widgetName);
100 }
101
102
103 void SystrayAnimationNotificationBackend::ConfigWidget::saveAutoWidgetValue(const QString &widgetName, const QVariant &value)
104 {
105     if (widgetName == "attentionBehavior") {
106         NotificationSettings s;
107         s.setValue("Systray/ChangeColor", false);
108         s.setValue("Systray/Animate", false);
109         switch (value.toInt()) {
110         case 1:
111             s.setValue("Systray/ChangeColor", true);
112             return;
113         case 2:
114             s.setValue("Systray/Animate", true);
115             return;
116         default:
117             return;
118         }
119     }
120
121     SettingsPage::saveAutoWidgetValue(widgetName, value);
122 }