mhtml: web_view -> tab rename
Otherwise this sounds like we still have a QWebView. This also fixes the cur_url access.
This commit is contained in:
parent
2befebaf3a
commit
b8086d1d13
@ -1197,21 +1197,21 @@ class CommandDispatcher:
|
|||||||
Args:
|
Args:
|
||||||
dest: The file path to write the download to.
|
dest: The file path to write the download to.
|
||||||
"""
|
"""
|
||||||
web_view = self._current_widget()
|
tab = self._current_widget()
|
||||||
if dest is None:
|
if dest is None:
|
||||||
suggested_fn = self._current_title() + ".mht"
|
suggested_fn = self._current_title() + ".mht"
|
||||||
suggested_fn = utils.sanitize_filename(suggested_fn)
|
suggested_fn = utils.sanitize_filename(suggested_fn)
|
||||||
filename, q = downloads.ask_for_filename(
|
filename, q = downloads.ask_for_filename(
|
||||||
suggested_fn, self._win_id, parent=web_view,
|
suggested_fn, self._win_id, parent=tab,
|
||||||
)
|
)
|
||||||
if filename is not None:
|
if filename is not None:
|
||||||
mhtml.start_download_checked(filename, web_view=web_view)
|
mhtml.start_download_checked(filename, tab=tab)
|
||||||
else:
|
else:
|
||||||
q.answered.connect(functools.partial(
|
q.answered.connect(functools.partial(
|
||||||
mhtml.start_download_checked, web_view=web_view))
|
mhtml.start_download_checked, tab=tab))
|
||||||
q.ask()
|
q.ask()
|
||||||
else:
|
else:
|
||||||
mhtml.start_download_checked(dest, web_view=web_view)
|
mhtml.start_download_checked(dest, tab=tab)
|
||||||
|
|
||||||
@cmdutils.register(instance='command-dispatcher', scope='window')
|
@cmdutils.register(instance='command-dispatcher', scope='window')
|
||||||
def view_source(self):
|
def view_source(self):
|
||||||
|
@ -222,7 +222,7 @@ class _Downloader:
|
|||||||
"""A class to download whole websites.
|
"""A class to download whole websites.
|
||||||
|
|
||||||
Attributes:
|
Attributes:
|
||||||
web_view: The QWebView which contains the website that will be saved.
|
tab: The AbstractTab which contains the website that will be saved.
|
||||||
dest: Destination filename.
|
dest: Destination filename.
|
||||||
writer: The MHTMLWriter object which is used to save the page.
|
writer: The MHTMLWriter object which is used to save the page.
|
||||||
loaded_urls: A set of QUrls of finished asset downloads.
|
loaded_urls: A set of QUrls of finished asset downloads.
|
||||||
@ -233,15 +233,15 @@ class _Downloader:
|
|||||||
_win_id: The window this downloader belongs to.
|
_win_id: The window this downloader belongs to.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self, web_view, dest):
|
def __init__(self, tab, dest):
|
||||||
self.web_view = web_view
|
self.tab = tab
|
||||||
self.dest = dest
|
self.dest = dest
|
||||||
self.writer = None
|
self.writer = None
|
||||||
self.loaded_urls = {web_view.cur_url}
|
self.loaded_urls = {tab.url()}
|
||||||
self.pending_downloads = set()
|
self.pending_downloads = set()
|
||||||
self._finished_file = False
|
self._finished_file = False
|
||||||
self._used = False
|
self._used = False
|
||||||
self._win_id = web_view.win_id
|
self._win_id = tab.win_id
|
||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
"""Download and save the page.
|
"""Download and save the page.
|
||||||
@ -252,10 +252,10 @@ class _Downloader:
|
|||||||
if self._used:
|
if self._used:
|
||||||
raise ValueError("Downloader already used")
|
raise ValueError("Downloader already used")
|
||||||
self._used = True
|
self._used = True
|
||||||
web_url = self.web_view.cur_url
|
web_url = self.tab.url()
|
||||||
|
|
||||||
# FIXME:qtwebengine have a proper API for this
|
# FIXME:qtwebengine have a proper API for this
|
||||||
page = self.web_view._widget.page() # pylint: disable=protected-access
|
page = self.tab._widget.page() # pylint: disable=protected-access
|
||||||
web_frame = page.mainFrame()
|
web_frame = page.mainFrame()
|
||||||
|
|
||||||
self.writer = MHTMLWriter(
|
self.writer = MHTMLWriter(
|
||||||
@ -482,28 +482,28 @@ class _NoCloseBytesIO(io.BytesIO):
|
|||||||
super().close()
|
super().close()
|
||||||
|
|
||||||
|
|
||||||
def _start_download(dest, web_view):
|
def _start_download(dest, tab):
|
||||||
"""Start downloading the current page and all assets to an MHTML file.
|
"""Start downloading the current page and all assets to an MHTML file.
|
||||||
|
|
||||||
This will overwrite dest if it already exists.
|
This will overwrite dest if it already exists.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
dest: The filename where the resulting file should be saved.
|
dest: The filename where the resulting file should be saved.
|
||||||
web_view: Specify the webview whose page should be loaded.
|
tab: Specify the tab whose page should be loaded.
|
||||||
"""
|
"""
|
||||||
loader = _Downloader(web_view, dest)
|
loader = _Downloader(tab, dest)
|
||||||
loader.run()
|
loader.run()
|
||||||
|
|
||||||
|
|
||||||
def start_download_checked(dest, web_view):
|
def start_download_checked(dest, tab):
|
||||||
"""First check if dest is already a file, then start the download.
|
"""First check if dest is already a file, then start the download.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
dest: The filename where the resulting file should be saved.
|
dest: The filename where the resulting file should be saved.
|
||||||
web_view: Specify the webview whose page should be loaded.
|
tab: Specify the tab whose page should be loaded.
|
||||||
"""
|
"""
|
||||||
# The default name is 'page title.mht'
|
# The default name is 'page title.mht'
|
||||||
title = web_view.title()
|
title = tab.title()
|
||||||
default_name = utils.sanitize_filename(title + '.mht')
|
default_name = utils.sanitize_filename(title + '.mht')
|
||||||
|
|
||||||
# Remove characters which cannot be expressed in the file system encoding
|
# Remove characters which cannot be expressed in the file system encoding
|
||||||
@ -527,12 +527,12 @@ def start_download_checked(dest, web_view):
|
|||||||
# saving the file anyway.
|
# saving the file anyway.
|
||||||
if not os.path.isdir(os.path.dirname(path)):
|
if not os.path.isdir(os.path.dirname(path)):
|
||||||
folder = os.path.dirname(path)
|
folder = os.path.dirname(path)
|
||||||
message.error(web_view.win_id,
|
message.error(tab.win_id,
|
||||||
"Directory {} does not exist.".format(folder))
|
"Directory {} does not exist.".format(folder))
|
||||||
return
|
return
|
||||||
|
|
||||||
if not os.path.isfile(path):
|
if not os.path.isfile(path):
|
||||||
_start_download(path, web_view=web_view)
|
_start_download(path, tab=tab)
|
||||||
return
|
return
|
||||||
|
|
||||||
q = usertypes.Question()
|
q = usertypes.Question()
|
||||||
@ -540,7 +540,7 @@ def start_download_checked(dest, web_view):
|
|||||||
q.text = "{} exists. Overwrite?".format(path)
|
q.text = "{} exists. Overwrite?".format(path)
|
||||||
q.completed.connect(q.deleteLater)
|
q.completed.connect(q.deleteLater)
|
||||||
q.answered_yes.connect(functools.partial(
|
q.answered_yes.connect(functools.partial(
|
||||||
_start_download, path, web_view=web_view))
|
_start_download, path, tab=tab))
|
||||||
message_bridge = objreg.get('message-bridge', scope='window',
|
message_bridge = objreg.get('message-bridge', scope='window',
|
||||||
window=web_view.win_id)
|
window=tab.win_id)
|
||||||
message_bridge.ask(q, blocking=False)
|
message_bridge.ask(q, blocking=False)
|
||||||
|
Loading…
Reference in New Issue
Block a user