From b64092f881e15d2cddb4370576558273344b101f Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Wed, 5 May 2010 12:17:58 -0600 Subject: [PATCH] Move update check into its own thread --- src/calibre/gui2/ui.py | 8 +++---- src/calibre/gui2/update.py | 46 +++++++++++++++++--------------------- 2 files changed, 25 insertions(+), 29 deletions(-) diff --git a/src/calibre/gui2/ui.py b/src/calibre/gui2/ui.py index b35270f963..ccbe04db9f 100644 --- a/src/calibre/gui2/ui.py +++ b/src/calibre/gui2/ui.py @@ -258,9 +258,9 @@ class Main(MainWindow, Ui_MainWindow, DeviceGUI): self.device_info = ' ' if not opts.no_update_check: self.update_checker = CheckForUpdates(self) - QObject.connect(self.update_checker, - SIGNAL('update_found(PyQt_PyObject)'), self.update_found) - self.update_checker.start(2000) + self.update_checker.update_found.connect(self.update_found, + type=Qt.QueuedConnection) + self.update_checker.start() ####################### Status Bar ##################### self.status_bar.initialize(self.system_tray_icon) self.status_bar.show_book_info.connect(self.show_book_info) @@ -2493,7 +2493,7 @@ class Main(MainWindow, Ui_MainWindow, DeviceGUI): if write_settings: self.write_settings() self.check_messages_timer.stop() - self.update_checker.stop() + self.update_checker.terminate() self.listener.close() self.job_manager.server.close() while self.spare_servers: diff --git a/src/calibre/gui2/update.py b/src/calibre/gui2/update.py index 69337bb494..92e9db1cf2 100644 --- a/src/calibre/gui2/update.py +++ b/src/calibre/gui2/update.py @@ -3,7 +3,7 @@ __copyright__ = '2008, Kovid Goyal ' import traceback -from PyQt4.QtCore import QObject, SIGNAL, QTimer +from PyQt4.QtCore import QThread, pyqtSignal import mechanize from calibre.constants import __version__, iswindows, isosx @@ -12,31 +12,27 @@ from calibre.utils.config import prefs URL = 'http://status.calibre-ebook.com/latest' -class CheckForUpdates(QObject): +class CheckForUpdates(QThread): + + update_found = pyqtSignal(object) + INTERVAL = 24*60*60 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 + QThread.__init__(self, parent) - def __call__(self): - if self.first: - self.timer.setInterval(1000*24*60*60) - self.first = False - - try: - br = browser() - req = mechanize.Request(URL) - req.add_header('CALIBRE_VERSION', __version__) - req.add_header('CALIBRE_OS', - 'win' if iswindows else 'osx' if isosx else 'oth') - req.add_header('CALIBRE_INSTALL_UUID', prefs['installation_uuid']) - version = br.open(req).read().strip() - if version and version != __version__: - self.emit(SIGNAL('update_found(PyQt_PyObject)'), version) - except: - traceback.print_exc() + def run(self): + while True: + try: + br = browser() + req = mechanize.Request(URL) + req.add_header('CALIBRE_VERSION', __version__) + req.add_header('CALIBRE_OS', + 'win' if iswindows else 'osx' if isosx else 'oth') + req.add_header('CALIBRE_INSTALL_UUID', prefs['installation_uuid']) + version = br.open(req).read().strip() + if version and version != __version__: + self.update_found.emit(version) + except: + traceback.print_exc() + self.sleep(self.INTERVAL)