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