on xenial help sign in
Added synchronous/confirmation notification support to unity8. Fixes: 1232633, 1373404, 1378618

Approved by: Andrea Cimitan, Albert Astals Cid

commit9c6d98ee0e82e574cc9124a2ccf9d460817f8059 authorMirco Müller <mirco.mueller@ubuntu.com> dateThu 30 Oct 2014, 10:49 (12 years ago) parent96445fccbf8aaa
3 files changed+245−49
qml/Notifications/Notification.qml+72−8 qml/Notifications/Notifications.qml+1 tests/qmltests/Notifications/tst_Notifications.qml+172−41
qml/Notifications/Notification.qml+72−8
@@ -31,6 +31,7 @@ Item {
3131 property alias secondaryIconSource: secondaryIcon.source
3232 property alias summary: summaryLabel.text
3333 property alias body: bodyLabel.text
34+ property alias value: valueIndicator.value
3435 property var actions
3536 property var notificationId
3637 property var type
@@ -40,6 +41,7 @@ Item {
4041 property bool fullscreen: false
4142 property int maxHeight
4243 property int margins
44+ readonly property bool darkOnBright: panel.indicators.shown || type === Notification.SnapDecision
4345 readonly property color red: "#fc4949"
4446 readonly property color green: "#3fb24f"
4547 readonly property color sdLightGrey: "#eaeaea"
@@ -48,9 +50,9 @@ Item {
4850 readonly property real contentSpacing: units.gu(2)
4951
5052 objectName: "background"
51− implicitHeight: type !== Notification.PlaceHolder ? (fullscreen ? maxHeight : outterColumn.height + contentSpacing * 2) : 0
53+ implicitHeight: type !== Notification.PlaceHolder ? (fullscreen ? maxHeight : outterColumn.height - shapedBack.anchors.topMargin + contentSpacing * 2) : 0
5254
53− color: type == Notification.SnapDecision ? sdLightGrey : Qt.rgba(0.132, 0.117, 0.109, 0.97)
55+ color: (type === Notification.Confirmation && notificationList.useModal && !greeter.shown) || darkOnBright ? sdLightGrey : Qt.rgba(0.132, 0.117, 0.109, 0.97)
5456 opacity: 1 // FIXME: 1 because of LP: #1354406 workaround, has to be 0 really
5557
5658 state: {
@@ -78,6 +80,7 @@ Item {
7880 Audio {
7981 id: sound
8082 objectName: "sound"
83+ audioRole: MediaPlayer.alert
8184 source: hints["suppress-sound"] != "true" && hints["sound-file"] != undefined ? hints["sound-file"] : ""
8285 }
8386
@@ -88,6 +91,12 @@ Item {
8891 }
8992 }
9093
94+ onHintsChanged: {
95+ if (type === Notification.Confirmation && opacity == 1.0 && hints["suppress-sound"] != "true" && sound.source != "") {
96+ sound.play();
97+ }
98+ }
99+
91100 Behavior on height {
92101 id: normalHeightBehavior
93102
@@ -126,6 +135,7 @@ Item {
126135 fill: parent
127136 leftMargin: notification.margins
128137 rightMargin: notification.margins
138+ topMargin: type === Notification.Confirmation ? units.gu(.5) : 0
129139 }
130140 color: parent.color
131141 opacity: parent.opacity
@@ -206,10 +216,10 @@ Item {
206216 right: parent.right
207217 top: parent.top
208218 margins: 0
209− topMargin: fullscreen ? 0 : units.gu(2)
219+ topMargin: fullscreen ? 0 : type === Notification.Confirmation ? units.gu(1) : units.gu(2)
210220 }
211221
212− spacing: units.gu(2)
222+ spacing: type === Notification.Confirmation ? units.gu(1) : units.gu(2)
213223
214224 Row {
215225 id: topRow
@@ -228,7 +238,7 @@ Item {
228238 width: type == Notification.Ephemeral && !bodyLabel.visible ? units.gu(3) : units.gu(6)
229239 height: width
230240 shaped: notification.hints["x-canonical-non-shaped-icon"] == "true" ? false : true
231− visible: iconSource !== undefined && iconSource != ""
241+ visible: iconSource !== undefined && iconSource !== "" && type !== Notification.Confirmation
232242 }
233243
234244 Column {
@@ -245,8 +255,9 @@ Item {
245255 left: parent.left
246256 right: parent.right
247257 }
258+ visible: type !== Notification.Confirmation
248259 fontSize: "medium"
249− color: type == Notification.SnapDecision ? sdFontColor : Theme.palette.selected.backgroundText
260+ color: darkOnBright ? sdFontColor : Theme.palette.selected.backgroundText
250261 elide: Text.ElideRight
251262 textFormat: Text.PlainText
252263 }
@@ -259,9 +270,9 @@ Item {
259270 left: parent.left
260271 right: parent.right
261272 }
262− visible: body != ""
273+ visible: body != "" && type !== Notification.Confirmation
263274 fontSize: "small"
264− color: type == Notification.SnapDecision ? sdFontColor : Theme.palette.selected.backgroundText
275+ color: darkOnBright ? sdFontColor : Theme.palette.selected.backgroundText
265276 wrapMode: Text.WordWrap
266277 maximumLineCount: type == Notification.SnapDecision ? 12 : 2
267278 elide: Text.ElideRight
@@ -284,6 +295,59 @@ Item {
284295 visible: type == Notification.SnapDecision
285296 }
286297
298+ ShapedIcon {
299+ id: centeredIcon
300+ objectName: "centeredIcon"
301+ width: units.gu(5)
302+ height: width
303+ shaped: notification.hints["x-canonical-non-shaped-icon"] == "true" ? false : true
304+ fileSource: icon.fileSource
305+ visible: fileSource !== undefined && fileSource !== "" && type === Notification.Confirmation
306+ anchors.horizontalCenter: parent.horizontalCenter
307+ }
308+
309+ Label {
310+ id: valueLabel
311+ objectName: "valueLabel"
312+ text: body
313+ anchors.horizontalCenter: parent.horizontalCenter
314+ visible: type === Notification.Confirmation && body !== ""
315+ fontSize: "medium"
316+ color: darkOnBright ? sdFontColor : Theme.palette.selected.backgroundText
317+ wrapMode: Text.WordWrap
318+ maximumLineCount: 1
319+ elide: Text.ElideRight
320+ textFormat: Text.PlainText
321+ }
322+
323+ UbuntuShape {
324+ id: valueIndicator
325+ objectName: "valueIndicator"
326+ visible: type === Notification.Confirmation
327+ property double value
328+
329+ anchors {
330+ left: parent.left
331+ right: parent.right
332+ margins: contentSpacing
333+ }
334+
335+ height: units.gu(1)
336+ color: darkOnBright ? UbuntuColors.darkGrey : UbuntuColors.lightGrey
337+ borderSource: "none"
338+ radius: "small"
339+
340+ UbuntuShape {
341+ id: innerBar
342+ objectName: "innerBar"
343+ width: valueIndicator.width * valueIndicator.value / 100
344+ height: units.gu(1)
345+ color: notification.hints["x-canonical-value-bar-tint"] === "true" ? UbuntuColors.orange : darkOnBright ? UbuntuColors.lightGrey : "white"
346+ borderSource: "none"
347+ radius: "small"
348+ }
349+ }
350+
287351 Column {
288352 id: dialogColumn
289353 objectName: "dialogListView"
qml/Notifications/Notifications.qml+1
@@ -56,6 +56,7 @@ Flickables.ListView {
5656 secondaryIconSource: model.secondaryIcon
5757 summary: model.summary
5858 body: model.body
59+ value: model.value
5960 actions: model.actions
6061 notificationId: model.id
6162 notification: notificationList.model.getRaw(notificationId)
tests/qmltests/Notifications/tst_Notifications.qml+172−41
@@ -53,6 +53,7 @@ Row {
5353 summary: "",
5454 body: "",
5555 icon: "",
56+ value: 0,
5657 secondaryIcon: "",
5758 actions: []
5859 }
@@ -125,10 +126,11 @@ Row {
125126 function addEphemeralIconSummaryNotification() {
126127 var n = {
127128 type: Notification.Ephemeral,
129+ hints: {"x-canonical-non-shaped-icon": "false"},
128130 summary: "Photo upload completed",
129131 body: "",
130− icon: "",
131− secondaryIcon: "../graphics/applicationIcons/facebook.png",
132+ icon: "../graphics/applicationIcons/facebook.png",
133+ secondaryIcon: "",
132134 actions: []
133135 }
134136
@@ -148,20 +150,53 @@ Row {
148150 mockModel.append(n)
149151 }
150152
153+ function addConfirmationNotification() {
154+ var n = {
155+ type: Notification.Confirmation,
156+ hints: {"x-canonical-non-shaped-icon": "true"},
157+ summary: "Confirmation notification",
158+ body: "",
159+ icon: "image://theme/audio-volume-medium",
160+ secondaryIcon: "",
161+ value: 50,
162+ actions: [],
163+ }
164+
165+ mockModel.append(n)
166+ }
167+
168+ function add2ndConfirmationNotification() {
169+ var n = {
170+ type: Notification.Confirmation,
171+ hints: {"x-canonical-non-shaped-icon": "true",
172+ "x-canonical-value-bar-tint": "true"},
173+ summary: "Confirmation notification",
174+ body: "High Volume",
175+ icon: "image://theme/audio-volume-high",
176+ secondaryIcon: "",
177+ value: 85,
178+ actions: [],
179+ }
180+
181+ mockModel.append(n)
182+ }
183+
151184 function clearNotifications() {
152− mockModel.clear()
185+ while(mockModel.count > 1) {
186+ remove1stNotification()
187+ }
153188 }
154189
155190 function remove1stNotification() {
156− if (mockModel.count > 0)
157− mockModel.remove(0)
191+ if (mockModel.count > 1)
192+ mockModel.remove(1)
158193 }
159194
160195 Rectangle {
161196 id: notificationsRect
162197
163198 width: units.gu(40)
164− height: units.gu(71)
199+ height: units.gu(115)
165200
166201 MouseArea{
167202 id: clickThroughCatcher
@@ -183,7 +218,7 @@ Row {
183218 id: interactiveControls
184219
185220 width: units.gu(30)
186− height: units.gu(81)
221+ height: units.gu(115)
187222 color: "grey"
188223
189224 Column {
@@ -227,6 +262,18 @@ Row {
227262 onClicked: addInteractiveNotification()
228263 }
229264
265+ Button {
266+ width: parent.width
267+ text: "add a confirmation"
268+ onClicked: addConfirmationNotification()
269+ }
270+
271+ Button {
272+ width: parent.width
273+ text: "add a 2nd confirmation"
274+ onClicked: add2ndConfirmationNotification()
275+ }
276+
230277 Button {
231278 width: parent.width
232279 text: "remove 1st notification"
@@ -264,12 +311,16 @@ Row {
264311 summaryVisible: true,
265312 bodyVisible: true,
266313 iconVisible: true,
267− shapedIcon: true,
268− nonShapedIcon: false,
314+ centeredIconVisible: false,
315+ shaped: true,
316+ nonShaped: false,
269317 secondaryIconVisible: true,
270318 buttonRowVisible: true,
271319 buttonTinted: true,
272− hasSound: false
320+ hasSound: false,
321+ valueVisible: false,
322+ valueLabelVisible: false,
323+ valueTinted: false
273324 },
274325 {
275326 tag: "2-over-1 Snap Decision with button-tint",
@@ -285,31 +336,37 @@ Row {
285336 summaryVisible: true,
286337 bodyVisible: true,
287338 iconVisible: false,
288− shapedIcon: false,
289− nonShapedIcon: false,
339+ centeredIconVisible: false,
340+ shaped: false,
290341 secondaryIconVisible: false,
291342 buttonRowVisible: false,
292343 buttonTinted: true,
293− hasSound: false
344+ hasSound: false,
345+ valueVisible: false,
346+ valueLabelVisible: false,
347+ valueTinted: false
294348 },
295349 {
296350 tag: "Ephemeral notification - icon-summary layout",
297351 type: Notification.Ephemeral,
298− hints: {"x-canonical-private-affirmative-tint": "false"},
352+ hints: {},
299353 summary: "Photo upload completed",
300354 body: "",
301− icon: "",
302− secondaryIcon: "../graphics/applicationIcons/facebook.png",
355+ icon: "../graphics/applicationIcons/facebook.png",
356+ secondaryIcon: "",
303357 actions: [],
304358 summaryVisible: true,
305359 bodyVisible: false,
306− iconVisible: false,
307− shapedIcon: false,
308− nonShapedIcon: false,
309− secondaryIconVisible: true,
360+ iconVisible: true,
361+ centeredIconVisible: false,
362+ shaped: true,
363+ secondaryIconVisible: false,
310364 buttonRowVisible: false,
311365 buttonTinted: false,
312− hasSound: false
366+ hasSound: false,
367+ valueVisible: false,
368+ valueLabelVisible: false,
369+ valueTinted: false
313370 },
314371 {
315372 tag: "Ephemeral notification - check suppression of secondary icon for icon-summary layout",
@@ -326,12 +383,15 @@ Row {
326383 bodyVisible: false,
327384 interactiveAreaEnabled: false,
328385 iconVisible: false,
329− shapedIcon: false,
330− nonShapedIcon: false,
386+ centeredIconVisible: false,
387+ shaped: false,
331388 secondaryIconVisible: true,
332389 buttonRowVisible: false,
333390 buttonTinted: false,
334− hasSound: false
391+ hasSound: false,
392+ valueVisible: false,
393+ valueLabelVisible: false,
394+ valueTinted: false
335395 },
336396 {
337397 tag: "Interactive notification",
@@ -346,12 +406,15 @@ Row {
346406 summaryVisible: true,
347407 bodyVisible: true,
348408 iconVisible: true,
349− shapedIcon: true,
350− nonShapedIcon: false,
409+ centeredIconVisible: false,
410+ shaped: true,
351411 secondaryIconVisible: false,
352412 buttonRowVisible: false,
353413 buttonTinted: false,
354− hasSound: true
414+ hasSound: true,
415+ valueVisible: false,
416+ valueLabelVisible: false,
417+ valueTinted: false
355418 },
356419 {
357420 tag: "Snap Decision without secondary icon and no button-tint",
@@ -367,12 +430,15 @@ Row {
367430 summaryVisible: true,
368431 bodyVisible: true,
369432 iconVisible: true,
370− shapedIcon: true,
371− nonShapedIcon: false,
433+ centeredIconVisible: false,
434+ shaped: true,
372435 secondaryIconVisible: false,
373436 buttonRowVisible: true,
374437 buttonTinted: false,
375− hasSound: true
438+ hasSound: true,
439+ valueVisible: false,
440+ valueLabelVisible: false,
441+ valueTinted: false
376442 },
377443 {
378444 tag: "Ephemeral notification",
@@ -387,12 +453,15 @@ Row {
387453 summaryVisible: true,
388454 bodyVisible: true,
389455 iconVisible: true,
390− shapedIcon: true,
391− nonShapedIcon: false,
456+ centeredIconVisible: false,
457+ shaped: true,
392458 secondaryIconVisible: true,
393459 buttonRowVisible: false,
394460 buttonTinted: false,
395− hasSound: true
461+ hasSound: true,
462+ valueVisible: false,
463+ valueLabelVisible: false,
464+ valueTinted: false
396465 },
397466 {
398467 tag: "Ephemeral notification with non-shaped icon",
@@ -401,18 +470,68 @@ Row {
401470 "x-canonical-non-shaped-icon": "true"},
402471 summary: "Contacts",
403472 body: "Synchronised contacts-database with cloud-storage.",
404− icon: "../graphics/applicationIcons/contacts-app.png",
473+ icon: "image://theme/contacts-app",
405474 secondaryIcon: "",
406475 actions: [],
407476 summaryVisible: true,
408477 bodyVisible: true,
409478 iconVisible: true,
410− shapedIcon: false,
411− nonShapedIcon: true,
479+ centeredIconVisible: false,
480+ shaped: false,
481+ secondaryIconVisible: false,
482+ buttonRowVisible: false,
483+ buttonTinted: false,
484+ hasSound: false,
485+ valueVisible: false,
486+ valueLabelVisible: false,
487+ valueTinted: false
488+ },
489+ {
490+ tag: "Confirmation notification with value",
491+ type: Notification.Confirmation,
492+ hints: {"x-canonical-non-shaped-icon": "true"},
493+ summary: "",
494+ body: "",
495+ icon: "image://theme/audio-volume-medium",
496+ secondaryIcon: "",
497+ value: 50,
498+ actions: [],
499+ summaryVisible: false,
500+ bodyVisible: false,
501+ iconVisible: false,
502+ centeredIconVisible: true,
503+ shaped: false,
412504 secondaryIconVisible: false,
413505 buttonRowVisible: false,
414506 buttonTinted: false,
415− hasSound: false
507+ hasSound: false,
508+ valueVisible: true,
509+ valueLabelVisible: false,
510+ valueTinted: false
511+ },
512+ {
513+ tag: "Confirmation notification with value, label and tint",
514+ type: Notification.Confirmation,
515+ hints: {"x-canonical-non-shaped-icon": "true",
516+ "x-canonical-value-bar-tint" : "true"},
517+ summary: "",
518+ body: "High Volume",
519+ icon: "image://theme/audio-volume-high",
520+ secondaryIcon: "",
521+ value: 85,
522+ actions: [],
523+ summaryVisible: false,
524+ bodyVisible: false,
525+ iconVisible: false,
526+ centeredIconVisible: true,
527+ shaped: false,
528+ secondaryIconVisible: false,
529+ buttonRowVisible: false,
530+ buttonTinted: false,
531+ hasSound: false,
532+ valueVisible: true,
533+ valueLabelVisible: true,
534+ valueTinted: true
416535 }
417536 ]
418537 }
@@ -450,17 +569,29 @@ Row {
450569 waitForRendering(notification);
451570
452571 var icon = findChild(notification, "icon")
453− var shapedIcon = findChild(notification, "shapedIcon")
454− var nonShapedIcon = findChild(notification, "nonShapedIcon")
572+ var centeredIcon = findChild(notification, "centeredIcon")
455573 var interactiveArea = findChild(notification, "interactiveArea")
456574 var secondaryIcon = findChild(notification, "secondaryIcon")
457575 var summaryLabel = findChild(notification, "summaryLabel")
458576 var bodyLabel = findChild(notification, "bodyLabel")
459577 var buttonRow = findChild(notification, "buttonRow")
578+ var valueIndicator = findChild(notification, "valueIndicator")
579+ var valueLabel = findChild(notification, "valueLabel")
580+ var innerBar = findChild(notification, "innerBar")
460581
461582 compare(icon.visible, data.iconVisible, "avatar-icon visibility is incorrect")
462− compare(shapedIcon.visible, data.shapedIcon, "shaped-icon visibility is incorrect")
463− compare(nonShapedIcon.visible, data.nonShapedIcon, "non-shaped-icon visibility is incorrect")
583+ if (icon.visible) {
584+ compare(icon.shaped, data.shaped, "shaped-status is incorrect")
585+ }
586+ compare(centeredIcon.visible, data.centeredIconVisible, "centered-icon visibility is incorrect")
587+ if (centeredIcon.visible) {
588+ compare(centeredIcon.shaped, data.shaped, "shaped-status is incorrect")
589+ }
590+ compare(valueIndicator.visible, data.valueVisible, "value-indicator visibility is incorrect")
591+ if (valueIndicator.visible) {
592+ verify(innerBar.color === data.valueTinted ? UbuntuColors.orange : "white", "value-bar has the wrong color-tint")
593+ }
594+ compare(valueLabel.visible, data.valueLabelVisible, "value-label visibility is incorrect")
464595
465596 // test input does not fall through
466597 mouseClick(notification, notification.width / 2, notification.height / 2)