This commit is contained in:
Kovid Goyal 2008-02-16 18:49:47 +00:00
parent 6aa7f8cb8f
commit 1697a8b535
2 changed files with 15 additions and 4 deletions

View File

@ -32,11 +32,13 @@ from libprs500.ebooks import BOOK_EXTENSIONS
from libprs500.ebooks.metadata.library_thing import login, cover_from_isbn, LibraryThingError from libprs500.ebooks.metadata.library_thing import login, cover_from_isbn, LibraryThingError
class Format(QListWidgetItem): class Format(QListWidgetItem):
def __init__(self, parent, ext, path=None): def __init__(self, parent, ext, size, path=None):
self.path = path self.path = path
self.ext = ext 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), QListWidgetItem.__init__(self, file_icon_provider().icon_from_ext(ext),
ext.upper(), parent, QListWidgetItem.UserType) text, parent, QListWidgetItem.UserType)
class MetadataSingleDialog(QDialog, Ui_MetadataSingleDialog): class MetadataSingleDialog(QDialog, Ui_MetadataSingleDialog):
@ -86,6 +88,7 @@ class MetadataSingleDialog(QDialog, Ui_MetadataSingleDialog):
QErrorMessage(self.window).showMessage("You do not have "+\ QErrorMessage(self.window).showMessage("You do not have "+\
"permission to read the file: " + _file) "permission to read the file: " + _file)
continue continue
size = os.stat(_file).st_size
ext = os.path.splitext(_file)[1].lower() ext = os.path.splitext(_file)[1].lower()
if '.' in ext: if '.' in ext:
ext = ext.replace('.', '') ext = ext.replace('.', '')
@ -94,7 +97,7 @@ class MetadataSingleDialog(QDialog, Ui_MetadataSingleDialog):
if fmt.ext == ext: if fmt.ext == ext:
self.formats.takeItem(row) self.formats.takeItem(row)
break break
Format(self.formats, ext, path=_file) Format(self.formats, ext, size, path=_file)
self.formats_changed = True self.formats_changed = True
def remove_format(self, x): def remove_format(self, x):
@ -180,7 +183,8 @@ class MetadataSingleDialog(QDialog, Ui_MetadataSingleDialog):
for ext in exts: for ext in exts:
if not ext: if not ext:
ext = '' ext = ''
Format(self.formats, ext) size = self.db.sizeof_format(row, ext)
Format(self.formats, ext, size)
all_series = self.db.all_series() all_series = self.db.all_series()
all_series.sort(cmp=lambda x, y : cmp(x[1], y[1])) all_series.sort(cmp=lambda x, y : cmp(x[1], y[1]))

View File

@ -960,6 +960,13 @@ ALTER TABLE books ADD COLUMN isbn TEXT DEFAULT "" COLLATE NOCASE;
return None return None
return matches[0][0] return matches[0][0]
def sizeof_format(self, index, format, index_is_id=False):
''' Return size of C{format} for book C{index} in bytes'''
id = index if index_is_id else self.id(index)
format = format.upper()
return self.conn.execute('SELECT uncompressed_size FROM data WHERE data.book=? AND data.format=?', (id, format)).fetchone()[0]
def format(self, index, format): def format(self, index, format):
id = self.id(index) id = self.id(index)
return decompress(self.conn.execute('SELECT data FROM data WHERE book=? AND format=?', (id, format)).fetchone()[0]) return decompress(self.conn.execute('SELECT data FROM data WHERE book=? AND format=?', (id, format)).fetchone()[0])