From 8aab9adb4d9e0b4d669e44824d2e193f7278d480 Mon Sep 17 00:00:00 2001 From: Jeena Date: Wed, 10 Feb 2016 19:54:53 +0100 Subject: [PATCH] Implement OPML import in the desktop and touch ui The core has already implemented parsing OPML files from URLs and files, it only needs to be exposed by the UI which this parch does. --- desktop/dialogs/AddPodcastDialog.qml | 2 ++ desktop/gpodder.qml | 13 +++++++++++++ main.py | 17 +++++++++++++++++ touch/PodcastsPage.qml | 14 ++++++++++++++ 4 files changed, 46 insertions(+) diff --git a/desktop/dialogs/AddPodcastDialog.qml b/desktop/dialogs/AddPodcastDialog.qml index 88defa1..9a2d199 100644 --- a/desktop/dialogs/AddPodcastDialog.qml +++ b/desktop/dialogs/AddPodcastDialog.qml @@ -7,6 +7,7 @@ import '../common' import '../common/util.js' as Util Dialog { + property alias labelText: urlEntyLabel.text signal addUrl(string url) width: 300 @@ -18,6 +19,7 @@ Dialog { anchors.fill: parent Label { + id: urlEntyLabel text: 'URL:' } diff --git a/desktop/gpodder.qml b/desktop/gpodder.qml index 54a822e..7d4dec7 100644 --- a/desktop/gpodder.qml +++ b/desktop/gpodder.qml @@ -54,6 +54,19 @@ ApplicationWindow { } } + MenuItem { + text: 'Add from OPML' + onTriggered: { + openDialog('dialogs/AddPodcastDialog.qml', function(dialog) { + dialog.title = "Add from OPML" + dialog.labelText = "OPML URL:" + dialog.addUrl.connect(function (url) { + py.call('main.import_opml', [url]); + }) + }) + } + } + MenuItem { text: 'Quit' onTriggered: Qt.quit() diff --git a/main.py b/main.py index f7ec09e..3af1676 100644 --- a/main.py +++ b/main.py @@ -32,6 +32,7 @@ from gpodder.api import core from gpodder.api import util from gpodder.api import query from gpodder.api import registry +from gpodder import opml import logging import functools @@ -221,6 +222,21 @@ class gPotherSide: summary.sort(key=lambda e: e['newEpisodes'], reverse=True) return summary[:int(count)] + @run_in_background_thread + def import_opml(self, url): + """Import subscriptions from an OPML file + + import http://example.com/subscriptions.opml + + Import subscriptions from the given URL + + import ./feeds.opml + + Import subscriptions from a local file + """ + for channel in opml.Importer(url).items: + self.subscribe(channel['url']) + @run_in_background_thread def subscribe(self, url): url = self.core.model.normalize_feed_url(url) @@ -545,6 +561,7 @@ load_podcasts = gpotherside.load_podcasts load_episodes = gpotherside.load_episodes show_episode = gpotherside.show_episode play_episode = gpotherside.play_episode +import_opml = gpotherside.import_opml subscribe = gpotherside.subscribe unsubscribe = gpotherside.unsubscribe check_for_episodes = gpotherside.check_for_episodes diff --git a/touch/PodcastsPage.qml b/touch/PodcastsPage.qml index 882252b..6cdab93 100644 --- a/touch/PodcastsPage.qml +++ b/touch/PodcastsPage.qml @@ -66,6 +66,20 @@ SlidePage { }); }, }, + { + label: 'Add from OPML', + callback: function () { + var ctx = { py: py }; + pgst.loadPage('TextInputDialog.qml', { + buttonText: 'Subscribe', + placeholderText: 'OPML URL', + pasteOnLoad: true, + callback: function (url) { + ctx.py.call('main.import_opml', [url]); + } + }); + }, + }, { label: 'Discover new podcasts', callback: function () {