From a6c1e806c27d8d1ea7ab6abe5e4e5f53ac324557 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Wed, 23 Jul 2014 11:09:57 +0530 Subject: [PATCH] Edit Book: Make the warning dialog that pops up when you try to quit while the editor is saving changes in the background a little more clear. Fixes #1347171 [Background save dialog confusion with "save changes"](https://bugs.launchpad.net/calibre/+bug/1347171) --- src/calibre/gui2/__init__.py | 11 +++++--- src/calibre/gui2/dialogs/message_box.py | 11 +++++++- src/calibre/gui2/tweak_book/boss.py | 36 +++++++++++++++---------- 3 files changed, 40 insertions(+), 18 deletions(-) diff --git a/src/calibre/gui2/__init__.py b/src/calibre/gui2/__init__.py index b6e356e950..16d9e5ce95 100644 --- a/src/calibre/gui2/__init__.py +++ b/src/calibre/gui2/__init__.py @@ -323,7 +323,11 @@ def question_dialog(parent, title, msg, det_msg='', show_copy_button=False, 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) - override_icon=None): + override_icon=None, + # Change the text/icons of the yes and no buttons. + # The icons must be QIcon objects or strings for I() + yes_text=None, no_text=None, yes_icon=None, no_icon=None, + ): from calibre.gui2.dialogs.message_box import MessageBox auto_skip = set(gprefs.get('questions_to_auto_skip', [])) @@ -331,8 +335,9 @@ def question_dialog(parent, title, msg, det_msg='', show_copy_button=False, return bool(skip_dialog_skipped_value) d = MessageBox(MessageBox.QUESTION, title, msg, det_msg, parent=parent, - show_copy_button=show_copy_button, default_yes=default_yes, - q_icon=override_icon) + show_copy_button=show_copy_button, default_yes=default_yes, + q_icon=override_icon, yes_text=yes_text, no_text=no_text, + yes_icon=yes_icon, no_icon=no_icon) if skip_dialog_name is not None and skip_dialog_msg: tc = d.toggle_checkbox diff --git a/src/calibre/gui2/dialogs/message_box.py b/src/calibre/gui2/dialogs/message_box.py index 927b92e99c..ba2ff5f3da 100644 --- a/src/calibre/gui2/dialogs/message_box.py +++ b/src/calibre/gui2/dialogs/message_box.py @@ -25,7 +25,8 @@ class MessageBox(QDialog, Ui_Dialog): # {{{ det_msg='', q_icon=None, show_copy_button=True, - parent=None, default_yes=True): + parent=None, default_yes=True, + yes_text=None, no_text=None, yes_icon=None, no_icon=None): QDialog.__init__(self, parent) if q_icon is None: icon = { @@ -71,6 +72,14 @@ class MessageBox(QDialog, Ui_Dialog): # {{{ self.bb.button(self.bb.Yes if default_yes else self.bb.No ).setDefault(True) self.default_yes = default_yes + if yes_text is not None: + self.bb.button(self.bb.Yes).setText(yes_text) + if no_text is not None: + self.bb.button(self.bb.No).setText(no_text) + if yes_icon is not None: + self.bb.button(self.bb.Yes).setIcon(yes_icon if isinstance(yes_icon, QIcon) else QIcon(I(yes_icon))) + if no_icon is not None: + self.bb.button(self.bb.No).setIcon(yes_icon if isinstance(no_icon, QIcon) else QIcon(I(no_icon))) else: self.bb.button(self.bb.Ok).setDefault(True) diff --git a/src/calibre/gui2/tweak_book/boss.py b/src/calibre/gui2/tweak_book/boss.py index a9f8d22519..996eb1a699 100644 --- a/src/calibre/gui2/tweak_book/boss.py +++ b/src/calibre/gui2/tweak_book/boss.py @@ -1281,23 +1281,27 @@ class Boss(QObject): self.gui.insert_char.show() # Shutdown {{{ - def quit(self): - if not self.confirm_quit(): - return - self.save_state() - self.shutdown() - QApplication.instance().quit() - def confirm_quit(self): + def quit(self): if self.doing_terminal_save: return False if self.save_manager.has_tasks: - if not question_dialog( + if question_dialog( self.gui, _('Are you sure?'), _( - 'The current book is being saved in the background, quitting will abort' - ' the save process, are you sure?'), default_yes=False): + 'The current book is being saved in the background. Quitting now will' + ' abort the save process! Finish saving first?'), + yes_text=_('Finish &saving first'), no_text=_('&Quit immediately')): + self.start_terminal_save_indicator() return False + if not self.confirm_quit(): + return False + self.save_state() + self.shutdown() + QApplication.instance().quit() + return True + + def confirm_quit(self): if self.gui.action_save.isEnabled(): d = QDialog(self.gui) d.l = QGridLayout(d) @@ -1329,14 +1333,18 @@ class Boss(QObject): return False if d.do_save: self.gui.action_save.trigger() - self.gui.blocking_job.set_msg(_('Saving, please wait...')) - self.gui.blocking_job.start() - self.doing_terminal_save = True - QTimer.singleShot(50, self.check_terminal_save) + self.start_terminal_save_indicator() return False return True + def start_terminal_save_indicator(self): + self.save_state() + self.gui.blocking_job.set_msg(_('Saving, please wait...')) + self.gui.blocking_job.start() + self.doing_terminal_save = True + QTimer.singleShot(50, self.check_terminal_save) + def check_terminal_save(self): if self.save_manager.has_tasks: return QTimer.singleShot(50, self.check_terminal_save)