62554a6501ab9ce5dba0b7d7a35d439fec1894b8
[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     /*Rectangle {
11         anchors.fill: parent
12         color: "red"
13     }*/
14
15     height: taskView.height+Const.DEFAULT_MARGIN
16
17     function addTask(type,filename)
18     {
19         //emptyLabel.visible = Utils.emptyQuee();
20         //emptyLabel.visible = false;
21         //console.log("1. taskView.childrens.length: "+taskView.children.length);
22         //console.log("1. taskView.height: "+taskView.height);
23         var comp = Qt.createComponent("components/Bar.qml");
24         //var obj = comp.createObject(taskView,{"width": root.width});
25         var obj = comp.createObject(taskView);
26         if (obj==null) {
27             console.log("Error creating object");
28         } else {
29             root.count++;
30             //obj.width = root.width
31             obj.label = filename;
32             obj.cancel.connect(function(file) {
33                                    Utils.cancelFile(file);
34                                 });
35             if(type=="download")
36                 obj.isDownload = true;
37             if(type=="upload")
38                 obj.isUpload = true;
39         }
40         //console.log("2. taskView.childrens.length: "+taskView.children.length);
41         //console.log("2. taskView.height: "+taskView.height);
42     }
43
44     function setProgress(filename, progress)
45     {
46         var l = taskView.children.length;
47         for(var i=0;i<l;++i) {
48             var item = taskView.children[i];
49             if(item && item.label==filename) {
50                 item.setProgres(progress);
51                 return;
52             }
53         }
54     }
55
56     function start(filename)
57     {
58         var l = taskView.children.length;
59         for(var i=0;i<l;++i) {
60             var item = taskView.children[i];
61             if(item && item.label==filename) {
62                 item.start();
63                 return;
64             }
65         }
66     }
67
68     function stop(filename)
69     {
70         //console.log("stop task");
71         //console.log("3. taskView.childrens.length: "+taskView.children.length);
72         var l = taskView.children.length;
73         for(var i=0;i<l;++i) {
74             var item = taskView.children[i];
75             if(item && item.label==filename) {
76                 //console.log("stop task 2");
77                 item.destroy();
78                 root.count--;
79                 return;
80             }
81         }
82         //console.log("4. taskView.childrens.length: "+taskView.children.length);
83         //emptyLabel.visible = Utils.emptyQuee();
84     }
85
86     Column {
87         id: taskView
88         width: parent.width
89         spacing: Const.DEFAULT_MARGIN
90
91         //onHeightChanged: console.log("takView.height: "+height)
92
93         Text {
94             font.pixelSize: Const.DEFAULT_FONT_PIXEL_SIZE
95             color: Const.DEFAULT_FOREGROUND_COLOR
96             width: parent.width
97             wrapMode: Text.WordWrap
98             text: root.count==0 ?
99                       qsTr("No active downloads or uploads") :
100                       qsTr("Active downloads and uploads")
101             anchors.bottomMargin: 2*Const.DEFAULT_MARGIN
102             visible: root.count==0
103         }
104     }
105 }