Sat, 19 Apr 2008 18:46:30 +0200 <thp@perli.net>

Additional fields for the device remove episodes dialog; refactoring

	* src/gpodder/gui.py: Add "Podcast" and "Released" columns to the
	episode selector; hide all columns in our "delete from device" episode
	selector that have all rows set to "None"; make the first text column
	of the gPodderEpisodeSelector bigger, so the episode selector is
	easier to read when there are many columns
	* src/gpodder/libpodcasts.py: Use util.format_date() for
	cute_pubdate() in podcastItem
	* src/gpodder/sync.py: Document SyncTrack a bit better, add
	needed/possible keyword arguments that are used in the UI; default
	some values to None in case they are not provided; get "released" date
	from iPod's iTunesDB and get podcast name from MP3 player's sync
	folder (if this feature has been activated)
	* src/gpodder/util.py: Add format_date() function that converts a Unix
	timestamp to a good representation for a date (either Today,
	Yesterday, a weekday or the locale's appropriate representation); the
	code has been re-factored from podcastItem's cute_pubdate() function
	in gpodder.libpodcasts and is now used from there



git-svn-id: svn://svn.berlios.de/gpodder/trunk@677 b0d088ad-0a06-0410-aad2-9ed5178a7e87
This commit is contained in:
Thomas Perl 2008-04-19 17:01:09 +00:00
parent 2f6c16e636
commit 0abbea437c
5 changed files with 105 additions and 18 deletions

View File

@ -1,3 +1,24 @@
Sat, 19 Apr 2008 18:46:30 +0200 <thp@perli.net>
Additional fields for the device remove episodes dialog; refactoring
* src/gpodder/gui.py: Add "Podcast" and "Released" columns to the
episode selector; hide all columns in our "delete from device" episode
selector that have all rows set to "None"; make the first text column
of the gPodderEpisodeSelector bigger, so the episode selector is
easier to read when there are many columns
* src/gpodder/libpodcasts.py: Use util.format_date() for
cute_pubdate() in podcastItem
* src/gpodder/sync.py: Document SyncTrack a bit better, add
needed/possible keyword arguments that are used in the UI; default
some values to None in case they are not provided; get "released" date
from iPod's iTunesDB and get podcast name from MP3 player's sync
folder (if this feature has been activated)
* src/gpodder/util.py: Add format_date() function that converts a Unix
timestamp to a good representation for a date (either Today,
Yesterday, a weekday or the locale's appropriate representation); the
code has been re-factored from podcastItem's cute_pubdate() function
in gpodder.libpodcasts and is now used from there
Thu, 17 Apr 2008 17:54:48 +0200 <thp@perli.net>
Calculate total percentage based on byte size instead of percentage

View File

@ -1334,9 +1334,11 @@ class gPodder(GladeWidget):
def on_cleanup_ipod_activate(self, widget, *args):
columns = (
('title', _('Episode')),
('podcast', _('Podcast')),
('filesize', _('Size')),
('modified', _('Copied')),
('playcount', _('Play count')),
('released', _('Released')),
)
device = sync.open_device()
@ -1358,9 +1360,19 @@ class gPodder(GladeWidget):
tracks = device.get_all_tracks()
if len(tracks) > 0:
remove_tracks_callback = lambda tracks: self.ipod_cleanup_callback(device, tracks)
wanted_columns = []
for key, caption in columns:
want_this_column = False
for track in tracks:
if getattr(track, key) is not None:
want_this_column = True
break
if want_this_column:
wanted_columns.append((key, caption))
title = _('Remove podcasts from device')
instructions = _('Select the podcast episodes you want to remove from your device.')
gPodderEpisodeSelector(title=title, instructions=instructions, episodes=tracks, columns=columns, \
gPodderEpisodeSelector(title=title, instructions=instructions, episodes=tracks, columns=wanted_columns, \
stock_ok_button=gtk.STOCK_DELETE, callback=remove_tracks_callback)
else:
title = _('No files on device')
@ -2586,11 +2598,11 @@ class gPodderEpisodeSelector( GladeWidget):
next_column = self.COLUMN_ADDITIONAL
for name, caption in self.columns:
renderer = gtk.CellRendererText()
if next_column > self.COLUMN_ADDITIONAL:
renderer.set_property( 'ellipsize', pango.ELLIPSIZE_END)
renderer.set_property( 'ellipsize', pango.ELLIPSIZE_END)
column = gtk.TreeViewColumn( caption, renderer, text=next_column)
column.set_resizable( True)
column.set_expand( True)
# Only set "expand" on the first column (so more text is displayed there)
column.set_expand(next_column == self.COLUMN_ADDITIONAL)
self.treeviewEpisodes.append_column( column)
next_column += 1

View File

@ -745,21 +745,16 @@ class podcastItem(object):
return pubdate
def cute_pubdate( self):
seconds_in_a_day = 86400
try:
timestamp = int(mktime_tz( parsedate_tz( self.pubDate)))
timestamp = int(mktime_tz(parsedate_tz(self.pubDate)))
except:
return _("(unknown)")
diff = int((time.time()+1)/seconds_in_a_day) - int(timestamp/seconds_in_a_day)
timestamp = None
if diff == 0:
return _("Today")
if diff == 1:
return _("Yesterday")
if diff < 7:
return str(datetime.fromtimestamp( timestamp).strftime( "%A"))
return str(datetime.fromtimestamp( timestamp).strftime( "%x"))
result = util.format_date(timestamp)
if result is None:
return '(%s)' % _('unknown')
else:
return result
pubdate_prop = property(fget=cute_pubdate)

View File

@ -93,11 +93,35 @@ def get_track_length(filename):
class SyncTrack(object):
"""
This represents a track that is on a device. You need
to specify at least the following keyword arguments,
because these will be used to display the track in the
GUI. All other keyword arguments are optional and can
be used to reference internal objects, etc... See the
iPod synchronization code for examples.
Keyword arguments needed:
playcount (How often has the track been played?)
podcast (Which podcast is this track from? Or: Folder name)
released (The release date of the episode)
If any of these fields is unknown, it should not be
passed to the function (the values will default to None
for all required fields).
"""
def __init__(self, title, length, modified, **kwargs):
self.title = title
self.length = length
self.filesize = util.format_filesize(length, gl.config.use_si_units)
self.modified = modified
# Set some (possible) keyword arguments to default values
self.playcount = None
self.podcast = None
self.released = None
# Convert keyword arguments to object attributes
self.__dict__.update(kwargs)
@ -230,8 +254,10 @@ class iPodDevice(Device):
age_in_days = util.file_age_in_days(filename)
modified = util.file_age_to_string(age_in_days)
released = gpod.itdb_time_mac_to_host(track.time_released)
released = util.format_date(released)
t = SyncTrack(track.title, length, modified, libgpodtrack=track, playcount=track.playcount)
t = SyncTrack(track.title, length, modified, libgpodtrack=track, playcount=track.playcount, released=released, podcast=track.artist)
tracks.append(t)
return tracks
@ -553,8 +579,12 @@ class MP3PlayerDevice(Device):
age_in_days = util.file_age_in_days(filename)
modified = util.file_age_to_string(age_in_days)
if gl.config.fssync_channel_subfolders:
podcast_name = os.path.basename(os.path.dirname(filename))
else:
podcast_name = None
t = SyncTrack(title, length, modified, filename=filename, playcount=0)
t = SyncTrack(title, length, modified, filename=filename, podcast=podcast_name)
tracks.append(t)
return tracks

View File

@ -248,6 +248,35 @@ def get_free_disk_space(path):
return s.f_bavail * s.f_bsize
def format_date(timestamp):
"""
Converts a UNIX timestamp to a date representation. This
function returns "Today", "Yesterday", a weekday name or
the date in %x format, which (according to the Python docs)
is the "Locale's appropriate date representation".
Returns None if there has been an error converting the
timestamp to a string representation.
"""
seconds_in_a_day = 60*60*24
try:
diff = int((time.time()+1)/seconds_in_a_day) - int(timestamp/seconds_in_a_day)
except:
log('Warning: Cannot convert "%s" to date.', timestamp, traceback=True)
return None
if diff == 0:
return _('Today')
elif diff == 1:
return _('Yesterday')
elif diff < 7:
# Weekday name
return str(datetime.datetime.fromtimestamp(timestamp).strftime('%A'))
else:
# Locale's appropriate date representation
return str(datetime.datetime.fromtimestamp(timestamp).strftime('%x'))
def format_filesize(bytesize, use_si_units=False, digits=2):
"""
Formats the given size in bytes to be human-readable,