Implement #6252 (View Format Timestamp)

This commit is contained in:
Kovid Goyal 2010-07-22 12:58:46 -06:00
parent f58ee6472a
commit 4650923e91
2 changed files with 22 additions and 5 deletions

View File

@ -27,10 +27,11 @@ from calibre.ebooks.metadata import string_to_authors, \
from calibre.ebooks.metadata.library_thing import cover_from_isbn
from calibre.ebooks.metadata.meta import get_metadata
from calibre.utils.config import prefs, tweaks
from calibre.utils.date import qt_to_dt
from calibre.utils.date import qt_to_dt, local_tz, utcfromtimestamp
from calibre.customize.ui import run_plugins_on_import, get_isbndb_key
from calibre.gui2.dialogs.config.social import SocialMetadata
from calibre.gui2.custom_column_widgets import populate_metadata_page
from calibre import strftime
class CoverFetcher(QThread):
@ -75,13 +76,20 @@ class CoverFetcher(QThread):
class Format(QListWidgetItem):
def __init__(self, parent, ext, size, path=None):
def __init__(self, parent, ext, size, path=None, timestamp=None):
self.path = path
self.ext = ext
self.size = float(size)/(1024*1024)
text = '%s (%.2f MB)'%(self.ext.upper(), self.size)
QListWidgetItem.__init__(self, file_icon_provider().icon_from_ext(ext),
text, parent, QListWidgetItem.UserType)
if timestamp is not None:
ts = timestamp.astimezone(local_tz)
t = strftime('%a, %d %b %Y [%H:%M:%S]', ts.timetuple())
text = _('Last modified: %s')%t
self.setToolTip(text)
self.setStatusTip(text)
class MetadataSingleDialog(ResizableDialog, Ui_MetadataSingleDialog):
@ -151,14 +159,16 @@ class MetadataSingleDialog(ResizableDialog, Ui_MetadataSingleDialog):
nfile = run_plugins_on_import(_file)
if nfile is not None:
_file = nfile
size = os.stat(_file).st_size
stat = os.stat(_file)
size = stat.st_size
ext = os.path.splitext(_file)[1].lower().replace('.', '')
timestamp = utcfromtimestamp(stat.st_mtime)
for row in range(self.formats.count()):
fmt = self.formats.item(row)
if fmt.ext.lower() == ext:
self.formats.takeItem(row)
break
Format(self.formats, ext, size, path=_file)
Format(self.formats, ext, size, path=_file, timestamp=timestamp)
self.formats_changed = True
added = True
if bad_perms:
@ -379,9 +389,10 @@ class MetadataSingleDialog(ResizableDialog, Ui_MetadataSingleDialog):
if not ext:
ext = ''
size = self.db.sizeof_format(row, ext)
timestamp = self.db.format_last_modified(self.id, ext)
if size is None:
continue
Format(self.formats, ext, size)
Format(self.formats, ext, size, timestamp=timestamp)
self.initialize_combos()

View File

@ -327,6 +327,7 @@ class LibraryDatabase2(LibraryDatabase, SchemaUpgrade, CustomColumns):
''' Return last modified time as a UTC datetime object'''
return utcfromtimestamp(os.stat(self.dbpath).st_mtime)
def check_if_modified(self):
if self.last_modified() > self.last_update_check:
self.refresh()
@ -597,6 +598,11 @@ class LibraryDatabase2(LibraryDatabase, SchemaUpgrade, CustomColumns):
def has_format(self, index, format, index_is_id=False):
return self.format_abspath(index, format, index_is_id) is not None
def format_last_modified(self, id_, fmt):
path = self.format_abspath(id_, fmt, index_is_id=True)
if path is not None:
return utcfromtimestamp(os.stat(path).st_mtime)
def format_abspath(self, index, format, index_is_id=False):
'Return absolute path to the ebook file of format `format`'
id = index if index_is_id else self.id(index)