From 29435392c664e26b5fedbcfe6a6eda9e54c8872a Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Wed, 6 Sep 2023 12:12:50 +0530 Subject: [PATCH] Also implement caching of images for the comments editor --- src/calibre/gui2/comments_editor.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/calibre/gui2/comments_editor.py b/src/calibre/gui2/comments_editor.py index 2a74cd588a..ce7c256a25 100644 --- a/src/calibre/gui2/comments_editor.py +++ b/src/calibre/gui2/comments_editor.py @@ -840,20 +840,23 @@ class EditorWidget(QTextEdit, LineEditECM): # {{{ if qurl.isRelative(): qurl = self.base_url.resolved(qurl) if qurl.isLocalFile(): + data = None path = qurl.toLocalFile() try: with open(path, 'rb') as f: data = f.read() except OSError: if path.rpartition('.')[-1].lower() in {'jpg', 'jpeg', 'gif', 'png', 'bmp', 'webp'}: - return QByteArray(bytearray.fromhex( + data = bytearray.fromhex( '89504e470d0a1a0a0000000d49484452' '000000010000000108060000001f15c4' '890000000a49444154789c6300010000' '0500010d0a2db40000000049454e44ae' - '426082')) - else: - return QByteArray(data) + '426082') + if data is not None: + r = QByteArray(data) + self.document().addResource(rtype, qurl, r) + return r def set_html(self, val, allow_undo=True): if not allow_undo or self.readonly: