on 436b607 help sign in
unity8/qml/Dash/Previews/PreviewProgress.qml
71 lines 2.3 kB history raw
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 */
17import QtQuick 2.1
18import Ubuntu.Components 0.1
19import Ubuntu.DownloadDaemonListener 0.1
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 */
28PreviewWidget {
29 id: root
31 implicitHeight: progressBar.implicitHeight
32 implicitWidth: progressBar.implicitWidth
34 ProgressBar {
35 id: progressBar
36 objectName: "progressBar"
37 anchors.right: parent.right
38 value: 0
39 maximumValue: 100
40 implicitHeight: units.gu(4)
41 height: parent.height
42 width: (root.width - units.gu(1)) / 2
44 property var source: widgetData["source"]
45 // TODO Eventually we will need to support more sources other
46 // than DownloadTracker via dbus so we'll need a Loader based on source contents
48 DownloadTracker {
49 service: progressBar.source["dbus-name"] || ""
50 dbusPath: progressBar.source["dbus-object"] || ""
52 onProgress: {
53 if (total <= 0) {
54 progressBar.indeterminate = true;
55 } else {
56 progressBar.indeterminate = false;
57 var percentage = parseInt(received * 100 / total);
58 progressBar.value = percentage;
59 }
60 }
62 onFinished: {
63 root.triggered(widgetId, "finished", widgetData)
64 }
66 onError: {
67 root.triggered(widgetId, "failed", widgetData)
68 }
69 }
70 }