Add suggested_fn argument to get_request

This commit is contained in:
Iordanis Grigoriou 2017-06-26 23:21:32 +02:00
parent a24d7f6686
commit 8a5b48d374
2 changed files with 12 additions and 7 deletions

View File

@ -1443,9 +1443,13 @@ class CommandDispatcher:
download_manager.get_mhtml(tab, target) download_manager.get_mhtml(tab, target)
else: else:
qnam = tab.networkaccessmanager() qnam = tab.networkaccessmanager()
download_manager.get(self._current_url(), user_agent=user_agent, download_manager.get(
qnam=qnam, target=target, self._current_url(),
title=self._current_title()) user_agent=user_agent,
qnam=qnam,
target=target,
suggested_fn=utils.sanitize_filename(tab.title() + ".html")
)
@cmdutils.register(instance='command-dispatcher', scope='window') @cmdutils.register(instance='command-dispatcher', scope='window')
def view_source(self): def view_source(self):

View File

@ -412,7 +412,7 @@ class DownloadManager(downloads.AbstractDownloadManager):
mhtml.start_download_checked, tab=tab)) mhtml.start_download_checked, tab=tab))
message.global_bridge.ask(question, blocking=False) message.global_bridge.ask(question, blocking=False)
def get_request(self, request, *, target=None, title=None, **kwargs): def get_request(self, request, *, target=None, suggested_fn=None, **kwargs):
"""Start a download with a QNetworkRequest. """Start a download with a QNetworkRequest.
Args: Args:
@ -428,9 +428,10 @@ class DownloadManager(downloads.AbstractDownloadManager):
request.setAttribute(QNetworkRequest.CacheLoadControlAttribute, request.setAttribute(QNetworkRequest.CacheLoadControlAttribute,
QNetworkRequest.AlwaysNetwork) QNetworkRequest.AlwaysNetwork)
if request.url().scheme().lower() != 'data': if suggested_fn is not None:
suggested_fn = (utils.sanitize_filename(title) + ".html" if title pass
else urlutils.filename_from_url(request.url())) elif request.url().scheme().lower() != 'data':
suggested_fn = urlutils.filename_from_url(request.url())
else: else:
# We might be downloading a binary blob embedded on a page or even # We might be downloading a binary blob embedded on a page or even
# generated dynamically via javascript. We try to figure out a more # generated dynamically via javascript. We try to figure out a more