mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Fix #4. Also fix bug in dragging cover image that was introduced by r154
This commit is contained in:
parent
77eeb1fe7a
commit
ca54c6f3b1
@ -197,17 +197,25 @@ class LibraryDatabase(object):
|
||||
self.add_format(_id, "lrf", c.getvalue())
|
||||
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
|
||||
if cover:
|
||||
data = sqlite.Binary(compress(cover))
|
||||
self.con.execute('update books_meta set cover=? where id=?', (data, _id))
|
||||
if not scaled:
|
||||
scaled = cover
|
||||
if scaled:
|
||||
lrf = self.get_format(_id, "lrf")
|
||||
if lrf:
|
||||
c = cStringIO()
|
||||
c.write(lrf)
|
||||
lrf = LRFMetaFile(c)
|
||||
lrf.thumbnail = cover
|
||||
lrf.thumbnail = scaled
|
||||
self.add_format(_id, "lrf", c.getvalue())
|
||||
self.update_max_size(_id)
|
||||
self.commit()
|
||||
|
@ -224,9 +224,9 @@ class CoverDisplay(FileDragAndDrop, QLabel):
|
||||
drag, files = self.drag_object(["jpeg"])
|
||||
if drag and files:
|
||||
_file = files[0]
|
||||
drag.setPixmap(self.pixmap())
|
||||
self.pixmap().save(_file)
|
||||
_file.close()
|
||||
drag.setPixmap(self.pixmap())
|
||||
self.pixmap().save(os.path.abspath(_file.name))
|
||||
drag.start(Qt.MoveAction)
|
||||
|
||||
class DeviceView(FileDragAndDrop, QListView):
|
||||
@ -414,13 +414,18 @@ class LibraryBooksModel(QAbstractTableModel):
|
||||
return files
|
||||
|
||||
def update_cover(self, index, pix):
|
||||
spix = pix.scaledToHeight(68, Qt.SmoothTransformation)
|
||||
_id = self.id_from_index(index)
|
||||
qb = QBuffer()
|
||||
qb, sqb = QBuffer(), QBuffer()
|
||||
qb.open(QBuffer.ReadWrite)
|
||||
sqb.open(QBuffer.ReadWrite)
|
||||
pix.save(qb, "JPG")
|
||||
spix.save(sqb, "JPG")
|
||||
data = str(qb.data())
|
||||
sdata = str(sqb.data())
|
||||
qb.close()
|
||||
self.db.update_cover(_id, data)
|
||||
sqb.close()
|
||||
self.db.update_cover(_id, data, scaled=sdata)
|
||||
self.refresh_row(index.row())
|
||||
|
||||
def add_formats(self, paths, index):
|
||||
|
Loading…
x
Reference in New Issue
Block a user