Fix #4. Also fix bug in dragging cover image that was introduced by r154

This commit is contained in:
Kovid Goyal 2006-12-22 01:42:06 +00:00
parent 77eeb1fe7a
commit ca54c6f3b1
2 changed files with 28 additions and 15 deletions

View File

@ -197,19 +197,27 @@ class LibraryDatabase(object):
self.add_format(_id, "lrf", c.getvalue()) self.add_format(_id, "lrf", c.getvalue())
self.con.commit() self.con.commit()
def update_cover(self, _id, cover): def update_cover(self, _id, cover, scaled=None):
"""
@param cover: The cover data
@param scaled: scaled version of cover that shoould be written to
format files. If None, cover is used.
"""
data = None data = None
if cover: if cover:
data = sqlite.Binary(compress(cover)) data = sqlite.Binary(compress(cover))
self.con.execute('update books_meta set cover=? where id=?', (data, _id)) self.con.execute('update books_meta set cover=? where id=?', (data, _id))
lrf = self.get_format(_id, "lrf") if not scaled:
if lrf: scaled = cover
c = cStringIO() if scaled:
c.write(lrf) lrf = self.get_format(_id, "lrf")
lrf = LRFMetaFile(c) if lrf:
lrf.thumbnail = cover c = cStringIO()
self.add_format(_id, "lrf", c.getvalue()) c.write(lrf)
self.update_max_size(_id) lrf = LRFMetaFile(c)
lrf.thumbnail = scaled
self.add_format(_id, "lrf", c.getvalue())
self.update_max_size(_id)
self.commit() self.commit()
def update_max_size(self, _id): def update_max_size(self, _id):

View File

@ -224,9 +224,9 @@ class CoverDisplay(FileDragAndDrop, QLabel):
drag, files = self.drag_object(["jpeg"]) drag, files = self.drag_object(["jpeg"])
if drag and files: if drag and files:
_file = files[0] _file = files[0]
drag.setPixmap(self.pixmap())
self.pixmap().save(_file)
_file.close() _file.close()
drag.setPixmap(self.pixmap())
self.pixmap().save(os.path.abspath(_file.name))
drag.start(Qt.MoveAction) drag.start(Qt.MoveAction)
class DeviceView(FileDragAndDrop, QListView): class DeviceView(FileDragAndDrop, QListView):
@ -239,7 +239,7 @@ class DeviceView(FileDragAndDrop, QListView):
def hide_card(self, x): def hide_card(self, x):
self.model().update_devices(card=not x) self.model().update_devices(card=not x)
def files_dropped(self, files, event): def files_dropped(self, files, event):
ids = [] ids = []
md = event.mimeData() md = event.mimeData()
@ -414,13 +414,18 @@ class LibraryBooksModel(QAbstractTableModel):
return files return files
def update_cover(self, index, pix): def update_cover(self, index, pix):
spix = pix.scaledToHeight(68, Qt.SmoothTransformation)
_id = self.id_from_index(index) _id = self.id_from_index(index)
qb = QBuffer() qb, sqb = QBuffer(), QBuffer()
qb.open(QBuffer.ReadWrite) qb.open(QBuffer.ReadWrite)
sqb.open(QBuffer.ReadWrite)
pix.save(qb, "JPG") pix.save(qb, "JPG")
spix.save(sqb, "JPG")
data = str(qb.data()) data = str(qb.data())
sdata = str(sqb.data())
qb.close() qb.close()
self.db.update_cover(_id, data) sqb.close()
self.db.update_cover(_id, data, scaled=sdata)
self.refresh_row(index.row()) self.refresh_row(index.row())
def add_formats(self, paths, index): def add_formats(self, paths, index):