2 * Copyright (C) 2013, 2015 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/>.
19 import Ubuntu.Components 1.3
20 import Ubuntu.Components.ListItems 1.3 as ListItem
21 import Unity.Notifications 1.0
24 import "../Components"
29 property alias iconSource: icon.fileSource
30 property alias secondaryIconSource: secondaryIcon.source
31 property alias summary: summaryLabel.text
32 property alias body: bodyLabel.text
33 property alias value: valueIndicator.value
35 property var notificationId
38 property var notification
40 property bool fullscreen: false
41 property int maxHeight
43 readonly property bool draggable: (type === Notification.SnapDecision && state === "contracted") || type === Notification.Interactive || type === Notification.Ephemeral
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)
51 readonly property bool canBeClosed: type === Notification.Ephemeral
52 property bool hasMouse
53 property url background: ""
55 objectName: "background"
56 implicitHeight: type !== Notification.PlaceHolder ? (fullscreen ? maxHeight : outterColumn.height - shapedBack.anchors.topMargin + contentSpacing * 2) : 0
58 color: (type === Notification.Confirmation && notificationList.useModal && !greeter.shown) || darkOnBright ? sdLightGrey : Qt.rgba(0.132, 0.117, 0.109, 0.97)
59 opacity: 1 - (x / notification.width) // FIXME: non-zero initially because of LP: #1354406 workaround, we want this to start at 0 upon creation eventually
64 if (type == Notification.SnapDecision) {
65 if (ListView.view.currentIndex == index) {
68 if (ListView.view.count > 2) {
69 if (ListView.view.currentIndex == -1 && index == 1) {
72 result = "contracted";
86 source: hints["suppress-sound"] !== "true" && hints["sound-file"] !== undefined ? hints["sound-file"] : ""
89 Component.onCompleted: {
90 // Turn on screen as needed (Powerd.Notification means the screen
91 // stays on for a shorter amount of time)
92 if (type == Notification.SnapDecision) {
93 Powerd.setStatus(Powerd.On, Powerd.SnapDecision);
94 } else if (type != Notification.Confirmation) {
95 Powerd.setStatus(Powerd.On, Powerd.Notification);
98 // FIXME: using onCompleted because of LP: #1354406 workaround, has to be onOpacityChanged really
99 if (opacity == 1.0 && hints["suppress-sound"] !== "true" && sound.source !== "") {
108 UbuntuNumberAnimation {
109 duration: UbuntuAnimation.FastDuration
110 easing.type: Easing.OutBounce
115 if (type === Notification.Confirmation && opacity == 1.0 && hints["suppress-sound"] !== "true" && sound.source !== "") {
121 id: normalHeightBehavior
123 //enabled: menuItemFactory.progress == 1
125 UbuntuNumberAnimation {
126 duration: UbuntuAnimation.SnapDuration
133 PropertyChanges {target: notification; height: units.gu(10)}
137 PropertyChanges {target: notification; height: implicitHeight}
141 clip: fullscreen ? false : true
143 visible: type != Notification.PlaceHolder
151 leftMargin: notification.margins
152 rightMargin: notification.margins
153 topMargin: type === Notification.Confirmation ? units.gu(.5) : 0
155 backgroundColor: parent.color
156 opacity: parent.opacity
158 aspect: UbuntuShape.Flat
167 opacity: parent.opacity
171 if (draggable && notification.x > 0.75 * notification.width) {
172 notification.notification.close()
178 anchors.fill: fullscreen ? nonShapedBack : shapedBack
180 UnityMenuModelPaths {
183 source: hints["x-canonical-private-menu-model"]
185 busNameHint: "busName"
186 actionsHint: "actions"
187 menuObjectPathHint: "menuPath"
193 property string lastNameOwner: ""
195 busName: paths.busName
196 actions: paths.actions
197 menuObjectPath: paths.menuObjectPath
198 onNameOwnerChanged: {
199 if (lastNameOwner !== "" && nameOwner === "" && notification.notification !== undefined) {
200 notification.notification.close()
202 lastNameOwner = nameOwner
210 objectName: "interactiveArea"
212 drag.target: draggable ? notification : undefined
213 drag.axis: Drag.XAxis
215 drag.maximumX: notification.width
218 if (notification.type == Notification.Interactive) {
219 notification.notification.invokeAction(actionRepeater.itemAt(0).actionId)
220 } else if (hasMouse && canBeClosed) {
221 notification.notification.close()
223 notificationList.currentIndex = index;
227 if (notification.x < notification.width / 2) {
230 notification.x = notification.width
243 topMargin: fullscreen ? 0 : type === Notification.Confirmation ? units.gu(1) : units.gu(2)
246 spacing: type === Notification.Confirmation ? units.gu(1) : units.gu(2)
251 spacing: contentSpacing
255 margins: contentSpacing
262 width: type == Notification.Ephemeral && !bodyLabel.visible ? units.gu(3) : units.gu(6)
264 shaped: notification.hints["x-canonical-non-shaped-icon"] == "true" ? false : true
265 visible: iconSource !== undefined && iconSource !== "" && type !== Notification.Confirmation
270 width: secondaryIcon.visible ? parent.width - x - units.gu(4.5) : parent.width - x
272 anchors.verticalCenter: (icon.visible && !bodyLabel.visible) ? icon.verticalCenter : undefined
277 objectName: "summaryLabel"
282 visible: type !== Notification.Confirmation
284 color: darkOnBright ? sdFontColor : theme.palette.selected.backgroundText
285 elide: Text.ElideRight
286 textFormat: Text.PlainText
292 objectName: "bodyLabel"
297 visible: body != "" && type !== Notification.Confirmation
299 color: darkOnBright ? sdFontColor : theme.palette.selected.backgroundText
300 wrapMode: Text.WordWrap
301 maximumLineCount: type == Notification.SnapDecision ? 12 : 2
302 elide: Text.ElideRight
303 textFormat: Text.PlainText
310 objectName: "secondaryIcon"
313 visible: status === Image.Ready
314 fillMode: Image.PreserveAspectCrop
318 ListItem.ThinDivider {
319 visible: type == Notification.SnapDecision
324 objectName: "centeredIcon"
327 shaped: notification.hints["x-canonical-non-shaped-icon"] == "true" ? false : true
328 fileSource: icon.fileSource
329 visible: fileSource !== undefined && fileSource !== "" && type === Notification.Confirmation
330 anchors.horizontalCenter: parent.horizontalCenter
335 objectName: "valueLabel"
337 anchors.horizontalCenter: parent.horizontalCenter
338 visible: type === Notification.Confirmation && body !== ""
340 color: darkOnBright ? sdFontColor : theme.palette.selected.backgroundText
341 wrapMode: Text.WordWrap
343 elide: Text.ElideRight
344 textFormat: Text.PlainText
349 objectName: "valueIndicator"
350 visible: type === Notification.Confirmation
351 property double value
356 margins: contentSpacing
360 backgroundColor: darkOnBright ? UbuntuColors.darkGrey : UbuntuColors.lightGrey
361 aspect: UbuntuShape.Flat
366 objectName: "innerBar"
367 width: valueIndicator.width * valueIndicator.value / 100
369 backgroundColor: notification.hints["x-canonical-value-bar-tint"] === "true" ? UbuntuColors.orange : darkOnBright ? UbuntuColors.lightGrey : "white"
370 aspect: UbuntuShape.Flat
377 objectName: "dialogListView"
385 top: fullscreen ? parent.top : undefined
386 bottom: fullscreen ? parent.bottom : undefined
390 model: unityMenuModel
392 NotificationMenuItemFactory {
396 left: dialogColumn.left
397 right: dialogColumn.right
400 menuModel: unityMenuModel
403 maxHeight: notification.maxHeight
404 background: notification.background
407 notification.fullscreen = Qt.binding(function() { return fullscreen; });
410 notification.notification.invokeAction(actionRepeater.itemAt(0).actionId)
422 margins: contentSpacing
425 spacing: contentSpacing
427 visible: notification.type === Notification.SnapDecision && oneOverTwoRepeaterTop.count === 3
430 id: oneOverTwoRepeaterTop
432 model: notification.actions
434 id: oneOverTwoLoaderTop
436 property string actionId: id
437 property string actionLabel: label
440 id: oneOverTwoButtonTop
443 objectName: "notify_oot_button" + index
444 width: oneOverTwoCase.width
445 text: oneOverTwoLoaderTop.actionLabel
446 color: notification.hints["x-canonical-private-affirmative-tint"] == "true" ? green : sdDarkGrey
447 onClicked: notification.notification.invokeAction(oneOverTwoLoaderTop.actionId)
450 sourceComponent: index == 0 ? oneOverTwoButtonTop : undefined
455 spacing: contentSpacing
458 id: oneOverTwoRepeaterBottom
460 model: notification.actions
462 id: oneOverTwoLoaderBottom
464 property string actionId: id
465 property string actionLabel: label
468 id: oneOverTwoButtonBottom
471 objectName: "notify_oot_button" + index
472 width: oneOverTwoCase.width / 2 - spacing * 2
473 text: oneOverTwoLoaderBottom.actionLabel
474 color: index == 1 && notification.hints["x-canonical-private-rejection-tint"] == "true" ? red : sdDarkGrey
475 onClicked: notification.notification.invokeAction(oneOverTwoLoaderBottom.actionId)
478 sourceComponent: (index == 1 || index == 2) ? oneOverTwoButtonBottom : undefined
487 objectName: "buttonRow"
491 margins: contentSpacing
493 visible: notification.type === Notification.SnapDecision && actionRepeater.count > 0 && !oneOverTwoCase.visible
494 spacing: contentSpacing
495 layoutDirection: Qt.RightToLeft
498 id: notifySwipeButtonLoader
499 active: notification.hints["x-canonical-snap-decisions-swipe"] === "true"
501 sourceComponent: SwipeToAct {
502 objectName: "notify_swipe_button"
503 width: buttonRow.width
504 leftIconName: "call-end"
505 rightIconName: "call-start"
506 clickToAct: notification.hasMouse
508 notification.notification.invokeAction(notification.actions.data(0, ActionModel.RoleActionId))
512 notification.notification.invokeAction(notification.actions.data(1, ActionModel.RoleActionId))
519 model: notification.actions
523 property string actionId: id
524 property string actionLabel: label
525 active: !notifySwipeButtonLoader.active
531 objectName: "notify_button" + index
532 width: buttonRow.width / 2 - spacing * 2
533 text: loader.actionLabel
535 var result = sdDarkGrey;
536 if (index == 0 && notification.hints["x-canonical-private-affirmative-tint"] == "true") {
539 if (index == 1 && notification.hints["x-canonical-private-rejection-tint"] == "true") {
544 onClicked: notification.notification.invokeAction(loader.actionId)
547 sourceComponent: (index == 0 || index == 1) ? actionButton : undefined
554 objectName: "notify_button2"
559 margins: contentSpacing
562 visible: notification.type == Notification.SnapDecision && actionRepeater.count > 3 && !oneOverTwoCase.visible
563 model: notification.actions
567 notification.notification.invokeAction(id)