From 11b41633b70ffb575bc0a5756ab2182a1cf8c76d Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Fri, 8 Oct 2010 12:20:10 -0600 Subject: [PATCH] Nicer, non-blocking update notification --- src/calibre/gui2/update.py | 65 +++++++++++++++++++++++++++++++------- 1 file changed, 53 insertions(+), 12 deletions(-) diff --git a/src/calibre/gui2/update.py b/src/calibre/gui2/update.py index ce6d134298..30cfe8f5e4 100644 --- a/src/calibre/gui2/update.py +++ b/src/calibre/gui2/update.py @@ -3,13 +3,14 @@ __copyright__ = '2008, Kovid Goyal ' import traceback -from PyQt4.Qt import QThread, pyqtSignal, Qt, QUrl +from PyQt4.Qt import QThread, pyqtSignal, Qt, QUrl, QDialog, QGridLayout, \ + QLabel, QCheckBox, QDialogButtonBox, QIcon, QPixmap import mechanize from calibre.constants import __appname__, __version__, iswindows, isosx from calibre import browser from calibre.utils.config import prefs -from calibre.gui2 import config, dynamic, question_dialog, open_url +from calibre.gui2 import config, dynamic, open_url URL = 'http://status.calibre-ebook.com/latest' @@ -37,6 +38,53 @@ class CheckForUpdates(QThread): traceback.print_exc() self.sleep(self.INTERVAL) +class UpdateNotification(QDialog): + + def __init__(self, version, parent=None): + QDialog.__init__(self, parent) + self.resize(400, 250) + self.l = QGridLayout() + self.setLayout(self.l) + self.logo = QLabel() + self.logo.setMaximumWidth(110) + self.logo.setPixmap(QPixmap(I('lt.png')).scaled(100, 100, + Qt.IgnoreAspectRatio, Qt.SmoothTransformation)) + self.label = QLabel('

'+ + _('%s has been updated to version %s. ' + 'See the new features. Visit the download pa' + 'ge?')%(__appname__, version)) + self.label.setOpenExternalLinks(True) + self.label.setWordWrap(True) + self.setWindowTitle(_('Update available!')) + self.setWindowIcon(QIcon(I('lt.png'))) + self.l.addWidget(self.logo, 0, 0) + self.l.addWidget(self.label, 0, 1) + self.cb = QCheckBox( + _('Show this notification for future updates'), self) + self.l.addWidget(self.cb, 1, 0, 1, -1) + self.cb.setChecked(config.get('new_version_notification')) + self.cb.stateChanged.connect(self.show_future) + self.bb = QDialogButtonBox(self) + b = self.bb.addButton(_('&Get update'), self.bb.AcceptRole) + b.setDefault(True) + b.setIcon(QIcon(I('arrow-down.png'))) + 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) + + 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') + open_url(QUrl(url)) + + QDialog.accept(self) + class UpdateMixin(object): def __init__(self, opts): @@ -53,15 +101,8 @@ class UpdateMixin(object): if config.get('new_version_notification') and \ dynamic.get('update to version %s'%version, True): - if question_dialog(self, _('Update available'), - _('%s has been updated to version %s. ' - 'See the new features. Visit the download pa' - 'ge?')%(__appname__, version)): - url = 'http://calibre-ebook.com/download_'+\ - ('windows' if iswindows else 'osx' if isosx else 'linux') - open_url(QUrl(url)) - dynamic.set('update to version %s'%version, False) - + self._update_notification__ = UpdateNotification(version, + parent=self) + self._update_notification__.show()