Support marking episodes new/old in Fremantle

This commit is contained in:
Thomas Perl 2009-09-21 23:34:12 +02:00
parent 68349b1c1b
commit 36f42f702f
4 changed files with 44 additions and 19 deletions

View File

@ -73,4 +73,12 @@
<property name="stock_id">gtk-close</property>
<signal name="activate" handler="on_close_button_clicked"/>
</object>
<object class="GtkAction" id="action_mark_as_new">
<property name="label" translatable="yes">Mark as new</property>
<signal name="activate" handler="on_mark_as_new_button_clicked"/>
</object>
<object class="GtkAction" id="action_mark_as_old">
<property name="label" translatable="yes">Remove new mark</property>
<signal name="activate" handler="on_do_not_download_button_clicked"/>
</object>
</interface>

View File

@ -52,6 +52,8 @@ class gPodderShownotes(gPodderShownotesBase):
self.action_pause, \
self.action_resume, \
self.action_cancel, \
self.action_mark_as_new, \
self.action_mark_as_old, \
self.action_visit_website):
button = gtk.Button()
action.connect_proxy(button)
@ -117,24 +119,27 @@ class gPodderShownotes(gPodderShownotesBase):
self.text_buffer.set_text('')
def on_episode_status_changed(self):
downloaded = self.episode.was_downloaded(and_exists=True)
downloading = self.task is not None and self.task.status in \
(self.task.QUEUED, self.task.DOWNLOADING, self.task.PAUSED)
can_set_new_mark = not downloaded and not downloading
self.download_progress.set_property('visible', \
self.task is not None and \
self.task.status != self.task.CANCELLED)
self.action_play.set_visible(\
self.episode.was_downloaded(and_exists=True))
self.action_delete.set_visible(\
self.episode.was_downloaded(and_exists=True))
self.action_download.set_visible((self.task is None and not \
self.episode.was_downloaded(and_exists=True)) or \
self.action_play.set_visible(downloaded)
self.action_delete.set_visible(downloaded)
self.action_download.set_visible(\
(self.task is None and not downloaded) or \
(self.task is not None and \
self.task.status in (self.task.CANCELLED, self.task.FAILED)))
self.action_pause.set_visible(self.task is not None and \
self.task.status in (self.task.QUEUED, self.task.DOWNLOADING))
self.action_resume.set_visible(self.task is not None and \
self.task.status == self.task.PAUSED)
self.action_cancel.set_visible(self.task is not None and \
self.task.status in (self.task.QUEUED, self.task.DOWNLOADING, \
self.task.PAUSED))
self.action_cancel.set_visible(downloading)
self.action_mark_as_new.set_visible(can_set_new_mark and not self.episode_is_new())
self.action_mark_as_old.set_visible(can_set_new_mark and self.episode_is_new())
self.action_visit_website.set_visible(self.episode is not None and \
self.episode.link is not None and \
self.episode.link != self.episode.url)

View File

@ -153,6 +153,15 @@ class gPodderShownotesBase(BuilderWidget):
#############################################################
def episode_is_new(self):
if self.episode is None:
return False
else:
return self.episode.check_is_new(downloading=\
self._episode_is_downloading)
#############################################################
def show(self, episode):
if self.main_window.get_property('visible'):
self.episode = None

View File

@ -421,17 +421,9 @@ class PodcastChannel(PodcastModelObject):
By default, "downloading" is implemented so that it
reports all episodes as not downloading.
"""
def check_is_new(episode):
"""
For a given episode, returns True if it is to
be considered new or False if it is "not new".
"""
return episode.state == gpodder.STATE_NORMAL and \
not episode.is_played and \
not downloading(episode)
return [episode for episode in self.db.load_episodes(self, \
factory=self.episode_factory) if check_is_new(episode)]
factory=self.episode_factory) if \
episode.check_is_new(downloading=downloading)]
def update_m3u_playlist(self):
# If the save_dir doesn't end with a slash (which it really should
@ -945,6 +937,17 @@ class PodcastEpisode(PodcastModelObject):
ext = util.extension_from_mimetype(self.mimetype)
return ext
def check_is_new(self, downloading=lambda e: False):
"""
Returns True if this episode is to be considered new.
"Downloading" should be a callback that gets an episode
as its parameter and returns True if the episode is
being downloaded at the moment.
"""
return self.state == gpodder.STATE_NORMAL and \
not self.is_played and \
not downloading(self)
def mark_new(self):
self.state = gpodder.STATE_NORMAL
self.is_played = False