mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Also implement caching of images for the comments editor
This commit is contained in:
parent
d540c6db88
commit
29435392c6
@ -840,20 +840,23 @@ class EditorWidget(QTextEdit, LineEditECM): # {{{
|
|||||||
if qurl.isRelative():
|
if qurl.isRelative():
|
||||||
qurl = self.base_url.resolved(qurl)
|
qurl = self.base_url.resolved(qurl)
|
||||||
if qurl.isLocalFile():
|
if qurl.isLocalFile():
|
||||||
|
data = None
|
||||||
path = qurl.toLocalFile()
|
path = qurl.toLocalFile()
|
||||||
try:
|
try:
|
||||||
with open(path, 'rb') as f:
|
with open(path, 'rb') as f:
|
||||||
data = f.read()
|
data = f.read()
|
||||||
except OSError:
|
except OSError:
|
||||||
if path.rpartition('.')[-1].lower() in {'jpg', 'jpeg', 'gif', 'png', 'bmp', 'webp'}:
|
if path.rpartition('.')[-1].lower() in {'jpg', 'jpeg', 'gif', 'png', 'bmp', 'webp'}:
|
||||||
return QByteArray(bytearray.fromhex(
|
data = bytearray.fromhex(
|
||||||
'89504e470d0a1a0a0000000d49484452'
|
'89504e470d0a1a0a0000000d49484452'
|
||||||
'000000010000000108060000001f15c4'
|
'000000010000000108060000001f15c4'
|
||||||
'890000000a49444154789c6300010000'
|
'890000000a49444154789c6300010000'
|
||||||
'0500010d0a2db40000000049454e44ae'
|
'0500010d0a2db40000000049454e44ae'
|
||||||
'426082'))
|
'426082')
|
||||||
else:
|
if data is not None:
|
||||||
return QByteArray(data)
|
r = QByteArray(data)
|
||||||
|
self.document().addResource(rtype, qurl, r)
|
||||||
|
return r
|
||||||
|
|
||||||
def set_html(self, val, allow_undo=True):
|
def set_html(self, val, allow_undo=True):
|
||||||
if not allow_undo or self.readonly:
|
if not allow_undo or self.readonly:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user