Refactored question logic.
This commit is contained in:
parent
f0779f8cc0
commit
6c6ae4e465
@ -267,15 +267,17 @@ class DownloadItem(QObject):
|
|||||||
else:
|
else:
|
||||||
self.set_fileobj(fileobj)
|
self.set_fileobj(fileobj)
|
||||||
|
|
||||||
def _create_overwrite_question(self):
|
def _ask_overwrite_question(self):
|
||||||
"""Create a Question object to be asked."""
|
"""Create a Question object to be asked."""
|
||||||
q = usertypes.Question(self)
|
q = usertypes.Question(self)
|
||||||
q.text = " already exists. Overwrite? (y/n)"
|
q.text = self._filename + " already exists. Overwrite? (y/n)"
|
||||||
q.mode = usertypes.PromptMode.yesno
|
q.mode = usertypes.PromptMode.yesno
|
||||||
q.answered_yes.connect(self._create_fileobj)
|
q.answered_yes.connect(self._create_fileobj)
|
||||||
q.answered_no.connect(functools.partial(self.cancel, False))
|
q.answered_no.connect(functools.partial(self.cancel, False))
|
||||||
q.cancelled.connect(functools.partial(self.cancel, False))
|
q.cancelled.connect(functools.partial(self.cancel, False))
|
||||||
return q
|
message_bridge = objreg.get('message-bridge', scope='window',
|
||||||
|
window=self._win_id)
|
||||||
|
message_bridge.ask(q, blocking=False)
|
||||||
|
|
||||||
def _die(self, msg):
|
def _die(self, msg):
|
||||||
"""Abort the download and emit an error."""
|
"""Abort the download and emit an error."""
|
||||||
@ -405,11 +407,7 @@ class DownloadItem(QObject):
|
|||||||
if os.path.isfile(self._filename):
|
if os.path.isfile(self._filename):
|
||||||
# The file already exists, so ask the user if it should be
|
# The file already exists, so ask the user if it should be
|
||||||
# overwritten.
|
# overwritten.
|
||||||
q = self._create_overwrite_question()
|
self._ask_overwrite_question()
|
||||||
q.text = self._filename + q.text
|
|
||||||
message_bridge = objreg.get('message-bridge', scope='window',
|
|
||||||
window=self._win_id)
|
|
||||||
message_bridge.ask(q, blocking=False)
|
|
||||||
else:
|
else:
|
||||||
self._create_fileobj()
|
self._create_fileobj()
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user