Ask question instead of aborting

This commit is contained in:
Martin Tournoij 2015-06-27 22:28:06 +02:00
parent 26664ba644
commit d114e64b05

View File

@ -296,10 +296,10 @@ class DownloadItem(QObject):
else: else:
self.set_fileobj(fileobj) self.set_fileobj(fileobj)
def _ask_overwrite_question(self): def _ask_confirm_question(self, message):
"""Create a Question object to be asked.""" """Create a Question object to be asked."""
q = usertypes.Question(self) q = usertypes.Question(self)
q.text = self._filename + " already exists. Overwrite? (y/n)" q.text = message + ' (N/y)'
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))
@ -452,14 +452,11 @@ 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.
self._ask_overwrite_question() self._ask_confirm_question(self._filename + " already exists. Overwrite?")
# FIFO, device node, etc. Don't even try. # FIFO, device node, etc. Make sure we want to do this
elif (os.path.exists(self._filename) and not elif (os.path.exists(self._filename) and not
os.path.isdir(self._filename)): os.path.isdir(self._filename)):
self.cancel(False) self._ask_confirm_question(self._filename + " already exists and is a special file. Write to this?")
message.error(self._win_id, "The file {} already exists, and is a "
"special file. Aborting.".format(
self._filename))
else: else:
self._create_fileobj() self._create_fileobj()