From 6b086d159d337451d5d2a9363211aa662d0c4733 Mon Sep 17 00:00:00 2001 From: Daniel Date: Tue, 22 Sep 2015 13:37:03 +0200 Subject: [PATCH] Ask for filename when none is given --- qutebrowser/browser/commands.py | 18 ++++++++++++++++-- qutebrowser/misc/mhtml.py | 2 ++ 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/qutebrowser/browser/commands.py b/qutebrowser/browser/commands.py index 641e4aaee..6477bf3f4 100644 --- a/qutebrowser/browser/commands.py +++ b/qutebrowser/browser/commands.py @@ -43,6 +43,8 @@ from qutebrowser.utils import (message, usertypes, log, qtutils, urlutils, objreg, utils) from qutebrowser.utils.usertypes import KeyMode from qutebrowser.misc import editor, guiprocess, mhtml +from qutebrowser.browser.downloads import (_path_suggestion as + download_path_suggestion) class CommandDispatcher: @@ -1158,13 +1160,25 @@ class CommandDispatcher: download_manager.get(self._current_url(), page=page) @cmdutils.register(instance='command-dispatcher', scope='window') - def download_whole(self, dest): + def download_whole(self, dest=None): """Download the current page as a MHTML file, including all assets. Args: dest: The file path to write the download to. """ - mhtml.start_download(dest) + if dest is None: + suggested_fn = self._current_title() + ".mht" + q = usertypes.Question() + q.text = "Save page to: " + q.mode = usertypes.PromptMode.text + q.completed.connect(q.deleteLater) + q.default = download_path_suggestion(suggested_fn) + q.answered.connect(mhtml.start_download) + message_bridge = objreg.get("message-bridge", scope="window", + window=self._win_id) + message_bridge.ask(q, blocking=False) + else: + mhtml.start_download(dest) @cmdutils.register(instance='command-dispatcher', scope='window', deprecated="Use :download instead.") diff --git a/qutebrowser/misc/mhtml.py b/qutebrowser/misc/mhtml.py index 424d405bc..2353602fc 100644 --- a/qutebrowser/misc/mhtml.py +++ b/qutebrowser/misc/mhtml.py @@ -21,6 +21,7 @@ import functools import io +import os from collections import namedtuple from base64 import b64encode @@ -285,6 +286,7 @@ def start_download(dest): Args: dest: The filename where the resulting file should be saved. """ + dest = os.path.expanduser(dest) web_view = objreg.get("webview", scope="tab", tab="current") loader = _Downloader(web_view, dest) loader.run()