When presenting the calibre must be restarted warning after installing a new plugin, add a restart now button so that the user can conveniently restart calibre

This commit is contained in:
Kovid Goyal 2012-07-27 09:20:30 +05:30
parent 9d90cfd756
commit ffdbd911e0
5 changed files with 32 additions and 2 deletions

View File

@ -45,6 +45,8 @@ class PreferencesAction(InterfaceAction):
d = PluginUpdaterDialog(self.gui, d = PluginUpdaterDialog(self.gui,
initial_filter=FILTER_NOT_INSTALLED) initial_filter=FILTER_NOT_INSTALLED)
d.exec_() d.exec_()
if d.do_restart:
self.gui.quit(restart=True)
def do_config(self, checked=False, initial_plugin=None, def do_config(self, checked=False, initial_plugin=None,
close_after_initial=False): close_after_initial=False):

View File

@ -456,6 +456,7 @@ class PluginUpdaterDialog(SizePersistedDialog):
self.gui = gui self.gui = gui
self.forum_link = None self.forum_link = None
self.model = None self.model = None
self.do_restart = False
self._initialize_controls() self._initialize_controls()
self._create_context_menu() self._create_context_menu()
@ -720,6 +721,7 @@ class PluginUpdaterDialog(SizePersistedDialog):
prints('Installing plugin: ', zip_path) prints('Installing plugin: ', zip_path)
self.gui.status_bar.showMessage(_('Installing plugin: %s') % zip_path) self.gui.status_bar.showMessage(_('Installing plugin: %s') % zip_path)
do_restart = False
try: try:
try: try:
plugin = add_plugin(zip_path) plugin = add_plugin(zip_path)
@ -731,11 +733,21 @@ class PluginUpdaterDialog(SizePersistedDialog):
widget.gui = self.gui widget.gui = self.gui
widget.check_for_add_to_toolbars(plugin) widget.check_for_add_to_toolbars(plugin)
self.gui.status_bar.showMessage(_('Plugin installed: %s') % display_plugin.name) self.gui.status_bar.showMessage(_('Plugin installed: %s') % display_plugin.name)
info_dialog(self.gui, _('Success'), d = info_dialog(self.gui, _('Success'),
_('Plugin <b>{0}</b> successfully installed under <b>' _('Plugin <b>{0}</b> successfully installed under <b>'
' {1} plugins</b>. You may have to restart calibre ' ' {1} plugins</b>. You may have to restart calibre '
'for the plugin to take effect.').format(plugin.name, plugin.type), 'for the plugin to take effect.').format(plugin.name, plugin.type),
show=True, show_copy_button=False) show_copy_button=False)
b = d.bb.addButton(_('Restart calibre now'), d.bb.AcceptRole)
b.setIcon(QIcon(I('lt.png')))
d.do_restart = False
def rf():
d.do_restart = True
b.clicked.connect(rf)
d.set_details('')
d.exec_()
b.clicked.disconnect()
do_restart = d.do_restart
display_plugin.plugin = plugin display_plugin.plugin = plugin
# We cannot read the 'actual' version information as the plugin will not be loaded yet # We cannot read the 'actual' version information as the plugin will not be loaded yet
@ -762,6 +774,9 @@ class PluginUpdaterDialog(SizePersistedDialog):
else: else:
self.model.refresh_plugin(display_plugin) self.model.refresh_plugin(display_plugin)
self._select_and_focus_view(change_selection=False) self._select_and_focus_view(change_selection=False)
if do_restart:
self.do_restart = True
self.accept()
def _history_clicked(self): def _history_clicked(self):
display_plugin = self._selected_display_plugin() display_plugin = self._selected_display_plugin()

View File

@ -236,6 +236,7 @@ class ConfigWidgetBase(QWidget, ConfigWidgetInterface):
''' '''
changed_signal = pyqtSignal() changed_signal = pyqtSignal()
restart_now = pyqtSignal()
supports_restoring_to_defaults = True supports_restoring_to_defaults = True
restart_critical = False restart_critical = False

View File

@ -290,6 +290,7 @@ class Preferences(QMainWindow):
self.apply_action.setEnabled(False) self.apply_action.setEnabled(False)
self.showing_widget.changed_signal.connect(lambda : self.showing_widget.changed_signal.connect(lambda :
self.apply_action.setEnabled(True)) self.apply_action.setEnabled(True))
self.showing_widget.restart_now.connect(self.restart_now)
self.restore_action.setEnabled(self.showing_widget.supports_restoring_to_defaults) self.restore_action.setEnabled(self.showing_widget.supports_restoring_to_defaults)
tt = self.showing_widget.restore_defaults_desc tt = self.showing_widget.restore_defaults_desc
if not self.restore_action.isEnabled(): if not self.restore_action.isEnabled():
@ -319,6 +320,15 @@ class Preferences(QMainWindow):
elif self.stack.currentIndex() == 0: elif self.stack.currentIndex() == 0:
self.close() self.close()
def restart_now(self):
try:
self.showing_widget.commit()
except AbortCommit:
return
self.hide_plugin()
self.close()
self.gui.quit(restart=True)
def commit(self, *args): def commit(self, *args):
try: try:
must_restart = self.showing_widget.commit() must_restart = self.showing_widget.commit()

View File

@ -384,6 +384,8 @@ class ConfigWidget(ConfigWidgetBase, Ui_Form):
self._plugin_model.populate() self._plugin_model.populate()
self._plugin_model.reset() self._plugin_model.reset()
self.changed_signal.emit() self.changed_signal.emit()
if d.do_restart:
self.restart_now.emit()
def reload_store_plugins(self): def reload_store_plugins(self):
self.gui.load_store_plugins() self.gui.load_store_plugins()