From a179632356579a954eccf2d23112f061e8187a68 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Sun, 3 Nov 2019 07:12:25 +0530 Subject: [PATCH] Also reset headers/footers when resetting interface And work Qt 5.13.2 bug in more places --- src/pyj/ajax.pyj | 10 +++++++--- src/pyj/viewer-main.pyj | 9 ++++++++- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/src/pyj/ajax.pyj b/src/pyj/ajax.pyj index 5a038eaed5..9337c6ad62 100644 --- a/src/pyj/ajax.pyj +++ b/src/pyj/ajax.pyj @@ -47,6 +47,12 @@ def absolute_path(path): return path +def workaround_qt_bug(xhr, end_type, ok_code=200): + if end_type is 'error' and xhr.status is ok_code: + end_type = 'load' + return end_type + + def ajax(path, on_complete, on_progress=None, bypass_cache=True, method='GET', query=None, timeout=None, ok_code=200, progress_totals_needed=True): # Run an AJAX request. on_complete must be a function that accepts three # arguments: end_type, xhr, ev where end_type is one of 'abort', 'error', @@ -102,9 +108,7 @@ def ajax(path, on_complete, on_progress=None, bypass_cache=True, method='GET', q is_network_error = ev if end_type is 'error' else False if xhr.status is not ok_code and end_type is 'load': end_type = 'error' - if xhr.status is ok_code and end_type is 'error': - # this apparently happens on Qt 5.13.2 - end_type = 'load' + end_type = workaround_qt_bug(xhr, end_type, ok_code) if end_type is not 'load': set_error(end_type, is_network_error) on_complete(end_type, xhr, ev) diff --git a/src/pyj/viewer-main.pyj b/src/pyj/viewer-main.pyj index 39cc53e9d5..4cb4d15b3b 100644 --- a/src/pyj/viewer-main.pyj +++ b/src/pyj/viewer-main.pyj @@ -7,7 +7,7 @@ from elementmaker import E from gettext import gettext as _, install import initialize # noqa: unused-import -from ajax import ajax +from ajax import ajax, workaround_qt_bug from book_list.globals import get_session_data, set_session_data from book_list.library_data import library_data from book_list.theme import get_color @@ -33,6 +33,7 @@ view = None def file_received(name, file_data, proceed, end_type, xhr, ev): + end_type = workaround_qt_bug(xhr, end_type) if end_type is 'abort': return if end_type is not 'load': @@ -61,6 +62,7 @@ def get_file(book, name, proceed): xhr.send() def mathjax_file_received(name, proceed, end_type, xhr, ev): + end_type = workaround_qt_bug(xhr, end_type) if end_type is 'abort': return if end_type is not 'load': @@ -138,6 +140,7 @@ def show_error(title, msg, details): def manifest_received(key, initial_cfi, initial_toc_node, initial_bookpos, pathtoebook, end_type, xhr, ev): nonlocal book + end_type = workaround_qt_bug(xhr, end_type) if end_type is 'load': book = new_book(key, {}) data = xhr.response @@ -324,11 +327,15 @@ if window is window.top: to_python.toggle_inspector() ui_operations.reset_interface = def(): sd = get_session_data() + defaults = session_defaults() m = sd.get('standalone_misc_settings', {}) v'delete m.show_actions_toolbar' sd.set('standalone_misc_settings', m) sd.set('book_scrollbar', False) view.book_scrollbar.apply_visibility() + sd.set('header', defaults.header) + sd.set('footer', defaults.footer) + view.update_header_footer() to_python.reset_interface() ui_operations.toggle_lookup = def(): to_python.toggle_lookup()