2 * Copyright (C) 2013-2016 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 Lomiri.Components 1.3
20 import Lomiri.Components.ListItems 1.3 as ListItem
21 import Lomiri.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
39 property color color: theme.palette.normal.background
40 property bool fullscreen: notification.notification && typeof notification.notification.fullscreen != "undefined" ?
41 notification.notification.fullscreen : false // fullscreen prop only exists in the mock
42 property int maxHeight
43 property int margins: units.gu(1)
45 readonly property real defaultOpacity: 1.0
46 property bool hasMouse
47 property url background: ""
49 objectName: "background"
50 implicitHeight: type !== Notification.PlaceHolder ? (fullscreen ? maxHeight : outterColumn.height + shapedBack.anchors.topMargin + margins * 2) : 0
52 // FIXME: non-zero initially because of LP: #1354406 workaround, we want this to start at 0 upon creation eventually
53 opacity: defaultOpacity - Math.abs(x / notification.width)
55 theme: ThemeSettings {
56 name: "Lomiri.Components.Themes.Ambiance"
59 readonly property bool expanded: type === Notification.SnapDecision && // expand only snap decisions, if...
60 (fullscreen || // - it's a fullscreen one
61 ListView.view.currentIndex === index || // - it's the one the user clicked on
62 (ListView.view.currentIndex === -1 && index == 0) // - the first one after the user closed the previous one
68 source: hints["suppress-sound"] !== "true" && hints["sound-file"] !== undefined ? hints["sound-file"] : ""
71 Component.onCompleted: {
72 if (type === Notification.PlaceHolder) {
76 // Turn on screen as needed (Powerd.Notification means the screen
77 // stays on for a shorter amount of time)
78 if (type === Notification.SnapDecision) {
79 Powerd.setStatus(Powerd.On, Powerd.SnapDecision);
80 } else if (type !== Notification.Confirmation) {
81 Powerd.setStatus(Powerd.On, Powerd.Notification);
84 // FIXME: using onCompleted because of LP: #1354406 workaround, has to be onOpacityChanged really
85 if (opacity == defaultOpacity && hints["suppress-sound"] !== "true" && sound.source !== "") {
90 Component.onDestruction: {
91 if (type === Notification.PlaceHolder) {
95 if (type === Notification.SnapDecision) {
96 Powerd.setStatus(Powerd.Off, Powerd.SnapDecision);
97 } else if (type !== Notification.Confirmation) {
98 Powerd.setStatus(Powerd.Off, Powerd.Notification);
102 function closeNotification() {
103 if (index === ListView.view.currentIndex) { // reset to get the 1st snap decision expanded
104 ListView.view.currentIndex = -1;
107 // perform the "reject" action
108 notification.notification.invokeAction(notification.actions.data(1, ActionModel.RoleActionId));
110 notification.notification.close();
114 LomiriNumberAnimation { easing.type: Easing.OutBounce }
118 if (type === Notification.Confirmation && opacity == defaultOpacity && hints["suppress-sound"] !== "true" && sound.source !== "") {
123 onFullscreenChanged: {
125 notification.notification.urgency = Notification.Critical;
128 ListView.view.topmostIsFullscreen = fullscreen;
132 Behavior on implicitHeight {
134 LomiriNumberAnimation {
135 duration: LomiriAnimation.SnapDuration
139 visible: type !== Notification.PlaceHolder
144 margins: shapedBack.visible ? -units.gu(1) : -units.gu(1.5)
146 source: "../graphics/dropshadow2gu.sci"
147 opacity: notification.opacity * 0.5
153 objectName: "shapedBack"
158 leftMargin: notification.margins
159 rightMargin: notification.margins
160 topMargin: index == 0 ? notification.margins : 0
162 backgroundColor: parent.color
164 aspect: LomiriShape.Flat
176 if (Math.abs(notification.x) > 0.75 * notification.width) {
183 anchors.fill: fullscreen ? nonShapedBack : shapedBack
185 LomiriMenuModelPaths {
188 source: hints["x-lomiri-private-menu-model"]
190 busNameHint: "busName"
191 actionsHint: "actions"
192 menuObjectPathHint: "menuPath"
198 property string lastNameOwner: ""
200 busName: paths.busName
201 actions: paths.actions
202 menuObjectPath: paths.menuObjectPath
203 onNameOwnerChanged: {
204 if (lastNameOwner !== "" && nameOwner === "" && notification.notification !== undefined) {
205 notification.notification.close()
207 lastNameOwner = nameOwner
215 objectName: "interactiveArea"
217 drag.target: !fullscreen ? notification : undefined
218 drag.axis: Drag.XAxis
219 drag.minimumX: -notification.width
220 drag.maximumX: notification.width
224 if (notification.type === Notification.Interactive) {
225 notification.notification.invokeAction(actionRepeater.itemAt(0).actionId)
227 notification.ListView.view.currentIndex = index;
231 if (Math.abs(notification.x) < notification.width / 2) {
234 notification.x = notification.width
240 objectName: "closeButton"
244 visible: hasMouse && (containsMouse || interactiveArea.containsMouse)
248 color: theme.palette.normal.negative
249 anchors.horizontalCenter: parent.left
250 anchors.horizontalCenterOffset: notification.parent.state === "narrow" ? notification.margins / 2 : 0
251 anchors.verticalCenter: parent.top
252 anchors.verticalCenterOffset: notification.parent.state === "narrow" ? notification.margins / 2 : 0
254 onClicked: closeNotification();
259 objectName: "outterColumn"
265 margins: !fullscreen ? notification.margins : 0
268 spacing: notification.margins
273 spacing: notification.margins
285 shaped: notification.hints["x-lomiri-non-shaped-icon"] !== "true"
286 visible: iconSource !== "" && type !== Notification.Confirmation
291 width: secondaryIcon.visible ? parent.width - x - units.gu(3) : parent.width - x
292 anchors.verticalCenter: (icon.visible && !bodyLabel.visible) ? icon.verticalCenter : undefined
293 spacing: units.gu(.4)
298 objectName: "summaryLabel"
303 visible: type !== Notification.Confirmation
305 font.weight: Font.Light
306 color: theme.palette.normal.backgroundSecondaryText
307 elide: Text.ElideRight
308 textFormat: Text.PlainText
314 objectName: "bodyLabel"
319 visible: body != "" && type !== Notification.Confirmation
321 font.weight: Font.Light
322 color: theme.palette.normal.backgroundTertiaryText
325 if (type === Notification.SnapDecision) {
327 } else if (notification.hints["x-lomiri-truncation"] === false) {
333 elide: Text.ElideRight
334 textFormat: Text.PlainText
342 objectName: "secondaryIcon"
345 visible: status === Image.Ready
346 fillMode: Image.PreserveAspectCrop
350 ListItem.ThinDivider {
351 visible: type === Notification.SnapDecision && notification.expanded
355 name: "toolkit_chevron-down_3gu"
356 visible: type === Notification.SnapDecision && !notification.expanded
359 anchors.horizontalCenter: parent.horizontalCenter
360 color: theme.palette.normal.base
365 objectName: "centeredIcon"
368 shaped: notification.hints["x-lomiri-non-shaped-icon"] !== "true"
369 fileSource: icon.fileSource
370 visible: fileSource !== "" && type === Notification.Confirmation
371 anchors.horizontalCenter: parent.horizontalCenter
376 objectName: "valueLabel"
378 anchors.horizontalCenter: parent.horizontalCenter
379 visible: type === Notification.Confirmation && body !== ""
381 font.weight: Font.Light
382 color: theme.palette.normal.backgroundSecondaryText
383 wrapMode: Text.WordWrap
385 elide: Text.ElideRight
386 textFormat: Text.PlainText
391 objectName: "valueIndicator"
392 visible: type === Notification.Confirmation
395 showProgressPercentage: false
405 objectName: "dialogListView"
406 spacing: notification.margins
408 visible: count > 0 && (notification.expanded || notification.fullscreen)
413 top: fullscreen ? parent.top : undefined
414 bottom: fullscreen ? parent.bottom : undefined
418 model: lomiriMenuModel
420 NotificationMenuItemFactory {
424 left: dialogColumn.left
425 right: dialogColumn.right
428 menuModel: lomiriMenuModel
431 maxHeight: notification.maxHeight
432 background: notification.background
435 notification.fullscreen = Qt.binding(function() { return fullscreen; });
438 notification.notification.invokeAction(actionRepeater.itemAt(0).actionId)
452 spacing: notification.margins
454 visible: notification.type === Notification.SnapDecision && oneOverTwoRepeaterTop.count === 3 && notification.expanded
457 id: oneOverTwoRepeaterTop
459 model: notification.actions
461 id: oneOverTwoLoaderTop
463 property string actionId: id
464 property string actionLabel: label
467 id: oneOverTwoButtonTop
470 objectName: "notify_oot_button" + index
471 width: oneOverTwoCase.width
472 text: oneOverTwoLoaderTop.actionLabel
473 outline: notification.hints["x-lomiri-private-affirmative-tint"] !== "true"
474 color: notification.hints["x-lomiri-private-affirmative-tint"] === "true" ? theme.palette.normal.positive
475 : theme.name == "Lomiri.Components.Themes.SuruDark" ? "#888"
477 onClicked: notification.notification.invokeAction(oneOverTwoLoaderTop.actionId)
480 sourceComponent: index == 0 ? oneOverTwoButtonTop : undefined
485 spacing: notification.margins
488 id: oneOverTwoRepeaterBottom
490 model: notification.actions
492 id: oneOverTwoLoaderBottom
494 property string actionId: id
495 property string actionLabel: label
498 id: oneOverTwoButtonBottom
501 objectName: "notify_oot_button" + index
502 width: oneOverTwoCase.width / 2 - spacing / 2
503 text: oneOverTwoLoaderBottom.actionLabel
504 outline: notification.hints["x-lomiri-private-rejection-tint"] !== "true"
505 color: index == 1 && notification.hints["x-lomiri-private-rejection-tint"] === "true" ? theme.palette.normal.negative
506 : theme.name == "Lomiri.Components.Themes.SuruDark" ? "#888"
508 onClicked: notification.notification.invokeAction(oneOverTwoLoaderBottom.actionId)
511 sourceComponent: (index == 1 || index == 2) ? oneOverTwoButtonBottom : undefined
520 objectName: "buttonRow"
525 visible: notification.type === Notification.SnapDecision && actionRepeater.count > 0 && !oneOverTwoCase.visible && notification.expanded
526 spacing: notification.margins
527 layoutDirection: Qt.RightToLeft
530 id: notifySwipeButtonLoader
531 active: notification.hints["x-lomiri-snap-decisions-swipe"] === "true"
533 sourceComponent: SwipeToAct {
534 objectName: "notify_swipe_button"
535 width: buttonRow.width
536 leftIconName: "call-end"
537 rightIconName: "call-start"
538 clickToAct: notification.hasMouse
540 notification.notification.invokeAction(notification.actions.data(0, ActionModel.RoleActionId))
544 notification.notification.invokeAction(notification.actions.data(1, ActionModel.RoleActionId))
551 model: notification.actions
555 property string actionId: id
556 property string actionLabel: label
557 active: !notifySwipeButtonLoader.active
563 objectName: "notify_button" + index
564 width: buttonRow.width / 2 - spacing / 2
565 text: loader.actionLabel
566 outline: (index == 0 && notification.hints["x-lomiri-private-affirmative-tint"] !== "true") ||
567 (index == 1 && notification.hints["x-lomiri-private-rejection-tint"] !== "true")
570 if (theme.name == "Lomiri.Components.Themes.SuruDark") {
573 if (index == 0 && notification.hints["x-lomiri-private-affirmative-tint"] === "true") {
574 result = theme.palette.normal.positive;
576 if (index == 1 && notification.hints["x-lomiri-private-rejection-tint"] === "true") {
577 result = theme.palette.normal.negative;
581 onClicked: notification.notification.invokeAction(loader.actionId)
584 sourceComponent: (index == 0 || index == 1) ? actionButton : undefined
591 objectName: "notify_button2"
598 visible: notification.type === Notification.SnapDecision && actionRepeater.count > 3 && !oneOverTwoCase.visible && notification.expanded
599 model: notification.actions
603 notification.notification.invokeAction(id)