Nicer, non-blocking update notification

This commit is contained in:
Kovid Goyal 2010-10-08 12:20:10 -06:00
parent ef070d0e51
commit 11b41633b7

View File

@ -3,13 +3,14 @@ __copyright__ = '2008, Kovid Goyal <kovid at kovidgoyal.net>'
import traceback 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 import mechanize
from calibre.constants import __appname__, __version__, iswindows, isosx from calibre.constants import __appname__, __version__, iswindows, isosx
from calibre import browser from calibre import browser
from calibre.utils.config import prefs 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' URL = 'http://status.calibre-ebook.com/latest'
@ -37,6 +38,53 @@ class CheckForUpdates(QThread):
traceback.print_exc() traceback.print_exc()
self.sleep(self.INTERVAL) 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('<p>'+
_('%s has been updated to version <b>%s</b>. '
'See the <a href="http://calibre-ebook.com/whats-new'
'">new features</a>. 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): class UpdateMixin(object):
def __init__(self, opts): def __init__(self, opts):
@ -53,15 +101,8 @@ class UpdateMixin(object):
if config.get('new_version_notification') and \ if config.get('new_version_notification') and \
dynamic.get('update to version %s'%version, True): dynamic.get('update to version %s'%version, True):
if question_dialog(self, _('Update available'), self._update_notification__ = UpdateNotification(version,
_('%s has been updated to version %s. ' parent=self)
'See the <a href="http://calibre-ebook.com/whats-new' self._update_notification__.show()
'">new features</a>. 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)