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: notification.notification && typeof notification.notification.fullscreen != "undefined" ?
41 notification.notification.fullscreen : false // fullscreen prop only exists in the mock
42 property int maxHeight
43 property int margins: units.gu(1)
45 readonly property real defaultOpacity: 1.0
46 property bool hasMouse
47 property url background: ""
49 objectName: "background"
50 implicitHeight: type !== Notification.PlaceHolder ? (fullscreen ? maxHeight : outterColumn.height + shapedBack.anchors.topMargin + margins * 2) : 0
52 // FIXME: non-zero initially because of LP: #1354406 workaround, we want this to start at 0 upon creation eventually
53 opacity: defaultOpacity - Math.abs(x / notification.width)
55 theme: ThemeSettings {
56 name: "Ubuntu.Components.Themes.Ambiance"
59 readonly property bool expanded: type === Notification.SnapDecision && // expand only snap decisions, if...
60 (fullscreen || // - it's a fullscreen one
61 ListView.view.currentIndex === index || // - it's the one the user clicked on
62 (ListView.view.currentIndex === -1 && index == 0) // - the first one after the user closed the previous one
68 source: hints["suppress-sound"] !== "true" && hints["sound-file"] !== undefined ? hints["sound-file"] : ""
71 Component.onCompleted: {
72 if (type === Notification.PlaceHolder) {
76 // Turn on screen as needed (Powerd.Notification means the screen
77 // stays on for a shorter amount of time)
78 if (type === Notification.SnapDecision) {
79 Powerd.setStatus(Powerd.On, Powerd.SnapDecision);
80 } else if (type !== Notification.Confirmation) {
81 Powerd.setStatus(Powerd.On, Powerd.Notification);
84 // FIXME: using onCompleted because of LP: #1354406 workaround, has to be onOpacityChanged really
85 if (opacity == defaultOpacity && hints["suppress-sound"] !== "true" && sound.source !== "") {
90 Component.onDestruction: {
91 if (type === Notification.PlaceHolder) {
95 if (type === Notification.SnapDecision) {
96 Powerd.setStatus(Powerd.Off, Powerd.SnapDecision);
97 } else if (type !== Notification.Confirmation) {
98 Powerd.setStatus(Powerd.Off, Powerd.Notification);
102 function closeNotification() {
103 if (index === ListView.view.currentIndex) { // reset to get the 1st snap decision expanded
104 ListView.view.currentIndex = -1;
107 // perform the "reject" action
108 notification.notification.invokeAction(notification.actions.data(1, ActionModel.RoleActionId));
110 notification.notification.close();
114 UbuntuNumberAnimation { easing.type: Easing.OutBounce }
118 if (type === Notification.Confirmation && opacity == defaultOpacity && hints["suppress-sound"] !== "true" && sound.source !== "") {
123 onFullscreenChanged: {
125 notification.notification.urgency = Notification.Critical;
128 ListView.view.topmostIsFullscreen = fullscreen;
132 Behavior on implicitHeight {
134 UbuntuNumberAnimation {
135 duration: UbuntuAnimation.SnapDuration
139 visible: type !== Notification.PlaceHolder
144 margins: shapedBack.visible ? -units.gu(1) : -units.gu(1.5)
146 source: "../graphics/dropshadow2gu.sci"
147 opacity: notification.opacity * 0.5
153 objectName: "shapedBack"
158 leftMargin: notification.margins
159 rightMargin: notification.margins
160 topMargin: index == 0 ? notification.margins : 0
162 backgroundColor: parent.color
164 aspect: UbuntuShape.Flat
176 if (Math.abs(notification.x) > 0.75 * notification.width) {
183 anchors.fill: fullscreen ? nonShapedBack : shapedBack
185 UnityMenuModelPaths {
188 source: hints["x-canonical-private-menu-model"]
190 busNameHint: "busName"
191 actionsHint: "actions"
192 menuObjectPathHint: "menuPath"
198 property string lastNameOwner: ""
200 busName: paths.busName
201 actions: paths.actions
202 menuObjectPath: paths.menuObjectPath
203 onNameOwnerChanged: {
204 if (lastNameOwner !== "" && nameOwner === "" && notification.notification !== undefined) {
205 notification.notification.close()
207 lastNameOwner = nameOwner
215 objectName: "interactiveArea"
217 drag.target: !fullscreen ? notification : undefined
218 drag.axis: Drag.XAxis
219 drag.minimumX: -notification.width
220 drag.maximumX: notification.width
224 if (notification.type === Notification.Interactive) {
225 notification.notification.invokeAction(actionRepeater.itemAt(0).actionId)
227 notification.ListView.view.currentIndex = index;
231 if (Math.abs(notification.x) < notification.width / 2) {
234 notification.x = notification.width
240 objectName: "closeButton"
244 visible: hasMouse && (containsMouse || interactiveArea.containsMouse)
248 color: theme.palette.normal.negative
249 anchors.horizontalCenter: parent.left
250 anchors.horizontalCenterOffset: notification.parent.state === "narrow" ? notification.margins / 2 : 0
251 anchors.verticalCenter: parent.top
252 anchors.verticalCenterOffset: notification.parent.state === "narrow" ? notification.margins / 2 : 0
254 onClicked: closeNotification();
259 objectName: "outterColumn"
265 margins: !fullscreen ? notification.margins : 0
268 spacing: notification.margins
273 spacing: notification.margins
285 shaped: notification.hints["x-canonical-non-shaped-icon"] !== "true"
286 visible: iconSource !== "" && type !== Notification.Confirmation
291 width: secondaryIcon.visible ? parent.width - x - units.gu(3) : parent.width - x
292 anchors.verticalCenter: (icon.visible && !bodyLabel.visible) ? icon.verticalCenter : undefined
293 spacing: units.gu(.4)
298 objectName: "summaryLabel"
303 visible: type !== Notification.Confirmation
305 font.weight: Font.Light
306 color: theme.palette.normal.backgroundSecondaryText
307 elide: Text.ElideRight
308 textFormat: Text.PlainText
314 objectName: "bodyLabel"
319 visible: body != "" && type !== Notification.Confirmation
321 font.weight: Font.Light
322 color: theme.palette.normal.backgroundTertiaryText
324 maximumLineCount: type === Notification.SnapDecision ? 12 : 2
325 elide: Text.ElideRight
326 textFormat: Text.PlainText
334 objectName: "secondaryIcon"
337 visible: status === Image.Ready
338 fillMode: Image.PreserveAspectCrop
342 ListItem.ThinDivider {
343 visible: type === Notification.SnapDecision && notification.expanded
347 name: "toolkit_chevron-down_3gu"
348 visible: type === Notification.SnapDecision && !notification.expanded
351 anchors.horizontalCenter: parent.horizontalCenter
352 color: theme.palette.normal.base
357 objectName: "centeredIcon"
360 shaped: notification.hints["x-canonical-non-shaped-icon"] !== "true"
361 fileSource: icon.fileSource
362 visible: fileSource !== "" && type === Notification.Confirmation
363 anchors.horizontalCenter: parent.horizontalCenter
368 objectName: "valueLabel"
370 anchors.horizontalCenter: parent.horizontalCenter
371 visible: type === Notification.Confirmation && body !== ""
373 font.weight: Font.Light
374 color: theme.palette.normal.backgroundSecondaryText
375 wrapMode: Text.WordWrap
377 elide: Text.ElideRight
378 textFormat: Text.PlainText
383 objectName: "valueIndicator"
384 visible: type === Notification.Confirmation
387 showProgressPercentage: false
397 objectName: "dialogListView"
398 spacing: notification.margins
400 visible: count > 0 && (notification.expanded || notification.fullscreen)
405 top: fullscreen ? parent.top : undefined
406 bottom: fullscreen ? parent.bottom : undefined
410 model: unityMenuModel
412 NotificationMenuItemFactory {
416 left: dialogColumn.left
417 right: dialogColumn.right
420 menuModel: unityMenuModel
423 maxHeight: notification.maxHeight
424 background: notification.background
427 notification.fullscreen = Qt.binding(function() { return fullscreen; });
430 notification.notification.invokeAction(actionRepeater.itemAt(0).actionId)
444 spacing: notification.margins
446 visible: notification.type === Notification.SnapDecision && oneOverTwoRepeaterTop.count === 3 && notification.expanded
449 id: oneOverTwoRepeaterTop
451 model: notification.actions
453 id: oneOverTwoLoaderTop
455 property string actionId: id
456 property string actionLabel: label
459 id: oneOverTwoButtonTop
462 objectName: "notify_oot_button" + index
463 width: oneOverTwoCase.width
464 text: oneOverTwoLoaderTop.actionLabel
465 outline: notification.hints["x-canonical-private-affirmative-tint"] !== "true"
466 color: notification.hints["x-canonical-private-affirmative-tint"] === "true" ? theme.palette.normal.positive
467 : theme.name == "Ubuntu.Components.Themes.SuruDark" ? "#888"
469 onClicked: notification.notification.invokeAction(oneOverTwoLoaderTop.actionId)
472 sourceComponent: index == 0 ? oneOverTwoButtonTop : undefined
477 spacing: notification.margins
480 id: oneOverTwoRepeaterBottom
482 model: notification.actions
484 id: oneOverTwoLoaderBottom
486 property string actionId: id
487 property string actionLabel: label
490 id: oneOverTwoButtonBottom
493 objectName: "notify_oot_button" + index
494 width: oneOverTwoCase.width / 2 - spacing / 2
495 text: oneOverTwoLoaderBottom.actionLabel
496 outline: notification.hints["x-canonical-private-rejection-tint"] !== "true"
497 color: index == 1 && notification.hints["x-canonical-private-rejection-tint"] === "true" ? theme.palette.normal.negative
498 : theme.name == "Ubuntu.Components.Themes.SuruDark" ? "#888"
500 onClicked: notification.notification.invokeAction(oneOverTwoLoaderBottom.actionId)
503 sourceComponent: (index == 1 || index == 2) ? oneOverTwoButtonBottom : undefined
512 objectName: "buttonRow"
517 visible: notification.type === Notification.SnapDecision && actionRepeater.count > 0 && !oneOverTwoCase.visible && notification.expanded
518 spacing: notification.margins
519 layoutDirection: Qt.RightToLeft
522 id: notifySwipeButtonLoader
523 active: notification.hints["x-canonical-snap-decisions-swipe"] === "true"
525 sourceComponent: SwipeToAct {
526 objectName: "notify_swipe_button"
527 width: buttonRow.width
528 leftIconName: "call-end"
529 rightIconName: "call-start"
530 clickToAct: notification.hasMouse
532 notification.notification.invokeAction(notification.actions.data(0, ActionModel.RoleActionId))
536 notification.notification.invokeAction(notification.actions.data(1, ActionModel.RoleActionId))
543 model: notification.actions
547 property string actionId: id
548 property string actionLabel: label
549 active: !notifySwipeButtonLoader.active
555 objectName: "notify_button" + index
556 width: buttonRow.width / 2 - spacing / 2
557 text: loader.actionLabel
558 outline: (index == 0 && notification.hints["x-canonical-private-affirmative-tint"] !== "true") ||
559 (index == 1 && notification.hints["x-canonical-private-rejection-tint"] !== "true")
562 if (theme.name == "Ubuntu.Components.Themes.SuruDark") {
565 if (index == 0 && notification.hints["x-canonical-private-affirmative-tint"] === "true") {
566 result = theme.palette.normal.positive;
568 if (index == 1 && notification.hints["x-canonical-private-rejection-tint"] === "true") {
569 result = theme.palette.normal.negative;
573 onClicked: notification.notification.invokeAction(loader.actionId)
576 sourceComponent: (index == 0 || index == 1) ? actionButton : undefined
583 objectName: "notify_button2"
590 visible: notification.type === Notification.SnapDecision && actionRepeater.count > 3 && !oneOverTwoCase.visible && notification.expanded
591 model: notification.actions
595 notification.notification.invokeAction(id)