From 5e3cb90b12f3b46fa24fa392e672a74ebdb74942 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Fri, 1 Jan 2010 11:26:30 -0700 Subject: [PATCH] Fix cover handling in device drivers --- src/calibre/devices/interface.py | 2 +- src/calibre/gui2/device.py | 10 ++++++---- src/calibre/gui2/library.py | 2 +- 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/src/calibre/devices/interface.py b/src/calibre/devices/interface.py index a774ed37ed..dec3f0304a 100644 --- a/src/calibre/devices/interface.py +++ b/src/calibre/devices/interface.py @@ -275,7 +275,7 @@ class DevicePlugin(Plugin): :metadata: If not None, it is a list of :class:`MetaInformation` objects. The idea is to use the metadata to determine where on the device to put the book. len(metadata) == len(files). Apart from the regular - cover_data, there may also be a thumbnail attribute, which should + cover (path to cover), there may also be a thumbnail attribute, which should be used in preference. The thumbnail attribute is of the form (width, height, cover_data as jpeg). In addition the MetaInformation objects can have a tag_order attribute. diff --git a/src/calibre/gui2/device.py b/src/calibre/gui2/device.py index a8c30f9532..b07d8fab8e 100644 --- a/src/calibre/gui2/device.py +++ b/src/calibre/gui2/device.py @@ -715,8 +715,9 @@ class DeviceGUI(object): prefix = ascii_filename(prefix) names.append('%s_%d%s'%(prefix, id, os.path.splitext(f.name)[1])) - if mi.cover_data and mi.cover_data[1]: - mi.thumbnail = self.cover_to_thumbnail(mi.cover_data[1]) + if mi.cover and os.path.access(mi.cover, os.R_OK): + mi.thumbnail = self.cover_to_thumbnail(open(mi.cover, + 'rb').read()) dynamic.set('news_to_be_synced', set([])) if config['upload_news_to_device'] and files: remove = ids if \ @@ -751,8 +752,9 @@ class DeviceGUI(object): metadata = self.library_view.model().metadata_for(ids) ids = iter(ids) for mi in metadata: - if mi.cover_data and mi.cover_data[1]: - mi.thumbnail = self.cover_to_thumbnail(mi.cover_data[1]) + if mi.cover and os.path.access(mi.cover, os.R_OK): + mi.thumbnail = self.cover_to_thumbnail(open(mi.cover, + 'rb').read()) imetadata = iter(metadata) files = [getattr(f, 'name', None) for f in _files] diff --git a/src/calibre/gui2/library.py b/src/calibre/gui2/library.py index 4737cdadcd..a7c74fa1cf 100644 --- a/src/calibre/gui2/library.py +++ b/src/calibre/gui2/library.py @@ -405,7 +405,7 @@ class BooksModel(QAbstractTableModel): mi = self.db.get_metadata(id, index_is_id=True) if mi.series is not None: mi.tag_order = { mi.series: self.db.books_in_series_of(id, - index_is_id=True)} + index_is_id=True, get_cover=True)} ans.append(mi) return ans