Skip to content

Commit

Permalink
Fix #2035215 ['abort' copy is too abrupt](https://bugs.launchpad.net/…
Browse files Browse the repository at this point in the history
  • Loading branch information
kovidgoyal committed Sep 13, 2023
1 parent 12d419f commit 7166229
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 5 deletions.
4 changes: 2 additions & 2 deletions src/calibre/gui2/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
skip_dialog_name=None, skip_dialog_msg=_('Show this confirmation again'),
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,
# 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,
# Add an Abort button which if clicked will cause this function to raise
# the Aborted exception
Expand Down
4 changes: 3 additions & 1 deletion src/calibre/gui2/actions/copy_to_library.py
Original file line number Diff line number Diff line change
Expand Up @@ -460,7 +460,9 @@ def do_copy(self, ids, db, loc, delete_after, add_duplicates=False):
aname = _('Moving to') if delete_after else _('Copying to')
dtitle = '%s %s'%(aname, os.path.basename(loc))
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):
self.pd.set_msg(title)
Expand Down
11 changes: 9 additions & 2 deletions src/calibre/gui2/dialogs/progress.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,17 @@
QDialog, pyqtSignal, Qt, QVBoxLayout, QLabel, QFont, QProgressBar, QSize,
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


class ProgressDialog(QDialog):

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)
self.cancel_confirm_msg = cancel_confirm_msg
if icon is None:
self.l = l = QVBoxLayout(self)
else:
Expand Down Expand Up @@ -113,6 +114,12 @@ def msg(self, val):
self.message.setText(elided_text(val, self.font(), self.message.minimumWidth()-10))

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.button_box.setDisabled(True)
self.title = _('Aborting...')
Expand Down

0 comments on commit 7166229

Please sign in to comment.