Fix _ask_confirm_question

This commit is contained in:
Florian Bruhin 2016-11-01 20:53:03 +01:00
parent bf994cd8da
commit ea9796403f
3 changed files with 25 additions and 9 deletions

View File

@ -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.

View File

@ -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.

View File

@ -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()