From ea9796403fe6f00995b5174ffef14b7093f10845 Mon Sep 17 00:00:00 2001 From: Florian Bruhin Date: Tue, 1 Nov 2016 20:53:03 +0100 Subject: [PATCH] Fix _ask_confirm_question --- qutebrowser/browser/downloads.py | 4 ++++ qutebrowser/browser/qtnetworkdownloads.py | 16 +++++++--------- .../browser/webengine/webenginedownloads.py | 14 ++++++++++++++ 3 files changed, 25 insertions(+), 9 deletions(-) diff --git a/qutebrowser/browser/downloads.py b/qutebrowser/browser/downloads.py index db4fd59dc..2df5d9731 100644 --- a/qutebrowser/browser/downloads.py +++ b/qutebrowser/browser/downloads.py @@ -475,6 +475,10 @@ class AbstractDownloadItem(QObject): """Finish initialization based on self._filename.""" raise NotImplementedError + def _ask_confirm_question(self, title, msg): + """Ask a confirmation question for the download.""" + raise NotImplementedError + def _set_fileobj(self, fileobj): """Set a file object to save the download to. diff --git a/qutebrowser/browser/qtnetworkdownloads.py b/qutebrowser/browser/qtnetworkdownloads.py index e841f2aca..d66f34162 100644 --- a/qutebrowser/browser/qtnetworkdownloads.py +++ b/qutebrowser/browser/qtnetworkdownloads.py @@ -106,15 +106,6 @@ class DownloadItem(downloads.AbstractDownloadItem): else: self._set_fileobj(fileobj) - def _ask_confirm_question(self, title, msg): - """Create a Question object to be asked.""" - # FIXME:qtwebengine move this? - no_action = functools.partial(self.cancel, remove_data=False) - message.confirm_async(title=title, text=msg, - yes_action=self._after_set_filename, - no_action=no_action, cancel_action=no_action, - abort_on=[self.cancelled, self.error]) - def _do_die(self): """Abort the download and emit an error.""" self._read_timer.stop() @@ -196,6 +187,13 @@ class DownloadItem(downloads.AbstractDownloadItem): def _after_set_filename(self): self._create_fileobj() + def _ask_confirm_question(self, title, msg): + no_action = functools.partial(self.cancel, remove_data=False) + message.confirm_async(title=title, text=msg, + yes_action=self._after_set_filename, + no_action=no_action, cancel_action=no_action, + abort_on=[self.cancelled, self.error]) + def _set_fileobj(self, fileobj): """"Set the file object to write the download to. diff --git a/qutebrowser/browser/webengine/webenginedownloads.py b/qutebrowser/browser/webengine/webenginedownloads.py index 1d1ef3e8e..77f970e88 100644 --- a/qutebrowser/browser/webengine/webenginedownloads.py +++ b/qutebrowser/browser/webengine/webenginedownloads.py @@ -19,6 +19,7 @@ """QtWebEngine specific code for downloads.""" +import functools from PyQt5.QtCore import pyqtSlot, Qt from PyQt5.QtWebEngineWidgets import QWebEngineDownloadItem @@ -93,6 +94,19 @@ class DownloadItem(downloads.AbstractDownloadItem): "{} (not in requested state)!".format( filename, self, state_name)) + def _ask_confirm_question(self, title, msg): + no_action = functools.partial(self.cancel, remove_data=False) + question = usertypes.Question() + question.title = title + question.text = msg + question.mode = usertypes.PromptMode.yesno + question.answered_yes.connect(self._after_set_filename) + question.answered_no.connect(no_action) + question.cancelled.connect(no_action) + self.cancelled.connect(question.abort) + self.error.connect(question.abort) + message.global_bridge.ask(question, blocking=True) + def _after_set_filename(self): self._qt_item.setPath(self._filename) self._qt_item.accept()