1 # -*- coding: utf-8 -*-
3 # gPodder - A media aggregator and podcast client
4 # Copyright (c) 2005-2009 Thomas Perl and the gPodder Team
6 # gPodder is free software; you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation; either version 3 of the License, or
9 # (at your option) any later version.
11 # gPodder is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License
17 # along with this program. If not, see <http://www.gnu.org/licenses/>.
28 from gpodder
import util
30 from gpodder
.gtkui
.interface
.common
import BuilderWidget
31 from gpodder
.gtkui
.model
import EpisodeListModel
33 from gpodder
.gtkui
.frmntl
.episodeactions
import gPodderEpisodeActions
35 class gPodderEpisodes(BuilderWidget
):
39 self
.episode_actions
= gPodderEpisodeActions(self
.main_window
, \
40 episode_list_status_changed
=self
.episode_list_status_changed
, \
41 episode_is_downloading
=self
.episode_is_downloading
, \
42 show_episode_shownotes
=self
.show_episode_shownotes
, \
43 playback_episodes
=self
.playback_episodes
, \
44 download_episode_list
=self
.download_episode_list
, \
45 show_episode_in_download_manager
=self
.show_episode_in_download_manager
, \
46 add_download_task_monitor
=self
.add_download_task_monitor
, \
47 remove_download_task_monitor
=self
.remove_download_task_monitor
, \
48 for_each_episode_set_task_status
=self
.for_each_episode_set_task_status
)
50 # Tap-and-hold (aka "long press") context menu
51 self
.touched_episode
= None
52 self
.context_menu
= gtk
.Menu()
53 # "Emulate" hildon_gtk_menu_new
54 self
.context_menu
.set_name('hildon-context-sensitive-menu')
55 self
.context_menu
.append(self
.action_shownotes
.create_menu_item())
56 self
.context_menu
.append(self
.action_download
.create_menu_item())
57 self
.context_menu
.append(self
.action_delete
.create_menu_item())
58 self
.context_menu
.append(self
.action_keep
.create_menu_item())
59 self
.context_menu
.append(self
.action_mark_as_old
.create_menu_item())
60 self
.context_menu
.show_all()
61 self
.treeview
.tap_and_hold_setup(self
.context_menu
)
63 # Workaround for Maemo bug XXX
64 self
.button_search_episodes_clear
.set_name('HildonButton-thumb')
65 appmenu
= hildon
.AppMenu()
66 for action
in (self
.action_rename
, \
67 self
.action_play_m3u
, \
69 self
.action_unsubscribe
, \
72 action
.connect_proxy(button
)
73 appmenu
.append(button
)
74 for filter in (self
.item_view_episodes_all
, \
75 self
.item_view_episodes_undeleted
, \
76 self
.item_view_episodes_downloaded
):
77 button
= gtk
.ToggleButton()
78 filter.connect_proxy(button
)
79 appmenu
.add_filter(button
)
81 self
.main_window
.set_app_menu(appmenu
)
83 def on_rename_button_clicked(self
, widget
):
84 if self
.channel
is None:
86 new_title
= self
.show_text_edit_dialog(_('Rename podcast'), \
87 _('New name:'), self
.channel
.title
)
88 if new_title
is not None and new_title
!= self
.channel
.title
:
89 self
.channel
.set_custom_title(new_title
)
90 self
.main_window
.set_title(self
.channel
.title
)
92 self
.show_message(_('Podcast renamed: %s') % new_title
)
93 self
.update_podcast_list_model(urls
=[self
.channel
.url
])
95 def on_login_button_clicked(self
, widget
):
96 accept
, auth_data
= self
.show_login_dialog(_('Login to %s') % \
97 self
.channel
.title
, '', \
98 self
.channel
.username
, \
99 self
.channel
.password
)
101 self
.channel
.username
, self
.channel
.password
= auth_data
104 def on_play_m3u_button_clicked(self
, widget
):
105 if self
.channel
is not None:
106 util
.gui_open(self
.channel
.get_playlist_filename())
108 def on_website_button_clicked(self
, widget
):
109 if self
.channel
is not None:
110 util
.open_website(self
.channel
.link
)
112 def on_update_button_clicked(self
, widget
):
113 self
.on_itemUpdateChannel_activate()
115 def on_unsubscribe_button_clicked(self
, widget
):
116 if self
.show_confirmation(_('Really delete this podcast and all downloaded episodes?')):
117 self
.on_delete_event(widget
, None)
118 self
.on_itemRemoveChannel_activate(widget
)
120 def on_episode_selected(self
, treeview
, path
, column
):
121 model
= treeview
.get_model()
122 episode
= model
.get_value(model
.get_iter(path
), \
123 EpisodeListModel
.C_EPISODE
)
124 self
.episode_actions
.show_episode(episode
)
126 def on_delete_event(self
, widget
, event
):
127 self
.main_window
.hide()
129 self
.hide_episode_search()
132 def on_treeview_button_press(self
, widget
, event
):
133 result
= self
.treeview
.get_path_at_pos(int(event
.x
), int(event
.y
))
134 if result
is not None:
135 path
, column
, x
, y
= result
136 model
= self
.treeview
.get_model()
137 episode
= model
.get_value(model
.get_iter(path
), \
138 EpisodeListModel
.C_EPISODE
)
140 if episode
.was_downloaded():
141 self
.action_delete
.set_property('visible', not episode
.is_locked
)
142 self
.action_keep
.set_property('visible', True)
143 self
.action_download
.set_property('visible', not episode
.was_downloaded(and_exists
=True))
145 self
.action_delete
.set_property('visible', False)
146 self
.action_keep
.set_property('visible', False)
147 self
.action_download
.set_property('visible', not self
.episode_is_downloading(episode
))
149 if episode
.is_locked
:
150 self
.action_keep
.set_property('label', _('Do not keep'))
152 self
.action_keep
.set_property('label', _('Keep'))
154 if episode
.is_played
:
155 self
.action_mark_as_old
.set_property('label', _('Mark as new'))
157 self
.action_mark_as_old
.set_property('label', _('Mark as old'))
159 self
.touched_episode
= episode
161 self
.touched_episode
= None
163 def on_shownotes_button_clicked(self
, widget
):
164 if self
.touched_episode
is not None:
165 self
.show_episode_shownotes(self
.touched_episode
)
167 def on_download_button_clicked(self
, widget
):
168 if self
.touched_episode
is not None:
169 self
.show_message(_('Downloading episode'))
170 self
.download_episode_list([self
.touched_episode
])
172 def on_delete_button_clicked(self
, widget
):
173 if self
.touched_episode
is not None:
174 self
.delete_episode_list([self
.touched_episode
])
176 def on_keep_button_clicked(self
, widget
):
177 if self
.touched_episode
is not None:
178 self
.touched_episode
.mark(is_locked
=not self
.touched_episode
.is_locked
)
179 self
.episode_list_status_changed([self
.touched_episode
])
181 def on_mark_as_old_button_clicked(self
, widget
):
182 if self
.touched_episode
is not None:
183 self
.touched_episode
.mark(is_played
=not self
.touched_episode
.is_played
)
184 self
.episode_list_status_changed([self
.touched_episode
])
187 self
.main_window
.set_title(self
.channel
.title
)
188 self
.main_window
.show()
189 self
.treeview
.grab_focus()