on xenial help sign in
Merges
commitb3b2a035093c404a16feb3f129c2bea20b1a867a authorAndrea Cimitan <andrea.cimitan@gmail.com> dateWed 12 Feb 2014, 12:47 (13 years ago) parentb6de2694cfe7e3
5 files changed+153
qml/Dash/Previews/PreviewProgress.qml+64 qml/Dash/Previews/PreviewWidgetFactory.qml+1 tests/qmltests/CMakeLists.txt+2 tests/qmltests/Dash/Previews/tst_PreviewProgress.qml+85 tests/qmltests/Dash/Previews/tst_PreviewWidgetFactory.qml+1
qml/Dash/Previews/PreviewProgress.qmlnew file+64
@@ -0,0 +1,64 @@
1+/*
2+ * Copyright (C) 2014 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+ */
16+
17+import QtQuick 2.1
18+import Ubuntu.Components 0.1
19+import Ubuntu.DownloadDaemonListener 0.1
20+
21+/*! This preview widget shows a progress bar.
22+ * It feeds itself from the source determined in widgetData["source"]
23+ * At the moment we only support the dbus source defined
24+ * by source["dbus-name"] and source["dbus-object"]
25+ */
26+
27+PreviewWidget {
28+ id: root
29+
30+ implicitHeight: progressBar.implicitHeight
31+ implicitWidth: progressBar.implicitWidth
32+
33+ ProgressBar {
34+ id: progressBar
35+ objectName: "progressBar"
36+ value: 0
37+ maximumValue: 100
38+ implicitHeight: units.gu(5)
39+ height: parent.height
40+ width: parent.width
41+
42+ property var source: widgetData["source"]
43+ // TODO Eventually we will need to support more sources other
44+ // than DownloadTracker via dbus so we'll need a Loader based on source contents
45+
46+ DownloadTracker {
47+ service: progressBar.source["dbus-name"] || ""
48+ dbusPath: progressBar.source["dbus-object"] || ""
49+
50+ onProgress: {
51+ var percentage = parseInt(received * 100 / total);
52+ progressBar.value = percentage;
53+ }
54+
55+ onFinished: {
56+ root.triggered(widgetId, "finished", widgetData)
57+ }
58+
59+ onError: {
60+ root.triggered(widgetId, "failed", widgetData)
61+ }
62+ }
63+ }
64+}
qml/Dash/Previews/PreviewWidgetFactory.qml+1
@@ -47,6 +47,7 @@ Loader {
4747 case "gallery": return "PreviewImageGallery.qml";
4848 case "header": return "PreviewHeader.qml";
4949 case "image": return "PreviewZoomableImage.qml"
50+ case "progress": return "PreviewProgress.qml";
5051 case "text": return "PreviewTextSummary.qml";
5152 case "video": return "PreviewVideoPlayback.qml";
5253 default: return "";
tests/qmltests/CMakeLists.txt+2
@@ -60,6 +60,8 @@ add_qml_test(Dash/Previews PreviewActions IMPORT_PATHS ${qmltest_DEFAULT_IMPORT_
6060add_qml_test(Dash/Previews PreviewAudioPlayback IMPORT_PATHS ${qmltest_DEFAULT_IMPORT_PATHS} ${CMAKE_BINARY_DIR}/tests/mocks)
6161add_qml_test(Dash/Previews PreviewHeader IMPORT_PATHS ${qmltest_DEFAULT_IMPORT_PATHS} ${CMAKE_BINARY_DIR}/tests/mocks)
6262add_qml_test(Dash/Previews PreviewImageGallery IMPORT_PATHS ${qmltest_DEFAULT_IMPORT_PATHS} ${CMAKE_BINARY_DIR}/tests/mocks)
63+add_qml_test(Dash/Previews PreviewHeader IMPORT_PATHS ${qmltest_DEFAULT_IMPORT_PATHS} ${CMAKE_BINARY_DIR}/tests/mocks)
64+add_qml_test(Dash/Previews PreviewProgress IMPORT_PATHS ${qmltest_DEFAULT_IMPORT_PATHS} ${CMAKE_BINARY_DIR}/tests/mocks)
6365add_qml_test(Dash/Previews PreviewRating IMPORT_PATHS ${qmltest_DEFAULT_IMPORT_PATHS} ${CMAKE_BINARY_DIR}/tests/mocks)
6466add_qml_test(Dash/Previews PreviewTextSummary IMPORT_PATHS ${qmltest_DEFAULT_IMPORT_PATHS} ${CMAKE_BINARY_DIR}/tests/mocks)
6567add_qml_test(Dash/Previews PreviewVideoPlayback IMPORT_PATHS ${qmltest_DEFAULT_IMPORT_PATHS} ${CMAKE_BINARY_DIR}/tests/mocks)
tests/qmltests/Dash/Previews/tst_PreviewProgress.qmlnew file+85
@@ -0,0 +1,85 @@
1+/*
2+ * Copyright 2014 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+ */
16+
17+import QtQuick 2.0
18+import QtTest 1.0
19+import "../../../../qml/Dash/Previews"
20+import Unity.Test 0.1 as UT
21+import Ubuntu.Components 0.1
22+
23+Rectangle {
24+ id: root
25+ width: units.gu(60)
26+ height: units.gu(80)
27+
28+ property var progressjson: {
29+ "type": "progress",
30+ "source": { "dbus-name" : "somename", "dbus-object": "somestring" }
31+ }
32+
33+ property var progressjsonFinish: {
34+ "type": "progress",
35+ "source": { "dbus-name" : "somename", "dbus-object": "finish" }
36+ }
37+
38+ property var progressjsonError: {
39+ "type": "progress",
40+ "source": { "dbus-name" : "somename", "dbus-object": "error" }
41+ }
42+
43+ SignalSpy {
44+ id: spy
45+ signalName: "triggered"
46+ }
47+
48+ PreviewProgress {
49+ id: previewProgress
50+ widgetId: "previewProgress"
51+ widgetData: progressjson
52+ width: units.gu(30)
53+
54+ Rectangle {
55+ anchors.fill: parent
56+ color: "red"
57+ opacity: 0.1
58+ }
59+ }
60+
61+ UT.UnityTestCase {
62+ name: "PreviewHeaderTest"
63+ when: windowShown
64+
65+ function test_json() {
66+ spy.target = previewProgress
67+
68+ // The mock DownloadTracker triggers its signals when you pass
69+ // finish/error as dbus-object to it. Exercise it here
70+ previewProgress.widgetData = progressjsonFinish;
71+ compare(spy.count, 1);
72+ var args = spy.signalArguments[0];
73+ compare(args[0], "previewProgress");
74+ compare(args[1], "finished");
75+ compare(args[2], progressjsonFinish);
76+
77+ previewProgress.widgetData = progressjsonError;
78+ compare(spy.count, 2);
79+ var args = spy.signalArguments[1];
80+ compare(args[0], "previewProgress");
81+ compare(args[1], "failed");
82+ compare(args[2], progressjsonError);
83+ }
84+ }
85+}
tests/qmltests/Dash/Previews/tst_PreviewWidgetFactory.qml+1
@@ -80,6 +80,7 @@ Rectangle {
8080 { tag: "Gallery", type: "gallery", source: "PreviewImageGallery.qml" },
8181 { tag: "Header", type: "header", source: "PreviewHeader.qml" },
8282 { tag: "Image", type: "image", source: "PreviewZoomableImage.qml" },
83+ { tag: "Progress", type: "progress", source: "PreviewProgress.qml" },
8384 { tag: "Text", type: "text", source: "PreviewTextSummary.qml" },
8485 { tag: "Video", type: "video", source: "PreviewVideoPlayback.qml" },
8586 ];