~jonas-drange/ubuntu-system-settings/wapi-support

« back to all changes in this revision

Viewing changes to plugins/notifications/ClickAppNotifications.qml

Implement extended Notifications panel using Gsettings to store notifications settings for each app

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * This file is part of system-settings
 
3
 *
 
4
 * Copyright (C) 2016 Canonical Ltd.
 
5
 *
 
6
 * This program is free software: you can redistribute it and/or modify it
 
7
 * under the terms of the GNU General Public License version 3, as published
 
8
 * by the Free Software Foundation.
 
9
 *
 
10
 * This program is distributed in the hope that it will be useful, but
 
11
 * WITHOUT ANY WARRANTY; without even the implied warranties of
 
12
 * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
 
13
 * PURPOSE.  See the GNU General Public License for more details.
 
14
 *
 
15
 * You should have received a copy of the GNU General Public License along
 
16
 * with this program.  If not, see <http://www.gnu.org/licenses/>.
 
17
 */
 
18
 
 
19
import QtQuick 2.4
 
20
import Ubuntu.Components 1.3
 
21
import Ubuntu.SystemSettings.Notifications 1.0
 
22
import SystemSettings 1.0
 
23
 
 
24
ItemPage {
 
25
    id: appNotificationsPage
 
26
 
 
27
    property var entry
 
28
    property int entryIndex
 
29
 
 
30
    title: entry ? entry.displayName : ""
 
31
 
 
32
    function disableNotificationsWhenAllUnchecked() {
 
33
        if (!entry) {
 
34
            return
 
35
        }
 
36
 
 
37
        if (!entry.soundsNotify && !entry.vibrationsNotify && !entry.bubblesNotify && !entry.listNotify) {
 
38
            enableNotificationsSwitch.checked = false
 
39
            entry.enableNotifications = false
 
40
        }
 
41
    }
 
42
 
 
43
    Component.onDestruction: disableNotificationsWhenAllUnchecked()
 
44
 
 
45
    Column {
 
46
        id: notificationsColumn
 
47
 
 
48
        anchors.fill: parent
 
49
 
 
50
        ListItem {
 
51
            height: enableNotificationsLayout.height + (divider.visible ? divider.height : 0)
 
52
            ListItemLayout {
 
53
                id: enableNotificationsLayout
 
54
                title.text: i18n.tr("Notifications")
 
55
                Switch {
 
56
                    id: enableNotificationsSwitch
 
57
                    objectName: "enableNotificationsSwitch"
 
58
                    SlotsLayout.position: SlotsLayout.Trailing
 
59
                    checked: entry ? entry.enableNotifications : false
 
60
 
 
61
                    onCheckedChanged: {
 
62
                        ClickApplicationsModel.setNotifyEnabled(ClickApplicationsModel.EnableNotifications,
 
63
                                                                appNotificationsPage.entryIndex,
 
64
                                                                checked)
 
65
                    }
 
66
                }
 
67
            }
 
68
        }
 
69
 
 
70
        ListItem {
 
71
            ListItemLayout {
 
72
                title.text: i18n.tr("Let this app alert me using:")
 
73
                title.color: theme.palette.normal.backgroundSecondaryText
 
74
            }
 
75
        }
 
76
 
 
77
        ListItem {
 
78
            height: soundsLayout.height + (divider.visible ? divider.height : 0)
 
79
            ListItemLayout {
 
80
                id: soundsLayout
 
81
                title.text: i18n.tr("Sounds")
 
82
                CheckBox {
 
83
                    id: soundsChecked
 
84
                    objectName: "soundsChecked"
 
85
                    SlotsLayout.position: SlotsLayout.Leading
 
86
                    enabled: entry ? entry.enableNotifications : false
 
87
                    checked: entry ? entry.soundsNotify : false
 
88
 
 
89
                    onCheckedChanged: {
 
90
                        ClickApplicationsModel.setNotifyEnabled(ClickApplicationsModel.SoundsNotify,
 
91
                                                                appNotificationsPage.entryIndex,
 
92
                                                                checked)
 
93
                        disableNotificationsWhenAllUnchecked()
 
94
                    }
 
95
                }
 
96
            }
 
97
        }
 
98
 
 
99
        ListItem {
 
100
            height: vibrationsLayout.height + (divider.visible ? divider.height : 0)
 
101
            ListItemLayout {
 
102
                id: vibrationsLayout
 
103
                title.text: i18n.tr("Vibrations")
 
104
                CheckBox {
 
105
                    id: vibrationsChecked
 
106
                    objectName: "vibrationsChecked"
 
107
                    SlotsLayout.position: SlotsLayout.Leading
 
108
                    enabled: entry ? entry.enableNotifications : false
 
109
                    checked: entry ? entry.vibrationsNotify : false
 
110
 
 
111
                    onCheckedChanged: {
 
112
                        ClickApplicationsModel.setNotifyEnabled(ClickApplicationsModel.VibrationsNotify,
 
113
                                                                appNotificationsPage.entryIndex,
 
114
                                                                checked)
 
115
                        disableNotificationsWhenAllUnchecked()
 
116
                    }
 
117
                }
 
118
            }
 
119
        }
 
120
 
 
121
        ListItem {
 
122
            height: bubblesLayout.height + (divider.visible ? divider.height : 0)
 
123
            ListItemLayout {
 
124
                id: bubblesLayout
 
125
                title.text: i18n.tr("Notification Bubbles")
 
126
                CheckBox {
 
127
                    id: bubblesChecked
 
128
                    objectName: "bubblesChecked"
 
129
                    SlotsLayout.position: SlotsLayout.Leading
 
130
                    enabled: entry ? entry.enableNotifications : false
 
131
                    checked: entry ? entry.bubblesNotify : false
 
132
 
 
133
                    onCheckedChanged: {
 
134
                        ClickApplicationsModel.setNotifyEnabled(ClickApplicationsModel.BubblesNotify,
 
135
                                                                appNotificationsPage.entryIndex,
 
136
                                                                checked)
 
137
                        disableNotificationsWhenAllUnchecked()
 
138
                    }
 
139
                }
 
140
            }
 
141
        }
 
142
 
 
143
        ListItem {
 
144
            height: listLayout.height + (divider.visible ? divider.height : 0)
 
145
            ListItemLayout {
 
146
                id: listLayout
 
147
                title.text: i18n.tr("Notification List")
 
148
                CheckBox {
 
149
                    id: listChecked
 
150
                    objectName: "listChecked"
 
151
                    SlotsLayout.position: SlotsLayout.Leading
 
152
                    enabled: entry ? entry.enableNotifications : false
 
153
                    checked: entry ? entry.listNotify : false
 
154
 
 
155
                    onCheckedChanged: {
 
156
                        ClickApplicationsModel.setNotifyEnabled(ClickApplicationsModel.ListNotify,
 
157
                                                                appNotificationsPage.entryIndex,
 
158
                                                                checked)
 
159
                        disableNotificationsWhenAllUnchecked()
 
160
                    }
 
161
                }
 
162
            }
 
163
        }
 
164
    }
 
165
}