mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Implement #525
This commit is contained in:
parent
6aa7f8cb8f
commit
1697a8b535
@ -32,11 +32,13 @@ from libprs500.ebooks import BOOK_EXTENSIONS
|
||||
from libprs500.ebooks.metadata.library_thing import login, cover_from_isbn, LibraryThingError
|
||||
|
||||
class Format(QListWidgetItem):
|
||||
def __init__(self, parent, ext, path=None):
|
||||
def __init__(self, parent, ext, size, path=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),
|
||||
ext.upper(), parent, QListWidgetItem.UserType)
|
||||
text, parent, QListWidgetItem.UserType)
|
||||
|
||||
class MetadataSingleDialog(QDialog, Ui_MetadataSingleDialog):
|
||||
|
||||
@ -86,6 +88,7 @@ class MetadataSingleDialog(QDialog, Ui_MetadataSingleDialog):
|
||||
QErrorMessage(self.window).showMessage("You do not have "+\
|
||||
"permission to read the file: " + _file)
|
||||
continue
|
||||
size = os.stat(_file).st_size
|
||||
ext = os.path.splitext(_file)[1].lower()
|
||||
if '.' in ext:
|
||||
ext = ext.replace('.', '')
|
||||
@ -94,7 +97,7 @@ class MetadataSingleDialog(QDialog, Ui_MetadataSingleDialog):
|
||||
if fmt.ext == ext:
|
||||
self.formats.takeItem(row)
|
||||
break
|
||||
Format(self.formats, ext, path=_file)
|
||||
Format(self.formats, ext, size, path=_file)
|
||||
self.formats_changed = True
|
||||
|
||||
def remove_format(self, x):
|
||||
@ -180,7 +183,8 @@ class MetadataSingleDialog(QDialog, Ui_MetadataSingleDialog):
|
||||
for ext in exts:
|
||||
if not 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.sort(cmp=lambda x, y : cmp(x[1], y[1]))
|
||||
|
@ -960,6 +960,13 @@ ALTER TABLE books ADD COLUMN isbn TEXT DEFAULT "" COLLATE NOCASE;
|
||||
return None
|
||||
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):
|
||||
id = self.id(index)
|
||||
return decompress(self.conn.execute('SELECT data FROM data WHERE book=? AND format=?', (id, format)).fetchone()[0])
|
||||
|
Loading…
x
Reference in New Issue
Block a user