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.
This commit is contained in:
Jeena 2016-02-10 19:54:53 +01:00
parent 1386245b50
commit 8aab9adb4d
4 changed files with 46 additions and 0 deletions

View file

@ -7,6 +7,7 @@ import '../common'
import '../common/util.js' as Util import '../common/util.js' as Util
Dialog { Dialog {
property alias labelText: urlEntyLabel.text
signal addUrl(string url) signal addUrl(string url)
width: 300 width: 300
@ -18,6 +19,7 @@ Dialog {
anchors.fill: parent anchors.fill: parent
Label { Label {
id: urlEntyLabel
text: 'URL:' text: 'URL:'
} }

View file

@ -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 { MenuItem {
text: 'Quit' text: 'Quit'
onTriggered: Qt.quit() onTriggered: Qt.quit()

17
main.py
View file

@ -32,6 +32,7 @@ from gpodder.api import core
from gpodder.api import util from gpodder.api import util
from gpodder.api import query from gpodder.api import query
from gpodder.api import registry from gpodder.api import registry
from gpodder import opml
import logging import logging
import functools import functools
@ -221,6 +222,21 @@ class gPotherSide:
summary.sort(key=lambda e: e['newEpisodes'], reverse=True) summary.sort(key=lambda e: e['newEpisodes'], reverse=True)
return summary[:int(count)] 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 @run_in_background_thread
def subscribe(self, url): def subscribe(self, url):
url = self.core.model.normalize_feed_url(url) url = self.core.model.normalize_feed_url(url)
@ -545,6 +561,7 @@ load_podcasts = gpotherside.load_podcasts
load_episodes = gpotherside.load_episodes load_episodes = gpotherside.load_episodes
show_episode = gpotherside.show_episode show_episode = gpotherside.show_episode
play_episode = gpotherside.play_episode play_episode = gpotherside.play_episode
import_opml = gpotherside.import_opml
subscribe = gpotherside.subscribe subscribe = gpotherside.subscribe
unsubscribe = gpotherside.unsubscribe unsubscribe = gpotherside.unsubscribe
check_for_episodes = gpotherside.check_for_episodes check_for_episodes = gpotherside.check_for_episodes

View file

@ -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', label: 'Discover new podcasts',
callback: function () { callback: function () {