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 theme: ThemeSettings {
62 name: "Lomiri.Components.Themes.Ambiance"
65 readonly property bool expanded: type === Notification.SnapDecision && // expand only snap decisions, if...
66 (fullscreen || // - it's a fullscreen one
67 ListView.view.currentIndex === index || // - it's the one the user clicked on
68 (ListView.view.currentIndex === -1 && index == 0) // - the first one after the user closed the previous one
74 source: hints["suppress-sound"] !== "true" && hints["sound-file"] !== undefined ? hints["sound-file"] : ""
77 Component.onCompleted: {
78 if (type === Notification.PlaceHolder) {
82 // Turn on screen as needed (Powerd.Notification means the screen
83 // stays on for a shorter amount of time)
84 if (type === Notification.SnapDecision) {
85 Powerd.setStatus(Powerd.On, Powerd.SnapDecision);
86 } else if (type !== Notification.Confirmation) {
87 Powerd.setStatus(Powerd.On, Powerd.Notification);
90 // FIXME: using onCompleted because of LP: #1354406 workaround, has to be onOpacityChanged really
91 if (opacity == defaultOpacity && hints["suppress-sound"] !== "true" && sound.source !== "") {
96 Component.onDestruction: {
97 if (type === Notification.PlaceHolder) {
101 if (type === Notification.SnapDecision) {
102 Powerd.setStatus(Powerd.Off, Powerd.SnapDecision);
103 } else if (type !== Notification.Confirmation) {
104 Powerd.setStatus(Powerd.Off, Powerd.Notification);
108 function closeNotification() {
109 if (index === ListView.view.currentIndex) { // reset to get the 1st snap decision expanded
110 ListView.view.currentIndex = -1;
113 // perform the "reject" action
114 notification.notification.invokeAction(notification.actions.data(1, ActionModel.RoleActionId));
116 notification.notification.close();
120 LomiriNumberAnimation { easing.type: Easing.OutBounce }
124 if (type === Notification.Confirmation && opacity == defaultOpacity && hints["suppress-sound"] !== "true" && sound.source !== "") {
129 onFullscreenChanged: {
131 notification.notification.urgency = Notification.Critical;
134 ListView.view.topmostIsFullscreen = fullscreen;
138 Behavior on implicitHeight {
140 LomiriNumberAnimation {
141 duration: LomiriAnimation.SnapDuration
145 visible: type !== Notification.PlaceHolder
150 margins: shapedBack.visible ? -units.gu(1) : -units.gu(1.5)
152 source: "../graphics/dropshadow2gu.sci"
153 opacity: notification.opacity * 0.5
159 objectName: "shapedBack"
164 leftMargin: notification.margins
165 rightMargin: notification.margins
166 topMargin: index == 0 ? notification.margins : 0
168 backgroundColor: parent.color
170 aspect: LomiriShape.Flat
182 if (Math.abs(notification.x) > 0.75 * notification.width) {
189 anchors.fill: fullscreen ? nonShapedBack : shapedBack
191 LomiriMenuModelPaths {
194 source: hints["x-lomiri-private-menu-model"]
196 busNameHint: "busName"
197 actionsHint: "actions"
198 menuObjectPathHint: "menuPath"
204 property string lastNameOwner: ""
206 busName: paths.busName
207 actions: paths.actions
208 menuObjectPath: paths.menuObjectPath
209 onNameOwnerChanged: {
210 if (lastNameOwner !== "" && nameOwner === "" && notification.notification !== undefined) {
211 notification.notification.close()
213 lastNameOwner = nameOwner
221 objectName: "interactiveArea"
223 drag.target: !fullscreen ? notification : undefined
224 drag.axis: Drag.XAxis
225 drag.minimumX: -notification.width
226 drag.maximumX: notification.width
230 if (notification.type === Notification.Interactive) {
231 notification.notification.invokeAction(actionRepeater.itemAt(0).actionId)
233 notification.ListView.view.currentIndex = index;
237 if (Math.abs(notification.x) < notification.width / 2) {
240 notification.x = notification.width
246 objectName: "closeButton"
250 visible: hasMouse && (containsMouse || interactiveArea.containsMouse)
254 color: theme.palette.normal.negative
255 anchors.horizontalCenter: parent.left
256 anchors.horizontalCenterOffset: notification.parent.state === "narrow" ? notification.margins / 2 : 0
257 anchors.verticalCenter: parent.top
258 anchors.verticalCenterOffset: notification.parent.state === "narrow" ? notification.margins / 2 : 0
260 onClicked: closeNotification();
265 objectName: "outterColumn"
271 margins: !fullscreen ? notification.margins : 0
274 spacing: notification.margins
279 spacing: notification.margins
289 visible: iconSource !== "" && type !== Notification.Confirmation
295 shaped: notification.hints["x-lomiri-non-shaped-icon"] !== "true"
296 visible: iconSource !== "" && !blurEffect.visible
301 objectName: "blurEffect"
302 visible: notification.hideContent
305 transparentBorder: true
311 objectName: "privacySummaryLabel"
312 width: secondaryIcon.visible ? parent.width - x - units.gu(3) : parent.width - x
314 anchors.verticalCenter: iconWrapper.verticalCenter
315 verticalAlignment: Text.AlignVCenter
316 visible: notification.hideContent
318 font.weight: Font.Light
319 color: theme.palette.normal.backgroundSecondaryText
320 elide: Text.ElideRight
321 textFormat: Text.PlainText
322 text: i18n.tr("New message")
327 width: secondaryIcon.visible ? parent.width - x - units.gu(3) : parent.width - x
328 anchors.verticalCenter: (icon.visible && !bodyLabel.visible) ? iconWrapper.verticalCenter : undefined
329 spacing: units.gu(.4)
330 visible: type !== Notification.Confirmation && !notification.hideContent
335 objectName: "summaryLabel"
341 font.weight: Font.Light
342 color: theme.palette.normal.backgroundSecondaryText
343 elide: Text.ElideRight
344 textFormat: Text.PlainText
350 objectName: "bodyLabel"
357 font.weight: Font.Light
358 color: theme.palette.normal.backgroundTertiaryText
361 if (type === Notification.SnapDecision) {
363 } else if (notification.hints["x-lomiri-truncation"] === false) {
369 elide: Text.ElideRight
370 textFormat: Text.PlainText
378 objectName: "secondaryIcon"
381 visible: status === Image.Ready
382 fillMode: Image.PreserveAspectCrop
386 ListItem.ThinDivider {
387 visible: type === Notification.SnapDecision && notification.expanded
391 name: "toolkit_chevron-down_3gu"
392 visible: type === Notification.SnapDecision && !notification.expanded
395 anchors.horizontalCenter: parent.horizontalCenter
396 color: theme.palette.normal.base
401 objectName: "centeredIcon"
404 shaped: notification.hints["x-lomiri-non-shaped-icon"] !== "true"
405 fileSource: icon.fileSource
406 visible: fileSource !== "" && type === Notification.Confirmation
407 anchors.horizontalCenter: parent.horizontalCenter
412 objectName: "valueLabel"
414 anchors.horizontalCenter: parent.horizontalCenter
415 visible: type === Notification.Confirmation && body !== ""
417 font.weight: Font.Light
418 color: theme.palette.normal.backgroundSecondaryText
419 wrapMode: Text.WordWrap
421 elide: Text.ElideRight
422 textFormat: Text.PlainText
427 objectName: "valueIndicator"
428 visible: type === Notification.Confirmation
431 showProgressPercentage: false
441 objectName: "dialogListView"
442 spacing: notification.margins
444 visible: count > 0 && (notification.expanded || notification.fullscreen)
449 top: fullscreen ? parent.top : undefined
450 bottom: fullscreen ? parent.bottom : undefined
454 model: lomiriMenuModel
456 NotificationMenuItemFactory {
460 left: dialogColumn.left
461 right: dialogColumn.right
464 menuModel: lomiriMenuModel
467 maxHeight: notification.maxHeight
468 background: notification.background
471 notification.fullscreen = Qt.binding(function() { return fullscreen; });
474 notification.notification.invokeAction(actionRepeater.itemAt(0).actionId)
488 spacing: notification.margins
490 visible: notification.type === Notification.SnapDecision && oneOverTwoRepeaterTop.count === 3 && notification.expanded
493 id: oneOverTwoRepeaterTop
495 model: notification.actions
497 id: oneOverTwoLoaderTop
499 property string actionId: id
500 property string actionLabel: label
503 id: oneOverTwoButtonTop
506 objectName: "notify_oot_button" + index
507 width: oneOverTwoCase.width
508 text: oneOverTwoLoaderTop.actionLabel
509 outline: notification.hints["x-lomiri-private-affirmative-tint"] !== "true"
510 color: notification.hints["x-lomiri-private-affirmative-tint"] === "true" ? theme.palette.normal.positive
511 : theme.name == "Lomiri.Components.Themes.SuruDark" ? "#888"
513 onClicked: notification.notification.invokeAction(oneOverTwoLoaderTop.actionId)
516 sourceComponent: index == 0 ? oneOverTwoButtonTop : undefined
521 spacing: notification.margins
524 id: oneOverTwoRepeaterBottom
526 model: notification.actions
528 id: oneOverTwoLoaderBottom
530 property string actionId: id
531 property string actionLabel: label
534 id: oneOverTwoButtonBottom
537 objectName: "notify_oot_button" + index
538 width: oneOverTwoCase.width / 2 - spacing / 2
539 text: oneOverTwoLoaderBottom.actionLabel
540 outline: notification.hints["x-lomiri-private-rejection-tint"] !== "true"
541 color: index == 1 && notification.hints["x-lomiri-private-rejection-tint"] === "true" ? theme.palette.normal.negative
542 : theme.name == "Lomiri.Components.Themes.SuruDark" ? "#888"
544 onClicked: notification.notification.invokeAction(oneOverTwoLoaderBottom.actionId)
547 sourceComponent: (index == 1 || index == 2) ? oneOverTwoButtonBottom : undefined
556 objectName: "buttonRow"
561 visible: notification.type === Notification.SnapDecision && actionRepeater.count > 0 && !oneOverTwoCase.visible && notification.expanded
562 spacing: notification.margins
563 layoutDirection: Qt.RightToLeft
566 id: notifySwipeButtonLoader
567 active: notification.hints["x-lomiri-snap-decisions-swipe"] === "true"
569 sourceComponent: SwipeToAct {
570 objectName: "notify_swipe_button"
571 width: buttonRow.width
572 leftIconName: "call-end"
573 rightIconName: "call-start"
574 clickToAct: notification.hasMouse
576 notification.notification.invokeAction(notification.actions.data(0, ActionModel.RoleActionId))
580 notification.notification.invokeAction(notification.actions.data(1, ActionModel.RoleActionId))
587 model: notification.actions
591 property string actionId: id
592 property string actionLabel: label
593 active: !notifySwipeButtonLoader.active
599 objectName: "notify_button" + index
600 width: buttonRow.width / 2 - spacing / 2
601 text: loader.actionLabel
602 outline: (index == 0 && notification.hints["x-lomiri-private-affirmative-tint"] !== "true") ||
603 (index == 1 && notification.hints["x-lomiri-private-rejection-tint"] !== "true")
606 if (theme.name == "Lomiri.Components.Themes.SuruDark") {
609 if (index == 0 && notification.hints["x-lomiri-private-affirmative-tint"] === "true") {
610 result = theme.palette.normal.positive;
612 if (index == 1 && notification.hints["x-lomiri-private-rejection-tint"] === "true") {
613 result = theme.palette.normal.negative;
617 onClicked: notification.notification.invokeAction(loader.actionId)
620 sourceComponent: (index == 0 || index == 1) ? actionButton : undefined
627 objectName: "notify_button2"
634 visible: notification.type === Notification.SnapDecision && actionRepeater.count > 3 && !oneOverTwoCase.visible && notification.expanded
635 model: notification.actions
639 notification.notification.invokeAction(id)