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 :)
commitf3279b6763158efffe045a6924772c884af5484b authorMirco Müller <mirco.mueller@ubuntu.com> dateMon 12 Jan 2015, 16:32 (12 years ago) parent2e39a7c
11 files changed+104−107
qml/Notifications/Notification.qml+3−2 qml/Notifications/Notifications.qml+1−1 tests/mocks/Unity/Notifications/CMakeLists.txt+1 tests/mocks/Unity/Notifications/MockActionModel.cpp+1−1 tests/mocks/Unity/Notifications/MockActionModel.h+1−1 tests/mocks/Unity/Notifications/MockNotificationTypes.cpp+1−4 tests/mocks/Unity/Notifications/MockNotificationTypes.h+1−1 tests/mocks/Unity/Notifications/plugin.cpp+3−1 tests/mocks/Unity/Notifications/plugin.h+1−2 tests/qmltests/Notifications/tst_Notifications.qml+84−90 tests/qmltests/Notifications/tst_OptionToggle.qml+7−4
qml/Notifications/Notification.qml+3−2
@@ -41,7 +41,7 @@ Item {
4141 property int maxHeight
4242 property int margins
4343 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
4545 readonly property color red: "#fc4949"
4646 readonly property color green: "#3fb24f"
4747 readonly property color sdLightGrey: "#eaeaea"
@@ -80,12 +80,13 @@ Item {
8080 Audio {
8181 id: sound
8282 objectName: "sound"
83− //audioRole: MediaPlayer.alert
83+ audioRole: MediaPlayer.alert
8484 source: hints["suppress-sound"] !== "true" && hints["sound-file"] !== undefined ? hints["sound-file"] : ""
8585 }
8686
8787 // FIXME: using onCompleted because of LP: #1354406 workaround, has to be onOpacityChanged really
8888 Component.onCompleted: {
89+ print("Added notification with summary:", summary)
8990 if (opacity == 1.0 && hints["suppress-sound"] !== "true" && sound.source !== "") {
9091 sound.play();
9192 }
qml/Notifications/Notifications.qml+1−1
@@ -54,7 +54,7 @@ ListView {
5454 body: model.body
5555 value: model.value
5656 actions: model.actions
57− notificationId: model.nid
57+ notificationId: model.id
5858 notification: notificationList.model.getRaw(notificationId)
5959 maxHeight: notificationList.height
6060 margins: notificationList.margin
tests/mocks/Unity/Notifications/CMakeLists.txt+1
@@ -5,6 +5,7 @@ include_directories(
55set(MockNotificationsPlugin_SOURCES
66 plugin.cpp
77 MockNotificationTypes.cpp
8+ MockNotificationModel.cpp
89 MockActionModel.cpp
910)
1011
tests/mocks/Unity/Notifications/MockActionModel.cpp+1−1
@@ -1,5 +1,5 @@
11/*
2− * Copyright 2014 Canonical Ltd.
2+ * Copyright 2015 Canonical Ltd.
33 *
44 * This program is free software; you can redistribute it and/or modify
55 * 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 @@
11/*
2− * Copyright 2014 Canonical Ltd.
2+ * Copyright 2015 Canonical Ltd.
33 *
44 * This program is free software; you can redistribute it and/or modify
55 * 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 @@
11/*
2− * Copyright 2014 Canonical Ltd.
2+ * Copyright 2015 Canonical Ltd.
33 *
44 * This program is free software; you can redistribute it and/or modify
55 * it under the terms of the GNU Lesser General Public License as published by
@@ -18,7 +18,6 @@
1818 */
1919
2020#include "MockNotificationTypes.h"
21−#include <QDebug>
2221
2322struct MockNotificationPrivate {
2423 unsigned int id;
@@ -164,7 +163,6 @@ void MockNotification::setHints(const QVariantMap& hints) {
164163void MockNotification::invokeAction(const QString &action) {
165164 for(int i=0; i<p->actions.size(); i++) {
166165 if(p->actions[i] == action) {
167− qDebug() << "MockNotification::invokeAction("<< action << ") called";
168166 Q_EMIT completed(p->id);
169167 return;
170168 }
@@ -173,6 +171,5 @@ void MockNotification::invokeAction(const QString &action) {
173171}
174172
175173void MockNotification::close() {
176− qDebug() << "MockNotification::close() called";
177174 Q_EMIT completed(p->id);
178175}
tests/mocks/Unity/Notifications/MockNotificationTypes.h+1−1
@@ -1,5 +1,5 @@
11/*
2− * Copyright 2014 Canonical Ltd.
2+ * Copyright 2015 Canonical Ltd.
33 *
44 * This program is free software; you can redistribute it and/or modify
55 * 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 @@
11/*
2− * Copyright 2014 Canonical Ltd.
2+ * Copyright 2015 Canonical Ltd.
33 *
44 * This program is free software; you can redistribute it and/or modify
55 * it under the terms of the GNU Lesser General Public License as published by
@@ -20,6 +20,7 @@
2020#include "plugin.h"
2121#include "MockActionModel.h"
2222#include "MockNotificationTypes.h"
23+#include "MockNotificationModel.h"
2324
2425#include <QtQml/qqml.h>
2526
@@ -27,5 +28,6 @@ void TestNotificationPlugin::registerTypes(const char* uri)
2728{
2829 // @uri Unity.Notifications
2930 qmlRegisterType<MockNotification>(uri, 1, 0, "Notification");
31+ qmlRegisterType<MockNotificationModel>(uri, 1, 0, "NotificationModel");
3032 qmlRegisterType<ActionModel>(uri, 1, 0, "ActionModel");
3133}
tests/mocks/Unity/Notifications/plugin.h+1−2
@@ -1,5 +1,5 @@
11/*
2− * Copyright 2014 Canonical Ltd.
2+ * Copyright 2015 Canonical Ltd.
33 *
44 * This program is free software; you can redistribute it and/or modify
55 * it under the terms of the GNU Lesser General Public License as published by
@@ -17,7 +17,6 @@
1717 * Mirco Mueller <mirco.mueller@canonical.com>
1818 */
1919
20−
2120#ifndef TESTNOTIFICATION_PLUGIN_H
2221#define TESTNOTIFICATION_PLUGIN_H
2322
tests/qmltests/Notifications/tst_Notifications.qml+84−90
@@ -1,17 +1,20 @@
11/*
2− * Copyright (C) 2013 Canonical, Ltd.
2+ * Copyright 2015 Canonical Ltd.
33 *
44 * 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
66 * the Free Software Foundation; version 3.
77 *
88 * This program is distributed in the hope that it will be useful,
99 * but WITHOUT ANY WARRANTY; without even the implied warranty of
1010 * 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.
1212 *
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
1414 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15+ *
16+ * Authors:
17+ * Mirco Mueller <mirco.mueller@canonical.com>
1518 */
1619
1720import QtQuick 2.0
@@ -27,44 +30,19 @@ Item {
2730 width: notificationsRect.width + interactiveControls.width
2831 height: notificationsRect.height
2932
30− Row {
31− id: rootRow
32−
33+ property list<Notification> dataList: [
3334 Notification {
34− id: mockNotificationDefault
35+ nid: 0
3536 type: Notification.PlaceHolder
36− nid: 1
3737 summary: ""
3838 body: ""
3939 icon: ""
4040 secondaryIcon: ""
4141 rawActions: ["reply_id", "Dummy"]
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−
42+ },
6443 Notification {
65− id: mock2over1SnapDecisionNotification
44+ nid: 1
6645 type: Notification.SnapDecision
67− nid: 2
6846 hints: {"x-canonical-private-affirmative-tint": "true"}
6947 summary: "Theatre at Ferria Stadium"
7048 body: "at Ferria Stadium in Bilbao, Spain\n07578545317"
@@ -73,86 +51,48 @@ Item {
7351 rawActions: ["ok_id", "Ok",
7452 "snooze_id", "Snooze",
7553 "view_id", "View"]
76− }
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−
54+ },
9055 Notification {
91− id: mockEphemeralNotification
56+ nid: 2
9257 type: Notification.Ephemeral
93− nid: 3
9458 summary: "Cole Raby"
9559 body: "I did not expect it to be that late."
9660 icon: "../graphics/avatars/amanda.png"
9761 secondaryIcon: "../graphics/applicationIcons/facebook.png"
9862 rawActions: ["reply_id", "Dummy"]
99− }
100−
101− function addEphemeralNotification() {
102− mockModel.append(mockEphemeralNotification)
103− }
104−
63+ },
10564 Notification {
106− id: mockEphemeralNonShapedIconNotification
65+ nid: 3
10766 type: Notification.Ephemeral
108− nid: 4
10967 hints: {"x-canonical-non-shaped-icon": "true"}
11068 summary: "Contacts"
11169 body: "Synchronised contacts-database with cloud-storage."
11270 icon: "../graphics/applicationIcons/contacts-app.png"
11371 secondaryIcon: ""
11472 rawActions: ["reply_id", "Dummy"]
115− }
116−
117− function addEphemeralNonShapedIconNotification() {
118− mockModel.append(mockEphemeralNonShapedIconNotification)
119− }
120−
73+ },
12174 Notification {
122− id: mockEphemeralIconSummaryNotification
75+ nid: 4
12376 type: Notification.Ephemeral
124− nid: 5
12577 hints: {"x-canonical-non-shaped-icon": "false"}
12678 summary: "Photo upload completed"
12779 body: ""
12880 icon: "../graphics/applicationIcons/facebook.png"
12981 secondaryIcon: ""
13082 rawActions: ["reply_id", "Dummy"]
131− }
132−
133− function addEphemeralIconSummaryNotification() {
134− mockModel.append(mockEphemeralIconSummaryNotification)
135− }
136−
83+ },
13784 Notification {
138− id: mockInteractiveNotification
85+ nid: 5
13986 type: Notification.Interactive
140− nid: 6
14187 summary: "Interactive notification"
14288 body: "This is a notification that can be clicked"
14389 icon: "../graphics/avatars/anna_olsson.png"
14490 secondaryIcon: ""
14591 rawActions: ["reply_id", "Dummy"]
146− }
147−
148− function addInteractiveNotification() {
149− mockModel.append(mockInteractiveNotification)
150− }
151−
92+ },
15293 Notification {
153− id: mockConfirmationNotification
94+ nid: 6
15495 type: Notification.Confirmation
155− nid: 7
15696 hints: {"x-canonical-non-shaped-icon": "true"}
15797 summary: "Confirmation notification"
15898 body: ""
@@ -160,16 +100,10 @@ Item {
160100 secondaryIcon: ""
161101 value: 50
162102 rawActions: ["reply_id", "Dummy"]
163− }
164−
165− function addConfirmationNotification() {
166− mockModel.append(mockConfirmationNotification)
167− }
168−
103+ },
169104 Notification {
170− id: mock2ndConfirmationNotification
105+ nid: 7
171106 type: Notification.Confirmation
172− nid: 8
173107 hints: {"x-canonical-non-shaped-icon": "true",
174108 "x-canonical-value-bar-tint": "true"}
175109 summary: "Confirmation notification"
@@ -179,9 +113,69 @@ Item {
179113 value: 85
180114 rawActions: ["reply_id", "Dummy"]
181115 }
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+ }
182176
183177 function add2ndConfirmationNotification() {
184− mockModel.append(mock2ndConfirmationNotification)
178+ mockModel.append(dataList[7])
185179 }
186180
187181 function clearNotifications() {
tests/qmltests/Notifications/tst_OptionToggle.qml+7−4
@@ -1,17 +1,20 @@
11/*
2− * Copyright (C) 2014 Canonical, Ltd.
2+ * Copyright 2015 Canonical Ltd.
33 *
44 * 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
66 * the Free Software Foundation; version 3.
77 *
88 * This program is distributed in the hope that it will be useful,
99 * but WITHOUT ANY WARRANTY; without even the implied warranty of
1010 * 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.
1212 *
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
1414 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15+ *
16+ * Authors:
17+ * Mirco Mueller <mirco.mueller@canonical.com>
1518 */
1619
1720import QtQuick 2.0