Remove workaround for Qt file:// URL based images not rendering on Windows

The proper fix from Qt has been patched into the calibre windows build.
This commit is contained in:
Kovid Goyal 2024-02-16 09:33:00 +05:30
parent 828dbe5ee4
commit e15ab16153
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
2 changed files with 5 additions and 24 deletions

View File

@ -1688,23 +1688,13 @@ def timed_print(*a, **kw):
def local_path_for_resource(qurl: QUrl, base_qurl: 'QUrl | None' = None) -> str: def local_path_for_resource(qurl: QUrl, base_qurl: 'QUrl | None' = None) -> str:
import re
def fix_qt_bodging_windows_paths(path: str) -> str:
# When loading <img src="file:///c:/path/to/img.png"> Qt gives us the
# URL: //c/path/to/img.png Le bubbling sigh
# https://bugreports.qt.io/browse/QTBUG-122201
if iswindows and re.match(r'//[a-zA-Z]/', path) is not None and not os.path.exists(path):
path = os.path.normpath(path[2] + ':' + path[3:])
return path
if base_qurl and qurl.isRelative(): if base_qurl and qurl.isRelative():
qurl = base_qurl.resolved(qurl) qurl = base_qurl.resolved(qurl)
if qurl.isLocalFile(): if qurl.isLocalFile():
return fix_qt_bodging_windows_paths(qurl.toLocalFile()) return qurl.toLocalFile()
if qurl.isRelative(): # this means has no scheme if qurl.isRelative(): # this means has no scheme
return fix_qt_bodging_windows_paths(qurl.path()) return qurl.path()
return '' return ''

View File

@ -23,7 +23,7 @@ from calibre import (
fit_image, human_readable, isbytestring, prepare_string_for_xml, strftime, fit_image, human_readable, isbytestring, prepare_string_for_xml, strftime,
) )
from calibre.constants import ( from calibre.constants import (
DEBUG, config_dir, dark_link_color, filesystem_encoding, iswindows, DEBUG, config_dir, dark_link_color, filesystem_encoding
) )
from calibre.db.search import CONTAINS_MATCH, EQUALS_MATCH, REGEXP_MATCH, _match from calibre.db.search import CONTAINS_MATCH, EQUALS_MATCH, REGEXP_MATCH, _match
from calibre.db.utils import force_to_bool from calibre.db.utils import force_to_bool
@ -916,17 +916,8 @@ class BooksModel(QAbstractTableModel): # {{{
text = fffunc(field_obj, idfunc(idx)) text = fffunc(field_obj, idfunc(idx))
return (text) if force_to_bool(text) is None else None return (text) if force_to_bool(text) is None else None
else: else:
if iswindows and dt == 'comments': def func(idx):
# https://bugreports.qt.io/browse/QTBUG-122201 return fffunc(field_obj, idfunc(idx), default_value='')
file_pat = re.compile(r'"file:///([a-zA-Z]):/(.+?)"')
def func(idx):
ans = fffunc(field_obj, idfunc(idx), default_value='')
if ans:
ans = file_pat.sub(r'"file:///\1%3a/\2"', ans)
return ans
else:
def func(idx):
return fffunc(field_obj, idfunc(idx), default_value='')
elif dt == 'datetime': elif dt == 'datetime':
def func(idx): def func(idx):
val = fffunc(field_obj, idfunc(idx), default_value=UNDEFINED_DATE) val = fffunc(field_obj, idfunc(idx), default_value=UNDEFINED_DATE)