Implement #4040 (Periodic check for updates)

This commit is contained in:
Kovid Goyal 2009-11-20 08:42:30 -07:00
parent 2fdc5b946c
commit 2d41520783
2 changed files with 18 additions and 5 deletions

View File

@ -221,10 +221,10 @@ class Main(MainWindow, Ui_MainWindow, DeviceGUI):
self.vanity.setText(self.vanity_template%dict(version=' ', device=' ')) self.vanity.setText(self.vanity_template%dict(version=' ', device=' '))
self.device_info = ' ' self.device_info = ' '
if not opts.no_update_check: if not opts.no_update_check:
self.update_checker = CheckForUpdates() self.update_checker = CheckForUpdates(self)
QObject.connect(self.update_checker, QObject.connect(self.update_checker,
SIGNAL('update_found(PyQt_PyObject)'), self.update_found) SIGNAL('update_found(PyQt_PyObject)'), self.update_found)
self.update_checker.start() self.update_checker.start(2000)
####################### Status Bar ##################### ####################### Status Bar #####################
self.status_bar = StatusBar(self.jobs_dialog, self.system_tray_icon) self.status_bar = StatusBar(self.jobs_dialog, self.system_tray_icon)
self.setStatusBar(self.status_bar) self.setStatusBar(self.status_bar)
@ -1755,6 +1755,7 @@ class Main(MainWindow, Ui_MainWindow, DeviceGUI):
if write_settings: if write_settings:
self.write_settings() self.write_settings()
self.check_messages_timer.stop() self.check_messages_timer.stop()
self.update_checker.stop()
self.listener.close() self.listener.close()
self.job_manager.server.close() self.job_manager.server.close()
while self.spare_servers: while self.spare_servers:

View File

@ -3,7 +3,7 @@ __copyright__ = '2008, Kovid Goyal <kovid at kovidgoyal.net>'
import traceback import traceback
from PyQt4.QtCore import QThread, SIGNAL from PyQt4.QtCore import QObject, SIGNAL, QTimer
import mechanize import mechanize
from calibre.constants import __version__, iswindows, isosx from calibre.constants import __version__, iswindows, isosx
@ -11,9 +11,21 @@ from calibre import browser
URL = 'http://status.calibre-ebook.com/latest' URL = 'http://status.calibre-ebook.com/latest'
class CheckForUpdates(QThread): class CheckForUpdates(QObject):
def __init__(self, parent):
QObject.__init__(self, parent)
self.timer = QTimer(self)
self.first = True
self.connect(self.timer, SIGNAL('timeout()'), self)
self.start = self.timer.start
self.stop = self.timer.stop
def __call__(self):
if self.first:
self.timer.setInterval(1000*24*60*60)
self.first = False
def run(self):
try: try:
br = browser() br = browser()
req = mechanize.Request(URL) req = mechanize.Request(URL)