~nik90/ubuntu-clock-app/sync-bottomedge-sep08

« back to all changes in this revision

Viewing changes to app/alarm/AlarmSettingsPage.qml

  • Committer: Tarmac
  • Author(s): Nekhelesh Ramananthan
  • Date: 2014-09-08 20:32:16 UTC
  • mfrom: (86.1.4 implement-snooze-settings)
  • Revision ID: tarmac-20140908203216-g08bao64vmccqt3c
Implement Alarm Snooze settings option as per design spec. Fixes: https://bugs.launchpad.net/bugs/1354400.

Approved by PS Jenkins bot, Alan Pope ㋛, Charles Kerr, Ubuntu Phone Apps Jenkins Bot.

Show diffs side-by-side

added added

removed removed

Lines of Context:
28
28
 
29
29
    title: i18n.tr("Settings")
30
30
    visible: false
 
31
    flickable: null
31
32
 
32
33
    Connections {
33
34
        target: clockApp
56
57
        }
57
58
    }
58
59
 
59
 
    Column {
60
 
        id: _settingsColumn
61
 
 
 
60
    ListModel {
 
61
        id: snoozeModel
 
62
        Component.onCompleted: initialise()
 
63
 
 
64
        function initialise() {
 
65
            snoozeModel.append({ "duration": 2, "text": i18n.tr("%1 minutes").arg(2) })
 
66
            snoozeModel.append({ "duration": 4, "text": i18n.tr("%1 minutes").arg(4) })
 
67
            snoozeModel.append({ "duration": 5, "text": i18n.tr("%1 minutes").arg(5) })
 
68
            snoozeModel.append({ "duration": 10, "text": i18n.tr("%1 minutes").arg(10) })
 
69
        }
 
70
    }
 
71
 
 
72
    Flickable {
 
73
        id: settingsPlugin
 
74
 
 
75
        contentHeight: _settingsColumn.height
62
76
        anchors.fill: parent
63
 
 
64
 
        ListItem.Base {
65
 
            height: 2 * implicitHeight
66
 
 
67
 
            Label {
68
 
                color: UbuntuColors.midAubergine
69
 
                text: i18n.tr("Alarm volume")
70
 
                anchors.top: parent.top
71
 
                anchors.topMargin: units.gu(1)
72
 
            }
73
 
 
74
 
            Slider {
75
 
                anchors.centerIn: parent
76
 
                width: parent.width
77
 
 
78
 
                minimumValue: 1
79
 
                maximumValue: 100
80
 
                value: alarmSettings.volume
81
 
 
82
 
                onValueChanged: {
83
 
                    alarmSettings.volume = formatValue(value)
84
 
                }
85
 
            }
86
 
        }
87
 
 
88
 
        ListItem.Expandable {
89
 
            id: _alarmDuration
 
77
        clip: true
 
78
 
 
79
        Column {
 
80
            id: _settingsColumn
90
81
 
91
82
            anchors {
 
83
                top: parent.top
92
84
                left: parent.left
93
85
                right: parent.right
94
 
                margins: units.gu(-2)
95
 
            }
96
 
 
97
 
            collapseOnClick: true
98
 
            expandedHeight: _contentColumn.height + units.gu(1)
99
 
 
100
 
            Column {
101
 
                id: _contentColumn
102
 
                width: parent.width
103
 
 
104
 
                Item {
105
 
                    width: parent.width
106
 
                    height: _alarmDuration.collapsedHeight
107
 
 
108
 
                    SubtitledListItem {
109
 
                        id: _header
110
 
                        text: i18n.tr("Silence after")
111
 
                        subText: i18n.tr("%1 minutes").arg(alarmSettings.duration)
112
 
                        onClicked: _alarmDuration.expanded = true
113
 
 
114
 
                        Icon {
115
 
                            id: _upArrow
116
 
 
117
 
                            width: units.gu(2)
118
 
                            height: width
119
 
                            anchors.right: parent.right
120
 
                            anchors.verticalCenter: parent.verticalCenter
121
 
 
122
 
                            name: "go-down"
123
 
                            color: "Grey"
124
 
                            rotation: _alarmDuration.expanded ? 180 : 0
125
 
 
126
 
                            Behavior on rotation {
127
 
                                UbuntuNumberAnimation {}
128
 
                            }
129
 
                        }
130
 
                    }
131
 
                }
132
 
 
133
 
                ListView {
134
 
                    id: _resultsList
135
 
                    clip: true
136
 
                    model: durationModel
137
 
                    width: parent.width
138
 
                    height: units.gu(24)
139
 
                    delegate: ListItem.Standard {
140
 
                        text: model.text
141
 
                        onClicked: {
142
 
                            alarmSettings.duration = duration
143
 
                            _alarmDuration.expanded = false
144
 
                        }
145
 
                    }
146
 
                }
147
 
            }
148
 
        }
149
 
 
150
 
        ListItem.Base {
151
 
            Label {
152
 
                text: i18n.tr("Vibration")
153
 
                color: UbuntuColors.midAubergine
154
 
                anchors.verticalCenter: parent.verticalCenter
155
 
            }
156
 
 
157
 
            Switch {
158
 
                id: vibrateSwitch
159
 
 
160
 
                anchors {
161
 
                    right: parent.right
162
 
                    verticalCenter: parent.verticalCenter
163
 
                }
164
 
 
165
 
                checked: alarmSettings.vibration === "pulse"
166
 
                onCheckedChanged: {
167
 
                    if(checked) {
168
 
                        alarmSettings.vibration = "pulse"
169
 
                    } else {
170
 
                        alarmSettings.vibration = "none"
171
 
                    }
172
 
                }
173
 
            }
174
 
 
175
 
            onClicked: {
176
 
                vibrateSwitch.checked = !vibrateSwitch.checked
177
 
            }
178
 
        }
179
 
 
180
 
        SubtitledListItem {
181
 
            text: i18n.tr("Change time and date")
182
 
            subText: {
183
 
                /*
 
86
            }
 
87
 
 
88
            ListItem.Base {
 
89
                height: 2 * implicitHeight
 
90
 
 
91
                Label {
 
92
                    color: UbuntuColors.midAubergine
 
93
                    text: i18n.tr("Alarm volume")
 
94
                    anchors.top: parent.top
 
95
                    anchors.topMargin: units.gu(1)
 
96
                }
 
97
 
 
98
                Slider {
 
99
                    anchors.centerIn: parent
 
100
                    width: parent.width
 
101
 
 
102
                    minimumValue: 1
 
103
                    maximumValue: 100
 
104
                    value: alarmSettings.volume
 
105
 
 
106
                    onValueChanged: {
 
107
                        alarmSettings.volume = formatValue(value)
 
108
                    }
 
109
                }
 
110
            }
 
111
 
 
112
            ListItem.Expandable {
 
113
                id: _alarmDuration
 
114
 
 
115
                anchors {
 
116
                    left: parent.left
 
117
                    right: parent.right
 
118
                    margins: units.gu(-2)
 
119
                }
 
120
 
 
121
                collapseOnClick: true
 
122
                expandedHeight: _contentColumn.height + units.gu(1)
 
123
 
 
124
                Column {
 
125
                    id: _contentColumn
 
126
                    width: parent.width
 
127
 
 
128
                    Item {
 
129
                        width: parent.width
 
130
                        height: _alarmDuration.collapsedHeight
 
131
 
 
132
                        SubtitledListItem {
 
133
                            id: _header
 
134
                            text: i18n.tr("Silence after")
 
135
                            subText: i18n.tr("%1 minutes").arg(alarmSettings.duration)
 
136
                            onClicked: _alarmDuration.expanded = true
 
137
 
 
138
                            Icon {
 
139
                                id: _upArrow
 
140
 
 
141
                                width: units.gu(2)
 
142
                                height: width
 
143
                                anchors.right: parent.right
 
144
                                anchors.verticalCenter: parent.verticalCenter
 
145
 
 
146
                                name: "go-down"
 
147
                                color: "Grey"
 
148
                                rotation: _alarmDuration.expanded ? 180 : 0
 
149
 
 
150
                                Behavior on rotation {
 
151
                                    UbuntuNumberAnimation {}
 
152
                                }
 
153
                            }
 
154
                        }
 
155
                    }
 
156
 
 
157
                    ListView {
 
158
                        id: _resultsList
 
159
                        clip: true
 
160
                        interactive: false
 
161
                        model: durationModel
 
162
                        width: parent.width
 
163
                        height: units.gu(24)
 
164
                        delegate: ListItem.Standard {
 
165
                            text: model.text
 
166
                            onClicked: {
 
167
                                alarmSettings.duration = duration
 
168
                                _alarmDuration.expanded = false
 
169
                            }
 
170
                        }
 
171
                    }
 
172
                }
 
173
            }
 
174
 
 
175
            ListItem.Expandable {
 
176
                id: _alarmSnooze
 
177
 
 
178
                anchors {
 
179
                    left: parent.left
 
180
                    right: parent.right
 
181
                    margins: units.gu(-2)
 
182
                }
 
183
 
 
184
                collapseOnClick: true
 
185
                expandedHeight: _snoozeContentColumn.height + units.gu(1)
 
186
 
 
187
                Column {
 
188
                    id: _snoozeContentColumn
 
189
                    width: parent.width
 
190
 
 
191
                    Item {
 
192
                        width: parent.width
 
193
                        height: _alarmSnooze.collapsedHeight
 
194
 
 
195
                        SubtitledListItem {
 
196
                            id: _snoozeHeader
 
197
                            text: i18n.tr("Snooze for")
 
198
                            subText: i18n.tr("%1 minutes").arg(alarmSettings.snoozeDuration)
 
199
                            onClicked: _alarmSnooze.expanded = true
 
200
 
 
201
                            Icon {
 
202
                                id: _snoozeUpArrow
 
203
 
 
204
                                width: units.gu(2)
 
205
                                height: width
 
206
                                anchors.right: parent.right
 
207
                                anchors.verticalCenter: parent.verticalCenter
 
208
 
 
209
                                name: "go-down"
 
210
                                color: "Grey"
 
211
                                rotation: _alarmSnooze.expanded ? 180 : 0
 
212
 
 
213
                                Behavior on rotation {
 
214
                                    UbuntuNumberAnimation {}
 
215
                                }
 
216
                            }
 
217
                        }
 
218
                    }
 
219
 
 
220
                    ListView {
 
221
                        id: _snoozeResultsList
 
222
                        clip: true
 
223
                        interactive: false
 
224
                        model: snoozeModel
 
225
                        width: parent.width
 
226
                        height: units.gu(24)
 
227
 
 
228
                        delegate: ListItem.Standard {
 
229
                            text: model.text
 
230
                            onClicked: {
 
231
                                alarmSettings.snoozeDuration = duration
 
232
                                _alarmSnooze.expanded = false
 
233
                            }
 
234
                        }
 
235
                    }
 
236
                }
 
237
            }
 
238
 
 
239
            ListItem.Base {
 
240
                Label {
 
241
                    text: i18n.tr("Vibration")
 
242
                    color: UbuntuColors.midAubergine
 
243
                    anchors.verticalCenter: parent.verticalCenter
 
244
                }
 
245
 
 
246
                Switch {
 
247
                    id: vibrateSwitch
 
248
 
 
249
                    anchors {
 
250
                        right: parent.right
 
251
                        verticalCenter: parent.verticalCenter
 
252
                    }
 
253
 
 
254
                    checked: alarmSettings.vibration === "pulse"
 
255
                    onCheckedChanged: {
 
256
                        if(checked) {
 
257
                            alarmSettings.vibration = "pulse"
 
258
                        } else {
 
259
                            alarmSettings.vibration = "none"
 
260
                        }
 
261
                    }
 
262
                }
 
263
 
 
264
                onClicked: {
 
265
                    vibrateSwitch.checked = !vibrateSwitch.checked
 
266
                }
 
267
            }
 
268
 
 
269
            SubtitledListItem {
 
270
                text: i18n.tr("Change time and date")
 
271
                subText: {
 
272
                    /*
184
273
                  FIXME: When the upstream QT bug at
185
274
                  https://bugreports.qt-project.org/browse/QTBUG-40275 is fixed
186
275
                  it will be possible to receive a datetime object directly
187
276
                  instead of using this hack.
188
277
                */
189
 
                var localTime = new Date
190
 
                        (
191
 
                            localTimeSource.localDateString.split(":")[0],
192
 
                            localTimeSource.localDateString.split(":")[1]-1,
193
 
                            localTimeSource.localDateString.split(":")[2],
194
 
                            localTimeSource.localTimeString.split(":")[0],
195
 
                            localTimeSource.localTimeString.split(":")[1],
196
 
                            localTimeSource.localTimeString.split(":")[2],
197
 
                            localTimeSource.localTimeString.split(":")[3]
198
 
                            )
199
 
                return localTime.toLocaleString()
200
 
            }
 
278
                    var localTime = new Date
 
279
                            (
 
280
                                localTimeSource.localDateString.split(":")[0],
 
281
                                localTimeSource.localDateString.split(":")[1]-1,
 
282
                                localTimeSource.localDateString.split(":")[2],
 
283
                                localTimeSource.localTimeString.split(":")[0],
 
284
                                localTimeSource.localTimeString.split(":")[1],
 
285
                                localTimeSource.localTimeString.split(":")[2],
 
286
                                localTimeSource.localTimeString.split(":")[3]
 
287
                                )
 
288
                    return localTime.toLocaleString()
 
289
                }
201
290
 
202
 
            onClicked: {
203
 
                Qt.openUrlExternally("settings:///system/time-date")
 
291
                onClicked: {
 
292
                    Qt.openUrlExternally("settings:///system/time-date")
 
293
                }
204
294
            }
205
295
        }
206
296
    }