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 // 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.SnapDecision);
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 == defaultOpacity && hints["suppress-sound"] !== "true" && sound.source !== "") {
103 function closeNotification() {
104 if (index === ListView.view.currentIndex) { // reset to get the 1st snap decision expanded
105 ListView.view.currentIndex = -1;
108 // perform the "reject" action
109 notification.notification.invokeAction(notification.actions.data(1, ActionModel.RoleActionId));
111 notification.notification.close();
112 notification.dismissed()
116 UbuntuNumberAnimation { easing.type: Easing.OutBounce }
120 if (type === Notification.Confirmation && opacity == defaultOpacity && hints["suppress-sound"] !== "true" && sound.source !== "") {
125 onFullscreenChanged: {
127 notification.notification.urgency = Notification.Critical;
132 UbuntuNumberAnimation {
133 duration: UbuntuAnimation.SnapDuration
137 visible: type !== Notification.PlaceHolder
142 margins: shapedBack.visible ? -units.gu(1) : -units.gu(1.5)
144 source: "../Stages/graphics/dropshadow2gu.sci"
145 opacity: notification.opacity * 0.5
151 objectName: "shapedBack"
156 leftMargin: notification.margins
157 rightMargin: notification.margins
158 topMargin: index == 0 ? notification.margins : 0
160 backgroundColor: parent.color
162 aspect: UbuntuShape.Flat
174 if (Math.abs(notification.x) > 0.75 * notification.width) {
181 anchors.fill: fullscreen ? nonShapedBack : shapedBack
183 UnityMenuModelPaths {
186 source: hints["x-canonical-private-menu-model"]
188 busNameHint: "busName"
189 actionsHint: "actions"
190 menuObjectPathHint: "menuPath"
196 property string lastNameOwner: ""
198 busName: paths.busName
199 actions: paths.actions
200 menuObjectPath: paths.menuObjectPath
201 onNameOwnerChanged: {
202 if (lastNameOwner !== "" && nameOwner === "" && notification.notification !== undefined) {
203 notification.notification.close()
204 notification.dismissed()
206 lastNameOwner = nameOwner
214 objectName: "interactiveArea"
216 drag.target: !fullscreen ? notification : undefined
217 drag.axis: Drag.XAxis
218 drag.minimumX: -notification.width
219 drag.maximumX: notification.width
223 if (notification.type === Notification.Interactive) {
224 notification.notification.invokeAction(actionRepeater.itemAt(0).actionId)
226 notificationList.currentIndex = index;
230 if (Math.abs(notification.x) < notification.width / 2) {
233 notification.x = notification.width
239 objectName: "closeButton"
243 visible: hasMouse && (containsMouse || interactiveArea.containsMouse)
247 color: theme.palette.normal.negative
248 anchors.horizontalCenter: parent.left
249 anchors.horizontalCenterOffset: notification.parent.state === "narrow" ? notification.margins / 2 : 0
250 anchors.verticalCenter: parent.top
251 anchors.verticalCenterOffset: notification.parent.state === "narrow" ? notification.margins / 2 : 0
253 onClicked: closeNotification();
258 objectName: "outterColumn"
264 margins: !fullscreen ? notification.margins : 0
267 spacing: notification.margins
272 spacing: notification.margins
284 shaped: notification.hints["x-canonical-non-shaped-icon"] !== "true"
285 visible: iconSource !== "" && type !== Notification.Confirmation
290 width: secondaryIcon.visible ? parent.width - x - units.gu(3) : parent.width - x
291 anchors.verticalCenter: (icon.visible && !bodyLabel.visible) ? icon.verticalCenter : undefined
292 spacing: units.gu(.4)
297 objectName: "summaryLabel"
302 visible: type !== Notification.Confirmation
304 font.weight: Font.Light
305 color: theme.palette.normal.backgroundSecondaryText
306 elide: Text.ElideRight
307 textFormat: Text.PlainText
313 objectName: "bodyLabel"
318 visible: body != "" && type !== Notification.Confirmation
320 font.weight: Font.Light
321 color: theme.palette.normal.backgroundTertiaryText
323 maximumLineCount: type === Notification.SnapDecision ? 12 : 2
324 elide: Text.ElideRight
325 textFormat: Text.PlainText
333 objectName: "secondaryIcon"
336 visible: status === Image.Ready
337 fillMode: Image.PreserveAspectCrop
341 ListItem.ThinDivider {
342 visible: type === Notification.SnapDecision && notification.expanded
346 name: "toolkit_chevron-down_3gu"
347 visible: type === Notification.SnapDecision && !notification.expanded
350 anchors.horizontalCenter: parent.horizontalCenter
351 color: theme.palette.normal.base
356 objectName: "centeredIcon"
359 shaped: notification.hints["x-canonical-non-shaped-icon"] !== "true"
360 fileSource: icon.fileSource
361 visible: fileSource !== "" && type === Notification.Confirmation
362 anchors.horizontalCenter: parent.horizontalCenter
367 objectName: "valueLabel"
369 anchors.horizontalCenter: parent.horizontalCenter
370 visible: type === Notification.Confirmation && body !== ""
372 font.weight: Font.Light
373 color: theme.palette.normal.backgroundSecondaryText
374 wrapMode: Text.WordWrap
376 elide: Text.ElideRight
377 textFormat: Text.PlainText
382 objectName: "valueIndicator"
383 visible: type === Notification.Confirmation
386 showProgressPercentage: false
396 objectName: "dialogListView"
397 spacing: notification.margins
399 visible: count > 0 && (notification.expanded || notification.fullscreen)
404 top: fullscreen ? parent.top : undefined
405 bottom: fullscreen ? parent.bottom : undefined
409 model: unityMenuModel
411 NotificationMenuItemFactory {
415 left: dialogColumn.left
416 right: dialogColumn.right
419 menuModel: unityMenuModel
422 maxHeight: notification.maxHeight
423 background: notification.background
426 notification.fullscreen = Qt.binding(function() { return fullscreen; });
429 notification.notification.invokeAction(actionRepeater.itemAt(0).actionId)
430 notification.dismissed()
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.palette.normal.foreground
468 onClicked: notification.notification.invokeAction(oneOverTwoLoaderTop.actionId)
471 sourceComponent: index == 0 ? oneOverTwoButtonTop : undefined
476 spacing: notification.margins
479 id: oneOverTwoRepeaterBottom
481 model: notification.actions
483 id: oneOverTwoLoaderBottom
485 property string actionId: id
486 property string actionLabel: label
489 id: oneOverTwoButtonBottom
492 objectName: "notify_oot_button" + index
493 width: oneOverTwoCase.width / 2 - spacing / 2
494 text: oneOverTwoLoaderBottom.actionLabel
495 outline: notification.hints["x-canonical-private-rejection-tint"] !== "true"
496 color: index == 1 && notification.hints["x-canonical-private-rejection-tint"] === "true" ? theme.palette.normal.negative
497 : theme.palette.normal.foreground
498 onClicked: notification.notification.invokeAction(oneOverTwoLoaderBottom.actionId)
501 sourceComponent: (index == 1 || index == 2) ? oneOverTwoButtonBottom : undefined
510 objectName: "buttonRow"
515 visible: notification.type === Notification.SnapDecision && actionRepeater.count > 0 && !oneOverTwoCase.visible && notification.expanded
516 spacing: notification.margins
517 layoutDirection: Qt.RightToLeft
520 id: notifySwipeButtonLoader
521 active: notification.hints["x-canonical-snap-decisions-swipe"] === "true"
523 sourceComponent: SwipeToAct {
524 objectName: "notify_swipe_button"
525 width: buttonRow.width
526 leftIconName: "call-end"
527 rightIconName: "call-start"
528 clickToAct: notification.hasMouse
530 notification.notification.invokeAction(notification.actions.data(0, ActionModel.RoleActionId))
534 notification.notification.invokeAction(notification.actions.data(1, ActionModel.RoleActionId))
541 model: notification.actions
545 property string actionId: id
546 property string actionLabel: label
547 active: !notifySwipeButtonLoader.active
553 objectName: "notify_button" + index
554 width: buttonRow.width / 2 - spacing / 2
555 text: loader.actionLabel
556 outline: (index == 0 && notification.hints["x-canonical-private-affirmative-tint"] !== "true") ||
557 (index == 1 && notification.hints["x-canonical-private-rejection-tint"] !== "true")
559 var result = theme.palette.normal.foreground;
560 if (index == 0 && notification.hints["x-canonical-private-affirmative-tint"] === "true") {
561 result = theme.palette.normal.positive;
563 if (index == 1 && notification.hints["x-canonical-private-rejection-tint"] === "true") {
564 result = theme.palette.normal.negative;
568 onClicked: notification.notification.invokeAction(loader.actionId)
571 sourceComponent: (index == 0 || index == 1) ? actionButton : undefined
578 objectName: "notify_button2"
585 visible: notification.type === Notification.SnapDecision && actionRepeater.count > 3 && !oneOverTwoCase.visible && notification.expanded
586 model: notification.actions
590 notification.notification.invokeAction(id)