From 2d415207838c445f9f249071dc6047672af6e4ec Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Fri, 20 Nov 2009 08:42:30 -0700 Subject: [PATCH] Implement #4040 (Periodic check for updates) --- src/calibre/gui2/main.py | 5 +++-- src/calibre/gui2/update.py | 18 +++++++++++++++--- 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/src/calibre/gui2/main.py b/src/calibre/gui2/main.py index 82613fd9a0..9068fdb6bd 100644 --- a/src/calibre/gui2/main.py +++ b/src/calibre/gui2/main.py @@ -221,10 +221,10 @@ class Main(MainWindow, Ui_MainWindow, DeviceGUI): self.vanity.setText(self.vanity_template%dict(version=' ', device=' ')) self.device_info = ' ' if not opts.no_update_check: - self.update_checker = CheckForUpdates() + self.update_checker = CheckForUpdates(self) QObject.connect(self.update_checker, SIGNAL('update_found(PyQt_PyObject)'), self.update_found) - self.update_checker.start() + self.update_checker.start(2000) ####################### Status Bar ##################### self.status_bar = StatusBar(self.jobs_dialog, self.system_tray_icon) self.setStatusBar(self.status_bar) @@ -1755,6 +1755,7 @@ class Main(MainWindow, Ui_MainWindow, DeviceGUI): if write_settings: self.write_settings() self.check_messages_timer.stop() + self.update_checker.stop() 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 f566109bf2..2023da1854 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 QThread, SIGNAL +from PyQt4.QtCore import QObject, SIGNAL, QTimer import mechanize from calibre.constants import __version__, iswindows, isosx @@ -11,9 +11,21 @@ from calibre import browser 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: br = browser() req = mechanize.Request(URL)