2 * Copyright (C) 2013 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/>.
18 import QtMultimedia 5.0
19 import Ubuntu.Components 1.1
20 import Unity.Notifications 1.0
24 import Ubuntu.Components.ListItems 0.1 as ListItem
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)
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
61 if (type == Notification.SnapDecision) {
62 if (ListView.view.currentIndex == index) {
65 if (ListView.view.count > 2) {
66 if (ListView.view.currentIndex == -1 && index == 1) {
69 result = "contracted";
83 audioRole: MediaPlayer.alert
84 source: hints["suppress-sound"] !== "true" && hints["sound-file"] !== undefined ? hints["sound-file"] : ""
87 // FIXME: using onCompleted because of LP: #1354406 workaround, has to be onOpacityChanged really
88 Component.onCompleted: {
89 if (opacity == 1.0 && hints["suppress-sound"] !== "true" && sound.source !== "") {
98 UbuntuNumberAnimation {
99 duration: UbuntuAnimation.FastDuration
100 easing.type: Easing.OutBounce
105 if (type === Notification.Confirmation && opacity == 1.0 && hints["suppress-sound"] !== "true" && sound.source !== "") {
111 id: normalHeightBehavior
113 //enabled: menuItemFactory.progress == 1
115 UbuntuNumberAnimation {
116 duration: UbuntuAnimation.SnapDuration
123 PropertyChanges {target: notification; height: units.gu(10)}
127 PropertyChanges {target: notification; height: implicitHeight}
131 clip: fullscreen ? false : true
133 visible: type != Notification.PlaceHolder
141 leftMargin: notification.margins
142 rightMargin: notification.margins
143 topMargin: type === Notification.Confirmation ? units.gu(.5) : 0
146 opacity: parent.opacity
157 opacity: parent.opacity
161 if (draggable && notification.x > 0.75 * notification.width) {
162 notification.notification.close()
168 anchors.fill: fullscreen ? nonShapedBack : shapedBack
170 UnityMenuModelPaths {
173 source: hints["x-canonical-private-menu-model"]
175 busNameHint: "busName"
176 actionsHint: "actions"
177 menuObjectPathHint: "menuPath"
183 property string lastNameOwner: ""
185 busName: paths.busName
186 actions: paths.actions
187 menuObjectPath: paths.menuObjectPath
188 onNameOwnerChanged: {
189 if (lastNameOwner !== "" && nameOwner === "" && notification.notification !== undefined) {
190 notification.notification.close()
192 lastNameOwner = nameOwner
200 objectName: "interactiveArea"
202 drag.target: draggable ? notification : undefined
203 drag.axis: Drag.XAxis
205 drag.maximumX: notification.width
208 if (notification.type == Notification.Interactive) {
209 notification.notification.invokeAction(actionRepeater.itemAt(0).actionId)
211 notificationList.currentIndex = index;
215 if (notification.x < notification.width / 2) {
218 notification.x = notification.width
231 topMargin: fullscreen ? 0 : type === Notification.Confirmation ? units.gu(1) : units.gu(2)
234 spacing: type === Notification.Confirmation ? units.gu(1) : units.gu(2)
239 spacing: contentSpacing
243 margins: contentSpacing
250 width: type == Notification.Ephemeral && !bodyLabel.visible ? units.gu(3) : units.gu(6)
252 shaped: notification.hints["x-canonical-non-shaped-icon"] == "true" ? false : true
253 visible: iconSource !== undefined && iconSource !== "" && type !== Notification.Confirmation
258 width: secondaryIcon.visible ? parent.width - x - units.gu(4.5) : parent.width - x
260 anchors.verticalCenter: (icon.visible && !bodyLabel.visible) ? icon.verticalCenter : undefined
265 objectName: "summaryLabel"
270 visible: type !== Notification.Confirmation
272 color: darkOnBright ? sdFontColor : Theme.palette.selected.backgroundText
273 elide: Text.ElideRight
274 textFormat: Text.PlainText
280 objectName: "bodyLabel"
285 visible: body != "" && type !== Notification.Confirmation
287 color: darkOnBright ? sdFontColor : Theme.palette.selected.backgroundText
288 wrapMode: Text.WordWrap
289 maximumLineCount: type == Notification.SnapDecision ? 12 : 2
290 elide: Text.ElideRight
291 textFormat: Text.PlainText
298 objectName: "secondaryIcon"
301 visible: status === Image.Ready
302 fillMode: Image.PreserveAspectCrop
306 ListItem.ThinDivider {
307 visible: type == Notification.SnapDecision
312 objectName: "centeredIcon"
315 shaped: notification.hints["x-canonical-non-shaped-icon"] == "true" ? false : true
316 fileSource: icon.fileSource
317 visible: fileSource !== undefined && fileSource !== "" && type === Notification.Confirmation
318 anchors.horizontalCenter: parent.horizontalCenter
323 objectName: "valueLabel"
325 anchors.horizontalCenter: parent.horizontalCenter
326 visible: type === Notification.Confirmation && body !== ""
328 color: darkOnBright ? sdFontColor : Theme.palette.selected.backgroundText
329 wrapMode: Text.WordWrap
331 elide: Text.ElideRight
332 textFormat: Text.PlainText
337 objectName: "valueIndicator"
338 visible: type === Notification.Confirmation
339 property double value
344 margins: contentSpacing
348 color: darkOnBright ? UbuntuColors.darkGrey : UbuntuColors.lightGrey
354 objectName: "innerBar"
355 width: valueIndicator.width * valueIndicator.value / 100
357 color: notification.hints["x-canonical-value-bar-tint"] === "true" ? UbuntuColors.orange : darkOnBright ? UbuntuColors.lightGrey : "white"
365 objectName: "dialogListView"
373 top: fullscreen ? parent.top : undefined
374 bottom: fullscreen ? parent.bottom : undefined
378 model: unityMenuModel
380 NotificationMenuItemFactory {
384 left: dialogColumn.left
385 right: dialogColumn.right
388 menuModel: unityMenuModel
391 maxHeight: notification.maxHeight
394 notification.fullscreen = Qt.binding(function() { return fullscreen; });
397 notification.notification.invokeAction(actionRepeater.itemAt(0).actionId)
409 margins: contentSpacing
412 spacing: contentSpacing
414 visible: notification.type === Notification.SnapDecision && oneOverTwoRepeaterTop.count === 3
417 id: oneOverTwoRepeaterTop
419 model: notification.actions
421 id: oneOverTwoLoaderTop
423 property string actionId: id
424 property string actionLabel: label
427 id: oneOverTwoButtonTop
430 objectName: "notify_oot_button" + index
431 width: oneOverTwoCase.width
432 text: oneOverTwoLoaderTop.actionLabel
433 color: notification.hints["x-canonical-private-affirmative-tint"] == "true" ? green : sdDarkGrey
434 onClicked: notification.notification.invokeAction(oneOverTwoLoaderTop.actionId)
437 sourceComponent: index == 0 ? oneOverTwoButtonTop : undefined
442 spacing: contentSpacing
445 id: oneOverTwoRepeaterBottom
447 model: notification.actions
449 id: oneOverTwoLoaderBottom
451 property string actionId: id
452 property string actionLabel: label
455 id: oneOverTwoButtonBottom
458 objectName: "notify_oot_button" + index
459 width: oneOverTwoCase.width / 2 - spacing * 2
460 text: oneOverTwoLoaderBottom.actionLabel
461 color: index == 1 && notification.hints["x-canonical-private-rejection-tint"] == "true" ? red : sdDarkGrey
462 onClicked: notification.notification.invokeAction(oneOverTwoLoaderBottom.actionId)
465 sourceComponent: (index == 1 || index == 2) ? oneOverTwoButtonBottom : undefined
474 objectName: "buttonRow"
478 margins: contentSpacing
480 visible: notification.type === Notification.SnapDecision && actionRepeater.count > 0 && !oneOverTwoCase.visible
482 layoutDirection: Qt.RightToLeft
485 id: notifySwipeButtonLoader
486 active: notification.hints["x-canonical-snap-decisions-swipe"] === "true"
488 sourceComponent: SwipeToAct {
489 objectName: "notify_swipe_button"
490 width: buttonRow.width
491 leftIconName: "call-end"
492 rightIconName: "call-start"
494 notification.notification.invokeAction(notification.actions.data(0, ActionModel.RoleActionId))
498 notification.notification.invokeAction(notification.actions.data(1, ActionModel.RoleActionId))
505 model: notification.actions
509 property string actionId: id
510 property string actionLabel: label
511 active: !notifySwipeButtonLoader.active
517 objectName: "notify_button" + index
518 width: buttonRow.width / 2 - spacing * 2
519 text: loader.actionLabel
521 var result = sdDarkGrey;
522 if (index == 0 && notification.hints["x-canonical-private-affirmative-tint"] == "true") {
525 if (index == 1 && notification.hints["x-canonical-private-rejection-tint"] == "true") {
530 onClicked: notification.notification.invokeAction(loader.actionId)
533 sourceComponent: (index == 0 || index == 1) ? actionButton : undefined
540 objectName: "notify_button2"
545 margins: contentSpacing
548 visible: notification.type == Notification.SnapDecision && actionRepeater.count > 3 && !oneOverTwoCase.visible
549 model: notification.actions
553 notification.notification.invokeAction(id)