tweak update code

- support for message pushing
- remove changelog from update message, as the path was wrong, and the
  changelog is mentioned in the download area instead
This commit is contained in:
Damien Elmes 2011-01-22 07:10:13 +09:00
parent ffb28df83b
commit 3c5aaecd14
3 changed files with 16 additions and 7 deletions

View file

@ -63,6 +63,7 @@ class Config(dict):
'iconSize': 32, 'iconSize': 32,
'id': genID(), 'id': genID(),
'interfaceLang': "", 'interfaceLang': "",
'lastMsg': -1,
'loadLastDeck': False, 'loadLastDeck': False,
'mainWindowGeom': None, 'mainWindowGeom': None,
'mainWindowState': None, 'mainWindowState': None,

View file

@ -2621,12 +2621,16 @@ This deck already exists on your computer. Overwrite the local copy?"""),
def setupAutoUpdate(self): def setupAutoUpdate(self):
self.autoUpdate = ui.update.LatestVersionFinder(self) self.autoUpdate = ui.update.LatestVersionFinder(self)
self.connect(self.autoUpdate, SIGNAL("newVerAvail"), self.newVerAvail) self.connect(self.autoUpdate, SIGNAL("newVerAvail"), self.newVerAvail)
self.connect(self.autoUpdate, SIGNAL("newMsg"), self.newMsg)
self.connect(self.autoUpdate, SIGNAL("clockIsOff"), self.clockIsOff) self.connect(self.autoUpdate, SIGNAL("clockIsOff"), self.clockIsOff)
self.autoUpdate.start() self.autoUpdate.start()
def newVerAvail(self, version): def newVerAvail(self, data):
if self.config['suppressUpdate'] < version['latestVersion']: if self.config['suppressUpdate'] < data['latestVersion']:
ui.update.askAndUpdate(self, version) ui.update.askAndUpdate(self, data)
def newMsg(self, data):
ui.update.showMessages(self, data)
def clockIsOff(self, diff): def clockIsOff(self, diff):
if diff < 0: if diff < 0:

View file

@ -23,6 +23,7 @@ class LatestVersionFinder(QThread):
"pver": pver, "pver": pver,
"plat": plat, "plat": plat,
"id": self.config['id'], "id": self.config['id'],
"lm": self.config['lastMsg'],
"conf": self.config['created']} "conf": self.config['created']}
self.stats = d self.stats = d
@ -41,6 +42,8 @@ class LatestVersionFinder(QThread):
except: except:
# behind proxy, corrupt message, etc # behind proxy, corrupt message, etc
return return
if resp['msg']:
self.emit(SIGNAL("newMsg"), resp)
if resp['latestVersion'] > ankiqt.appVersion: if resp['latestVersion'] > ankiqt.appVersion:
self.emit(SIGNAL("newVerAvail"), resp) self.emit(SIGNAL("newVerAvail"), resp)
diff = resp['currentTime'] - time.time() diff = resp['currentTime'] - time.time()
@ -51,10 +54,7 @@ class LatestVersionFinder(QThread):
def askAndUpdate(parent, version=None): def askAndUpdate(parent, version=None):
version = version['latestVersion'] version = version['latestVersion']
baseStr = ( baseStr = (
_('''<h1>Anki updated</h1>Anki %s has been released.<br> _('''<h1>Anki Updated</h1>Anki %s has been released.<br><br>''') %
The release notes are
<a href="http://ichi2.net/anki/download/index.html#changes">here</a>.
<br><br>''') %
version) version)
msg = QMessageBox(parent) msg = QMessageBox(parent)
msg.setStandardButtons(QMessageBox.Yes | QMessageBox.No) msg.setStandardButtons(QMessageBox.Yes | QMessageBox.No)
@ -68,3 +68,7 @@ The release notes are
parent.config['suppressUpdate'] = version parent.config['suppressUpdate'] = version
elif ret == QMessageBox.Yes: elif ret == QMessageBox.Yes:
QDesktopServices.openUrl(QUrl(ankiqt.appWebsite)) QDesktopServices.openUrl(QUrl(ankiqt.appWebsite))
def showMessages(main, data):
ankiqt.ui.utils.showText(data['msg'], main, type="html")
main.config['lastMsg'] = data['msgId']