on xenial help sign in
Progress Preview Widget
commita57f52bc144f78bb5773c539188324efe4a7b68a authorAlbert Astals <albert.astals@canonical.com> dateTue 18 Feb 2014, 11:39 (13 years ago) parentb4e41b5ae231fc
5 files changed+160
qml/Dash/Previews/PreviewProgress.qml+70 qml/Dash/Previews/PreviewWidgetFactory.qml+1 tests/qmltests/CMakeLists.txt+1 tests/qmltests/Dash/Previews/tst_PreviewProgress.qml+87 tests/qmltests/Dash/Previews/tst_PreviewWidgetFactory.qml+1
qml/Dash/Previews/PreviewProgress.qmlnew file+70
@@ -0,0 +1,70 @@
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+/*! \brief Preview widget for a progress bar.
22+ *
23+ * It feeds itself from the source determined in widgetData["source"]
24+ * At the moment we only support the dbus source defined
25+ * by source["dbus-name"] and source["dbus-object"]
26+ */
27+
28+PreviewWidget {
29+ id: root
30+
31+ implicitHeight: progressBar.implicitHeight
32+ implicitWidth: progressBar.implicitWidth
33+
34+ ProgressBar {
35+ id: progressBar
36+ objectName: "progressBar"
37+ value: 0
38+ maximumValue: 100
39+ implicitHeight: units.gu(5)
40+ height: parent.height
41+ width: parent.width
42+
43+ property var source: widgetData["source"]
44+ // TODO Eventually we will need to support more sources other
45+ // than DownloadTracker via dbus so we'll need a Loader based on source contents
46+
47+ DownloadTracker {
48+ service: progressBar.source["dbus-name"] || ""
49+ dbusPath: progressBar.source["dbus-object"] || ""
50+
51+ onProgress: {
52+ if (total <= 0) {
53+ progressBar.indeterminate = true;
54+ } else {
55+ progressBar.indeterminate = false;
56+ var percentage = parseInt(received * 100 / total);
57+ progressBar.value = percentage;
58+ }
59+ }
60+
61+ onFinished: {
62+ root.triggered(widgetId, "finished", widgetData)
63+ }
64+
65+ onError: {
66+ root.triggered(widgetId, "failed", widgetData)
67+ }
68+ }
69+ }
70+}
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+1
@@ -61,6 +61,7 @@ add_qml_test(Dash/Previews PreviewActions IMPORT_PATHS ${qmltest_DEFAULT_IMPORT_
6161add_qml_test(Dash/Previews PreviewAudioPlayback 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)
6363add_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)
6465add_qml_test(Dash/Previews PreviewTextSummary IMPORT_PATHS ${qmltest_DEFAULT_IMPORT_PATHS} ${CMAKE_BINARY_DIR}/tests/mocks)
6566add_qml_test(Dash/Previews PreviewVideoPlayback IMPORT_PATHS ${qmltest_DEFAULT_IMPORT_PATHS} ${CMAKE_BINARY_DIR}/tests/mocks)
6667add_qml_test(Dash/Previews PreviewZoomableImage IMPORT_PATHS ${qmltest_DEFAULT_IMPORT_PATHS} ${CMAKE_BINARY_DIR}/tests/mocks)
tests/qmltests/Dash/Previews/tst_PreviewProgress.qmlnew file+87
@@ -0,0 +1,87 @@
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: "PreviewProgressTest"
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+ spy.clear();
78+
79+ previewProgress.widgetData = progressjsonError;
80+ compare(spy.count, 1);
81+ var args = spy.signalArguments[0];
82+ compare(args[0], "previewProgress");
83+ compare(args[1], "failed");
84+ compare(args[2], progressjsonError);
85+ }
86+ }
87+}
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 ];