~mterry/podbird/ok

« back to all changes in this revision

Viewing changes to app/podbird.qml

  • Committer: Nekhelesh Ramananthan
  • Date: 2016-03-16 21:44:13 UTC
  • mfrom: (131.2.9 add-download-manager)
  • Revision ID: krnekhelesh@gmail.com-20160316214413-nldnwxzifd93q3cw
- Migrated to DownloadManager to support truly multiple downloads while app is suspended.
- Integrated with the files indicator.
- Added "Downloads in Progress" to the Downloads view to keep track of all episodes that are being downloaded.

Show diffs side-by-side

added added

removed removed

Lines of Context:
18
18
 
19
19
import QtQuick 2.4
20
20
import Podbird 1.0
21
 
import UserMetrics 0.1
22
21
import QtMultimedia 5.6
23
22
import Ubuntu.Connectivity 1.0
24
23
import Qt.labs.settings 1.0
25
24
import Ubuntu.Components 1.3
26
25
import QtQuick.LocalStorage 2.0
27
 
import Ubuntu.DownloadManager 0.1
 
26
import Ubuntu.DownloadManager 1.2
28
27
import "ui"
29
28
import "themes" as Themes
30
29
import "podcasts.js" as Podcasts
45
44
 
46
45
    Component.onDestruction: {
47
46
        console.log("[LOG]: Download cancelled");
48
 
        downloader.cancel();
49
47
        var db = Podcasts.init()
50
48
        db.transaction(function (tx) {
51
49
            tx.executeSql('UPDATE Episode SET queued=0 WHERE queued=1');
139
137
        }
140
138
    }
141
139
 
142
 
    SingleDownload {
 
140
    Component {
 
141
        id: singleDownloadComponent
 
142
        SingleDownload {
 
143
            id: singleDownloadObject
 
144
            property string image
 
145
            property string title
 
146
            property string guid
 
147
            metadata: Metadata {
 
148
                showInIndicator: true
 
149
                title: singleDownloadObject.title
 
150
            }
 
151
        }
 
152
    }
 
153
 
 
154
    function downloadEpisode(image, title, guid, url) {
 
155
        var singleDownload = singleDownloadComponent.createObject(podbird, {"image": image, "title": title, "guid": guid})
 
156
        singleDownload.download(url)
 
157
    }
 
158
 
 
159
    DownloadManager {
143
160
        id: downloader
144
 
        property var queue: []
145
 
        property string downloadingGuid
146
 
 
147
 
        onFinished: {
 
161
 
 
162
        property string downloadingGuid: downloads.length > 0 ? downloads[0].guid : "NULL"
 
163
        property int progress: downloads.length > 0 ? downloads[0].progress : 0
 
164
 
 
165
        cleanDownloads: true
 
166
        onDownloadFinished: {
148
167
            var db = Podcasts.init();
149
168
            var finalLocation = fileManager.saveDownload(path);
150
169
            db.transaction(function (tx) {
151
 
                tx.executeSql("UPDATE Episode SET downloadedfile=?, queued=0 WHERE guid=?", [finalLocation, downloadingGuid]);
152
 
                queue.shift();
153
 
                if (queue.length > 0) {
154
 
                    downloadingGuid = queue[0][0];
155
 
                    download(queue[0][1]);
156
 
                } else {
157
 
                    downloadingGuid = "";
158
 
                }
 
170
                tx.executeSql("UPDATE Episode SET downloadedfile=?, queued=0 WHERE guid=?", [finalLocation, download.guid]);
159
171
            });
160
172
        }
161
173
 
162
 
        function addDownload(guid, url) {
163
 
            queue.push([guid, url]);
164
 
            if (queue.length == 1) {
165
 
                downloadingGuid = guid;
166
 
                download(url);
167
 
            }
 
174
        onErrorFound: {
 
175
            console.log("[ERROR]: " + download.errorMessage)
168
176
        }
169
177
    }
170
178