How to use Ubuntu SDK downloadmanager to download multiple files at the same time

Source: Internet
Author: User
Tags file url git clone

In the previous article, "How to use Download Manager in the Ubuntu SDK to download files," We've covered how to use Singledownload to download a file. In this article, we'll show you how to use Downloadmanager to download multiple files at the same time.


We can create a simple ' QML App with Easy UI (qmlproject) ' project in the same way. A specific description of the API for Downloadmanager can be specific to an article. This is no longer a statement of exhaustion. We can declare an example of a downloadmanager:


        Downloadmanager {            Id:manager            ondownloadschanged: {                Console.log ("Something is changed!");                var length = downloads.length;                Console.log ("Length:" + length);                for (var i = 0; i < length; i + +) {                    downloads[i].finished.connect (onfinished);                }                function onfinished (path) {                    Console.log ("path:" + path);                    Mymodel.append ({"FileName": Path})}}}        

Remember to add the following libraries:


Import Ubuntu.downloadmanager 0.1

Here, in order to get the information of the downloaded file, we capture the signal "ondownloadschanged" and make a dynamic signal/slot binding to it:


                for (var i = 0; i < length; i + +) {                    downloads[i].finished.connect (onfinished);                }


So we can get the downloaded file. There is nothing special about the others. This is to understand that each of the downloads is singledownload. It's not hard to understand.


We have modified our main.qml as follows:


Import QtQuick 2.0import ubuntu.components 1.1import ubuntu.downloadmanager 0.1/*! \brief MainView with a Label and Button Elements.*/mainview {//ObjectName for functional testing purposes (autopilot- QT5) ObjectName: "MainView"//note!    ApplicationName needs to match the "name" field of the click Manifest ApplicationName: "Downloadmanager.liu-xiao-guo" /* The enables the application to change orientation when the device is rotated.    The default is False.    *///automaticorientation:true//Removes the old toolbar and enables new features of the new header. Usedeprecatedtoolbar:false width:units.gu (height:units.gu) page {title:i18n.tr ("Download manag ER ") listmodel {Id:mymodel} downloadmanager {Id:manager ondownl                Oadschanged: {Console.log ("Something is changed!");                var length = Downloads.length; Console.log ("LenGth: "+ Length";                for (var i = 0; i < length; i + +) {downloads[i].finished.connect (onfinished);                    } function onfinished (path) {Console.log ("path:" + path);            Mymodel.append ({"FileName": Path})}}} TextField {Id:text Placeholdertext: "File URL to download ..." Height:units.gu (5) Anchors {left:p Arent.left right:button.left RightMargin:units.gu (2)} text: "http:/ /img0.bdstatic.com/img/image/6446027056db8afa73b23eaf953dadde1410240902.jpg "} button {Id:butto N Text: "Download" height:50 anchors.top:text.top Anchors.bottom:text.botto        M anchors.right:parent.right anchors.verticalCenter:text.verticalCenter onclicked: {        Manager.download (Text.text); }} ListView {id:list clip:true anchors {left:parent.le            FT right:parent.right Top:text.bottom} height:units.gu (20) Model:manager.downloads Delegate:progressbar {width:parent.width MINIMUMV            alue:0 maximumvalue:100 Value:modelData.progress}} GridView {            Id:pics clip:true Anchors.bottom:parent.bottom Anchors.left:parent.left Anchors.right:parent.right Anchors.top:list.bottom Model:mymodel Cellwidth:p ICS.WIDTH/4; Cellheight:cellwidth + units.gu (2) delegate:image {WIDTH:PARENT.WIDTH/4 hei Ght:width + units.gu (2) Source:filename Fillmode:imaGe. Preserveaspectfit}}}}


Run the app, shown as:




We can modify the link address of the download, or you can press the download button directly. Each time a new download is generated. Let's show the pictures.


All source code in: Git clone https://gitcafe.com/ubuntu/downloadmanager.git



How to use Ubuntu SDK downloadmanager to download multiple files at the same time

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.