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
23 import "../Components/Flickables" as Flickables
25 import Ubuntu.Components.ListItems 0.1 as ListItem
30 property alias iconSource: icon.fileSource
31 property alias secondaryIconSource: secondaryIcon.source
32 property alias summary: summaryLabel.text
33 property alias body: bodyLabel.text
35 property var notificationId
38 property var notification
40 property bool fullscreen: false
41 property int maxHeight
43 readonly property color red: "#fc4949"
44 readonly property color green: "#3fb24f"
45 readonly property color sdLightGrey: "#eaeaea"
46 readonly property color sdDarkGrey: "#dddddd"
47 readonly property color sdFontColor: "#5d5d5d"
48 readonly property real contentSpacing: units.gu(2)
50 objectName: "background"
51 implicitHeight: type !== Notification.PlaceHolder ? (fullscreen ? maxHeight : outterColumn.height + contentSpacing * 2) : 0
53 color: type == Notification.SnapDecision ? sdLightGrey : Qt.rgba(0.132, 0.117, 0.109, 0.97)
54 opacity: 1 // FIXME: 1 because of LP: #1354406 workaround, has to be 0 really
59 if (type == Notification.SnapDecision) {
60 if (ListView.view.currentIndex == index) {
63 if (ListView.view.count > 2) {
64 if (ListView.view.currentIndex == -1 && index == 1) {
67 result = "contracted";
81 source: hints["suppress-sound"] != "true" && hints["sound-file"] != undefined ? hints["sound-file"] : ""
84 // FIXME: using onCompleted because of LP: #1354406 workaround, has to be onOpacityChanged really
85 Component.onCompleted: {
86 if (opacity == 1.0 && hints["suppress-sound"] != "true" && sound.source != "") {
92 id: normalHeightBehavior
94 //enabled: menuItemFactory.progress == 1
98 duration: UbuntuAnimation.SnapDuration
100 UbuntuNumberAnimation {
101 duration: UbuntuAnimation.SnapDuration
109 PropertyChanges {target: notification; height: units.gu(10)}
113 PropertyChanges {target: notification; height: implicitHeight}
117 clip: fullscreen ? false : true
119 visible: type != Notification.PlaceHolder
127 leftMargin: notification.margins
128 rightMargin: notification.margins
131 opacity: parent.opacity
142 opacity: parent.opacity
147 anchors.fill: fullscreen ? nonShapedBack : shapedBack
149 UnityMenuModelPaths {
152 source: hints["x-canonical-private-menu-model"]
154 busNameHint: "busName"
155 actionsHint: "actions"
156 menuObjectPathHint: "menuPath"
162 property string lastNameOwner: ""
164 busName: paths.busName
165 actions: paths.actions
166 menuObjectPath: paths.menuObjectPath
167 onNameOwnerChanged: {
168 if (lastNameOwner != "" && nameOwner == "" && notification.notification != undefined) {
169 notification.notification.close()
171 lastNameOwner = nameOwner
175 Behavior on implicitHeight {
179 UbuntuNumberAnimation {
180 duration: UbuntuAnimation.SnapDuration
184 // delay enabling height behavior until the add transition is complete
185 onOpacityChanged: if (opacity == 1) heightBehavior.enabled = true
191 objectName: "interactiveArea"
193 if (notification.type == Notification.Interactive) {
194 notification.notification.invokeAction(actionRepeater.itemAt(0).actionId)
196 notificationList.currentIndex = index;
209 topMargin: fullscreen ? 0 : units.gu(2)
217 spacing: contentSpacing
221 margins: contentSpacing
228 width: type == Notification.Ephemeral && !bodyLabel.visible ? units.gu(3) : units.gu(6)
230 shaped: notification.hints["x-canonical-non-shaped-icon"] == "true" ? false : true
231 visible: iconSource !== undefined && iconSource != ""
236 width: secondaryIcon.visible ? parent.width - x - units.gu(4.5) : parent.width - x
238 anchors.verticalCenter: (icon.visible && !bodyLabel.visible) ? icon.verticalCenter : undefined
243 objectName: "summaryLabel"
249 color: type == Notification.SnapDecision ? sdFontColor : Theme.palette.selected.backgroundText
250 elide: Text.ElideRight
251 textFormat: Text.PlainText
257 objectName: "bodyLabel"
264 color: type == Notification.SnapDecision ? sdFontColor : Theme.palette.selected.backgroundText
265 wrapMode: Text.WordWrap
266 maximumLineCount: type == Notification.SnapDecision ? 12 : 2
267 elide: Text.ElideRight
268 textFormat: Text.PlainText
275 objectName: "secondaryIcon"
278 visible: status === Image.Ready
279 fillMode: Image.PreserveAspectCrop
283 ListItem.ThinDivider {
284 visible: type == Notification.SnapDecision
289 objectName: "dialogListView"
297 top: fullscreen ? parent.top : undefined
298 bottom: fullscreen ? parent.bottom : undefined
302 model: unityMenuModel
304 NotificationMenuItemFactory {
308 left: dialogColumn.left
309 right: dialogColumn.right
312 menuModel: unityMenuModel
315 maxHeight: notification.maxHeight
318 notification.fullscreen = Qt.binding(function() { return fullscreen; });
321 notification.notification.invokeAction(actionRepeater.itemAt(0).actionId)
333 margins: contentSpacing
336 spacing: contentSpacing
338 visible: notification.type == Notification.SnapDecision && oneOverTwoRepeaterTop.count == 3
341 id: oneOverTwoRepeaterTop
343 model: notification.actions
345 id: oneOverTwoLoaderTop
347 property string actionId: id
348 property string actionLabel: label
351 id: oneOverTwoButtonTop
354 objectName: "notify_oot_button" + index
355 width: oneOverTwoCase.width
356 text: oneOverTwoLoaderTop.actionLabel
357 color: notification.hints["x-canonical-private-affirmative-tint"] == "true" ? green : sdDarkGrey
358 onClicked: notification.notification.invokeAction(oneOverTwoLoaderTop.actionId)
361 sourceComponent: index == 0 ? oneOverTwoButtonTop : undefined
366 spacing: contentSpacing
369 id: oneOverTwoRepeaterBottom
371 model: notification.actions
373 id: oneOverTwoLoaderBottom
375 property string actionId: id
376 property string actionLabel: label
379 id: oneOverTwoButtonBottom
382 objectName: "notify_oot_button" + index
383 width: oneOverTwoCase.width / 2 - spacing * 2
384 text: oneOverTwoLoaderBottom.actionLabel
385 color: index == 1 && notification.hints["x-canonical-private-rejection-tint"] == "true" ? red : sdDarkGrey
386 onClicked: notification.notification.invokeAction(oneOverTwoLoaderBottom.actionId)
389 sourceComponent: (index == 1 || index == 2) ? oneOverTwoButtonBottom : undefined
398 objectName: "buttonRow"
402 margins: contentSpacing
404 visible: notification.type == Notification.SnapDecision && actionRepeater.count > 0 && !oneOverTwoCase.visible
406 layoutDirection: Qt.RightToLeft
411 model: notification.actions
415 property string actionId: id
416 property string actionLabel: label
422 objectName: "notify_button" + index
423 width: buttonRow.width / 2 - spacing*2
424 text: loader.actionLabel
426 var result = sdDarkGrey;
427 if (index == 0 && notification.hints["x-canonical-private-affirmative-tint"] == "true") {
430 if (index == 1 && notification.hints["x-canonical-private-rejection-tint"] == "true") {
435 onClicked: notification.notification.invokeAction(loader.actionId)
438 sourceComponent: (index == 0 || index == 1) ? actionButton : undefined
446 objectName: "notify_button2"
451 margins: contentSpacing
454 visible: notification.type == Notification.SnapDecision && actionRepeater.count > 3 && !oneOverTwoCase.visible
456 onClicked: notification.notification.invokeAction(comboRepeater.itemAt(2).actionId)
458 expandedHeight: (comboRepeater.count - 2) * units.gu(4) + units.gu(.5)
459 comboList: Flickables.Flickable {
460 // this has to be wrapped inside a flickable
461 // to work around a feature/bug? of the
462 // ComboButton SDK-element, making a regular
463 // unwrapped Column item flickable
471 comboButton.text = comboRepeater.count >= 3 ? comboRepeater.itemAt(2).actionLabel : ""
474 model: notification.actions
479 visible: status == Loader.Ready
480 property string actionId: id
481 property string actionLabel: label
482 readonly property var splitLabel: actionLabel.match(/(^([-a-z0-9]+):)?(.*)$/)
489 objectName: "notify_button" + index
490 width: comboButton.width
491 height: comboIcon.height + units.gu(2)
494 notification.notification.invokeAction(actionId)
497 ListItem.ThinDivider {
506 leftMargin: units.gu(.5)
507 verticalCenter: parent.verticalCenter
519 left: comboIcon.right
520 leftMargin: units.gu(1)
521 verticalCenter: comboIcon.verticalCenter
529 sourceComponent: (index > 2) ? comboEntry : undefined