mirror of
https://github.com/ankitects/anki.git
synced 2025-09-19 06:22:22 -04:00
74 lines
2.4 KiB
Python
74 lines
2.4 KiB
Python
# Copyright: Damien Elmes <anki@ichi2.net>
|
|
# License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
|
|
|
from PyQt4.QtCore import *
|
|
from PyQt4.QtGui import *
|
|
import urllib, urllib2, os, sys, time, httplib
|
|
import anki, anki.utils, anki.lang, anki.stats
|
|
import aqt
|
|
import simplejson, platform
|
|
|
|
baseUrl = "http://ankiweb.net/update/"
|
|
#baseUrl = "http://localhost:8001/update/"
|
|
|
|
class LatestVersionFinder(QThread):
|
|
|
|
def __init__(self, main):
|
|
QThread.__init__(self)
|
|
self.main = main
|
|
self.config = main.config
|
|
plat=sys.platform
|
|
pver=platform.platform()
|
|
d = {"ver": aqt.appVersion,
|
|
"pver": pver,
|
|
"plat": plat,
|
|
"id": self.config['id'],
|
|
"lm": self.config['lastMsg'],
|
|
"conf": self.config['created']}
|
|
self.stats = d
|
|
|
|
def run(self):
|
|
if not self.config['checkForUpdates']:
|
|
return
|
|
d = self.stats
|
|
d['proto'] = 2
|
|
d = urllib.urlencode(d)
|
|
try:
|
|
f = urllib2.urlopen(baseUrl + "getQtVersion", d)
|
|
resp = f.read()
|
|
if not resp:
|
|
return
|
|
resp = simplejson.loads(resp)
|
|
except:
|
|
# behind proxy, corrupt message, etc
|
|
return
|
|
if resp['msg']:
|
|
self.emit(SIGNAL("newMsg"), resp)
|
|
if resp['latestVersion'] > aqt.appVersion:
|
|
self.emit(SIGNAL("newVerAvail"), resp)
|
|
diff = resp['currentTime'] - time.time()
|
|
# a fairly liberal time check - sync is more strict
|
|
if abs(diff) > 86400:
|
|
self.emit(SIGNAL("clockIsOff"), diff)
|
|
|
|
def askAndUpdate(parent, version=None):
|
|
version = version['latestVersion']
|
|
baseStr = (
|
|
_('''<h1>Anki Updated</h1>Anki %s has been released.<br><br>''') %
|
|
version)
|
|
msg = QMessageBox(parent)
|
|
msg.setStandardButtons(QMessageBox.Yes | QMessageBox.No)
|
|
msg.setIcon(QMessageBox.Information)
|
|
msg.setText(baseStr + _("Would you like to download it now?"))
|
|
button = QPushButton(_("Ignore this update"))
|
|
msg.addButton(button, QMessageBox.RejectRole)
|
|
ret = msg.exec_()
|
|
if msg.clickedButton() == button:
|
|
# ignore this update
|
|
parent.config['suppressUpdate'] = version
|
|
elif ret == QMessageBox.Yes:
|
|
QDesktopServices.openUrl(QUrl(aqt.appWebsite))
|
|
|
|
def showMessages(main, data):
|
|
aqt.ui.utils.showText(data['msg'], main, type="html")
|
|
main.config['lastMsg'] = data['msgId']
|