This commit is contained in:
Kovid Goyal 2023-09-13 13:10:52 +05:30
parent 12d419ff41
commit 71662297a1
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
3 changed files with 14 additions and 5 deletions

View File

@ -624,10 +624,10 @@ def question_dialog(parent, title, msg, det_msg='', show_copy_button=False,
# Set skip_dialog_msg to a message displayed to the user # Set skip_dialog_msg to a message displayed to the user
skip_dialog_name=None, skip_dialog_msg=_('Show this confirmation again'), skip_dialog_name=None, skip_dialog_msg=_('Show this confirmation again'),
skip_dialog_skipped_value=True, skip_dialog_skip_precheck=True, skip_dialog_skipped_value=True, skip_dialog_skip_precheck=True,
# Override icon (QIcon to be used as the icon for this dialog or string for I()) # Override icon (QIcon to be used as the icon for this dialog or string for QIcon.ic())
override_icon=None, override_icon=None,
# Change the text/icons of the yes and no buttons. # Change the text/icons of the yes and no buttons.
# The icons must be QIcon objects or strings for I() # The icons must be QIcon objects or strings for QIcon.ic()
yes_text=None, no_text=None, yes_icon=None, no_icon=None, yes_text=None, no_text=None, yes_icon=None, no_icon=None,
# Add an Abort button which if clicked will cause this function to raise # Add an Abort button which if clicked will cause this function to raise
# the Aborted exception # the Aborted exception

View File

@ -460,7 +460,9 @@ class CopyToLibraryAction(InterfaceAction):
aname = _('Moving to') if delete_after else _('Copying to') aname = _('Moving to') if delete_after else _('Copying to')
dtitle = '%s %s'%(aname, os.path.basename(loc)) dtitle = '%s %s'%(aname, os.path.basename(loc))
self.pd = ProgressDialog(dtitle, min=0, max=len(ids)-1, self.pd = ProgressDialog(dtitle, min=0, max=len(ids)-1,
parent=self.gui, cancelable=True, icon='lt.png') parent=self.gui, cancelable=True, icon='lt.png', cancel_confirm_msg=_(
'Aborting this operation means that only some books will be copied'
' and resuming a partial copy is not supported. Are you sure you want to abort?'))
def progress(idx, title): def progress(idx, title):
self.pd.set_msg(title) self.pd.set_msg(title)

View File

@ -9,7 +9,7 @@ from qt.core import (
QDialog, pyqtSignal, Qt, QVBoxLayout, QLabel, QFont, QProgressBar, QSize, QDialog, pyqtSignal, Qt, QVBoxLayout, QLabel, QFont, QProgressBar, QSize,
QDialogButtonBox, QApplication, QFontMetrics, QHBoxLayout, QIcon) QDialogButtonBox, QApplication, QFontMetrics, QHBoxLayout, QIcon)
from calibre.gui2 import elided_text from calibre.gui2 import elided_text, question_dialog
from calibre.gui2.progress_indicator import ProgressIndicator from calibre.gui2.progress_indicator import ProgressIndicator
@ -17,8 +17,9 @@ class ProgressDialog(QDialog):
canceled_signal = pyqtSignal() canceled_signal = pyqtSignal()
def __init__(self, title, msg='\u00a0', min=0, max=99, parent=None, cancelable=True, icon=None): def __init__(self, title, msg='\u00a0', min=0, max=99, parent=None, cancelable=True, icon=None, cancel_confirm_msg=''):
QDialog.__init__(self, parent) QDialog.__init__(self, parent)
self.cancel_confirm_msg = cancel_confirm_msg
if icon is None: if icon is None:
self.l = l = QVBoxLayout(self) self.l = l = QVBoxLayout(self)
else: else:
@ -113,6 +114,12 @@ class ProgressDialog(QDialog):
self.message.setText(elided_text(val, self.font(), self.message.minimumWidth()-10)) self.message.setText(elided_text(val, self.font(), self.message.minimumWidth()-10))
def _canceled(self, *args): def _canceled(self, *args):
if self.cancel_confirm_msg:
if not question_dialog(
self, _('Are you sure?'), self.cancel_confirm_msg, override_icon='dialog_warning.png',
yes_text=_('Yes, abort'), no_text=_('No, keep copying')
):
return
self.canceled = True self.canceled = True
self.button_box.setDisabled(True) self.button_box.setDisabled(True)
self.title = _('Aborting...') self.title = _('Aborting...')