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 darkOnBright: panel.indicators.shown || type === Notification.SnapDecision
44 readonly property color red: "#fc4949"
45 readonly property color green: "#3fb24f"
46 readonly property color sdLightGrey: "#eaeaea"
47 readonly property color sdDarkGrey: "#dddddd"
48 readonly property color sdFontColor: "#5d5d5d"
49 readonly property real contentSpacing: units.gu(2)
51 objectName: "background"
52 implicitHeight: type !== Notification.PlaceHolder ? (fullscreen ? maxHeight : outterColumn.height - shapedBack.anchors.topMargin + contentSpacing * 2) : 0
54 color: (type === Notification.Confirmation && notificationList.useModal && !greeter.shown) || darkOnBright ? sdLightGrey : Qt.rgba(0.132, 0.117, 0.109, 0.97)
55 opacity: 1 // FIXME: 1 because of LP: #1354406 workaround, has to be 0 really
60 if (type == Notification.SnapDecision) {
61 if (ListView.view.currentIndex == index) {
64 if (ListView.view.count > 2) {
65 if (ListView.view.currentIndex == -1 && index == 1) {
68 result = "contracted";
82 audioRole: MediaPlayer.alert
83 source: hints["suppress-sound"] != "true" && hints["sound-file"] != undefined ? hints["sound-file"] : ""
86 // FIXME: using onCompleted because of LP: #1354406 workaround, has to be onOpacityChanged really
87 Component.onCompleted: {
88 if (opacity == 1.0 && hints["suppress-sound"] != "true" && sound.source != "") {
94 if (type === Notification.Confirmation && opacity == 1.0 && hints["suppress-sound"] != "true" && sound.source != "") {
100 id: normalHeightBehavior
102 //enabled: menuItemFactory.progress == 1
104 UbuntuNumberAnimation {
105 duration: UbuntuAnimation.SnapDuration
112 PropertyChanges {target: notification; height: units.gu(10)}
116 PropertyChanges {target: notification; height: implicitHeight}
120 clip: fullscreen ? false : true
122 visible: type != Notification.PlaceHolder
130 leftMargin: notification.margins
131 rightMargin: notification.margins
132 topMargin: type === Notification.Confirmation ? units.gu(.5) : 0
135 opacity: parent.opacity
146 opacity: parent.opacity
151 anchors.fill: fullscreen ? nonShapedBack : shapedBack
153 UnityMenuModelPaths {
156 source: hints["x-canonical-private-menu-model"]
158 busNameHint: "busName"
159 actionsHint: "actions"
160 menuObjectPathHint: "menuPath"
166 property string lastNameOwner: ""
168 busName: paths.busName
169 actions: paths.actions
170 menuObjectPath: paths.menuObjectPath
171 onNameOwnerChanged: {
172 if (lastNameOwner != "" && nameOwner == "" && notification.notification != undefined) {
173 notification.notification.close()
175 lastNameOwner = nameOwner
183 objectName: "interactiveArea"
185 if (notification.type == Notification.Interactive) {
186 notification.notification.invokeAction(actionRepeater.itemAt(0).actionId)
188 notificationList.currentIndex = index;
201 topMargin: fullscreen ? 0 : type === Notification.Confirmation ? units.gu(1) : units.gu(2)
204 spacing: type === Notification.Confirmation ? units.gu(1) : units.gu(2)
209 spacing: contentSpacing
213 margins: contentSpacing
220 width: type == Notification.Ephemeral && !bodyLabel.visible ? units.gu(3) : units.gu(6)
222 shaped: notification.hints["x-canonical-non-shaped-icon"] == "true" ? false : true
223 visible: iconSource !== undefined && iconSource !== "" && type !== Notification.Confirmation
228 width: secondaryIcon.visible ? parent.width - x - units.gu(4.5) : parent.width - x
230 anchors.verticalCenter: (icon.visible && !bodyLabel.visible) ? icon.verticalCenter : undefined
235 objectName: "summaryLabel"
240 visible: type !== Notification.Confirmation
242 color: darkOnBright ? sdFontColor : Theme.palette.selected.backgroundText
243 elide: Text.ElideRight
244 textFormat: Text.PlainText
250 objectName: "bodyLabel"
255 visible: body != "" && type !== Notification.Confirmation
257 color: darkOnBright ? sdFontColor : Theme.palette.selected.backgroundText
258 wrapMode: Text.WordWrap
259 maximumLineCount: type == Notification.SnapDecision ? 12 : 2
260 elide: Text.ElideRight
261 textFormat: Text.PlainText
268 objectName: "secondaryIcon"
271 visible: status === Image.Ready
272 fillMode: Image.PreserveAspectCrop
276 ListItem.ThinDivider {
277 visible: type == Notification.SnapDecision
282 objectName: "centeredIcon"
285 shaped: notification.hints["x-canonical-non-shaped-icon"] == "true" ? false : true
286 fileSource: icon.fileSource
287 visible: fileSource !== undefined && fileSource !== "" && type === Notification.Confirmation
288 anchors.horizontalCenter: parent.horizontalCenter
293 objectName: "valueLabel"
295 anchors.horizontalCenter: parent.horizontalCenter
296 visible: type === Notification.Confirmation && body !== ""
298 color: darkOnBright ? sdFontColor : Theme.palette.selected.backgroundText
299 wrapMode: Text.WordWrap
301 elide: Text.ElideRight
302 textFormat: Text.PlainText
307 objectName: "valueIndicator"
308 visible: type === Notification.Confirmation
309 property double value
314 margins: contentSpacing
318 color: darkOnBright ? UbuntuColors.darkGrey : UbuntuColors.lightGrey
324 objectName: "innerBar"
325 width: valueIndicator.width * valueIndicator.value / 100
327 color: notification.hints["x-canonical-value-bar-tint"] === "true" ? UbuntuColors.orange : darkOnBright ? UbuntuColors.lightGrey : "white"
335 objectName: "dialogListView"
343 top: fullscreen ? parent.top : undefined
344 bottom: fullscreen ? parent.bottom : undefined
348 model: unityMenuModel
350 NotificationMenuItemFactory {
354 left: dialogColumn.left
355 right: dialogColumn.right
358 menuModel: unityMenuModel
361 maxHeight: notification.maxHeight
364 notification.fullscreen = Qt.binding(function() { return fullscreen; });
367 notification.notification.invokeAction(actionRepeater.itemAt(0).actionId)
379 margins: contentSpacing
382 spacing: contentSpacing
384 visible: notification.type === Notification.SnapDecision && oneOverTwoRepeaterTop.count === 3
387 id: oneOverTwoRepeaterTop
389 model: notification.actions
391 id: oneOverTwoLoaderTop
393 property string actionId: id
394 property string actionLabel: label
397 id: oneOverTwoButtonTop
400 objectName: "notify_oot_button" + index
401 width: oneOverTwoCase.width
402 text: oneOverTwoLoaderTop.actionLabel
403 color: notification.hints["x-canonical-private-affirmative-tint"] == "true" ? green : sdDarkGrey
404 onClicked: notification.notification.invokeAction(oneOverTwoLoaderTop.actionId)
407 sourceComponent: index == 0 ? oneOverTwoButtonTop : undefined
412 spacing: contentSpacing
415 id: oneOverTwoRepeaterBottom
417 model: notification.actions
419 id: oneOverTwoLoaderBottom
421 property string actionId: id
422 property string actionLabel: label
425 id: oneOverTwoButtonBottom
428 objectName: "notify_oot_button" + index
429 width: oneOverTwoCase.width / 2 - spacing * 2
430 text: oneOverTwoLoaderBottom.actionLabel
431 color: index == 1 && notification.hints["x-canonical-private-rejection-tint"] == "true" ? red : sdDarkGrey
432 onClicked: notification.notification.invokeAction(oneOverTwoLoaderBottom.actionId)
435 sourceComponent: (index == 1 || index == 2) ? oneOverTwoButtonBottom : undefined
444 objectName: "buttonRow"
448 margins: contentSpacing
450 visible: notification.type == Notification.SnapDecision && actionRepeater.count > 0 && !oneOverTwoCase.visible
452 layoutDirection: Qt.RightToLeft
455 id: notifySwipeButtonLoader
456 active: notification.hints["x-canonical-snap-decisions-swipe"] === "true"
458 sourceComponent: SwipeToAct {
459 objectName: "notify_swipe_button"
460 width: buttonRow.width
461 leftIconName: "call-end"
462 rightIconName: "call-start"
464 notification.notification.invokeAction(notification.actions.data(0, ActionModel.RoleActionId))
468 notification.notification.invokeAction(notification.actions.data(1, ActionModel.RoleActionId))
475 model: notification.actions
479 property string actionId: id
480 property string actionLabel: label
481 active: !notifySwipeButtonLoader.active
487 objectName: "notify_button" + index
488 width: buttonRow.width / 2 - spacing * 2
489 text: loader.actionLabel
491 var result = sdDarkGrey;
492 if (index == 0 && notification.hints["x-canonical-private-affirmative-tint"] == "true") {
495 if (index == 1 && notification.hints["x-canonical-private-rejection-tint"] == "true") {
500 onClicked: notification.notification.invokeAction(loader.actionId)
503 sourceComponent: (index == 0 || index == 1) ? actionButton : undefined
510 objectName: "notify_button2"
515 margins: contentSpacing
518 visible: notification.type == Notification.SnapDecision && actionRepeater.count > 3 && !oneOverTwoCase.visible
519 model: notification.actions
523 notification.notification.invokeAction(id)