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
20 import Ubuntu.Components 1.1
21 import Unity.Notifications 1.0
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 draggable: (type === Notification.SnapDecision && state === "contracted") || type === Notification.Interactive || type === Notification.Ephemeral
45 readonly property bool darkOnBright: panel.indicators.shown || type === Notification.SnapDecision
46 readonly property color red: "#fc4949"
47 readonly property color green: "#3fb24f"
48 readonly property color sdLightGrey: "#eaeaea"
49 readonly property color sdDarkGrey: "#dddddd"
50 readonly property color sdFontColor: "#5d5d5d"
51 readonly property real contentSpacing: units.gu(2)
53 objectName: "background"
54 implicitHeight: type !== Notification.PlaceHolder ? (fullscreen ? maxHeight : outterColumn.height - shapedBack.anchors.topMargin + contentSpacing * 2) : 0
56 color: (type === Notification.Confirmation && notificationList.useModal && !greeter.shown) || darkOnBright ? sdLightGrey : Qt.rgba(0.132, 0.117, 0.109, 0.97)
57 opacity: 1 - (x / notification.width) // FIXME: non-zero initially because of LP: #1354406 workaround, we want this to start at 0 upon creation eventually
62 if (type == Notification.SnapDecision) {
63 if (ListView.view.currentIndex == index) {
66 if (ListView.view.count > 2) {
67 if (ListView.view.currentIndex == -1 && index == 1) {
70 result = "contracted";
84 audioRole: MediaPlayer.alert
85 source: hints["suppress-sound"] !== "true" && hints["sound-file"] !== undefined ? hints["sound-file"] : ""
88 Component.onCompleted: {
89 // Turn on screen as needed (Powerd.Notification means the screen
90 // stays on for a shorter amount of time)
91 if (type == Notification.SnapDecision) {
92 Powerd.setStatus(Powerd.On, Powerd.Unknown);
93 } else if (type != Notification.Confirmation) {
94 Powerd.setStatus(Powerd.On, Powerd.Notification);
97 // FIXME: using onCompleted because of LP: #1354406 workaround, has to be onOpacityChanged really
98 if (opacity == 1.0 && hints["suppress-sound"] !== "true" && sound.source !== "") {
107 UbuntuNumberAnimation {
108 duration: UbuntuAnimation.FastDuration
109 easing.type: Easing.OutBounce
114 if (type === Notification.Confirmation && opacity == 1.0 && hints["suppress-sound"] !== "true" && sound.source !== "") {
120 id: normalHeightBehavior
122 //enabled: menuItemFactory.progress == 1
124 UbuntuNumberAnimation {
125 duration: UbuntuAnimation.SnapDuration
132 PropertyChanges {target: notification; height: units.gu(10)}
136 PropertyChanges {target: notification; height: implicitHeight}
140 clip: fullscreen ? false : true
142 visible: type != Notification.PlaceHolder
150 leftMargin: notification.margins
151 rightMargin: notification.margins
152 topMargin: type === Notification.Confirmation ? units.gu(.5) : 0
155 opacity: parent.opacity
166 opacity: parent.opacity
170 if (draggable && notification.x > 0.75 * notification.width) {
171 notification.notification.close()
177 anchors.fill: fullscreen ? nonShapedBack : shapedBack
179 UnityMenuModelPaths {
182 source: hints["x-canonical-private-menu-model"]
184 busNameHint: "busName"
185 actionsHint: "actions"
186 menuObjectPathHint: "menuPath"
192 property string lastNameOwner: ""
194 busName: paths.busName
195 actions: paths.actions
196 menuObjectPath: paths.menuObjectPath
197 onNameOwnerChanged: {
198 if (lastNameOwner !== "" && nameOwner === "" && notification.notification !== undefined) {
199 notification.notification.close()
201 lastNameOwner = nameOwner
209 objectName: "interactiveArea"
211 drag.target: draggable ? notification : undefined
212 drag.axis: Drag.XAxis
214 drag.maximumX: notification.width
217 if (notification.type == Notification.Interactive) {
218 notification.notification.invokeAction(actionRepeater.itemAt(0).actionId)
220 notificationList.currentIndex = index;
224 if (notification.x < notification.width / 2) {
227 notification.x = notification.width
240 topMargin: fullscreen ? 0 : type === Notification.Confirmation ? units.gu(1) : units.gu(2)
243 spacing: type === Notification.Confirmation ? units.gu(1) : units.gu(2)
248 spacing: contentSpacing
252 margins: contentSpacing
259 width: type == Notification.Ephemeral && !bodyLabel.visible ? units.gu(3) : units.gu(6)
261 shaped: notification.hints["x-canonical-non-shaped-icon"] == "true" ? false : true
262 visible: iconSource !== undefined && iconSource !== "" && type !== Notification.Confirmation
267 width: secondaryIcon.visible ? parent.width - x - units.gu(4.5) : parent.width - x
269 anchors.verticalCenter: (icon.visible && !bodyLabel.visible) ? icon.verticalCenter : undefined
274 objectName: "summaryLabel"
279 visible: type !== Notification.Confirmation
281 color: darkOnBright ? sdFontColor : Theme.palette.selected.backgroundText
282 elide: Text.ElideRight
283 textFormat: Text.PlainText
289 objectName: "bodyLabel"
294 visible: body != "" && type !== Notification.Confirmation
296 color: darkOnBright ? sdFontColor : Theme.palette.selected.backgroundText
297 wrapMode: Text.WordWrap
298 maximumLineCount: type == Notification.SnapDecision ? 12 : 2
299 elide: Text.ElideRight
300 textFormat: Text.PlainText
307 objectName: "secondaryIcon"
310 visible: status === Image.Ready
311 fillMode: Image.PreserveAspectCrop
315 ListItem.ThinDivider {
316 visible: type == Notification.SnapDecision
321 objectName: "centeredIcon"
324 shaped: notification.hints["x-canonical-non-shaped-icon"] == "true" ? false : true
325 fileSource: icon.fileSource
326 visible: fileSource !== undefined && fileSource !== "" && type === Notification.Confirmation
327 anchors.horizontalCenter: parent.horizontalCenter
332 objectName: "valueLabel"
334 anchors.horizontalCenter: parent.horizontalCenter
335 visible: type === Notification.Confirmation && body !== ""
337 color: darkOnBright ? sdFontColor : Theme.palette.selected.backgroundText
338 wrapMode: Text.WordWrap
340 elide: Text.ElideRight
341 textFormat: Text.PlainText
346 objectName: "valueIndicator"
347 visible: type === Notification.Confirmation
348 property double value
353 margins: contentSpacing
357 color: darkOnBright ? UbuntuColors.darkGrey : UbuntuColors.lightGrey
363 objectName: "innerBar"
364 width: valueIndicator.width * valueIndicator.value / 100
366 color: notification.hints["x-canonical-value-bar-tint"] === "true" ? UbuntuColors.orange : darkOnBright ? UbuntuColors.lightGrey : "white"
374 objectName: "dialogListView"
382 top: fullscreen ? parent.top : undefined
383 bottom: fullscreen ? parent.bottom : undefined
387 model: unityMenuModel
389 NotificationMenuItemFactory {
393 left: dialogColumn.left
394 right: dialogColumn.right
397 menuModel: unityMenuModel
400 maxHeight: notification.maxHeight
403 notification.fullscreen = Qt.binding(function() { return fullscreen; });
406 notification.notification.invokeAction(actionRepeater.itemAt(0).actionId)
418 margins: contentSpacing
421 spacing: contentSpacing
423 visible: notification.type === Notification.SnapDecision && oneOverTwoRepeaterTop.count === 3
426 id: oneOverTwoRepeaterTop
428 model: notification.actions
430 id: oneOverTwoLoaderTop
432 property string actionId: id
433 property string actionLabel: label
436 id: oneOverTwoButtonTop
439 objectName: "notify_oot_button" + index
440 width: oneOverTwoCase.width
441 text: oneOverTwoLoaderTop.actionLabel
442 color: notification.hints["x-canonical-private-affirmative-tint"] == "true" ? green : sdDarkGrey
443 onClicked: notification.notification.invokeAction(oneOverTwoLoaderTop.actionId)
446 sourceComponent: index == 0 ? oneOverTwoButtonTop : undefined
451 spacing: contentSpacing
454 id: oneOverTwoRepeaterBottom
456 model: notification.actions
458 id: oneOverTwoLoaderBottom
460 property string actionId: id
461 property string actionLabel: label
464 id: oneOverTwoButtonBottom
467 objectName: "notify_oot_button" + index
468 width: oneOverTwoCase.width / 2 - spacing * 2
469 text: oneOverTwoLoaderBottom.actionLabel
470 color: index == 1 && notification.hints["x-canonical-private-rejection-tint"] == "true" ? red : sdDarkGrey
471 onClicked: notification.notification.invokeAction(oneOverTwoLoaderBottom.actionId)
474 sourceComponent: (index == 1 || index == 2) ? oneOverTwoButtonBottom : undefined
483 objectName: "buttonRow"
487 margins: contentSpacing
489 visible: notification.type === Notification.SnapDecision && actionRepeater.count > 0 && !oneOverTwoCase.visible
491 layoutDirection: Qt.RightToLeft
494 id: notifySwipeButtonLoader
495 active: notification.hints["x-canonical-snap-decisions-swipe"] === "true"
497 sourceComponent: SwipeToAct {
498 objectName: "notify_swipe_button"
499 width: buttonRow.width
500 leftIconName: "call-end"
501 rightIconName: "call-start"
503 notification.notification.invokeAction(notification.actions.data(0, ActionModel.RoleActionId))
507 notification.notification.invokeAction(notification.actions.data(1, ActionModel.RoleActionId))
514 model: notification.actions
518 property string actionId: id
519 property string actionLabel: label
520 active: !notifySwipeButtonLoader.active
526 objectName: "notify_button" + index
527 width: buttonRow.width / 2 - spacing * 2
528 text: loader.actionLabel
530 var result = sdDarkGrey;
531 if (index == 0 && notification.hints["x-canonical-private-affirmative-tint"] == "true") {
534 if (index == 1 && notification.hints["x-canonical-private-rejection-tint"] == "true") {
539 onClicked: notification.notification.invokeAction(loader.actionId)
542 sourceComponent: (index == 0 || index == 1) ? actionButton : undefined
549 objectName: "notify_button2"
554 margins: contentSpacing
557 visible: notification.type == Notification.SnapDecision && actionRepeater.count > 3 && !oneOverTwoCase.visible
558 model: notification.actions
562 notification.notification.invokeAction(id)