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: inverseMode || type === Notification.SnapDecision
45 readonly property color sdLightGrey: "#eaeaea"
46 readonly property real contentSpacing: units.gu(2)
47 readonly property bool canBeClosed: type === Notification.Ephemeral
48 property bool hasMouse
49 property bool inverseMode
50 property url background: ""
52 objectName: "background"
53 implicitHeight: type !== Notification.PlaceHolder ? (fullscreen ? maxHeight : outterColumn.height - shapedBack.anchors.topMargin + contentSpacing * 2) : 0
55 color: (type === Notification.Confirmation && notificationList.useModal && !greeter.shown) || darkOnBright ? sdLightGrey : Qt.rgba(0.132, 0.117, 0.109, 0.97)
56 opacity: 1 - (x / notification.width) // FIXME: non-zero initially because of LP: #1354406 workaround, we want this to start at 0 upon creation eventually
58 theme: ThemeSettings {
59 name: darkOnBright ? "Ubuntu.Components.Themes.Ambiance" : "Ubuntu.Components.Themes.SuruDark"
65 if (type == Notification.SnapDecision) {
66 if (ListView.view.currentIndex == index) {
69 if (ListView.view.count > 2) {
70 if (ListView.view.currentIndex == -1 && index == 1) {
73 result = "contracted";
87 source: hints["suppress-sound"] !== "true" && hints["sound-file"] !== undefined ? hints["sound-file"] : ""
90 Component.onCompleted: {
91 // Turn on screen as needed (Powerd.Notification means the screen
92 // stays on for a shorter amount of time)
93 if (type == Notification.SnapDecision) {
94 Powerd.setStatus(Powerd.On, Powerd.SnapDecision);
95 } else if (type != Notification.Confirmation) {
96 Powerd.setStatus(Powerd.On, Powerd.Notification);
99 // FIXME: using onCompleted because of LP: #1354406 workaround, has to be onOpacityChanged really
100 if (opacity == 1.0 && hints["suppress-sound"] !== "true" && sound.source !== "") {
109 UbuntuNumberAnimation {
110 duration: UbuntuAnimation.FastDuration
111 easing.type: Easing.OutBounce
116 if (type === Notification.Confirmation && opacity == 1.0 && hints["suppress-sound"] !== "true" && sound.source !== "") {
122 id: normalHeightBehavior
124 //enabled: menuItemFactory.progress == 1
126 UbuntuNumberAnimation {
127 duration: UbuntuAnimation.SnapDuration
134 PropertyChanges {target: notification; height: units.gu(10)}
138 PropertyChanges {target: notification; height: implicitHeight}
142 clip: fullscreen ? false : true
144 visible: type != Notification.PlaceHolder
152 leftMargin: notification.margins
153 rightMargin: notification.margins
154 topMargin: type === Notification.Confirmation ? units.gu(.5) : 0
156 backgroundColor: parent.color
157 opacity: parent.opacity
159 aspect: UbuntuShape.Flat
168 opacity: parent.opacity
172 if (draggable && notification.x > 0.75 * notification.width) {
173 notification.notification.close()
179 anchors.fill: fullscreen ? nonShapedBack : shapedBack
181 UnityMenuModelPaths {
184 source: hints["x-canonical-private-menu-model"]
186 busNameHint: "busName"
187 actionsHint: "actions"
188 menuObjectPathHint: "menuPath"
194 property string lastNameOwner: ""
196 busName: paths.busName
197 actions: paths.actions
198 menuObjectPath: paths.menuObjectPath
199 onNameOwnerChanged: {
200 if (lastNameOwner !== "" && nameOwner === "" && notification.notification !== undefined) {
201 notification.notification.close()
203 lastNameOwner = nameOwner
211 objectName: "interactiveArea"
213 drag.target: draggable ? notification : undefined
214 drag.axis: Drag.XAxis
216 drag.maximumX: notification.width
219 if (notification.type == Notification.Interactive) {
220 notification.notification.invokeAction(actionRepeater.itemAt(0).actionId)
221 } else if (hasMouse && canBeClosed) {
222 notification.notification.close()
224 notificationList.currentIndex = index;
228 if (notification.x < notification.width / 2) {
231 notification.x = notification.width
244 topMargin: fullscreen ? 0 : type === Notification.Confirmation ? units.gu(1) : units.gu(2)
247 spacing: type === Notification.Confirmation ? units.gu(1) : units.gu(2)
252 spacing: contentSpacing
256 margins: contentSpacing
263 width: type == Notification.Ephemeral && !bodyLabel.visible ? units.gu(3) : units.gu(6)
265 shaped: notification.hints["x-canonical-non-shaped-icon"] == "true" ? false : true
266 visible: iconSource !== undefined && iconSource !== "" && type !== Notification.Confirmation
271 width: secondaryIcon.visible ? parent.width - x - units.gu(4.5) : parent.width - x
273 anchors.verticalCenter: (icon.visible && !bodyLabel.visible) ? icon.verticalCenter : undefined
278 objectName: "summaryLabel"
283 visible: type !== Notification.Confirmation
285 elide: Text.ElideRight
286 textFormat: Text.PlainText
292 objectName: "bodyLabel"
297 visible: body != "" && type !== Notification.Confirmation
300 maximumLineCount: type == Notification.SnapDecision ? 12 : 2
301 elide: Text.ElideRight
302 textFormat: Text.PlainText
309 objectName: "secondaryIcon"
312 visible: status === Image.Ready
313 fillMode: Image.PreserveAspectCrop
317 ListItem.ThinDivider {
318 visible: type == Notification.SnapDecision
323 objectName: "centeredIcon"
326 shaped: notification.hints["x-canonical-non-shaped-icon"] == "true" ? false : true
327 fileSource: icon.fileSource
328 visible: fileSource !== undefined && fileSource !== "" && type === Notification.Confirmation
329 anchors.horizontalCenter: parent.horizontalCenter
334 objectName: "valueLabel"
336 anchors.horizontalCenter: parent.horizontalCenter
337 visible: type === Notification.Confirmation && body !== ""
339 wrapMode: Text.WordWrap
341 elide: Text.ElideRight
342 textFormat: Text.PlainText
347 objectName: "valueIndicator"
348 visible: type === Notification.Confirmation
349 property double value
354 margins: contentSpacing
358 backgroundColor: theme.palette.normal.background
359 aspect: UbuntuShape.Flat
364 objectName: "innerBar"
365 width: valueIndicator.width * valueIndicator.value / 100
367 backgroundColor: notification.hints["x-canonical-value-bar-tint"] === "true" ? theme.palette.normal.activity : theme.palette.highlighted.foreground
368 aspect: UbuntuShape.Flat
375 objectName: "dialogListView"
383 top: fullscreen ? parent.top : undefined
384 bottom: fullscreen ? parent.bottom : undefined
388 model: unityMenuModel
390 NotificationMenuItemFactory {
394 left: dialogColumn.left
395 right: dialogColumn.right
398 menuModel: unityMenuModel
401 maxHeight: notification.maxHeight
402 background: notification.background
405 notification.fullscreen = Qt.binding(function() { return fullscreen; });
408 notification.notification.invokeAction(actionRepeater.itemAt(0).actionId)
420 margins: contentSpacing
423 spacing: contentSpacing
425 visible: notification.type === Notification.SnapDecision && oneOverTwoRepeaterTop.count === 3
428 id: oneOverTwoRepeaterTop
430 model: notification.actions
432 id: oneOverTwoLoaderTop
434 property string actionId: id
435 property string actionLabel: label
438 id: oneOverTwoButtonTop
441 objectName: "notify_oot_button" + index
442 width: oneOverTwoCase.width
443 text: oneOverTwoLoaderTop.actionLabel
444 color: notification.hints["x-canonical-private-affirmative-tint"] == "true" ? UbuntuColors.green : theme.palette.normal.baseText
445 onClicked: notification.notification.invokeAction(oneOverTwoLoaderTop.actionId)
448 sourceComponent: index == 0 ? oneOverTwoButtonTop : undefined
453 spacing: contentSpacing
456 id: oneOverTwoRepeaterBottom
458 model: notification.actions
460 id: oneOverTwoLoaderBottom
462 property string actionId: id
463 property string actionLabel: label
466 id: oneOverTwoButtonBottom
469 objectName: "notify_oot_button" + index
470 width: oneOverTwoCase.width / 2 - spacing * 2
471 text: oneOverTwoLoaderBottom.actionLabel
472 color: index == 1 && notification.hints["x-canonical-private-rejection-tint"] == "true" ? UbuntuColors.red : theme.palette.normal.baseText
473 onClicked: notification.notification.invokeAction(oneOverTwoLoaderBottom.actionId)
476 sourceComponent: (index == 1 || index == 2) ? oneOverTwoButtonBottom : undefined
485 objectName: "buttonRow"
489 margins: contentSpacing
491 visible: notification.type === Notification.SnapDecision && actionRepeater.count > 0 && !oneOverTwoCase.visible
492 spacing: contentSpacing
493 layoutDirection: Qt.RightToLeft
496 id: notifySwipeButtonLoader
497 active: notification.hints["x-canonical-snap-decisions-swipe"] === "true"
499 sourceComponent: SwipeToAct {
500 objectName: "notify_swipe_button"
501 width: buttonRow.width
502 leftIconName: "call-end"
503 rightIconName: "call-start"
504 clickToAct: notification.hasMouse
506 notification.notification.invokeAction(notification.actions.data(0, ActionModel.RoleActionId))
510 notification.notification.invokeAction(notification.actions.data(1, ActionModel.RoleActionId))
517 model: notification.actions
521 property string actionId: id
522 property string actionLabel: label
523 active: !notifySwipeButtonLoader.active
529 objectName: "notify_button" + index
530 width: buttonRow.width / 2 - spacing * 2
531 text: loader.actionLabel
533 var result = theme.palette.normal.baseText;
534 if (index == 0 && notification.hints["x-canonical-private-affirmative-tint"] == "true") {
535 result = UbuntuColors.green;
537 if (index == 1 && notification.hints["x-canonical-private-rejection-tint"] == "true") {
538 result = UbuntuColors.red;
542 onClicked: notification.notification.invokeAction(loader.actionId)
545 sourceComponent: (index == 0 || index == 1) ? actionButton : undefined
552 objectName: "notify_button2"
557 margins: contentSpacing
560 visible: notification.type == Notification.SnapDecision && actionRepeater.count > 3 && !oneOverTwoCase.visible
561 model: notification.actions
565 notification.notification.invokeAction(id)