# SingleDownload QML Type

Manage file downloads and tracking the progress. More...

Import Statement: | import Lomiri.DownloadManager 1.2

- List of all members, including inherited members

## Properties

- algorithm : string
- allowMobileDownload : bool
- autoStart : bool
- downloadId : string
- downloadInProgress : bool
- downloading : bool
- errorMessage : string
- hash : string
- headers : QVariantMap
- isCompleted : bool
- metadata : Metadata
- progress : int
- throttle : long

## Signals

- finished(QString path)

## Methods

- void cancel()
- void download(string url)
- void pause()
- void resume()
- void start()

## Detailed Description

SingleDownload provides facilities for downloading a single file, track the process, react to error conditions, etc.

Example usage:

    import QtQuick 2.0
    import Lomiri.Components 1.2
    import Lomiri.DownloadManager 1.2

    Rectangle {
        width: units.gu(100)
        height: units.gu(20)

        TextField {
            id: text
            placeholderText: "File URL to download..."
            height: 50
            anchors {
                left: parent.left
                right: button.left
                rightMargin: units.gu(2)
            }
        }

        Button {
            id: button
            text: "Download"
            height: 50
            anchors.right: parent.right

            onClicked: {
                single.download(text.text);
            }
        }

        ProgressBar {
            minimumValue: 0
            maximumValue: 100
            value: single.progress
            anchors {
                left: parent.left
                right: parent.right
                bottom: parent.bottom
            }

            SingleDownload {
                id: single
            }
        }
    }

See also DownloadManager.

## Property Documentation

algorithm : string

This property indicates the algorithm to use when verifying a hash. The algorithm can be of one of the following string values:

- "md5" - "sha1" - "sha224" - "sha256" - "sha384" - "sha512"

If no value is specified md5 will be used. If used, this should be set prior to calling the download() method.

This property was introduced in Lomiri.DownloadManager 1.3.

allowMobileDownload : bool

This property sets if the download handled by this object will work under mobile data connection.

autoStart : bool

This property sets if the downloads should start automatically, or let the user decide when to start them calling the "start()" method.

downloadId : string

This property provides the unique identifier that represents the download within the download manager.

downloadInProgress : bool

This property represents if the download is active, no matter if it's paused or anything. If a download is active, the value will be True. It will become False when the download finished or get canceled.

downloading : bool

This property represents the current state of the download. False if paused or not downloading anything. True if the file is currently being downloaded.

errorMessage : string

The error message associated with the current download, if there is any.

hash : string

This property specifies a hash to check against the downloaded file. If used, this should be set prior to calling the download() method.

This property was introduced in Lomiri.DownloadManager 1.3.

headers : QVariantMap

This property allows to get and set the headers that will be used to perform the download request. All headers must be strings or at least QVariant should be able to convert them to strings.

isCompleted : bool

The current state of the download. True if the download already finished, False otherwise.

metadata : Metadata

This property allows to get and set the metadata that will be linked to the download request.

progress : int

This property reports the current progress in percentage of the download, from 0 to 100.

throttle : long

This property can be used to limit the bandwidth used for the download.

## Signal Documentation

finished(QString path)

This signal is emitted when a download has finished. The downloaded file path is provided via the 'path' paremeter. The corresponding handler is `onFinished`

Note: The corresponding handler is `onFinished`.

## Method Documentation

void cancel()

Cancels a download.

void download(string url)

Creates the download for the given url and reports the different states through the properties.

void pause()

Pauses the download. An error is returned if the download was already paused.

void resume()

Resumes and already paused download. An error is returned if the download was already resumed or not paused.

void start()

Starts the download, used when autoStart is False.