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
61 theme: ThemeSettings {
62 name: "Ubuntu.Components.Themes.Ambiance"
68 if (type == Notification.SnapDecision) {
69 if (ListView.view.currentIndex == index) {
72 if (ListView.view.count > 2) {
73 if (ListView.view.currentIndex == -1 && index == 1) {
76 result = "contracted";
90 source: hints["suppress-sound"] !== "true" && hints["sound-file"] !== undefined ? hints["sound-file"] : ""
93 Component.onCompleted: {
94 // Turn on screen as needed (Powerd.Notification means the screen
95 // stays on for a shorter amount of time)
96 if (type == Notification.SnapDecision) {
97 Powerd.setStatus(Powerd.On, Powerd.SnapDecision);
98 } else if (type != Notification.Confirmation) {
99 Powerd.setStatus(Powerd.On, Powerd.Notification);
102 // FIXME: using onCompleted because of LP: #1354406 workaround, has to be onOpacityChanged really
103 if (opacity == 1.0 && hints["suppress-sound"] !== "true" && sound.source !== "") {
112 UbuntuNumberAnimation {
113 duration: UbuntuAnimation.FastDuration
114 easing.type: Easing.OutBounce
119 if (type === Notification.Confirmation && opacity == 1.0 && hints["suppress-sound"] !== "true" && sound.source !== "") {
125 id: normalHeightBehavior
127 //enabled: menuItemFactory.progress == 1
129 UbuntuNumberAnimation {
130 duration: UbuntuAnimation.SnapDuration
137 PropertyChanges {target: notification; height: units.gu(10)}
141 PropertyChanges {target: notification; height: implicitHeight}
145 clip: fullscreen ? false : true
147 visible: type != Notification.PlaceHolder
155 leftMargin: notification.margins
156 rightMargin: notification.margins
157 topMargin: type === Notification.Confirmation ? units.gu(.5) : 0
159 backgroundColor: parent.color
160 opacity: parent.opacity
162 aspect: UbuntuShape.Flat
171 opacity: parent.opacity
175 if (draggable && notification.x > 0.75 * notification.width) {
176 notification.notification.close()
182 anchors.fill: fullscreen ? nonShapedBack : shapedBack
184 UnityMenuModelPaths {
187 source: hints["x-canonical-private-menu-model"]
189 busNameHint: "busName"
190 actionsHint: "actions"
191 menuObjectPathHint: "menuPath"
197 property string lastNameOwner: ""
199 busName: paths.busName
200 actions: paths.actions
201 menuObjectPath: paths.menuObjectPath
202 onNameOwnerChanged: {
203 if (lastNameOwner !== "" && nameOwner === "" && notification.notification !== undefined) {
204 notification.notification.close()
206 lastNameOwner = nameOwner
214 objectName: "interactiveArea"
216 drag.target: draggable ? notification : undefined
217 drag.axis: Drag.XAxis
219 drag.maximumX: notification.width
222 if (notification.type == Notification.Interactive) {
223 notification.notification.invokeAction(actionRepeater.itemAt(0).actionId)
224 } else if (hasMouse && canBeClosed) {
225 notification.notification.close()
227 notificationList.currentIndex = index;
231 if (notification.x < notification.width / 2) {
234 notification.x = notification.width
247 topMargin: fullscreen ? 0 : type === Notification.Confirmation ? units.gu(1) : units.gu(2)
250 spacing: type === Notification.Confirmation ? units.gu(1) : units.gu(2)
255 spacing: contentSpacing
259 margins: contentSpacing
266 width: type == Notification.Ephemeral && !bodyLabel.visible ? units.gu(3) : units.gu(6)
268 shaped: notification.hints["x-canonical-non-shaped-icon"] == "true" ? false : true
269 visible: iconSource !== undefined && iconSource !== "" && type !== Notification.Confirmation
274 width: secondaryIcon.visible ? parent.width - x - units.gu(4.5) : parent.width - x
276 anchors.verticalCenter: (icon.visible && !bodyLabel.visible) ? icon.verticalCenter : undefined
281 objectName: "summaryLabel"
286 visible: type !== Notification.Confirmation
288 color: darkOnBright ? sdFontColor : theme.palette.normal.backgroundText
289 elide: Text.ElideRight
290 textFormat: Text.PlainText
296 objectName: "bodyLabel"
301 visible: body != "" && type !== Notification.Confirmation
303 color: darkOnBright ? sdFontColor : theme.palette.normal.backgroundText
305 maximumLineCount: type == Notification.SnapDecision ? 12 : 2
306 elide: Text.ElideRight
307 textFormat: Text.PlainText
314 objectName: "secondaryIcon"
317 visible: status === Image.Ready
318 fillMode: Image.PreserveAspectCrop
322 ListItem.ThinDivider {
323 visible: type == Notification.SnapDecision
328 objectName: "centeredIcon"
331 shaped: notification.hints["x-canonical-non-shaped-icon"] == "true" ? false : true
332 fileSource: icon.fileSource
333 visible: fileSource !== undefined && fileSource !== "" && type === Notification.Confirmation
334 anchors.horizontalCenter: parent.horizontalCenter
339 objectName: "valueLabel"
341 anchors.horizontalCenter: parent.horizontalCenter
342 visible: type === Notification.Confirmation && body !== ""
344 color: darkOnBright ? sdFontColor : theme.palette.normal.backgroundText
345 wrapMode: Text.WordWrap
347 elide: Text.ElideRight
348 textFormat: Text.PlainText
353 objectName: "valueIndicator"
354 visible: type === Notification.Confirmation
355 property double value
360 margins: contentSpacing
364 backgroundColor: darkOnBright ? UbuntuColors.darkGrey : UbuntuColors.lightGrey
365 aspect: UbuntuShape.Flat
370 objectName: "innerBar"
371 width: valueIndicator.width * valueIndicator.value / 100
373 backgroundColor: notification.hints["x-canonical-value-bar-tint"] === "true" ? UbuntuColors.orange : darkOnBright ? UbuntuColors.lightGrey : "white"
374 aspect: UbuntuShape.Flat
381 objectName: "dialogListView"
389 top: fullscreen ? parent.top : undefined
390 bottom: fullscreen ? parent.bottom : undefined
394 model: unityMenuModel
396 NotificationMenuItemFactory {
400 left: dialogColumn.left
401 right: dialogColumn.right
404 menuModel: unityMenuModel
407 maxHeight: notification.maxHeight
408 background: notification.background
411 notification.fullscreen = Qt.binding(function() { return fullscreen; });
414 notification.notification.invokeAction(actionRepeater.itemAt(0).actionId)
426 margins: contentSpacing
429 spacing: contentSpacing
431 visible: notification.type === Notification.SnapDecision && oneOverTwoRepeaterTop.count === 3
434 id: oneOverTwoRepeaterTop
436 model: notification.actions
438 id: oneOverTwoLoaderTop
440 property string actionId: id
441 property string actionLabel: label
444 id: oneOverTwoButtonTop
447 objectName: "notify_oot_button" + index
448 width: oneOverTwoCase.width
449 text: oneOverTwoLoaderTop.actionLabel
450 color: notification.hints["x-canonical-private-affirmative-tint"] == "true" ? green : sdDarkGrey
451 onClicked: notification.notification.invokeAction(oneOverTwoLoaderTop.actionId)
454 sourceComponent: index == 0 ? oneOverTwoButtonTop : undefined
459 spacing: contentSpacing
462 id: oneOverTwoRepeaterBottom
464 model: notification.actions
466 id: oneOverTwoLoaderBottom
468 property string actionId: id
469 property string actionLabel: label
472 id: oneOverTwoButtonBottom
475 objectName: "notify_oot_button" + index
476 width: oneOverTwoCase.width / 2 - spacing * 2
477 text: oneOverTwoLoaderBottom.actionLabel
478 color: index == 1 && notification.hints["x-canonical-private-rejection-tint"] == "true" ? red : sdDarkGrey
479 onClicked: notification.notification.invokeAction(oneOverTwoLoaderBottom.actionId)
482 sourceComponent: (index == 1 || index == 2) ? oneOverTwoButtonBottom : undefined
491 objectName: "buttonRow"
495 margins: contentSpacing
497 visible: notification.type === Notification.SnapDecision && actionRepeater.count > 0 && !oneOverTwoCase.visible
498 spacing: contentSpacing
499 layoutDirection: Qt.RightToLeft
502 id: notifySwipeButtonLoader
503 active: notification.hints["x-canonical-snap-decisions-swipe"] === "true"
505 sourceComponent: SwipeToAct {
506 objectName: "notify_swipe_button"
507 width: buttonRow.width
508 leftIconName: "call-end"
509 rightIconName: "call-start"
510 clickToAct: notification.hasMouse
512 notification.notification.invokeAction(notification.actions.data(0, ActionModel.RoleActionId))
516 notification.notification.invokeAction(notification.actions.data(1, ActionModel.RoleActionId))
523 model: notification.actions
527 property string actionId: id
528 property string actionLabel: label
529 active: !notifySwipeButtonLoader.active
535 objectName: "notify_button" + index
536 width: buttonRow.width / 2 - spacing * 2
537 text: loader.actionLabel
539 var result = sdDarkGrey;
540 if (index == 0 && notification.hints["x-canonical-private-affirmative-tint"] == "true") {
543 if (index == 1 && notification.hints["x-canonical-private-rejection-tint"] == "true") {
548 onClicked: notification.notification.invokeAction(loader.actionId)
551 sourceComponent: (index == 0 || index == 1) ? actionButton : undefined
558 objectName: "notify_button2"
563 margins: contentSpacing
566 visible: notification.type == Notification.SnapDecision && actionRepeater.count > 3 && !oneOverTwoCase.visible
567 model: notification.actions
571 notification.notification.invokeAction(id)