0.9.3-1 release
[ubi] / qml / ubi / DownloadArea.qml
1 import QtQuick 1.0 // to target S60 5th Edition or Maemo 5
2 import "components"
3 import "UIConstants.js" as Const
4
5 Item {
6     id: root
7
8     property int count: 0
9
10     height: taskView.height+Const.DEFAULT_MARGIN
11
12     function addTask(type,filename)
13     {
14         var comp = Qt.createComponent("components/Bar.qml");
15         //var obj = comp.createObject(taskView,{"width": root.width});
16         var obj = comp.createObject(taskView);
17         if (obj==null) {
18             console.log("Error creating object");
19         } else {
20             root.count++;
21             //obj.width = root.width
22             obj.label = filename;
23             obj.cancel.connect(function(file) {
24                                    Utils.cancelFile(file);
25                                 });
26             if(type=="download")
27                 obj.isDownload = true;
28             if(type=="upload")
29                 obj.isUpload = true;
30         }
31     }
32
33     function setProgress(filename, progress)
34     {
35         var l = taskView.children.length;
36         for(var i=0;i<l;++i) {
37             var item = taskView.children[i];
38             if(item && item.label==filename) {
39                 item.setProgres(progress);
40                 return;
41             }
42         }
43     }
44
45     function start(filename)
46     {
47         var l = taskView.children.length;
48         for(var i=0;i<l;++i) {
49             var item = taskView.children[i];
50             if(item && item.label==filename) {
51                 item.start();
52                 return;
53             }
54         }
55     }
56
57     function stop(filename)
58     {
59         var l = taskView.children.length;
60         for(var i=0;i<l;++i) {
61             var item = taskView.children[i];
62             if(item && item.label==filename) {
63                 //console.log("stop task 2");
64                 item.destroy();
65                 root.count--;
66                 return;
67             }
68         }
69     }
70
71     Column {
72         id: taskView
73         width: parent.width
74         spacing: Const.DEFAULT_MARGIN
75
76         Text {
77             font.pixelSize: Const.DEFAULT_FONT_PIXEL_SIZE
78             color: Const.DEFAULT_FOREGROUND_COLOR
79             width: parent.width
80             wrapMode: Text.WordWrap
81             text: root.count==0 ?
82                       qsTr("No active downloads or uploads") :
83                       qsTr("Active downloads and uploads")
84             anchors.bottomMargin: 2*Const.DEFAULT_MARGIN
85             visible: root.count==0
86         }
87     }
88 }