Fix sort order in "Remove podcasts" dialog (bug 408)

When I sort on the Copied-column in the Remove podcasts dialog, it sorts
in lexicographical order. Also, files copied within the last day only
show an empty string.

This patch fixes these issues.
This commit is contained in:
Torbjörn Wassberg 2009-05-26 13:56:49 +02:00 committed by Thomas Perl
parent 437d5fa2a5
commit a050637fd5
3 changed files with 25 additions and 8 deletions

View file

@ -2703,7 +2703,7 @@ class gPodder(BuilderWidget, dbus.service.Object):
('title', None, None, _('Episode')),
('podcast', None, None, _('Podcast')),
('filesize', None, None, _('Size')),
('modified', None, None, _('Copied')),
('modified', 'modified_sort', gobject.TYPE_INT, _('Copied')),
('playcount', None, None, _('Play count')),
('released', None, None, _('Released')),
)

View file

@ -369,12 +369,12 @@ class iPodDevice(Device):
filename = gpod.itdb_filename_on_ipod(track)
length = util.calculate_size(filename)
age_in_days = util.file_age_in_days(filename)
modified = util.file_age_to_string(age_in_days)
timestamp = util.file_modification_timestamp(filename)
modified = util.format_date(timestamp)
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, released=released, podcast=track.artist)
t = SyncTrack(track.title, length, modified, modified_sort=timestamp, libgpodtrack=track, playcount=track.playcount, released=released, podcast=track.artist)
tracks.append(t)
return tracks
@ -686,15 +686,15 @@ class MP3PlayerDevice(Device):
# fallback: use the basename of the file
title = filetitle
age_in_days = util.file_age_in_days(filename)
modified = util.file_age_to_string(age_in_days)
timestamp = util.file_modification_timestamp(filename)
modified = util.format_date(timestamp)
if gl.config.fssync_channel_subfolders:
podcast_name = os.path.basename(os.path.dirname(filename))
else:
podcast_name = None
# SyncTrack.filetitle will be used by Device._track_on_device (see above)
t = SyncTrack(title, length, modified, filename=filename, filetitle=filetitle, podcast=podcast_name)
t = SyncTrack(title, length, modified, modified_sort=timestamp, filename=filename, filetitle=filetitle, podcast=podcast_name)
tracks.append(t)
return tracks
@ -969,10 +969,12 @@ class MTPDevice(Device):
date = self.__mtp_to_date(track.date)
if not date:
modified = track.date # not a valid mtp date. Display what mtp gave anyway
modified_sort = -1 # no idea how to sort invalid date
else:
modified = util.format_date(date)
modified_sort = date
t = SyncTrack(title, length, modified, mtptrack=track, podcast=artist)
t = SyncTrack(title, length, modified, modified_sort=modified_sort, mtptrack=track, podcast=artist)
tracks.append(t)
return tracks

View file

@ -281,6 +281,21 @@ def file_modification_datetime(filename):
return None
def file_modification_timestamp(filename):
"""
Returns the modification date of the specified file as a number
or -1 if the modification date cannot be determined.
"""
if filename is None:
return -1
try:
s = os.stat(filename)
return s[stat.ST_MTIME]
except:
log('Cannot get modification timestamp for %s', filename)
return -1
def file_age_in_days(filename):
"""
Returns the age of the specified filename in days or