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
34 property var notificationId
37 property var notification
39 property bool fullscreen: false
40 property int maxHeight
42 readonly property color red: "#fc4949"
43 readonly property color green: "#3fb24f"
44 readonly property color sdLightGrey: "#eaeaea"
45 readonly property color sdDarkGrey: "#dddddd"
46 readonly property color sdFontColor: "#5d5d5d"
47 readonly property real contentSpacing: units.gu(2)
49 objectName: "background"
50 implicitHeight: type !== Notification.PlaceHolder ? (fullscreen ? maxHeight : outterColumn.height + contentSpacing * 2) : 0
52 color: type == Notification.SnapDecision ? sdLightGrey : Qt.rgba(0.132, 0.117, 0.109, 0.97)
53 opacity: 1 // FIXME: 1 because of LP: #1354406 workaround, has to be 0 really
58 if (type == Notification.SnapDecision) {
59 if (ListView.view.currentIndex == index) {
62 if (ListView.view.count > 2) {
63 if (ListView.view.currentIndex == -1 && index == 1) {
66 result = "contracted";
80 source: hints["suppress-sound"] != "true" && hints["sound-file"] != undefined ? hints["sound-file"] : ""
83 // FIXME: using onCompleted because of LP: #1354406 workaround, has to be onOpacityChanged really
84 Component.onCompleted: {
85 if (opacity == 1.0 && hints["suppress-sound"] != "true" && sound.source != "") {
91 id: normalHeightBehavior
93 //enabled: menuItemFactory.progress == 1
97 duration: UbuntuAnimation.SnapDuration
99 UbuntuNumberAnimation {
100 duration: UbuntuAnimation.SnapDuration
108 PropertyChanges {target: notification; height: units.gu(10)}
112 PropertyChanges {target: notification; height: implicitHeight}
116 clip: fullscreen ? false : true
118 visible: type != Notification.PlaceHolder
126 leftMargin: notification.margins
127 rightMargin: notification.margins
130 opacity: parent.opacity
141 opacity: parent.opacity
146 anchors.fill: fullscreen ? nonShapedBack : shapedBack
148 UnityMenuModelPaths {
151 source: hints["x-canonical-private-menu-model"]
153 busNameHint: "busName"
154 actionsHint: "actions"
155 menuObjectPathHint: "menuPath"
161 property string lastNameOwner: ""
163 busName: paths.busName
164 actions: paths.actions
165 menuObjectPath: paths.menuObjectPath
166 onNameOwnerChanged: {
167 if (lastNameOwner != "" && nameOwner == "" && notification.notification != undefined) {
168 notification.notification.close()
170 lastNameOwner = nameOwner
174 Behavior on implicitHeight {
178 UbuntuNumberAnimation {
179 duration: UbuntuAnimation.SnapDuration
183 // delay enabling height behavior until the add transition is complete
184 onOpacityChanged: if (opacity == 1) heightBehavior.enabled = true
190 objectName: "interactiveArea"
192 if (notification.type == Notification.Interactive) {
193 notification.notification.invokeAction(actionRepeater.itemAt(0).actionId)
195 notificationList.currentIndex = index;
208 topMargin: fullscreen ? 0 : units.gu(2)
216 spacing: contentSpacing
220 margins: contentSpacing
227 width: type == Notification.Ephemeral && !bodyLabel.visible ? units.gu(3) : units.gu(6)
229 shaped: notification.hints["x-canonical-non-shaped-icon"] == "true" ? false : true
230 visible: iconSource !== undefined && iconSource != ""
235 width: secondaryIcon.visible ? parent.width - x - units.gu(4.5) : parent.width - x
237 anchors.verticalCenter: (icon.visible && !bodyLabel.visible) ? icon.verticalCenter : undefined
242 objectName: "summaryLabel"
248 color: type == Notification.SnapDecision ? sdFontColor : Theme.palette.selected.backgroundText
249 elide: Text.ElideRight
250 textFormat: Text.PlainText
256 objectName: "bodyLabel"
263 color: type == Notification.SnapDecision ? sdFontColor : Theme.palette.selected.backgroundText
264 wrapMode: Text.WordWrap
265 maximumLineCount: type == Notification.SnapDecision ? 12 : 2
266 elide: Text.ElideRight
267 textFormat: Text.PlainText
274 objectName: "secondaryIcon"
277 visible: status === Image.Ready
278 fillMode: Image.PreserveAspectCrop
282 ListItem.ThinDivider {
283 visible: type == Notification.SnapDecision
288 objectName: "dialogListView"
296 top: fullscreen ? parent.top : undefined
297 bottom: fullscreen ? parent.bottom : undefined
301 model: unityMenuModel
303 NotificationMenuItemFactory {
307 left: dialogColumn.left
308 right: dialogColumn.right
311 menuModel: unityMenuModel
314 maxHeight: notification.maxHeight
317 notification.fullscreen = Qt.binding(function() { return fullscreen; });
320 notification.notification.invokeAction(actionRepeater.itemAt(0).actionId)
332 margins: contentSpacing
335 spacing: contentSpacing
337 visible: notification.type == Notification.SnapDecision && oneOverTwoRepeaterTop.count == 3
340 id: oneOverTwoRepeaterTop
342 model: notification.actions
344 id: oneOverTwoLoaderTop
346 property string actionId: id
347 property string actionLabel: label
350 id: oneOverTwoButtonTop
353 objectName: "notify_oot_button" + index
354 width: oneOverTwoCase.width
355 text: oneOverTwoLoaderTop.actionLabel
356 color: notification.hints["x-canonical-private-affirmative-tint"] == "true" ? green : sdDarkGrey
357 onClicked: notification.notification.invokeAction(oneOverTwoLoaderTop.actionId)
360 sourceComponent: index == 0 ? oneOverTwoButtonTop : undefined
365 spacing: contentSpacing
368 id: oneOverTwoRepeaterBottom
370 model: notification.actions
372 id: oneOverTwoLoaderBottom
374 property string actionId: id
375 property string actionLabel: label
378 id: oneOverTwoButtonBottom
381 objectName: "notify_oot_button" + index
382 width: oneOverTwoCase.width / 2 - spacing * 2
383 text: oneOverTwoLoaderBottom.actionLabel
384 color: index == 1 && notification.hints["x-canonical-private-rejection-tint"] == "true" ? red : sdDarkGrey
385 onClicked: notification.notification.invokeAction(oneOverTwoLoaderBottom.actionId)
388 sourceComponent: (index == 1 || index == 2) ? oneOverTwoButtonBottom : undefined
397 objectName: "buttonRow"
401 margins: contentSpacing
403 visible: notification.type == Notification.SnapDecision && actionRepeater.count > 0 && !oneOverTwoCase.visible
405 layoutDirection: Qt.RightToLeft
410 model: notification.actions
414 property string actionId: id
415 property string actionLabel: label
421 objectName: "notify_button" + index
422 width: buttonRow.width / 2 - spacing*2
423 text: loader.actionLabel
425 var result = sdDarkGrey;
426 if (index == 0 && notification.hints["x-canonical-private-affirmative-tint"] == "true") {
429 if (index == 1 && notification.hints["x-canonical-private-rejection-tint"] == "true") {
434 onClicked: notification.notification.invokeAction(loader.actionId)
437 sourceComponent: (index == 0 || index == 1) ? actionButton : undefined
445 objectName: "notify_button2"
450 margins: contentSpacing
453 visible: notification.type == Notification.SnapDecision && actionRepeater.count > 3 && !oneOverTwoCase.visible
455 onClicked: notification.notification.invokeAction(comboRepeater.itemAt(2).actionId)
457 expandedHeight: (comboRepeater.count - 2) * units.gu(4) + units.gu(.5)
458 comboList: Flickable {
459 // this has to be wrapped inside a flickable
460 // to work around a feature/bug? of the
461 // ComboButton SDK-element, making a regular
462 // unwrapped Column item flickable
470 comboButton.text = comboRepeater.count >= 3 ? comboRepeater.itemAt(2).actionLabel : ""
473 model: notification.actions
478 visible: status == Loader.Ready
479 property string actionId: id
480 property string actionLabel: label
481 readonly property var splitLabel: actionLabel.match(/(^([-a-z0-9]+):)?(.*)$/)
488 objectName: "notify_button" + index
489 width: comboButton.width
490 height: comboIcon.height + units.gu(2)
493 notification.notification.invokeAction(actionId)
496 ListItem.ThinDivider {
505 leftMargin: units.gu(.5)
506 verticalCenter: parent.verticalCenter
518 left: comboIcon.right
519 leftMargin: units.gu(1)
520 verticalCenter: comboIcon.verticalCenter
528 sourceComponent: (index > 2) ? comboEntry : undefined