~mterry/podbird/ok

« back to all changes in this revision

Viewing changes to app/ui/EpisodesTab.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:
20
20
import QtMultimedia 5.6
21
21
import Ubuntu.Components 1.3
22
22
import QtQuick.LocalStorage 2.0
23
 
import Ubuntu.DownloadManager 0.1
 
23
import Ubuntu.DownloadManager 1.2
24
24
import Ubuntu.Components.Popups 1.3
25
25
import "../podcasts.js" as Podcasts
26
26
import "../components"
83
83
 
84
84
                Action {
85
85
                    iconName: "save"
86
 
                    visible: episodesPageHeaderSections.selectedIndex === 0
 
86
                    visible: episodesPageHeaderSections.selectedIndex !== 1
87
87
                    text: i18n.tr("Download all")
88
88
                    onTriggered: {
89
89
                        var db = Podcasts.init();
92
92
                                if (!episodesModel.get(i).downloadedfile) {
93
93
                                    episodesModel.setProperty(i, "queued", 1)
94
94
                                    tx.executeSql("UPDATE Episode SET queued=1 WHERE guid = ?", [episodesModel.get(i).guid]);
95
 
                                    downloader.addDownload(episodesModel.get(i).guid, episodesModel.get(i).audiourl);
 
95
                                    if (episodesModel.get(i).audiourl) {
 
96
                                        podbird.downloadEpisode(episodesModel.get(i).image, episodesModel.get(i).name, episodesModel.get(i).guid, episodesModel.get(i).audiourl)
 
97
                                    } else {
 
98
                                        console.log("[ERROR]: Invalid download url: " + episodesModel.get(i).audiourl)
 
99
                                    }
96
100
                                }
97
101
                            }
98
102
                        });
131
135
                    selectedSectionColor: podbird.appTheme.focusText
132
136
                }
133
137
 
134
 
                model: [i18n.tr("Recent"), i18n.tr("Downloaded"), i18n.tr("Favourites")]
 
138
                model: [i18n.tr("Recent"), i18n.tr("Downloads"), i18n.tr("Favourites")]
135
139
                onSelectedIndexChanged: {
136
140
                    refreshModel();
137
141
                }
184
188
                verticalCenterOffset: Qt.inputMethod.visible ? units.gu(4) : 0
185
189
            }
186
190
 
187
 
            sourceComponent: episodesModel.count === 0 || sortedEpisodeModel.count === 0 ? emptyStateComponent : undefined
 
191
            sourceComponent: (episodesModel.count === 0 || sortedEpisodeModel.count === 0) && downloader.downloads.length === 0 ? emptyStateComponent : undefined
188
192
        }
189
193
 
190
194
        Component {
332
336
 
333
337
            clip: true
334
338
            model: sortedEpisodeModel
 
339
 
 
340
            header: Column {
 
341
                width: episodeList.width
 
342
                visible: height !== 0
 
343
                height: downloader.downloads.length > 0 && episodesPageHeaderSections.selectedIndex === 1 ? childrenRect.height : 0
 
344
 
 
345
                HeaderListItem {
 
346
                    title.text: i18n.tr("Downloads in progress")
 
347
                }
 
348
 
 
349
                Repeater {
 
350
                    model: downloader.downloads
 
351
                    delegate: ListItem {
 
352
                        divider.visible: false
 
353
                        height: inProgressLayout.height
 
354
                        SlotsLayout {
 
355
                            id: inProgressLayout
 
356
 
 
357
                            Image {
 
358
                                height: width
 
359
                                width: units.gu(6)
 
360
                                source: modelData.image !== undefined ? modelData.image : Qt.resolvedUrl("../graphics/podbird.png")
 
361
                                SlotsLayout.position: SlotsLayout.Leading
 
362
                                sourceSize { width: width; height: height }
 
363
                            }
 
364
 
 
365
                            mainSlot: Column {
 
366
                                spacing: units.gu(0.5)
 
367
 
 
368
                                Label {
 
369
                                    text: modelData.title
 
370
                                    width: parent.width
 
371
                                    elide: Text.ElideRight
 
372
                                }
 
373
 
 
374
                                CustomProgressBar {
 
375
                                    width: parent.width
 
376
                                    height: modelData.progress > 0 ? units.dp(5) : 0
 
377
                                    progress: modelData.progress
 
378
                                    indeterminateProgress: modelData.progress < 0 || modelData.progress > 100
 
379
                                }
 
380
                            }
 
381
                        }
 
382
                    }
 
383
                }
 
384
 
 
385
                HeaderListItem {
 
386
                    title.text: i18n.tr("Downloaded episodes")
 
387
                    visible: sortedEpisodeModel.count !== 0 || episodesModel.count !== 0
 
388
                }
 
389
            }
 
390
 
335
391
            section.property: "diff"
336
392
            section.labelPositioning: ViewSection.InlineLabels
337
 
 
338
393
            section.delegate: ListItem {
339
394
                height: headerText.title.text !== "" ? headerText.height + divider.height : units.gu(0)
340
395
                divider.anchors.leftMargin: units.gu(2)
439
494
                                        tx.executeSql("UPDATE Episode SET queued=1 WHERE guid = ?", [model.guid]);
440
495
                                    });
441
496
                                    episodesModel.setProperty(model.index, "queued", 1)
442
 
                                    downloader.addDownload(model.guid, model.audiourl);
 
497
                                    if (model.audiourl) {
 
498
                                        podbird.downloadEpisode(model.image, model.name, model.guid, model.audiourl)
 
499
                                    } else {
 
500
                                        console.log("[ERROR]: Invalid download url: " + model.audiourl)
 
501
                                    }
443
502
                                }
444
503
                            }
445
504
                        },