Fix _ask_confirm_question
This commit is contained in:
parent
bf994cd8da
commit
ea9796403f
@ -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.
|
||||
|
||||
|
@ -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.
|
||||
|
||||
|
@ -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()
|
||||
|
Loading…
Reference in New Issue
Block a user