on xenial help sign in
Added mocked notification-model (based on real implementation of backend) and made it compile... still need to make it work with the notification qml-test though :)
f3279b6Mirco Müller
qml/Notifications/Notification.qml+3−2
@@ -41,7 +41,7 @@ Item {
41 property int maxHeight
41 property int maxHeight
42 property int margins
42 property int margins
43 readonly property bool draggable: (type === Notification.SnapDecision && state === "contracted") || type === Notification.Interactive || type === Notification.Ephemeral
43 readonly property bool draggable: (type === Notification.SnapDecision && state === "contracted") || type === Notification.Interactive || type === Notification.Ephemeral
44− readonly property bool darkOnBright: true //panel.indicators.shown || type === Notification.SnapDecision
44+ readonly property bool darkOnBright: panel.indicators.shown || type === Notification.SnapDecision
45 readonly property color red: "#fc4949"
45 readonly property color red: "#fc4949"
46 readonly property color green: "#3fb24f"
46 readonly property color green: "#3fb24f"
47 readonly property color sdLightGrey: "#eaeaea"
47 readonly property color sdLightGrey: "#eaeaea"
@@ -80,12 +80,13 @@ Item {
80 Audio {
80 Audio {
81 id: sound
81 id: sound
82 objectName: "sound"
82 objectName: "sound"
83− //audioRole: MediaPlayer.alert
83+ audioRole: MediaPlayer.alert
84 source: hints["suppress-sound"] !== "true" && hints["sound-file"] !== undefined ? hints["sound-file"] : ""
84 source: hints["suppress-sound"] !== "true" && hints["sound-file"] !== undefined ? hints["sound-file"] : ""
85 }
85 }
86
86
87 // FIXME: using onCompleted because of LP: #1354406 workaround, has to be onOpacityChanged really
87 // FIXME: using onCompleted because of LP: #1354406 workaround, has to be onOpacityChanged really
88 Component.onCompleted: {
88 Component.onCompleted: {
89+ print("Added notification with summary:", summary)
89 if (opacity == 1.0 && hints["suppress-sound"] !== "true" && sound.source !== "") {
90 if (opacity == 1.0 && hints["suppress-sound"] !== "true" && sound.source !== "") {
90 sound.play();
91 sound.play();
91 }
92 }
qml/Notifications/Notifications.qml+1−1
@@ -54,7 +54,7 @@ ListView {
54 body: model.body
54 body: model.body
55 value: model.value
55 value: model.value
56 actions: model.actions
56 actions: model.actions
57− notificationId: model.nid
57+ notificationId: model.id
58 notification: notificationList.model.getRaw(notificationId)
58 notification: notificationList.model.getRaw(notificationId)
59 maxHeight: notificationList.height
59 maxHeight: notificationList.height
60 margins: notificationList.margin
60 margins: notificationList.margin
tests/mocks/Unity/Notifications/CMakeLists.txt+1
@@ -5,6 +5,7 @@ include_directories(
5set(MockNotificationsPlugin_SOURCES
5set(MockNotificationsPlugin_SOURCES
6 plugin.cpp
6 plugin.cpp
7 MockNotificationTypes.cpp
7 MockNotificationTypes.cpp
8+ MockNotificationModel.cpp
8 MockActionModel.cpp
9 MockActionModel.cpp
9)
10)
10
11
tests/mocks/Unity/Notifications/MockActionModel.cpp+1−1
@@ -1,5 +1,5 @@
1/*
1/*
2− * Copyright 2014 Canonical Ltd.
2+ * Copyright 2015 Canonical Ltd.
3 *
3 *
4 * This program is free software; you can redistribute it and/or modify
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU Lesser General Public License as published by
5 * it under the terms of the GNU Lesser General Public License as published by
tests/mocks/Unity/Notifications/MockActionModel.h+1−1
@@ -1,5 +1,5 @@
1/*
1/*
2− * Copyright 2014 Canonical Ltd.
2+ * Copyright 2015 Canonical Ltd.
3 *
3 *
4 * This program is free software; you can redistribute it and/or modify
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU Lesser General Public License as published by
5 * it under the terms of the GNU Lesser General Public License as published by
tests/mocks/Unity/Notifications/MockNotificationTypes.cpp+1−4
@@ -1,5 +1,5 @@
1/*
1/*
2− * Copyright 2014 Canonical Ltd.
2+ * Copyright 2015 Canonical Ltd.
3 *
3 *
4 * This program is free software; you can redistribute it and/or modify
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU Lesser General Public License as published by
5 * it under the terms of the GNU Lesser General Public License as published by
@@ -18,7 +18,6 @@
18 */
18 */
19
19
20#include "MockNotificationTypes.h"
20#include "MockNotificationTypes.h"
21−#include <QDebug>
22
21
23struct MockNotificationPrivate {
22struct MockNotificationPrivate {
24 unsigned int id;
23 unsigned int id;
@@ -164,7 +163,6 @@ void MockNotification::setHints(const QVariantMap& hints) {
164void MockNotification::invokeAction(const QString &action) {
163void MockNotification::invokeAction(const QString &action) {
165 for(int i=0; i<p->actions.size(); i++) {
164 for(int i=0; i<p->actions.size(); i++) {
166 if(p->actions[i] == action) {
165 if(p->actions[i] == action) {
167− qDebug() << "MockNotification::invokeAction("<< action << ") called";
168 Q_EMIT completed(p->id);
166 Q_EMIT completed(p->id);
169 return;
167 return;
170 }
168 }
@@ -173,6 +171,5 @@ void MockNotification::invokeAction(const QString &action) {
173}
171}
174
172
175void MockNotification::close() {
173void MockNotification::close() {
176− qDebug() << "MockNotification::close() called";
177 Q_EMIT completed(p->id);
174 Q_EMIT completed(p->id);
178}
175}
tests/mocks/Unity/Notifications/MockNotificationTypes.h+1−1
@@ -1,5 +1,5 @@
1/*
1/*
2− * Copyright 2014 Canonical Ltd.
2+ * Copyright 2015 Canonical Ltd.
3 *
3 *
4 * This program is free software; you can redistribute it and/or modify
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU Lesser General Public License as published by
5 * it under the terms of the GNU Lesser General Public License as published by
tests/mocks/Unity/Notifications/plugin.cpp+3−1
@@ -1,5 +1,5 @@
1/*
1/*
2− * Copyright 2014 Canonical Ltd.
2+ * Copyright 2015 Canonical Ltd.
3 *
3 *
4 * This program is free software; you can redistribute it and/or modify
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU Lesser General Public License as published by
5 * it under the terms of the GNU Lesser General Public License as published by
@@ -20,6 +20,7 @@
20#include "plugin.h"
20#include "plugin.h"
21#include "MockActionModel.h"
21#include "MockActionModel.h"
22#include "MockNotificationTypes.h"
22#include "MockNotificationTypes.h"
23+#include "MockNotificationModel.h"
23
24
24#include <QtQml/qqml.h>
25#include <QtQml/qqml.h>
25
26
@@ -27,5 +28,6 @@ void TestNotificationPlugin::registerTypes(const char* uri)
27{
28{
28 // @uri Unity.Notifications
29 // @uri Unity.Notifications
29 qmlRegisterType<MockNotification>(uri, 1, 0, "Notification");
30 qmlRegisterType<MockNotification>(uri, 1, 0, "Notification");
31+ qmlRegisterType<MockNotificationModel>(uri, 1, 0, "NotificationModel");
30 qmlRegisterType<ActionModel>(uri, 1, 0, "ActionModel");
32 qmlRegisterType<ActionModel>(uri, 1, 0, "ActionModel");
31}
33}
tests/mocks/Unity/Notifications/plugin.h+1−2
@@ -1,5 +1,5 @@
1/*
1/*
2− * Copyright 2014 Canonical Ltd.
2+ * Copyright 2015 Canonical Ltd.
3 *
3 *
4 * This program is free software; you can redistribute it and/or modify
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU Lesser General Public License as published by
5 * it under the terms of the GNU Lesser General Public License as published by
@@ -17,7 +17,6 @@
17 * Mirco Mueller <mirco.mueller@canonical.com>
17 * Mirco Mueller <mirco.mueller@canonical.com>
18 */
18 */
19
19
20−
21#ifndef TESTNOTIFICATION_PLUGIN_H
20#ifndef TESTNOTIFICATION_PLUGIN_H
22#define TESTNOTIFICATION_PLUGIN_H
21#define TESTNOTIFICATION_PLUGIN_H
23
22
tests/qmltests/Notifications/tst_Notifications.qml+84−90
@@ -1,17 +1,20 @@
1/*
1/*
2− * Copyright (C) 2013 Canonical, Ltd.
2+ * Copyright 2015 Canonical Ltd.
3 *
3 *
4 * This program is free software; you can redistribute it and/or modify
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
5+ * it under the terms of the GNU Lesser General Public License as published by
6 * the Free Software Foundation; version 3.
6 * the Free Software Foundation; version 3.
7 *
7 *
8 * This program is distributed in the hope that it will be useful,
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11− * GNU General Public License for more details.
11+ * GNU Lesser General Public License for more details.
12 *
12 *
13− * You should have received a copy of the GNU General Public License
13+ * You should have received a copy of the GNU Lesser General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15+ *
16+ * Authors:
17+ * Mirco Mueller <mirco.mueller@canonical.com>
15 */
18 */
16
19
17import QtQuick 2.0
20import QtQuick 2.0
@@ -27,44 +30,19 @@ Item {
27 width: notificationsRect.width + interactiveControls.width
30 width: notificationsRect.width + interactiveControls.width
28 height: notificationsRect.height
31 height: notificationsRect.height
29
32
30− Row {
33+ property list<Notification> dataList: [
31− id: rootRow
32−
33 Notification {
34 Notification {
34− id: mockNotificationDefault
35+ nid: 0
35 type: Notification.PlaceHolder
36 type: Notification.PlaceHolder
36− nid: 1
37 summary: ""
37 summary: ""
38 body: ""
38 body: ""
39 icon: ""
39 icon: ""
40 secondaryIcon: ""
40 secondaryIcon: ""
41 rawActions: ["reply_id", "Dummy"]
41 rawActions: ["reply_id", "Dummy"]
42− }
42+ },
43−
44− ListModel {
45− id: mockModel
46− dynamicRoles: true
47−
48− signal actionInvoked(string actionId)
49−
50− function getRaw(id) {
51− for (var i = 0; i < mockModel.count; i++) {
52− if (id === mockModel.get(i).nid) {
53− return mockModel.get(i)
54− }
55− }
56− }
57−
58− // add the default/PlaceHolder notification to the model
59− Component.onCompleted: {
60− append(mockNotificationDefault)
61− }
62− }
63−
64 Notification {
43 Notification {
65− id: mock2over1SnapDecisionNotification
44+ nid: 1
66 type: Notification.SnapDecision
45 type: Notification.SnapDecision
67− nid: 2
68 hints: {"x-canonical-private-affirmative-tint": "true"}
46 hints: {"x-canonical-private-affirmative-tint": "true"}
69 summary: "Theatre at Ferria Stadium"
47 summary: "Theatre at Ferria Stadium"
70 body: "at Ferria Stadium in Bilbao, Spain\n07578545317"
48 body: "at Ferria Stadium in Bilbao, Spain\n07578545317"
@@ -73,86 +51,48 @@ Item {
73 rawActions: ["ok_id", "Ok",
51 rawActions: ["ok_id", "Ok",
74 "snooze_id", "Snooze",
52 "snooze_id", "Snooze",
75 "view_id", "View"]
53 "view_id", "View"]
76− }
54+ },
77−
78− function add2over1SnapDecisionNotification() {
79− mockModel.append(mock2over1SnapDecisionNotification)
80−
81− // trying out/debugging stuff
82− mockModel.getRaw(2).close()
83− print("summary:", mock2over1SnapDecisionNotification.summary)
84− print("summary:", mockModel.getRaw(2).summary)
85− print("summary:", mockModel.get(1).summary)
86− mock2over1SnapDecisionNotification.close()
87− mock2over1SnapDecisionNotification.invokeAction("ok_id")
88− }
89−
90 Notification {
55 Notification {
91− id: mockEphemeralNotification
56+ nid: 2
92 type: Notification.Ephemeral
57 type: Notification.Ephemeral
93− nid: 3
94 summary: "Cole Raby"
58 summary: "Cole Raby"
95 body: "I did not expect it to be that late."
59 body: "I did not expect it to be that late."
96 icon: "../graphics/avatars/amanda.png"
60 icon: "../graphics/avatars/amanda.png"
97 secondaryIcon: "../graphics/applicationIcons/facebook.png"
61 secondaryIcon: "../graphics/applicationIcons/facebook.png"
98 rawActions: ["reply_id", "Dummy"]
62 rawActions: ["reply_id", "Dummy"]
99− }
63+ },
100−
101− function addEphemeralNotification() {
102− mockModel.append(mockEphemeralNotification)
103− }
104−
105 Notification {
64 Notification {
106− id: mockEphemeralNonShapedIconNotification
65+ nid: 3
107 type: Notification.Ephemeral
66 type: Notification.Ephemeral
108− nid: 4
109 hints: {"x-canonical-non-shaped-icon": "true"}
67 hints: {"x-canonical-non-shaped-icon": "true"}
110 summary: "Contacts"
68 summary: "Contacts"
111 body: "Synchronised contacts-database with cloud-storage."
69 body: "Synchronised contacts-database with cloud-storage."
112 icon: "../graphics/applicationIcons/contacts-app.png"
70 icon: "../graphics/applicationIcons/contacts-app.png"
113 secondaryIcon: ""
71 secondaryIcon: ""
114 rawActions: ["reply_id", "Dummy"]
72 rawActions: ["reply_id", "Dummy"]
115− }
73+ },
116−
117− function addEphemeralNonShapedIconNotification() {
118− mockModel.append(mockEphemeralNonShapedIconNotification)
119− }
120−
121 Notification {
74 Notification {
122− id: mockEphemeralIconSummaryNotification
75+ nid: 4
123 type: Notification.Ephemeral
76 type: Notification.Ephemeral
124− nid: 5
125 hints: {"x-canonical-non-shaped-icon": "false"}
77 hints: {"x-canonical-non-shaped-icon": "false"}
126 summary: "Photo upload completed"
78 summary: "Photo upload completed"
127 body: ""
79 body: ""
128 icon: "../graphics/applicationIcons/facebook.png"
80 icon: "../graphics/applicationIcons/facebook.png"
129 secondaryIcon: ""
81 secondaryIcon: ""
130 rawActions: ["reply_id", "Dummy"]
82 rawActions: ["reply_id", "Dummy"]
131− }
83+ },
132−
133− function addEphemeralIconSummaryNotification() {
134− mockModel.append(mockEphemeralIconSummaryNotification)
135− }
136−
137 Notification {
84 Notification {
138− id: mockInteractiveNotification
85+ nid: 5
139 type: Notification.Interactive
86 type: Notification.Interactive
140− nid: 6
141 summary: "Interactive notification"
87 summary: "Interactive notification"
142 body: "This is a notification that can be clicked"
88 body: "This is a notification that can be clicked"
143 icon: "../graphics/avatars/anna_olsson.png"
89 icon: "../graphics/avatars/anna_olsson.png"
144 secondaryIcon: ""
90 secondaryIcon: ""
145 rawActions: ["reply_id", "Dummy"]
91 rawActions: ["reply_id", "Dummy"]
146− }
92+ },
147−
148− function addInteractiveNotification() {
149− mockModel.append(mockInteractiveNotification)
150− }
151−
152 Notification {
93 Notification {
153− id: mockConfirmationNotification
94+ nid: 6
154 type: Notification.Confirmation
95 type: Notification.Confirmation
155− nid: 7
156 hints: {"x-canonical-non-shaped-icon": "true"}
96 hints: {"x-canonical-non-shaped-icon": "true"}
157 summary: "Confirmation notification"
97 summary: "Confirmation notification"
158 body: ""
98 body: ""
@@ -160,16 +100,10 @@ Item {
160 secondaryIcon: ""
100 secondaryIcon: ""
161 value: 50
101 value: 50
162 rawActions: ["reply_id", "Dummy"]
102 rawActions: ["reply_id", "Dummy"]
163− }
103+ },
164−
165− function addConfirmationNotification() {
166− mockModel.append(mockConfirmationNotification)
167− }
168−
169 Notification {
104 Notification {
170− id: mock2ndConfirmationNotification
105+ nid: 7
171 type: Notification.Confirmation
106 type: Notification.Confirmation
172− nid: 8
173 hints: {"x-canonical-non-shaped-icon": "true",
107 hints: {"x-canonical-non-shaped-icon": "true",
174 "x-canonical-value-bar-tint": "true"}
108 "x-canonical-value-bar-tint": "true"}
175 summary: "Confirmation notification"
109 summary: "Confirmation notification"
@@ -179,9 +113,69 @@ Item {
179 value: 85
113 value: 85
180 rawActions: ["reply_id", "Dummy"]
114 rawActions: ["reply_id", "Dummy"]
181 }
115 }
116+ ]
117+
118+ Row {
119+ id: rootRow
120+
121+ ListModel {
122+ id: mockModel
123+ dynamicRoles: true
124+
125+ signal actionInvoked(string actionId)
126+
127+ function getRaw(id) {
128+ return dataList[id]
129+ }
130+
131+ // add the default/PlaceHolder notification to the model
132+ Component.onCompleted: {
133+ append(dataList[0])
134+ }
135+ }
136+
137+ function add2over1SnapDecisionNotification() {
138+ var n = {
139+ type: Notification.SnapDecision,
140+ hints: {"x-canonical-private-affirmative-tint": "true"},
141+ summary: "Incoming call",
142+ body: "Frank Zappa\n+44 (0)7736 027340",
143+ icon: "../graphics/avatars/funky.png",
144+ secondaryIcon: "image://theme/incoming-call",
145+ actions: [{ id: "ok_id", label: "Ok"},
146+ { id: "cancel_id", label: "Cancel"},
147+ { id: "dummy_id", label: "Quick reply"},
148+ { id: "late_id", label: "messages:I'm running late. I'm on my way."},
149+ { id: "later_id", label: "messages:I'm busy at the moment. I'll call later."}]
150+ }
151+
152+ mockModel.append(n)
153+
154+ //mockModel.append(dataList[1])
155+ }
156+
157+ function addEphemeralNotification() {
158+ mockModel.append(dataList[2])
159+ }
160+
161+ function addEphemeralNonShapedIconNotification() {
162+ mockModel.append(dataList[3])
163+ }
164+
165+ function addEphemeralIconSummaryNotification() {
166+ mockModel.append(dataList[4])
167+ }
168+
169+ function addInteractiveNotification() {
170+ mockModel.append(dataList[5])
171+ }
172+
173+ function addConfirmationNotification() {
174+ mockModel.append(dataList[6])
175+ }
182
176
183 function add2ndConfirmationNotification() {
177 function add2ndConfirmationNotification() {
184− mockModel.append(mock2ndConfirmationNotification)
178+ mockModel.append(dataList[7])
185 }
179 }
186
180
187 function clearNotifications() {
181 function clearNotifications() {
tests/qmltests/Notifications/tst_OptionToggle.qml+7−4
@@ -1,17 +1,20 @@
1/*
1/*
2− * Copyright (C) 2014 Canonical, Ltd.
2+ * Copyright 2015 Canonical Ltd.
3 *
3 *
4 * This program is free software; you can redistribute it and/or modify
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
5+ * it under the terms of the GNU Lesser General Public License as published by
6 * the Free Software Foundation; version 3.
6 * the Free Software Foundation; version 3.
7 *
7 *
8 * This program is distributed in the hope that it will be useful,
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11− * GNU General Public License for more details.
11+ * GNU Lesser General Public License for more details.
12 *
12 *
13− * You should have received a copy of the GNU General Public License
13+ * You should have received a copy of the GNU Lesser General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15+ *
16+ * Authors:
17+ * Mirco Mueller <mirco.mueller@canonical.com>
15 */
18 */
16
19
17import QtQuick 2.0
20import QtQuick 2.0