on fab9bd9 help sign in
unity8/qml/Notifications/Notification.qml
462 lines 16 kB history raw
1/*
2 * Copyright (C) 2013 Canonical, Ltd.
3 *
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.
7 *
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.
12 *
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/>.
15 */
17import QtQuick 2.0
18import QtMultimedia 5.0
19import Ubuntu.Components 1.1
20import Unity.Notifications 1.0
21import QMenuModel 0.1
22import Utils 0.1
24import Ubuntu.Components.ListItems 0.1 as ListItem
26Item {
27 id: notification
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 var actions
34 property var notificationId
35 property var type
36 property var hints
37 property var notification
38 property color color
39 property bool fullscreen: false
40 property int maxHeight
41 property int margins
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: 0
55 state: {
56 var result = "";
58 if (type == Notification.SnapDecision) {
59 if (ListView.view.currentIndex == index) {
60 result = "expanded";
61 } else {
62 if (ListView.view.count > 2) {
63 if (ListView.view.currentIndex == -1 && index == 1) {
64 result = "expanded";
65 } else {
66 result = "contracted";
67 }
68 } else {
69 result = "expanded";
70 }
71 }
72 }
74 return result;
75 }
77 Audio {
78 id: sound
79 objectName: "sound"
80 source: hints["suppress-sound"] != "true" && hints["sound-file"] != undefined ? hints["sound-file"] : ""
81 }
83 onOpacityChanged: {
84 if (opacity == 1.0 && hints["suppress-sound"] != "true" && sound.source) {
85 sound.play();
86 }
87 }
89 Behavior on height {
90 id: normalHeightBehavior
92 //enabled: menuItemFactory.progress == 1
93 enabled: true
94 SequentialAnimation {
95 PauseAnimation {
96 duration: UbuntuAnimation.SnapDuration
97 }
98 UbuntuNumberAnimation {
99 duration: UbuntuAnimation.SnapDuration
100 }
101 }
102 }
104 states:[
105 State {
106 name: "contracted"
107 PropertyChanges {target: notification; height: units.gu(8)}
108 },
109 State {
110 name: "expanded"
111 PropertyChanges {target: notification; height: implicitHeight}
112 }
113 ]
115 clip: fullscreen ? false : true
117 visible: type != Notification.PlaceHolder
119 UbuntuShape {
120 id: shapedBack
122 visible: !fullscreen
123 anchors {
124 fill: parent
125 leftMargin: notification.margins
126 rightMargin: notification.margins
127 }
128 color: parent.color
129 opacity: parent.opacity
130 radius: "medium"
131 }
133 Rectangle {
134 id: nonShapedBack
136 visible: fullscreen
137 anchors.fill: parent
138 color: parent.color
139 opacity: parent.opacity
140 }
142 Item {
143 id: contents
144 anchors.fill: fullscreen ? nonShapedBack : shapedBack
146 UnityMenuModelPaths {
147 id: paths
149 source: hints["x-canonical-private-menu-model"]
151 busNameHint: "busName"
152 actionsHint: "actions"
153 menuObjectPathHint: "menuPath"
154 }
156 UnityMenuModel {
157 id: unityMenuModel
159 property string lastNameOwner: ""
161 busName: paths.busName
162 actions: paths.actions
163 menuObjectPath: paths.menuObjectPath
164 onNameOwnerChanged: {
165 if (lastNameOwner != "" && nameOwner == "" && notification.notification != undefined) {
166 notification.notification.close()
167 }
168 lastNameOwner = nameOwner
169 }
170 }
172 Behavior on implicitHeight {
173 id: heightBehavior
175 enabled: false
176 UbuntuNumberAnimation {
177 duration: UbuntuAnimation.SnapDuration
178 }
179 }
181 // delay enabling height behavior until the add transition is complete
182 onOpacityChanged: if (opacity == 1) heightBehavior.enabled = true
184 MouseArea {
185 id: interactiveArea
187 anchors.fill: parent
188 objectName: "interactiveArea"
189 onClicked: {
190 if (notification.type == Notification.Interactive) {
191 notification.notification.invokeAction(actionRepeater.itemAt(0).actionId)
192 } else {
193 notificationList.currentIndex = index;
194 }
195 }
196 }
198 Column {
199 id: outterColumn
201 anchors {
202 left: parent.left
203 right: parent.right
204 top: parent.top
205 margins: 0
206 topMargin: units.gu(2)
207 }
209 spacing: units.gu(2)
211 Row {
212 id: topRow
214 spacing: contentSpacing
215 anchors {
216 left: parent.left
217 right: parent.right
218 margins: contentSpacing
219 }
221 ShapedIcon {
222 id: icon
224 objectName: "icon"
225 width: type == Notification.Ephemeral && !bodyLabel.visible ? units.gu(3) : units.gu(6)
226 height: type == Notification.Ephemeral && !bodyLabel.visible ? units.gu(3) : units.gu(6)
227 shaped: notification.hints["x-canonical-non-shaped-icon"] == "true" ? false : true
228 visible: iconSource !== undefined && iconSource != ""
229 }
231 Column {
232 id: labelColumn
233 width: secondaryIcon.visible ? parent.width - x - units.gu(4.5) : parent.width - x
235 anchors.verticalCenter: (icon.visible && !bodyLabel.visible) ? icon.verticalCenter : undefined
237 Label {
238 id: summaryLabel
240 objectName: "summaryLabel"
241 anchors {
242 left: parent.left
243 right: parent.right
244 }
245 fontSize: "medium"
246 color: type == Notification.SnapDecision ? sdFontColor :Theme.palette.selected.backgroundText
247 elide: Text.ElideRight
248 }
250 Label {
251 id: bodyLabel
253 objectName: "bodyLabel"
254 anchors {
255 left: parent.left
256 right: parent.right
257 }
258 visible: body != ""
259 fontSize: "small"
260 color: type == Notification.SnapDecision ? sdFontColor : Theme.palette.selected.backgroundText
261 opacity: type == Notification.SnapDecision ? 1.0 : 0.6
262 wrapMode: Text.WordWrap
263 maximumLineCount: 10
264 elide: Text.ElideRight
265 }
266 }
268 Image {
269 id: secondaryIcon
271 objectName: "secondaryIcon"
272 width: units.gu(3)
273 height: units.gu(3)
274 visible: source !== undefined && source != ""
275 fillMode: Image.PreserveAspectCrop
276 }
277 }
279 ListItem.ThinDivider {
280 visible: type == Notification.SnapDecision
281 }
283 Column {
284 id: dialogColumn
285 objectName: "dialogListView"
286 spacing: units.gu(2)
288 visible: count > 0
290 anchors {
291 left: parent.left
292 right: parent.right
293 top: fullscreen ? parent.top : undefined
294 bottom: fullscreen ? parent.bottom : undefined
295 }
297 Repeater {
298 model: unityMenuModel
300 NotificationMenuItemFactory {
301 id: menuItemFactory
303 anchors {
304 left: dialogColumn.left
305 right: dialogColumn.right
306 }
308 menuModel: unityMenuModel
309 menuData: model
310 menuIndex: index
311 maxHeight: notification.maxHeight
313 onLoaded: {
314 notification.fullscreen = Qt.binding(function() { return fullscreen; });
315 }
316 }
317 }
318 }
320 Row {
321 id: buttonRow
323 objectName: "buttonRow"
324 anchors {
325 left: parent.left
326 right: parent.right
327 margins: contentSpacing
328 }
329 visible: notification.type == Notification.SnapDecision && actionRepeater.count > 0
330 spacing: units.gu(2)
331 layoutDirection: Qt.RightToLeft
333 Repeater {
334 id: actionRepeater
336 model: notification.actions
337 delegate: Loader {
338 id: loader
340 property string actionId: id
341 property string actionLabel: label
343 Component {
344 id: actionButton
346 Button {
347 objectName: "button" + index
348 width: buttonRow.width / 2 - spacing*2
349 text: loader.actionLabel
350 color: {
351 var result = sdDarkGrey;
352 if (index == 0 && notification.hints["x-canonical-private-affirmative-tint"] == "true") {
353 result = green;
354 }
355 if (index == 1 && notification.hints["x-canonical-private-rejection-tint"] == "true") {
356 result = red;
357 }
358 return result;
359 }
360 onClicked: notification.notification.invokeAction(loader.actionId)
361 }
362 }
363 sourceComponent: (index == 0 || index == 1) ? actionButton : undefined
364 }
365 }
366 }
368 ComboButton {
369 id: comboButton
371 objectName: "button2"
372 width: parent.width
373 anchors {
374 left: parent.left
375 right: parent.right
376 margins: contentSpacing
377 }
379 visible: notification.type == Notification.SnapDecision && actionRepeater.count > 3
380 color: sdDarkGrey
381 onClicked: notification.notification.invokeAction(comboRepeater.itemAt(2).actionId)
382 expanded: false
383 expandedHeight: (comboRepeater.count - 2) * units.gu(4) + units.gu(.5)
384 comboList: Flickable {
385 // this has to be wrapped inside a flickable
386 // to work around a feature/bug? of the
387 // ComboButton SDK-element, making a regular
388 // unwrapped Column item flickable
389 // see LP: #1332590
390 interactive: false
391 Column {
392 Repeater {
393 id: comboRepeater
395 onVisibleChanged: {
396 comboButton.text = comboRepeater.itemAt(2).actionLabel
397 }
399 model: notification.actions
400 delegate: Loader {
401 id: comboLoader
403 asynchronous: true
404 visible: status == Loader.Ready
405 property string actionId: id
406 property string actionLabel: label
407 readonly property var splitLabel: actionLabel.match(/(^([-a-z0-9]+):)?(.*)$/)
408 Component {
409 id: comboEntry
411 MouseArea {
412 id: comboInputArea
414 objectName: "button" + index
415 width: comboButton.width
416 height: comboIcon.height + units.gu(2)
418 onClicked: {
419 notification.notification.invokeAction(actionId)
420 }
422 ListItem.ThinDivider {
423 visible: index > 3
424 }
426 Icon {
427 id: comboIcon
429 anchors {
430 left: parent.left
431 leftMargin: units.gu(.5)
432 verticalCenter: parent.verticalCenter
433 }
434 width: units.gu(2)
435 height: units.gu(2)
436 color: "#5d5d5d"
437 name: splitLabel[2]
438 }
440 Label {
441 id: comboLabel
443 anchors {
444 left: comboIcon.right
445 leftMargin: units.gu(1)
446 verticalCenter: comboIcon.verticalCenter
447 }
448 fontSize: "small"
449 color: "#5d5d5d"
450 text: splitLabel[3]
451 }
452 }
453 }
454 sourceComponent: (index > 2) ? comboEntry : undefined
455 }
456 }
457 }
458 }
459 }
460 }
461 }