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/>.
18import QtGraphicalEffects 1.12
20import Lomiri.Components 1.3
21import Lomiri.Components.ListItems 1.3 as ListItem
22import Lomiri.Notifications 1.0
30 property alias iconSource: icon.fileSource
31 property alias secondaryIconSource: secondaryIcon.source
32 property alias summary: summaryLabel.text
33 property alias body: bodyLabel.text
34 property alias value: valueIndicator.value
36 property var notificationId
39 property var notification
40 property color color: theme.palette.normal.background
41 property bool fullscreen: notification.notification && typeof notification.notification.fullscreen != "undefined" ?
42 notification.notification.fullscreen : false // fullscreen prop only exists in the mock
43 property int maxHeight
44 property int margins: units.gu(1)
45 property bool privacyMode: false
46 property bool hideContent: notification.privacyMode &&
47 notification.notification.urgency !== Notification.Critical &&
48 (notification.type === Notification.Ephemeral || notification.type === Notification.Interactive)
51 readonly property real defaultOpacity: 1.0
52 property bool hasMouse
53 property url background: ""
55 objectName: "background"
56 implicitHeight: type !== Notification.PlaceHolder ? (fullscreen ? maxHeight : outterColumn.height + shapedBack.anchors.topMargin + margins * 2) : 0
58 // FIXME: non-zero initially because of LP: #1354406 workaround, we want this to start at 0 upon creation eventually
59 opacity: defaultOpacity - Math.abs(x / notification.width)
61 readonly property bool expanded: type === Notification.SnapDecision && // expand only snap decisions, if...
62 (fullscreen || // - it's a fullscreen one
63 ListView.view.currentIndex === index || // - it's the one the user clicked on
64 (ListView.view.currentIndex === -1 && index == 0) // - the first one after the user closed the previous one
70 source: hints["suppress-sound"] !== "true" && hints["sound-file"] !== undefined ? hints["sound-file"] : ""
73 Component.onCompleted: {
74 if (type === Notification.PlaceHolder) {
78 // Turn on screen as needed (Powerd.Notification means the screen
79 // stays on for a shorter amount of time)
80 if (type === Notification.SnapDecision) {
81 Powerd.setStatus(Powerd.On, Powerd.SnapDecision);
82 } else if (type !== Notification.Confirmation) {
83 Powerd.setStatus(Powerd.On, Powerd.Notification);
86 // FIXME: using onCompleted because of LP: #1354406 workaround, has to be onOpacityChanged really
87 if (opacity == defaultOpacity && hints["suppress-sound"] !== "true" && sound.source !== "") {
92 Component.onDestruction: {
93 if (type === Notification.PlaceHolder) {
97 if (type === Notification.SnapDecision) {
98 Powerd.setStatus(Powerd.Off, Powerd.SnapDecision);
99 } else if (type !== Notification.Confirmation) {
100 Powerd.setStatus(Powerd.Off, Powerd.Notification);
104 function closeNotification() {
105 if (index === ListView.view.currentIndex) { // reset to get the 1st snap decision expanded
106 ListView.view.currentIndex = -1;
109 // perform the "reject" action
110 notification.notification.invokeAction(notification.actions.data(1, ActionModel.RoleActionId));
112 notification.notification.close();
116 LomiriNumberAnimation { easing.type: Easing.OutBounce }
120 if (type === Notification.Confirmation && opacity == defaultOpacity && hints["suppress-sound"] !== "true" && sound.source !== "") {
125 onFullscreenChanged: {
127 notification.notification.urgency = Notification.Critical;
130 ListView.view.topmostIsFullscreen = fullscreen;
134 Behavior on implicitHeight {
136 LomiriNumberAnimation {
137 duration: LomiriAnimation.SnapDuration
141 visible: type !== Notification.PlaceHolder
146 margins: shapedBack.visible ? -units.gu(1) : -units.gu(1.5)
148 source: "../graphics/dropshadow2gu.sci"
149 opacity: notification.opacity * 0.5
155 objectName: "shapedBack"
160 leftMargin: notification.margins
161 rightMargin: notification.margins
162 topMargin: index == 0 ? notification.margins : 0
164 backgroundColor: parent.color
166 aspect: LomiriShape.Flat
178 if (Math.abs(notification.x) > 0.75 * notification.width) {
185 anchors.fill: fullscreen ? nonShapedBack : shapedBack
187 LomiriMenuModelPaths {
190 source: hints["x-lomiri-private-menu-model"]
192 busNameHint: "busName"
193 actionsHint: "actions"
194 menuObjectPathHint: "menuPath"
200 property string lastNameOwner: ""
202 busName: paths.busName
203 actions: paths.actions
204 menuObjectPath: paths.menuObjectPath
205 onNameOwnerChanged: {
206 if (lastNameOwner !== "" && nameOwner === "" && notification.notification !== undefined) {
207 notification.notification.close()
209 lastNameOwner = nameOwner
217 objectName: "interactiveArea"
219 drag.target: !fullscreen ? notification : undefined
220 drag.axis: Drag.XAxis
221 drag.minimumX: -notification.width
222 drag.maximumX: notification.width
226 if (notification.type === Notification.Interactive) {
227 notification.notification.invokeAction(actionRepeater.itemAt(0).actionId)
229 notification.ListView.view.currentIndex = index;
233 if (Math.abs(notification.x) < notification.width / 2) {
236 notification.x = notification.width
242 objectName: "closeButton"
246 visible: hasMouse && (containsMouse || interactiveArea.containsMouse)
250 color: theme.palette.normal.negative
251 anchors.horizontalCenter: parent.left
252 anchors.horizontalCenterOffset: notification.parent.state === "narrow" ? notification.margins / 2 : 0
253 anchors.verticalCenter: parent.top
254 anchors.verticalCenterOffset: notification.parent.state === "narrow" ? notification.margins / 2 : 0
256 onClicked: closeNotification();
261 objectName: "outterColumn"
267 margins: !fullscreen ? notification.margins : 0
270 spacing: notification.margins
275 spacing: notification.margins
285 visible: iconSource !== "" && type !== Notification.Confirmation
291 shaped: notification.hints["x-lomiri-non-shaped-icon"] !== "true"
292 visible: iconSource !== "" && !blurEffect.visible
297 objectName: "blurEffect"
298 visible: notification.hideContent
301 transparentBorder: true
307 objectName: "privacySummaryLabel"
308 width: secondaryIcon.visible ? parent.width - x - units.gu(3) : parent.width - x
310 anchors.verticalCenter: iconWrapper.verticalCenter
311 verticalAlignment: Text.AlignVCenter
312 visible: notification.hideContent
314 font.weight: Font.Light
315 color: theme.palette.normal.backgroundSecondaryText
316 elide: Text.ElideRight
317 textFormat: Text.PlainText
318 text: i18n.tr("New message")
323 width: secondaryIcon.visible ? parent.width - x - units.gu(3) : parent.width - x
324 anchors.verticalCenter: (icon.visible && !bodyLabel.visible) ? iconWrapper.verticalCenter : undefined
325 spacing: units.gu(.4)
326 visible: type !== Notification.Confirmation && !notification.hideContent
331 objectName: "summaryLabel"
337 font.weight: Font.Light
338 color: theme.palette.normal.backgroundSecondaryText
339 elide: Text.ElideRight
340 textFormat: Text.PlainText
346 objectName: "bodyLabel"
353 font.weight: Font.Light
354 color: theme.palette.normal.backgroundTertiaryText
357 if (type === Notification.SnapDecision) {
359 } else if (notification.hints["x-lomiri-truncation"] === false) {
365 elide: Text.ElideRight
366 textFormat: Text.PlainText
374 objectName: "secondaryIcon"
377 visible: status === Image.Ready
378 fillMode: Image.PreserveAspectCrop
382 ListItem.ThinDivider {
383 visible: type === Notification.SnapDecision && notification.expanded
387 name: "toolkit_chevron-down_3gu"
388 visible: type === Notification.SnapDecision && !notification.expanded
391 anchors.horizontalCenter: parent.horizontalCenter
392 color: theme.palette.normal.base
397 objectName: "centeredIcon"
400 shaped: notification.hints["x-lomiri-non-shaped-icon"] !== "true"
401 fileSource: icon.fileSource
402 visible: fileSource !== "" && type === Notification.Confirmation
403 anchors.horizontalCenter: parent.horizontalCenter
408 objectName: "valueLabel"
410 anchors.horizontalCenter: parent.horizontalCenter
411 visible: type === Notification.Confirmation && body !== ""
413 font.weight: Font.Light
414 color: theme.palette.normal.backgroundSecondaryText
415 wrapMode: Text.WordWrap
417 elide: Text.ElideRight
418 textFormat: Text.PlainText
423 objectName: "valueIndicator"
424 visible: type === Notification.Confirmation
427 showProgressPercentage: false
437 objectName: "dialogListView"
438 spacing: notification.margins
440 visible: count > 0 && (notification.expanded || notification.fullscreen)
445 top: fullscreen ? parent.top : undefined
446 bottom: fullscreen ? parent.bottom : undefined
450 model: lomiriMenuModel
452 NotificationMenuItemFactory {
456 left: dialogColumn.left
457 right: dialogColumn.right
460 menuModel: lomiriMenuModel
463 maxHeight: notification.maxHeight
464 background: notification.background
467 notification.fullscreen = Qt.binding(function() { return fullscreen; });
470 notification.notification.invokeAction(actionRepeater.itemAt(0).actionId)
484 spacing: notification.margins
486 visible: notification.type === Notification.SnapDecision && oneOverTwoRepeaterTop.count === 3 && notification.expanded
489 id: oneOverTwoRepeaterTop
491 model: notification.actions
493 id: oneOverTwoLoaderTop
495 property string actionId: id
496 property string actionLabel: label
499 id: oneOverTwoButtonTop
502 objectName: "notify_oot_button" + index
503 width: oneOverTwoCase.width
504 text: oneOverTwoLoaderTop.actionLabel
505 outline: notification.hints["x-lomiri-private-affirmative-tint"] !== "true"
506 color: notification.hints["x-lomiri-private-affirmative-tint"] === "true" ? theme.palette.normal.positive
507 : theme.name == "Lomiri.Components.Themes.SuruDark" ? "#888"
509 onClicked: notification.notification.invokeAction(oneOverTwoLoaderTop.actionId)
512 sourceComponent: index == 0 ? oneOverTwoButtonTop : undefined
517 spacing: notification.margins
520 id: oneOverTwoRepeaterBottom
522 model: notification.actions
524 id: oneOverTwoLoaderBottom
526 property string actionId: id
527 property string actionLabel: label
530 id: oneOverTwoButtonBottom
533 objectName: "notify_oot_button" + index
534 width: oneOverTwoCase.width / 2 - spacing / 2
535 text: oneOverTwoLoaderBottom.actionLabel
536 outline: notification.hints["x-lomiri-private-rejection-tint"] !== "true"
537 color: index == 1 && notification.hints["x-lomiri-private-rejection-tint"] === "true" ? theme.palette.normal.negative
538 : theme.name == "Lomiri.Components.Themes.SuruDark" ? "#888"
540 onClicked: notification.notification.invokeAction(oneOverTwoLoaderBottom.actionId)
543 sourceComponent: (index == 1 || index == 2) ? oneOverTwoButtonBottom : undefined
552 objectName: "buttonRow"
557 visible: notification.type === Notification.SnapDecision && actionRepeater.count > 0 && !oneOverTwoCase.visible && notification.expanded
558 spacing: notification.margins
559 layoutDirection: Qt.RightToLeft
562 id: notifySwipeButtonLoader
563 active: notification.hints["x-lomiri-snap-decisions-swipe"] === "true"
565 sourceComponent: SwipeToAct {
566 objectName: "notify_swipe_button"
567 width: buttonRow.width
568 leftIconName: "call-end"
569 rightIconName: "call-start"
570 clickToAct: notification.hasMouse
572 notification.notification.invokeAction(notification.actions.data(0, ActionModel.RoleActionId))
576 notification.notification.invokeAction(notification.actions.data(1, ActionModel.RoleActionId))
583 model: notification.actions
587 property string actionId: id
588 property string actionLabel: label
589 active: !notifySwipeButtonLoader.active
595 objectName: "notify_button" + index
596 width: buttonRow.width / 2 - spacing / 2
597 text: loader.actionLabel
598 outline: (index == 0 && notification.hints["x-lomiri-private-affirmative-tint"] !== "true") ||
599 (index == 1 && notification.hints["x-lomiri-private-rejection-tint"] !== "true")
602 if (theme.name == "Lomiri.Components.Themes.SuruDark") {
605 if (index == 0 && notification.hints["x-lomiri-private-affirmative-tint"] === "true") {
606 result = theme.palette.normal.positive;
608 if (index == 1 && notification.hints["x-lomiri-private-rejection-tint"] === "true") {
609 result = theme.palette.normal.negative;
613 onClicked: notification.notification.invokeAction(loader.actionId)
616 sourceComponent: (index == 0 || index == 1) ? actionButton : undefined
623 objectName: "notify_button2"
630 visible: notification.type === Notification.SnapDecision && actionRepeater.count > 3 && !oneOverTwoCase.visible && notification.expanded
631 model: notification.actions
635 notification.notification.invokeAction(id)