From 381c1d04ab09ff5f23ffccc7fc0ca7da238ce9d0 Mon Sep 17 00:00:00 2001 From: Thomas Perl Date: Thu, 24 Sep 2009 17:32:32 +0200 Subject: [PATCH] New menu behind the subscribe button (Maemo bug 5183) This adds the possibility to add podcasts via URL with the "Subscribe" button in the main view. --- data/ui/frmntl/gpodderpodcasts.ui | 4 - src/gpodder/gtkui/frmntl/podcastdirectory.py | 128 +++++++++++++++++++-------- src/gpodder/gtkui/frmntl/podcasts.py | 13 +-- src/gpodder/gui.py | 20 +++-- 4 files changed, 106 insertions(+), 59 deletions(-) diff --git a/data/ui/frmntl/gpodderpodcasts.ui b/data/ui/frmntl/gpodderpodcasts.ui index 265b9c10..e2d6467f 100644 --- a/data/ui/frmntl/gpodderpodcasts.ui +++ b/data/ui/frmntl/gpodderpodcasts.ui @@ -41,8 +41,4 @@ Check for new episodes - - Add podcast via URL - - diff --git a/src/gpodder/gtkui/frmntl/podcastdirectory.py b/src/gpodder/gtkui/frmntl/podcastdirectory.py index 25c5e23c..4b15254e 100644 --- a/src/gpodder/gtkui/frmntl/podcastdirectory.py +++ b/src/gpodder/gtkui/frmntl/podcastdirectory.py @@ -60,11 +60,7 @@ class gPodderPodcastDirectory(BuilderWidget): selection.set_mode(gtk.SELECTION_MULTIPLE) selection.unselect_all() self.app_menu = hildon.AppMenu() - for action in (self.action_load_toplist, \ - self.action_load_opml, \ - self.action_load_search, \ - self.action_load_youtube, \ - self.action_select_all, \ + for action in (self.action_select_all, \ self.action_select_none): button = gtk.Button() action.connect_proxy(button) @@ -86,7 +82,81 @@ class gPodderPodcastDirectory(BuilderWidget): self.main_window.fullscreen() self.main_window.show() - self.app_menu.popup(self.main_window) + @classmethod + def show_add_podcast_picker(cls, parent, toplist_url, opml_url, \ + add_urls_callback, subscribe_to_url_callback, \ + my_gpodder_callback, show_text_edit_dialog): + dialog = gtk.Dialog(_('Select a source'), parent) + pannable_area = hildon.PannableArea() + pannable_area.set_size_request_policy(hildon.SIZE_REQUEST_CHILDREN) + dialog.vbox.pack_start(pannable_area, expand=True) + vbox = gtk.VBox(spacing=1) + pannable_area.add_with_viewport(vbox) + + def load_opml_from_url(url): + if url is not None: + o = cls(parent, add_urls_callback=add_urls_callback) + o.download_opml_file(url) + + def choice_enter_feed_url(widget): + dialog.destroy() + subscribe_to_url_callback() + + def choice_load_opml_from_url(widget): + dialog.destroy() + url = show_text_edit_dialog(_('Load OPML file from the web'), \ + _('URL:'), is_url=True) + load_opml_from_url(url) + + def choice_load_examples(widget): + dialog.destroy() + load_opml_from_url(opml_url) + + def choice_load_toplist(widget): + dialog.destroy() + load_opml_from_url(toplist_url) + + def choice_search_podcast_de(widget): + dialog.destroy() + search_term = show_text_edit_dialog(_('Search podcast.de'), \ + _('Search for:')) + if search_term is not None: + url = 'http://api.podcast.de/opml/podcasts/suche/%s' % \ + (urllib.quote(search_term),) + load_opml_from_url(url) + + def choice_search_youtube(widget): + dialog.destroy() + search_term = show_text_edit_dialog(\ + _('Search YouTube user channels'), \ + _('Search for:')) + if search_term is not None: + url = 'youtube://%s' % (search_term,) + load_opml_from_url(url) + + def choice_mygpodder(widget): + dialog.destroy() + my_gpodder_callback() + + choices = ( + (_('Podcast feed/website URL'), choice_enter_feed_url), + (_('OPML file from the web'), choice_load_opml_from_url), + (_('Example podcasts'), choice_load_examples), + (_('Podcast Top 50'), choice_load_toplist), + (_('Search podcast.de'), choice_search_podcast_de), + (_('Search YouTube users'), choice_search_youtube), + (_('Download from my.gpodder.org'), choice_mygpodder), + ) + + for caption, handler in choices: + button = hildon.Button(gtk.HILDON_SIZE_AUTO_WIDTH | \ + gtk.HILDON_SIZE_FINGER_HEIGHT, \ + hildon.BUTTON_ARRANGEMENT_VERTICAL) + button.set_text(caption, '') + button.connect('clicked', handler) + vbox.pack_start(button) + + dialog.show_all() def on_treeview_expose_event(self, treeview, event): if event.window == treeview.get_bin_window(): @@ -121,31 +191,7 @@ class gPodderPodcastDirectory(BuilderWidget): return [model.get_value(model.get_iter(path), \ OpmlListModel.C_URL) for path in paths] - def on_load_opml_button_clicked(self, widget): - url = self.show_text_edit_dialog(_('Load OPML file from the web'), \ - _('URL:'), is_url=True) - if url is not None: - self.download_opml_file(url) - - def on_load_toplist_button_clicked(self, widget): - self.download_opml_file(self._config.toplist_url) - - def on_load_search_button_clicked(self, widget): - search_term = self.show_text_edit_dialog(_('Search podcast.de'), \ - _('Search for:')) - if search_term is not None: - url = 'http://api.podcast.de/opml/podcasts/suche/%s' % \ - (urllib.quote(search_term),) - self.download_opml_file(url) - - def on_load_youtube_button_clicked(self, widget): - search_term = self.show_text_edit_dialog(\ - _('Search YouTube user channels'), \ - _('Search for:')) - if search_term is not None: - self.download_opml_file(search_term, use_youtube=True) - - def download_opml_file(self, url, use_youtube=False): + def download_opml_file(self, url): selection = self.treeview.get_selection() selection.unselect_all() self.treeview.set_model(None) @@ -154,8 +200,9 @@ class gPodderPodcastDirectory(BuilderWidget): hildon.hildon_gtk_window_set_progress_indicator(self.main_window, True) def download_thread_func(): - if use_youtube: - importer = youtube.find_youtube_channels(url) + if url.startswith('youtube://'): + importer = youtube.find_youtube_channels(\ + url[len('youtube://'):]) else: importer = opml.Importer(url) @@ -178,7 +225,7 @@ class gPodderPodcastDirectory(BuilderWidget): if model is None: self.show_message(_('No podcasts found. Try another source.'), \ important=True) - self.app_menu.popup(self.main_window) + self.main_window.destroy() util.idle_add(download_thread_finished) @@ -194,12 +241,15 @@ class gPodderPodcastDirectory(BuilderWidget): def set_subscribe_button_sensitive(self): selection = self.treeview.get_selection() - count = selection.count_selected_rows() title = self.main_window.get_title() - if count == 1: - title += ' - %s' % (_('1 podcast selected'),) - elif count > 1: - title += ' - %s' % (_('%d podcasts selected') % count,) + if selection: + count = selection.count_selected_rows() + if count == 1: + title += ' - %s' % (_('1 podcast selected'),) + elif count > 1: + title += ' - %s' % (_('%d podcasts selected') % count,) + else: + count = 0 self.edit_toolbar.set_label(title) self.edit_toolbar.set_button_sensitive(count > 0) diff --git a/src/gpodder/gtkui/frmntl/podcasts.py b/src/gpodder/gtkui/frmntl/podcasts.py index 1487cd46..821169f3 100644 --- a/src/gpodder/gtkui/frmntl/podcasts.py +++ b/src/gpodder/gtkui/frmntl/podcasts.py @@ -32,11 +32,10 @@ from gpodder.gtkui.model import PodcastListModel class gPodderPodcasts(BuilderWidget): def new(self): appmenu = hildon.AppMenu() - for action in (self.action_update_feeds, \ - self.action_subscribe): - button = gtk.Button() - action.connect_proxy(button) - appmenu.append(button) + #for action in (self.action_update_feeds,): + # button = gtk.Button() + # action.connect_proxy(button) + # appmenu.append(button) for filter in (self.item_view_podcasts_all, \ self.item_view_podcasts_downloaded, \ self.item_view_podcasts_unplayed): @@ -50,10 +49,6 @@ class gPodderPodcasts(BuilderWidget): self.main_window.hide() util.idle_add(self.on_itemUpdate_activate, button) - def on_subscribe_button_clicked(self, button): - self.main_window.hide() - util.idle_add(self.on_itemAddChannel_activate, button) - def on_podcast_selected(self, treeview, path, column): model = treeview.get_model() channel = model.get_value(model.get_iter(path), \ diff --git a/src/gpodder/gui.py b/src/gpodder/gui.py index bf0c67bf..0f8219a5 100644 --- a/src/gpodder/gui.py +++ b/src/gpodder/gui.py @@ -159,7 +159,6 @@ class gPodder(BuilderWidget, dbus.service.Object): appmenu = hildon.AppMenu() for action in (self.itemUpdate, \ - self.itemAddChannel, \ self.itemRemoveOldEpisodes, \ self.itemAbout): button = gtk.Button() @@ -265,7 +264,6 @@ class gPodder(BuilderWidget, dbus.service.Object): self.podcasts_window = gPodderPodcasts(self.main_window, \ show_podcast_episodes=on_podcast_selected, \ on_treeview_expose_event=self.on_treeview_expose_event, \ - on_itemAddChannel_activate=self.on_itemAddChannel_activate, \ on_itemUpdate_activate=self.on_itemUpdate_activate, \ item_view_podcasts_all=self.item_view_podcasts_all, \ item_view_podcasts_downloaded=self.item_view_podcasts_downloaded, \ @@ -2524,7 +2522,7 @@ class gPodder(BuilderWidget, dbus.service.Object): if self.show_confirmation(_('gPodder can automatically upload your subscription list to my.gpodder.org when you close it. Do you want to enable this feature?'), _('Upload subscriptions on quit')): self.config.my_gpodder_autoupload = True - def on_download_from_mygpo(self, widget): + def on_download_from_mygpo(self, widget=None): if self.require_my_gpodder_authentication(): client = my.MygPodderClient(self.config.my_gpodder_username, self.config.my_gpodder_password) opml_data = client.download_subscriptions() @@ -2572,7 +2570,7 @@ class gPodder(BuilderWidget, dbus.service.Object): elif widget is not None: self.show_message(_('Please set up your username and password first.'), _('Username and password needed'), important=True) - def on_itemAddChannel_activate(self, widget, *args): + def on_itemAddChannel_activate(self, widget=None): gPodderAddPodcast(self.gPodder, \ add_urls_callback=self.add_podcast_list) @@ -2725,9 +2723,17 @@ class gPodder(BuilderWidget, dbus.service.Object): dlg.destroy() def on_itemImportChannels_activate(self, widget, *args): - dir = gPodderPodcastDirectory(self.gPodder, _config=self.config, \ - add_urls_callback=self.add_podcast_list) - if not gpodder.ui.fremantle: + if gpodder.ui.fremantle: + gPodderPodcastDirectory.show_add_podcast_picker(self.main_window, \ + self.config.toplist_url, \ + self.config.opml_url, \ + self.add_podcast_list, \ + self.on_itemAddChannel_activate, \ + self.on_download_from_mygpo, \ + self.show_text_edit_dialog) + else: + dir = gPodderPodcastDirectory(self.main_window, _config=self.config, \ + add_urls_callback=self.add_podcast_list) util.idle_add(dir.download_opml_file, self.config.opml_url) def on_homepage_activate(self, widget, *args): -- 2.11.4.GIT