2 * Copyright (C) 2013-2016 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
39 property color color: theme.palette.normal.background
40 property bool fullscreen: false
41 property int maxHeight
42 property int margins: units.gu(1)
44 readonly property real defaultOpacity: 1.0
45 property bool hasMouse
46 property url background: ""
48 objectName: "background"
49 implicitHeight: type !== Notification.PlaceHolder ? (fullscreen ? maxHeight : outterColumn.height + shapedBack.anchors.topMargin + margins * 2) : 0
51 // FIXME: non-zero initially because of LP: #1354406 workaround, we want this to start at 0 upon creation eventually
52 opacity: defaultOpacity - Math.abs(x / notification.width)
54 theme: ThemeSettings {
55 name: "Ubuntu.Components.Themes.Ambiance"
60 readonly property bool expanded: {
63 if (type === Notification.SnapDecision) {
64 if (ListView.view.currentIndex === index || fullscreen) {
67 if (ListView.view.count > 2) {
68 if (ListView.view.currentIndex === -1 && index == 1) {
85 source: hints["suppress-sound"] !== "true" && hints["sound-file"] !== undefined ? hints["sound-file"] : ""
88 Component.onCompleted: {
89 if (type === Notification.PlaceHolder) {
93 // Turn on screen as needed (Powerd.Notification means the screen
94 // stays on for a shorter amount of time)
95 if (type === Notification.SnapDecision) {
96 Powerd.setStatus(Powerd.On, Powerd.SnapDecision);
97 } else if (type !== Notification.Confirmation) {
98 Powerd.setStatus(Powerd.On, Powerd.Notification);
101 // FIXME: using onCompleted because of LP: #1354406 workaround, has to be onOpacityChanged really
102 if (opacity == defaultOpacity && hints["suppress-sound"] !== "true" && sound.source !== "") {
107 Component.onDestruction: {
108 if (type === Notification.PlaceHolder) {
112 if (type === Notification.SnapDecision) {
113 Powerd.setStatus(Powerd.Off, Powerd.SnapDecision);
114 } else if (type !== Notification.Confirmation) {
115 Powerd.setStatus(Powerd.Off, Powerd.Notification);
119 function closeNotification() {
120 if (index === ListView.view.currentIndex) { // reset to get the 1st snap decision expanded
121 ListView.view.currentIndex = -1;
124 // perform the "reject" action
125 notification.notification.invokeAction(notification.actions.data(1, ActionModel.RoleActionId));
127 notification.notification.close();
128 notification.dismissed()
132 UbuntuNumberAnimation { easing.type: Easing.OutBounce }
136 if (type === Notification.Confirmation && opacity == defaultOpacity && hints["suppress-sound"] !== "true" && sound.source !== "") {
141 onFullscreenChanged: {
143 notification.notification.urgency = Notification.Critical;
148 UbuntuNumberAnimation {
149 duration: UbuntuAnimation.SnapDuration
153 visible: type !== Notification.PlaceHolder
158 margins: shapedBack.visible ? -units.gu(1) : -units.gu(1.5)
160 source: "../Stages/graphics/dropshadow2gu.sci"
161 opacity: notification.opacity * 0.5
167 objectName: "shapedBack"
172 leftMargin: notification.margins
173 rightMargin: notification.margins
174 topMargin: index == 0 ? notification.margins : 0
176 backgroundColor: parent.color
178 aspect: UbuntuShape.Flat
190 if (Math.abs(notification.x) > 0.75 * notification.width) {
197 anchors.fill: fullscreen ? nonShapedBack : shapedBack
199 UnityMenuModelPaths {
202 source: hints["x-canonical-private-menu-model"]
204 busNameHint: "busName"
205 actionsHint: "actions"
206 menuObjectPathHint: "menuPath"
212 property string lastNameOwner: ""
214 busName: paths.busName
215 actions: paths.actions
216 menuObjectPath: paths.menuObjectPath
217 onNameOwnerChanged: {
218 if (lastNameOwner !== "" && nameOwner === "" && notification.notification !== undefined) {
219 notification.notification.close()
220 notification.dismissed()
222 lastNameOwner = nameOwner
230 objectName: "interactiveArea"
232 drag.target: !fullscreen ? notification : undefined
233 drag.axis: Drag.XAxis
234 drag.minimumX: -notification.width
235 drag.maximumX: notification.width
239 if (notification.type === Notification.Interactive) {
240 notification.notification.invokeAction(actionRepeater.itemAt(0).actionId)
242 notificationList.currentIndex = index;
246 if (Math.abs(notification.x) < notification.width / 2) {
249 notification.x = notification.width
255 objectName: "closeButton"
259 visible: hasMouse && (containsMouse || interactiveArea.containsMouse)
263 color: theme.palette.normal.negative
264 anchors.horizontalCenter: parent.left
265 anchors.horizontalCenterOffset: notification.parent.state === "narrow" ? notification.margins / 2 : 0
266 anchors.verticalCenter: parent.top
267 anchors.verticalCenterOffset: notification.parent.state === "narrow" ? notification.margins / 2 : 0
269 onClicked: closeNotification();
274 objectName: "outterColumn"
280 margins: !fullscreen ? notification.margins : 0
283 spacing: notification.margins
288 spacing: notification.margins
300 shaped: notification.hints["x-canonical-non-shaped-icon"] !== "true"
301 visible: iconSource !== "" && type !== Notification.Confirmation
306 width: secondaryIcon.visible ? parent.width - x - units.gu(3) : parent.width - x
307 anchors.verticalCenter: (icon.visible && !bodyLabel.visible) ? icon.verticalCenter : undefined
308 spacing: units.gu(.4)
313 objectName: "summaryLabel"
318 visible: type !== Notification.Confirmation
320 font.weight: Font.Light
321 color: theme.palette.normal.backgroundSecondaryText
322 elide: Text.ElideRight
323 textFormat: Text.PlainText
329 objectName: "bodyLabel"
334 visible: body != "" && type !== Notification.Confirmation
336 font.weight: Font.Light
337 color: theme.palette.normal.backgroundTertiaryText
339 maximumLineCount: type === Notification.SnapDecision ? 12 : 2
340 elide: Text.ElideRight
341 textFormat: Text.PlainText
349 objectName: "secondaryIcon"
352 visible: status === Image.Ready
353 fillMode: Image.PreserveAspectCrop
357 ListItem.ThinDivider {
358 visible: type === Notification.SnapDecision && notification.expanded
362 name: "toolkit_chevron-down_3gu"
363 visible: type === Notification.SnapDecision && !notification.expanded
366 anchors.horizontalCenter: parent.horizontalCenter
367 color: theme.palette.normal.base
372 objectName: "centeredIcon"
375 shaped: notification.hints["x-canonical-non-shaped-icon"] !== "true"
376 fileSource: icon.fileSource
377 visible: fileSource !== "" && type === Notification.Confirmation
378 anchors.horizontalCenter: parent.horizontalCenter
383 objectName: "valueLabel"
385 anchors.horizontalCenter: parent.horizontalCenter
386 visible: type === Notification.Confirmation && body !== ""
388 font.weight: Font.Light
389 color: theme.palette.normal.backgroundSecondaryText
390 wrapMode: Text.WordWrap
392 elide: Text.ElideRight
393 textFormat: Text.PlainText
398 objectName: "valueIndicator"
399 visible: type === Notification.Confirmation
402 showProgressPercentage: false
412 objectName: "dialogListView"
413 spacing: notification.margins
415 visible: count > 0 && (notification.expanded || notification.fullscreen)
420 top: fullscreen ? parent.top : undefined
421 bottom: fullscreen ? parent.bottom : undefined
425 model: unityMenuModel
427 NotificationMenuItemFactory {
431 left: dialogColumn.left
432 right: dialogColumn.right
435 menuModel: unityMenuModel
438 maxHeight: notification.maxHeight
439 background: notification.background
442 notification.fullscreen = Qt.binding(function() { return fullscreen; });
445 notification.notification.invokeAction(actionRepeater.itemAt(0).actionId)
446 notification.dismissed()
460 spacing: notification.margins
462 visible: notification.type === Notification.SnapDecision && oneOverTwoRepeaterTop.count === 3 && notification.expanded
465 id: oneOverTwoRepeaterTop
467 model: notification.actions
469 id: oneOverTwoLoaderTop
471 property string actionId: id
472 property string actionLabel: label
475 id: oneOverTwoButtonTop
478 objectName: "notify_oot_button" + index
479 width: oneOverTwoCase.width
480 text: oneOverTwoLoaderTop.actionLabel
481 outline: notification.hints["x-canonical-private-affirmative-tint"] !== "true"
482 color: notification.hints["x-canonical-private-affirmative-tint"] === "true" ? theme.palette.normal.positive
483 : theme.palette.normal.foreground
484 onClicked: notification.notification.invokeAction(oneOverTwoLoaderTop.actionId)
487 sourceComponent: index == 0 ? oneOverTwoButtonTop : undefined
492 spacing: notification.margins
495 id: oneOverTwoRepeaterBottom
497 model: notification.actions
499 id: oneOverTwoLoaderBottom
501 property string actionId: id
502 property string actionLabel: label
505 id: oneOverTwoButtonBottom
508 objectName: "notify_oot_button" + index
509 width: oneOverTwoCase.width / 2 - spacing / 2
510 text: oneOverTwoLoaderBottom.actionLabel
511 outline: notification.hints["x-canonical-private-rejection-tint"] !== "true"
512 color: index == 1 && notification.hints["x-canonical-private-rejection-tint"] === "true" ? theme.palette.normal.negative
513 : theme.palette.normal.foreground
514 onClicked: notification.notification.invokeAction(oneOverTwoLoaderBottom.actionId)
517 sourceComponent: (index == 1 || index == 2) ? oneOverTwoButtonBottom : undefined
526 objectName: "buttonRow"
531 visible: notification.type === Notification.SnapDecision && actionRepeater.count > 0 && !oneOverTwoCase.visible && notification.expanded
532 spacing: notification.margins
533 layoutDirection: Qt.RightToLeft
536 id: notifySwipeButtonLoader
537 active: notification.hints["x-canonical-snap-decisions-swipe"] === "true"
539 sourceComponent: SwipeToAct {
540 objectName: "notify_swipe_button"
541 width: buttonRow.width
542 leftIconName: "call-end"
543 rightIconName: "call-start"
544 clickToAct: notification.hasMouse
546 notification.notification.invokeAction(notification.actions.data(0, ActionModel.RoleActionId))
550 notification.notification.invokeAction(notification.actions.data(1, ActionModel.RoleActionId))
557 model: notification.actions
561 property string actionId: id
562 property string actionLabel: label
563 active: !notifySwipeButtonLoader.active
569 objectName: "notify_button" + index
570 width: buttonRow.width / 2 - spacing / 2
571 text: loader.actionLabel
572 outline: (index == 0 && notification.hints["x-canonical-private-affirmative-tint"] !== "true") ||
573 (index == 1 && notification.hints["x-canonical-private-rejection-tint"] !== "true")
575 var result = theme.palette.normal.foreground;
576 if (index == 0 && notification.hints["x-canonical-private-affirmative-tint"] === "true") {
577 result = theme.palette.normal.positive;
579 if (index == 1 && notification.hints["x-canonical-private-rejection-tint"] === "true") {
580 result = theme.palette.normal.negative;
584 onClicked: notification.notification.invokeAction(loader.actionId)
587 sourceComponent: (index == 0 || index == 1) ? actionButton : undefined
594 objectName: "notify_button2"
601 visible: notification.type === Notification.SnapDecision && actionRepeater.count > 3 && !oneOverTwoCase.visible && notification.expanded
602 model: notification.actions
606 notification.notification.invokeAction(id)