'+_('Update only if one of the ' 'new features or bug fixes is important to you. ' - 'If the current version works well for you, do not update.'))%(__appname__, version)) + 'If the current version works well for you, do not update.'))%( + __appname__, calibre_version)) self.label.setOpenExternalLinks(True) self.label.setWordWrap(True) self.setWindowTitle(_('Update available!')) @@ -78,18 +91,30 @@ class UpdateNotification(QDialog): b = self.bb.addButton(_('&Get update'), self.bb.AcceptRole) b.setDefault(True) b.setIcon(QIcon(I('arrow-down.png'))) + if plugin_updates > 0: + b = self.bb.addButton(_('Update &plugins'), self.bb.ActionRole) + b.setIcon(QIcon(I('plugins/plugin_updater.png'))) + b.clicked.connect(self.get_plugins, type=Qt.QueuedConnection) self.bb.addButton(self.bb.Cancel) self.l.addWidget(self.bb, 2, 0, 1, -1) self.bb.accepted.connect(self.accept) self.bb.rejected.connect(self.reject) - dynamic.set('update to version %s'%version, False) + dynamic.set('update to version %s'%calibre_version, False) + + def get_plugins(self): + from calibre.gui2.dialogs.plugin_updater import (PluginUpdaterDialog, + FILTER_UPDATE_AVAILABLE) + d = PluginUpdaterDialog(self.parent(), + initial_filter=FILTER_UPDATE_AVAILABLE) + d.exec_() def show_future(self, *args): config.set('new_version_notification', bool(self.cb.isChecked())) def accept(self): - url = 'http://calibre-ebook.com/download_'+\ - ('windows' if iswindows else 'osx' if isosx else 'linux') + url = ('http://calibre-ebook.com/download_' + + ('portable' if isportable else 'windows' if iswindows + else 'osx' if isosx else 'linux')) open_url(QUrl(url)) QDialog.accept(self) @@ -101,33 +126,68 @@ class UpdateMixin(object): self.update_checker = CheckForUpdates(self) self.update_checker.update_found.connect(self.update_found, type=Qt.QueuedConnection) - self.update_checker.plugin_update_found.connect(self.plugin_update_found, - type=Qt.QueuedConnection) self.update_checker.start() def update_found(self, version, force=False): - os = 'windows' if iswindows else 'osx' if isosx else 'linux' - url = 'http://calibre-ebook.com/download_%s'%os - self.status_bar.new_version_available(version, url) + try: + calibre_version, plugin_updates = version.split(VSEP) + plugin_updates = int(plugin_updates) + except: + traceback.print_exc() + return + has_calibre_update = calibre_version and calibre_version != NO_CALIBRE_UPDATE + has_plugin_updates = plugin_updates > 0 + if not has_calibre_update and not has_plugin_updates: + self.status_bar.update_label.setVisible(False) + return + if has_calibre_update: + plt = u'' + if has_plugin_updates: + plt = ' (%d plugin updates)'%plugin_updates + msg = (u'%s: ' + u'%s%s') % ( + _('Update found'), version, calibre_version, plt) + else: + msg = (u'%d %s')%(version, plugin_updates, + _('updated plugins')) + self.status_bar.update_label.setText(msg) + self.status_bar.update_label.setVisible(True) - if force or (config.get('new_version_notification') and \ - dynamic.get('update to version %s'%version, True)): - self._update_notification__ = UpdateNotification(version, - parent=self) - self._update_notification__.show() + if has_plugin_updates: + self.plugin_update_found(plugin_updates) - def plugin_update_found(self, updates, icon_only=False): + if has_calibre_update: + if force or (config.get('new_version_notification') and \ + dynamic.get('update to version %s'%calibre_version, True)): + self._update_notification__ = UpdateNotification(calibre_version, + plugin_updates, parent=self) + self._update_notification__.show() + elif has_plugin_updates: + if force: + from calibre.gui2.dialogs.plugin_updater import (PluginUpdaterDialog, + FILTER_UPDATE_AVAILABLE) + d = PluginUpdaterDialog(self, + initial_filter=FILTER_UPDATE_AVAILABLE) + d.exec_() + + def plugin_update_found(self, number_of_updates): # Change the plugin icon to indicate there are updates available plugin = self.iactions.get('Plugin Updates', None) if not plugin: return - if updates: + if number_of_updates: plugin.qaction.setText(_('Plugin Updates')+'*') plugin.qaction.setIcon(QIcon(I('plugins/plugin_updater_updates.png'))) - plugin.qaction.setToolTip(_('There are %d plugin updates available')%len(updates)) + plugin.qaction.setToolTip( + _('There are %d plugin updates available')%number_of_updates) else: plugin.qaction.setText(_('Plugin Updates')) plugin.qaction.setIcon(QIcon(I('plugins/plugin_updater.png'))) plugin.qaction.setToolTip(_('Install and configure user plugins')) + def update_link_clicked(self, url): + url = unicode(url) + if url.startswith('update:'): + version = url[len('update:'):] + self.update_found(version, force=True)