@@ -19,7 +19,9 @@
1919import QtQuick 2.4
2020import Ubuntu.Components 1.3
2121import QtQuick.LocalStorage 2.0
22+import QtQuick.XmlListModel 2.0
2223import Ubuntu.Components.Popups 1.3
24+import Ubuntu.Content 1.3
2325import "../podcasts.js" as Podcasts
2426import "../components"
2527
@@ -66,6 +68,17 @@ Page {
6668 searchPage.header = addHeader
6769 feedUrlField.item.forceActiveFocus()
6870 }
71+ },
72+ Action {
73+ text:i18n.tr("Import Podcasts")
74+ iconName: "import"
75+ onTriggered: {
76+ var importPage = mainStack.push(Qt.resolvedUrl("ImportPage.qml"),{"contentType": ContentType.Unknown, "handler": ContentHandler.Source})
77+ importPage.imported.connect(function(fileUrl) {
78+ mainStack.pop()
79+ parseOPML(fileUrl)
80+ })
81+ }
6982 }
7083 ]
7184 }
@@ -123,6 +136,7 @@ Page {
123136 onTriggered: {
124137 resultsView.forceActiveFocus()
125138 subscribeFromFeed(feedUrlField.item.text);
139+ tabs.selectedTabIndex = 2;
126140 }
127141 },
128142 Action {
@@ -150,6 +164,7 @@ Page {
150164 onAccepted: {
151165 resultsView.forceActiveFocus()
152166 subscribeFromFeed(feedUrlField.text);
167+ tabs.selectedTabIndex = 2;
153168 }
154169 }
155170 }
@@ -292,7 +307,6 @@ Page {
292307 }
293308 });
294309 }
295− tabs.selectedTabIndex = 2;
296310 }
297311 }
298312 }
@@ -412,6 +426,8 @@ Page {
412426 var artist = "";
413427 var image = "";
414428 if (xhr.readyState === XMLHttpRequest.DONE) {
429+ if(loadingDialog.visible)
430+ progressBar.value++
415431 if (xhr.status < 200 || xhr.status > 299 || xhr.responseXML === null) {
416432 PopupUtils.open(subscribeFailedDialog);
417433 searchPage.header = addHeader
@@ -440,7 +456,6 @@ Page {
440456 if(name != "") {
441457 Podcasts.subscribe(artist, name, feed, image);
442458 imageDownloader.addDownload(feed, image)
443− tabs.selectedTabIndex = 2;
444459 } else {
445460 PopupUtils.open(subscribeFailedDialog);
446461 searchPage.header = addHeader
@@ -451,4 +466,56 @@ Page {
451466 }
452467 xhr.send();
453468 }
469+
470+ function parseOPML(fileUrl) {
471+ opmlModel.source = fileUrl;
472+ opmlModel.reload()
473+ }
474+
475+ XmlListModel {
476+ id:opmlModel
477+
478+ query: "/opml/body/outline"
479+ XmlRole { name: "text"; query: "@text/string()" }
480+ XmlRole { name: "type"; query: "@type/string()" }
481+ XmlRole { name: "xmlUrl"; query: "@xmlUrl/string()" }
482+
483+ onRowsInserted: {
484+ progressBar.minimumValue = first
485+ progressBar.maximumValue = last
486+ progressBar.value = first
487+ loadingDialog.show()
488+ for(var i=first;i<=last;i++){
489+ subscribeFromFeed(opmlModel.get(i).xmlUrl)
490+ }
491+ }
492+ }
493+
494+ Dialog {
495+ id: loadingDialog
496+
497+ modal: true;
498+ title: i18n.tr("Please wait!")
499+ text: i18n.tr("Importing podcasts.")
500+
501+ ActivityIndicator {
502+ running: true
503+ }
504+
505+ ProgressBar {
506+ id:progressBar
507+
508+ onValueChanged: {
509+ if(value > maximumValue) {
510+ PopupUtils.close(loadingDialog)
511+ tabs.selectedTabIndex = 2;
512+ }
513+ }
514+ }
515+
516+ Label {
517+ text: progressBar.value + "/" + (progressBar.maximumValue+1) + " " + i18n.tr("imported")
518+ horizontalAlignment: Text.AlignHCenter
519+ }
520+ }
454521}