Use page title for filename with :download

This commit is contained in:
Iordanis Grigoriou 2017-06-26 12:25:03 +02:00
parent cb5cd1a910
commit a24d7f6686
3 changed files with 12 additions and 3 deletions

View File

@ -1444,7 +1444,8 @@ class CommandDispatcher:
else:
qnam = tab.networkaccessmanager()
download_manager.get(self._current_url(), user_agent=user_agent,
qnam=qnam, target=target)
qnam=qnam, target=target,
title=self._current_title())
@cmdutils.register(instance='command-dispatcher', scope='window')
def view_source(self):

View File

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

View File

@ -22,6 +22,13 @@ Feature: Downloading things from a website.
And I wait until the download is finished
Then the downloaded file download.bin should exist
Scenario: Using :download with no URL
When I set storage -> prompt-download-directory to false
And I open data/downloads/downloads.html
And I run :download
And I wait until the download is finished
Then the downloaded file Simple downloads.html should exist
Scenario: Using hints
When I set storage -> prompt-download-directory to false
And I open data/downloads/downloads.html