From a24d7f66861d0f2c7a30e55c87e70b7d63769082 Mon Sep 17 00:00:00 2001 From: Iordanis Grigoriou Date: Mon, 26 Jun 2017 12:25:03 +0200 Subject: [PATCH] Use page title for filename with :download --- qutebrowser/browser/commands.py | 3 ++- qutebrowser/browser/qtnetworkdownloads.py | 5 +++-- tests/end2end/features/downloads.feature | 7 +++++++ 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/qutebrowser/browser/commands.py b/qutebrowser/browser/commands.py index 8fead7269..f3d2473d6 100644 --- a/qutebrowser/browser/commands.py +++ b/qutebrowser/browser/commands.py @@ -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): diff --git a/qutebrowser/browser/qtnetworkdownloads.py b/qutebrowser/browser/qtnetworkdownloads.py index 71039dc2d..6dd7c27c9 100644 --- a/qutebrowser/browser/qtnetworkdownloads.py +++ b/qutebrowser/browser/qtnetworkdownloads.py @@ -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 diff --git a/tests/end2end/features/downloads.feature b/tests/end2end/features/downloads.feature index 95b775303..ed583cb61 100644 --- a/tests/end2end/features/downloads.feature +++ b/tests/end2end/features/downloads.feature @@ -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