2 * Copyright (C) 2013 Canonical, Ltd.
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; version 3.
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 import QtMultimedia 5.0
19 import Ubuntu.Components 1.1
20 import Unity.Notifications 1.0
23 import "../Components/Flickables" as Flickables
25 import Ubuntu.Components.ListItems 0.1 as ListItem
30 property alias iconSource: icon.fileSource
31 property alias secondaryIconSource: secondaryIcon.source
32 property alias summary: summaryLabel.text
33 property alias body: bodyLabel.text
34 property alias value: valueIndicator.value
36 property var notificationId
39 property var notification
41 property bool fullscreen: false
42 property int maxHeight
44 readonly property bool darkOnBright: panel.indicators.shown || type === Notification.SnapDecision
45 readonly property color red: "#fc4949"
46 readonly property color green: "#3fb24f"
47 readonly property color sdLightGrey: "#eaeaea"
48 readonly property color sdDarkGrey: "#dddddd"
49 readonly property color sdFontColor: "#5d5d5d"
50 readonly property real contentSpacing: units.gu(2)
52 objectName: "background"
53 implicitHeight: type !== Notification.PlaceHolder ? (fullscreen ? maxHeight : outterColumn.height - shapedBack.anchors.topMargin + contentSpacing * 2) : 0
55 color: (type === Notification.Confirmation && notificationList.useModal && !greeter.shown) || darkOnBright ? sdLightGrey : Qt.rgba(0.132, 0.117, 0.109, 0.97)
56 opacity: 1 // FIXME: 1 because of LP: #1354406 workaround, has to be 0 really
61 if (type == Notification.SnapDecision) {
62 if (ListView.view.currentIndex == index) {
65 if (ListView.view.count > 2) {
66 if (ListView.view.currentIndex == -1 && index == 1) {
69 result = "contracted";
83 audioRole: MediaPlayer.alert
84 source: hints["suppress-sound"] != "true" && hints["sound-file"] != undefined ? hints["sound-file"] : ""
87 // FIXME: using onCompleted because of LP: #1354406 workaround, has to be onOpacityChanged really
88 Component.onCompleted: {
89 if (opacity == 1.0 && hints["suppress-sound"] != "true" && sound.source != "") {
95 if (type === Notification.Confirmation && opacity == 1.0 && hints["suppress-sound"] != "true" && sound.source != "") {
101 id: normalHeightBehavior
103 //enabled: menuItemFactory.progress == 1
105 SequentialAnimation {
107 duration: UbuntuAnimation.SnapDuration
109 UbuntuNumberAnimation {
110 duration: UbuntuAnimation.SnapDuration
118 PropertyChanges {target: notification; height: units.gu(10)}
122 PropertyChanges {target: notification; height: implicitHeight}
126 clip: fullscreen ? false : true
128 visible: type != Notification.PlaceHolder
136 leftMargin: notification.margins
137 rightMargin: notification.margins
138 topMargin: type === Notification.Confirmation ? units.gu(.5) : 0
141 opacity: parent.opacity
152 opacity: parent.opacity
157 anchors.fill: fullscreen ? nonShapedBack : shapedBack
159 UnityMenuModelPaths {
162 source: hints["x-canonical-private-menu-model"]
164 busNameHint: "busName"
165 actionsHint: "actions"
166 menuObjectPathHint: "menuPath"
172 property string lastNameOwner: ""
174 busName: paths.busName
175 actions: paths.actions
176 menuObjectPath: paths.menuObjectPath
177 onNameOwnerChanged: {
178 if (lastNameOwner != "" && nameOwner == "" && notification.notification != undefined) {
179 notification.notification.close()
181 lastNameOwner = nameOwner
185 Behavior on implicitHeight {
189 UbuntuNumberAnimation {
190 duration: UbuntuAnimation.SnapDuration
194 // delay enabling height behavior until the add transition is complete
195 onOpacityChanged: if (opacity == 1) heightBehavior.enabled = true
201 objectName: "interactiveArea"
203 if (notification.type == Notification.Interactive) {
204 notification.notification.invokeAction(actionRepeater.itemAt(0).actionId)
206 notificationList.currentIndex = index;
219 topMargin: fullscreen ? 0 : type === Notification.Confirmation ? units.gu(1) : units.gu(2)
222 spacing: type === Notification.Confirmation ? units.gu(1) : units.gu(2)
227 spacing: contentSpacing
231 margins: contentSpacing
238 width: type == Notification.Ephemeral && !bodyLabel.visible ? units.gu(3) : units.gu(6)
240 shaped: notification.hints["x-canonical-non-shaped-icon"] == "true" ? false : true
241 visible: iconSource !== undefined && iconSource !== "" && type !== Notification.Confirmation
246 width: secondaryIcon.visible ? parent.width - x - units.gu(4.5) : parent.width - x
248 anchors.verticalCenter: (icon.visible && !bodyLabel.visible) ? icon.verticalCenter : undefined
253 objectName: "summaryLabel"
258 visible: type !== Notification.Confirmation
260 color: darkOnBright ? sdFontColor : Theme.palette.selected.backgroundText
261 elide: Text.ElideRight
262 textFormat: Text.PlainText
268 objectName: "bodyLabel"
273 visible: body != "" && type !== Notification.Confirmation
275 color: darkOnBright ? sdFontColor : Theme.palette.selected.backgroundText
276 wrapMode: Text.WordWrap
277 maximumLineCount: type == Notification.SnapDecision ? 12 : 2
278 elide: Text.ElideRight
279 textFormat: Text.PlainText
286 objectName: "secondaryIcon"
289 visible: status === Image.Ready
290 fillMode: Image.PreserveAspectCrop
294 ListItem.ThinDivider {
295 visible: type == Notification.SnapDecision
300 objectName: "centeredIcon"
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
311 objectName: "valueLabel"
313 anchors.horizontalCenter: parent.horizontalCenter
314 visible: type === Notification.Confirmation && body !== ""
316 color: darkOnBright ? sdFontColor : Theme.palette.selected.backgroundText
317 wrapMode: Text.WordWrap
319 elide: Text.ElideRight
320 textFormat: Text.PlainText
325 objectName: "valueIndicator"
326 visible: type === Notification.Confirmation
327 property double value
332 margins: contentSpacing
336 color: darkOnBright ? UbuntuColors.darkGrey : UbuntuColors.lightGrey
342 objectName: "innerBar"
343 width: valueIndicator.width * valueIndicator.value / 100
345 color: notification.hints["x-canonical-value-bar-tint"] === "true" ? UbuntuColors.orange : darkOnBright ? UbuntuColors.lightGrey : "white"
353 objectName: "dialogListView"
361 top: fullscreen ? parent.top : undefined
362 bottom: fullscreen ? parent.bottom : undefined
366 model: unityMenuModel
368 NotificationMenuItemFactory {
372 left: dialogColumn.left
373 right: dialogColumn.right
376 menuModel: unityMenuModel
379 maxHeight: notification.maxHeight
382 notification.fullscreen = Qt.binding(function() { return fullscreen; });
385 notification.notification.invokeAction(actionRepeater.itemAt(0).actionId)
397 margins: contentSpacing
400 spacing: contentSpacing
402 visible: notification.type == Notification.SnapDecision && oneOverTwoRepeaterTop.count == 3
405 id: oneOverTwoRepeaterTop
407 model: notification.actions
409 id: oneOverTwoLoaderTop
411 property string actionId: id
412 property string actionLabel: label
415 id: oneOverTwoButtonTop
418 objectName: "notify_oot_button" + index
419 width: oneOverTwoCase.width
420 text: oneOverTwoLoaderTop.actionLabel
421 color: notification.hints["x-canonical-private-affirmative-tint"] == "true" ? green : sdDarkGrey
422 onClicked: notification.notification.invokeAction(oneOverTwoLoaderTop.actionId)
425 sourceComponent: index == 0 ? oneOverTwoButtonTop : undefined
430 spacing: contentSpacing
433 id: oneOverTwoRepeaterBottom
435 model: notification.actions
437 id: oneOverTwoLoaderBottom
439 property string actionId: id
440 property string actionLabel: label
443 id: oneOverTwoButtonBottom
446 objectName: "notify_oot_button" + index
447 width: oneOverTwoCase.width / 2 - spacing * 2
448 text: oneOverTwoLoaderBottom.actionLabel
449 color: index == 1 && notification.hints["x-canonical-private-rejection-tint"] == "true" ? red : sdDarkGrey
450 onClicked: notification.notification.invokeAction(oneOverTwoLoaderBottom.actionId)
453 sourceComponent: (index == 1 || index == 2) ? oneOverTwoButtonBottom : undefined
462 objectName: "buttonRow"
466 margins: contentSpacing
468 visible: notification.type == Notification.SnapDecision && actionRepeater.count > 0 && !oneOverTwoCase.visible
470 layoutDirection: Qt.RightToLeft
475 model: notification.actions
479 property string actionId: id
480 property string actionLabel: label
486 objectName: "notify_button" + index
487 width: buttonRow.width / 2 - spacing*2
488 text: loader.actionLabel
490 var result = sdDarkGrey;
491 if (index == 0 && notification.hints["x-canonical-private-affirmative-tint"] == "true") {
494 if (index == 1 && notification.hints["x-canonical-private-rejection-tint"] == "true") {
499 onClicked: notification.notification.invokeAction(loader.actionId)
502 sourceComponent: (index == 0 || index == 1) ? actionButton : undefined
510 objectName: "notify_button2"
515 margins: contentSpacing
518 visible: notification.type == Notification.SnapDecision && actionRepeater.count > 3 && !oneOverTwoCase.visible
520 onClicked: notification.notification.invokeAction(comboRepeater.itemAt(2).actionId)
522 expandedHeight: (comboRepeater.count - 2) * units.gu(4) + units.gu(.5)
523 comboList: Flickables.Flickable {
524 // this has to be wrapped inside a flickable
525 // to work around a feature/bug? of the
526 // ComboButton SDK-element, making a regular
527 // unwrapped Column item flickable
535 comboButton.text = comboRepeater.count >= 3 ? comboRepeater.itemAt(2).actionLabel : ""
538 model: notification.actions
543 visible: status == Loader.Ready
544 property string actionId: id
545 property string actionLabel: label
546 readonly property var splitLabel: actionLabel.match(/(^([-a-z0-9]+):)?(.*)$/)
553 objectName: "notify_button" + index
554 width: comboButton.width
555 height: comboIcon.height + units.gu(2)
558 notification.notification.invokeAction(actionId)
561 ListItem.ThinDivider {
570 leftMargin: units.gu(.5)
571 verticalCenter: parent.verticalCenter
583 left: comboIcon.right
584 leftMargin: units.gu(1)
585 verticalCenter: comboIcon.verticalCenter
593 sourceComponent: (index > 2) ? comboEntry : undefined