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