Refactor is_played -> not is_new in PodcastEpisode

This commit is contained in:
Thomas Perl 2011-02-26 16:32:34 +01:00
parent 96709cca1b
commit ea02c40e08
9 changed files with 32 additions and 34 deletions

View file

@ -147,7 +147,7 @@ class Episode(object):
self.title = self._episode.title
self.url = self._episode.url
self.is_new = (self._episode.state == gpodder.STATE_NORMAL and \
not self._episode.is_played)
self._episode.is_new)
self.is_downloaded = (self._episode.state == gpodder.STATE_DOWNLOADED)
self.is_deleted = (self._episode.state == gpodder.STATE_DELETED)

View file

@ -118,7 +118,7 @@ class DBusPodcastsProxy(dbus.service.Object):
description = safe_first_line(episode.description)
filename = safe_str(episode.download_filename)
file_type = safe_str(episode.file_type())
is_new = (episode.state == gpodder.STATE_NORMAL and not episode.is_played)
is_new = (episode.state == gpodder.STATE_NORMAL and episode.is_new)
is_downloaded = episode.was_downloaded(and_exists=True)
is_deleted = (episode.state == gpodder.STATE_DELETED)

View file

@ -152,8 +152,8 @@ class gPodderEpisodeActions(BuilderWidget):
if self.episode.total_time > 0:
play_button.set_title(self.action_play.props.label)
mark_new_button.set_active(not self.episode.is_played)
mark_old_button.set_active(self.episode.is_played)
mark_new_button.set_active(self.episode.is_new)
mark_old_button.set_active(not self.episode.is_new)
table = gtk.Table(2, 2, True)
table.attach(download_button, 0, 1, 0, 1)
@ -281,11 +281,11 @@ class gPodderEpisodeActions(BuilderWidget):
if self.should_set_new_value:
value = self.radio_action_mark_new.get_current_value()
if value == self.CHOICE_MARK_NEW and \
self.episode.is_played:
not self.episode.is_new:
self.episode.mark(is_played=False)
changed = True
elif value == self.CHOICE_MARK_OLD and \
not self.episode.is_played:
self.episode.is_new:
self.episode.mark(is_played=True)
changed = True
if self.new_keep_value != self.episode.is_locked:

View file

@ -169,7 +169,7 @@ class gPodderEpisodes(BuilderWidget):
self.touched_episode = None
self.action_keep.set_active(episode.is_locked)
self.action_mark_as_old.set_active(not episode.is_played)
self.action_mark_as_old.set_active(episode.is_new)
self.touched_episode = episode
else:
@ -195,7 +195,7 @@ class gPodderEpisodes(BuilderWidget):
def on_mark_as_old_button_clicked(self, widget):
if self.touched_episode is not None:
self.touched_episode.mark(is_played=not self.touched_episode.is_played)
self.touched_episode.mark(is_played=self.touched_episode.is_new)
self.episode_list_status_changed([self.touched_episode])
def on_check_for_new_episodes_button_clicked(self, widget):

View file

@ -110,7 +110,7 @@ class EpisodeListModel(gtk.GenericTreeModel):
elif episode.state == gpodder.STATE_DELETED:
return self.ICON_DELETED
elif episode.state == gpodder.STATE_NORMAL and \
not episode.is_played and \
episode.is_new and \
not downloading(episode):
return None # self.ICON_NEW
elif episode.state == gpodder.STATE_DOWNLOADED:
@ -145,10 +145,10 @@ class EpisodeListModel(gtk.GenericTreeModel):
elif column == self.C_VIEW_SHOW_DOWNLOADED:
return episode.state == gpodder.STATE_DOWNLOADED or \
(episode.state == gpodder.STATE_NORMAL and \
not episode.is_played) or \
episode.is_new) or \
downloading(episode)
elif column == self.C_VIEW_SHOW_UNPLAYED:
return (not episode.is_played and (episode.state in \
return (episode.is_new and (episode.state in \
(gpodder.STATE_DOWNLOADED, gpodder.STATE_NORMAL))) or \
downloading(episode)
elif column == self.C_FILESIZE:
@ -298,10 +298,10 @@ class EpisodeListModel(gtk.GenericTreeModel):
elif self._view_mode == self.VIEW_DOWNLOADED:
is_visible = lambda episode: episode.state == gpodder.STATE_DOWNLOADED or \
(episode.state == gpodder.STATE_NORMAL and \
not episode.is_played) or \
episode.is_new) or \
self._downloading(episode)
elif self._view_mode == self.VIEW_UNPLAYED:
is_visible = lambda episode: (not episode.is_played and (episode.state in \
is_visible = lambda episode: (episode.is_new and (episode.state in \
(gpodder.STATE_DOWNLOADED, gpodder.STATE_NORMAL))) or \
self._downloading(episode)
else:
@ -345,6 +345,7 @@ class EpisodeListModel(gtk.GenericTreeModel):
def _format_description(self, episode):
filesize = self._format_filesize(episode)
# FIXME: Merge common code paths in this if-elif-else code block
if self._downloading(episode):
sub = _('in downloads list')
sub = '; '.join((sub, episode.cute_pubdate()))
@ -353,7 +354,7 @@ class EpisodeListModel(gtk.GenericTreeModel):
if self._all_episodes_view:
sub = '; '.join((sub, _('from %s') % cgi.escape(episode.channel.title,)))
return self._unplayed_markup % (cgi.escape(episode.title), sub)
elif episode.is_played:
elif not episode.is_new:
sub = episode.cute_pubdate()
if filesize:
sub = '; '.join((sub, filesize))

View file

@ -221,7 +221,7 @@ class EpisodeListModel(gtk.ListStore):
def _format_description(self, episode, include_description=False, is_downloading=None):
a, b = '', ''
if episode.state != gpodder.STATE_DELETED and not episode.is_played:
if episode.state != gpodder.STATE_DELETED and episode.is_new:
a, b = '<b>', '</b>'
if include_description and self._all_episodes_view:
return '%s%s%s\n<small>%s</small>' % (a, cgi.escape(episode.title), b,
@ -323,7 +323,7 @@ class EpisodeListModel(gtk.ListStore):
status_icon = self.ICON_DELETED
view_show_undeleted = False
elif episode.state == gpodder.STATE_NORMAL and \
not episode.is_played:
episode.is_new:
tooltip.append(_('New episode'))
status_icon = self.ICON_NEW
view_show_downloaded = True
@ -331,8 +331,8 @@ class EpisodeListModel(gtk.ListStore):
elif episode.state == gpodder.STATE_DOWNLOADED:
tooltip = []
view_show_downloaded = True
view_show_unplayed = not episode.is_played
show_bullet = not episode.is_played
view_show_unplayed = episode.is_new
show_bullet = episode.is_new
show_padlock = episode.is_locked
show_missing = not episode.file_exists()
filename = episode.local_filename(create=False, check_only=True)

View file

@ -1802,8 +1802,8 @@ class gPodder(BuilderWidget, dbus.service.Object):
if event.button == self.context_menu_mouse_button:
episodes = self.get_selected_episodes()
any_locked = any(e.is_locked for e in episodes)
any_played = any(e.is_played for e in episodes)
one_is_new = any(e.state == gpodder.STATE_NORMAL and not e.is_played for e in episodes)
any_played = any(not e.is_new for e in episodes)
one_is_new = any(e.state == gpodder.STATE_NORMAL and e.is_new for e in episodes)
downloaded = all(e.was_downloaded(and_exists=True) for e in episodes)
downloading = any(self.episode_is_downloading(e) for e in episodes)
@ -2179,7 +2179,7 @@ class gPodder(BuilderWidget, dbus.service.Object):
if episode.was_downloaded():
can_play = episode.was_downloaded(and_exists=True)
is_played = episode.is_played
is_played = not episode.is_new
is_locked = episode.is_locked
if not can_play:
can_download = True
@ -2876,12 +2876,12 @@ class gPodder(BuilderWidget, dbus.service.Object):
continue
# Do not delete played episodes (except if configured)
if episode.is_played:
if not episode.is_new:
if not self.config.auto_remove_played_episodes:
continue
# Do not delete unplayed episodes (except if configured)
if not episode.is_played:
if episode.is_new:
if not self.config.auto_remove_unplayed_episodes:
continue
@ -2972,7 +2972,7 @@ class gPodder(BuilderWidget, dbus.service.Object):
msg_older_than = N_('Select older than %(count)d day', 'Select older than %(count)d days', self.config.episode_old_age)
selection_buttons = {
_('Select played'): lambda episode: episode.is_played,
_('Select played'): lambda episode: not episode.is_new,
_('Select finished'): lambda episode: episode.is_finished(),
msg_older_than % {'count':self.config.episode_old_age}: lambda episode: episode.age_in_days() > self.config.episode_old_age,
}
@ -2991,7 +2991,7 @@ class gPodder(BuilderWidget, dbus.service.Object):
if not episode.is_locked or not episode.file_exists():
episodes.append(episode)
selected = [e.is_played or not e.file_exists() for e in episodes]
selected = [not e.is_new or not e.file_exists() for e in episodes]
gPodderEpisodeSelector(self.gPodder, title = _('Delete episodes'), instructions = instructions, \
episodes = episodes, selected = selected, columns = columns, \
@ -3021,7 +3021,7 @@ class gPodder(BuilderWidget, dbus.service.Object):
def on_item_toggle_played_activate( self, widget, toggle = True, new_value = False):
for episode in self.get_selected_episodes():
if toggle:
episode.mark(is_played=not episode.is_played)
episode.mark(is_played=episode.is_new)
else:
episode.mark(is_played=new_value)
self.on_selected_episodes_status_changed()

View file

@ -108,13 +108,10 @@ class PodcastEpisode(PodcastModelObject):
"""holds data for one object in a channel"""
MAX_FILENAME_LENGTH = 200
def _get_is_played(self):
return not self.is_new
def _deprecated(self):
raise Exception('Property is deprecated!')
def _set_is_played(self, is_played):
self.is_new = not is_played
is_played = property(fget=_get_is_played, fset=_set_is_played)
is_played = property(fget=_deprecated, fset=_deprecated)
def _get_podcast_id(self):
return self.channel.id

View file

@ -49,13 +49,13 @@ class Matcher(object):
# Adjectives (for direct usage)
if k == 'new':
return (episode.state == gpodder.STATE_NORMAL and not episode.is_played)
return (episode.state == gpodder.STATE_NORMAL and episode.is_new)
elif k in ('downloaded', 'dl'):
return episode.was_downloaded(and_exists=True)
elif k in ('deleted', 'rm'):
return episode.state == gpodder.STATE_DELETED
elif k == 'played':
return episode.is_played
return not episode.is_new
elif k == 'archive':
return episode.is_locked
elif k in ('finished', 'fin'):