Fix #1967149 [[Enhancement] Give notice to user about Amazon cover bugs.](https://bugs.launchpad.net/calibre/+bug/1967149)

This commit is contained in:
Kovid Goyal 2022-04-21 20:34:28 +05:30
parent e047a2c84e
commit 00776601aa
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
3 changed files with 63 additions and 1 deletions

View File

@ -8,6 +8,14 @@ from calibre.constants import iswindows
from calibre.customize import Plugin from calibre.customize import Plugin
class OpenPopupMessage:
def __init__(self, title='', message='', level='info'):
self.title = title
self.message = message
self.level = level
class DevicePlugin(Plugin): class DevicePlugin(Plugin):
""" """
Defines the interface that should be implemented by backends that Defines the interface that should be implemented by backends that
@ -69,7 +77,7 @@ class DevicePlugin(Plugin):
# Encapsulates an annotation fetched from the device # Encapsulates an annotation fetched from the device
UserAnnotation = namedtuple('Annotation','type, value') UserAnnotation = namedtuple('Annotation','type, value')
#: GUI displays this as a message if not None. Useful if opening can take a #: GUI displays this as a message if not None in the status bar. Useful if opening can take a
#: long time #: long time
OPEN_FEEDBACK_MESSAGE = None OPEN_FEEDBACK_MESSAGE = None
@ -126,6 +134,11 @@ class DevicePlugin(Plugin):
return cls.__name__ return cls.__name__
return cls.name return cls.name
@classmethod
def get_open_popup_message(self):
' GUI displays this as a non-modal popup. Should be an instance of OpenPopupMessage '
return None
# Device detection {{{ # Device detection {{{
def test_bcd(self, bcdDevice, bcd): def test_bcd(self, bcdDevice, bcd):
if bcd is None or len(bcd) == 0: if bcd is None or len(bcd) == 0:

View File

@ -9,6 +9,7 @@ Device driver for Amazon's Kindle
import datetime, os, re, json, hashlib, errno import datetime, os, re, json, hashlib, errno
from calibre.constants import DEBUG, filesystem_encoding from calibre.constants import DEBUG, filesystem_encoding
from calibre.devices.interface import OpenPopupMessage
from calibre.devices.kindle.bookmark import Bookmark from calibre.devices.kindle.bookmark import Bookmark
from calibre.devices.usbms.driver import USBMS from calibre.devices.usbms.driver import USBMS
from calibre import strftime, fsync, prints from calibre import strftime, fsync, prints
@ -95,6 +96,18 @@ class KINDLE(USBMS):
' Click "Show details" to see the list of books.' ' Click "Show details" to see the list of books.'
) )
@classmethod
def get_open_popup_message(cls):
from calibre.utils.localization import localize_website_link
return OpenPopupMessage(title=_('WARNING: E-book covers'), message=_(
'Amazon has <b>broken display of covers</b> for books sent to the Kindle by USB cable. To workaround it,'
' you have to: <ol><li>Send the books to the Kindle</li><li>Disconnect the Kindle and wait for the covers to be deleted'
' by Amazon</li><li>Reconnect the Kindle and calibre will restore the covers.</li></ol> After this the'
' covers for those books should stay put. <a href="{}">Click here</a> for details.').format(localize_website_link(
'https://manual.calibre-ebook.com/faq.html#covers-for-books-i'
'-send-to-my-e-ink-kindle-show-up-momentarily-and-then-are-replaced-by-a-generic-cover')
))
def is_allowed_book_file(self, filename, path, prefix): def is_allowed_book_file(self, filename, path, prefix):
lpath = os.path.join(path, filename).partition(self.normalize_path(prefix))[2].replace('\\', '/') lpath = os.path.join(path, filename).partition(self.normalize_path(prefix))[2].replace('\\', '/')
return '.sdr/' not in lpath return '.sdr/' not in lpath

View File

@ -132,6 +132,37 @@ class BusyCursor:
QApplication.restoreOverrideCursor() QApplication.restoreOverrideCursor()
def convert_open_popup(opm, skip_key):
class OPM(OpenFeedback):
def __init__(self, opm):
super().__init__('placeholder')
self.opm = opm
self.skip_key = skip_key
def custom_dialog(self, parent):
from calibre.gui2.dialogs.message_box import MessageBox
class M(MessageBox):
def on_cd_finished(s):
gprefs.set(self.skip_key, not s.toggle_checkbox.isChecked())
m = M({
'info': MessageBox.INFO, 'information': MessageBox.INFO,
'warn': MessageBox.WARNING, 'warning': MessageBox.WARNING,
}[self.opm.level], self.opm.title, self.opm.message,
parent=parent
)
tc = m.toggle_checkbox
tc.setVisible(True)
tc.setText(_('Show this message again'))
tc.setChecked(True)
m.resize_needed.emit()
m.finished.connect(m.on_cd_finished)
return m
return OPM(opm)
class DeviceManager(Thread): # {{{ class DeviceManager(Thread): # {{{
def __init__(self, connected_slot, job_manager, open_feedback_slot, def __init__(self, connected_slot, job_manager, open_feedback_slot,
@ -191,6 +222,11 @@ class DeviceManager(Thread): # {{{
for dev, detected_device in connected_devices: for dev, detected_device in connected_devices:
if dev.OPEN_FEEDBACK_MESSAGE is not None: if dev.OPEN_FEEDBACK_MESSAGE is not None:
self.open_feedback_slot(dev.OPEN_FEEDBACK_MESSAGE) self.open_feedback_slot(dev.OPEN_FEEDBACK_MESSAGE)
opm = dev.get_open_popup_message()
if opm is not None:
skip_key = f'do_not_show_device_open_popup_message_{dev.__class__.__name__}'
if not gprefs.get(skip_key, False):
self.open_feedback_msg(dev.get_gui_name(), convert_open_popup(opm, skip_key))
try: try:
dev.reset(detected_device=detected_device, dev.reset(detected_device=detected_device,
report_progress=self.report_progress) report_progress=self.report_progress)