From 33b165bfce093488accf1e98d149e7ab861b2520 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Wed, 18 Nov 2015 01:03:37 +0530 Subject: [PATCH] When sending books without a cover to the device, generate a cover with book metadata instead of using the blank book icon --- src/calibre/gui2/device.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/calibre/gui2/device.py b/src/calibre/gui2/device.py index 53395aa472..75c2d6a139 100644 --- a/src/calibre/gui2/device.py +++ b/src/calibre/gui2/device.py @@ -16,6 +16,7 @@ from calibre.customize.ui import (available_input_formats, available_output_form from calibre.devices.interface import DevicePlugin, currently_connected_device from calibre.devices.errors import (UserFeedback, OpenFeedback, OpenFailed, InitialConnectionError) +from calibre.ebooks.covers import cprefs, override_prefs, scale_cover, generate_cover from calibre.gui2.dialogs.choose_format_device import ChooseFormatDeviceDialog from calibre.utils.ipc.job import BaseJob from calibre.devices.scanner import DeviceScanner @@ -925,8 +926,9 @@ class DeviceMixin(object): # {{{ ) def set_default_thumbnail(self, height): - img = I('book.png', data=True) - self.default_thumbnail = scale_image(img, height, height, preserve_aspect_ratio=False) + ratio = height / float(cprefs['cover_height']) + self.default_thumbnail_prefs = prefs = override_prefs(cprefs) + scale_cover(prefs, ratio) def connect_to_folder_named(self, folder): if os.path.exists(folder) and os.path.isdir(folder): @@ -1730,9 +1732,11 @@ class DeviceMixin(object): # {{{ def update_thumbnail(self, book): if book.cover and os.access(book.cover, os.R_OK): - book.thumbnail = self.cover_to_thumbnail(open(book.cover, 'rb').read()) + with lopen(book.cover, 'rb') as f: + book.thumbnail = self.cover_to_thumbnail(f.read()) else: - book.thumbnail = self.default_thumbnail + cprefs = self.default_thumbnail_prefs + book.thumbnail = (cprefs['cover_width'], cprefs['cover_height'], generate_cover(book, prefs=cprefs)) def set_books_in_library(self, booklists, reset=False, add_as_step_to_job=None, force_send=False, do_device_sync=True):