mirror of
https://github.com/Hopiu/linkchecker.git
synced 2026-04-26 09:04:44 +00:00
Make update check in background thread.
This commit is contained in:
parent
25ee6d0980
commit
aa7de751a6
3 changed files with 77 additions and 25 deletions
|
|
@ -30,6 +30,7 @@ from .options import LinkCheckerOptions
|
|||
from .checker import CheckerThread
|
||||
from .contextmenu import ContextMenu
|
||||
from .editor import EditorWindow
|
||||
from .updater import UpdateDialog
|
||||
from .urlmodel import UrlItemModel
|
||||
from .urlsave import urlsave
|
||||
from .settings import Settings
|
||||
|
|
@ -236,30 +237,9 @@ to improve %(appname)s even more!
|
|||
@QtCore.pyqtSlot()
|
||||
def on_actionCheckUpdates_triggered (self):
|
||||
"""Display update check result."""
|
||||
title = _('%(app)s update information') % dict(app=configuration.App)
|
||||
# XXX check for update in background thread
|
||||
result, value = updater.check_update()
|
||||
if result:
|
||||
dialog = QtGui.QMessageBox.information
|
||||
if value is None:
|
||||
# no update available: display info
|
||||
text = _('Congratulations: you have the latest version '
|
||||
'%(app)s installed.')
|
||||
attrs = dict(app=configuration.App)
|
||||
else:
|
||||
# display update link
|
||||
version, url = 'hulla', 'bulla'
|
||||
text = _('A new version %(version)s of %(app)s is '
|
||||
'available for <a href="%(url)s">download</a>.')
|
||||
attrs = dict(version=version, app=configuration.AppName,
|
||||
url=url)
|
||||
else:
|
||||
# value is an error message
|
||||
dialog = QtGui.QMessageBox.warning
|
||||
text = _('An error occured while checking for an '
|
||||
'update of %(app)s: %(error)s.')
|
||||
attrs = dict(error=value, app=configuration.AppName)
|
||||
dialog(self, title, text % attrs)
|
||||
dialog = UpdateDialog(self)
|
||||
dialog.reset()
|
||||
dialog.show()
|
||||
|
||||
def start (self):
|
||||
"""Start a new check."""
|
||||
|
|
|
|||
72
linkcheck/gui/updater.py
Normal file
72
linkcheck/gui/updater.py
Normal file
|
|
@ -0,0 +1,72 @@
|
|||
# -*- coding: iso-8859-1 -*-
|
||||
# Copyright (C) 2010 Bastian Kleineidam
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation; either version 2 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License along
|
||||
# with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
|
||||
from PyQt4 import QtCore, QtGui
|
||||
from .. import updater, configuration
|
||||
|
||||
|
||||
class UpdateThread (QtCore.QThread):
|
||||
|
||||
def reset (self):
|
||||
"""Reset version information."""
|
||||
self.result = self.value = None
|
||||
|
||||
def run (self):
|
||||
"""Check for updated version."""
|
||||
self.result, self.value = updater.check_update()
|
||||
|
||||
|
||||
class UpdateDialog (QtGui.QMessageBox):
|
||||
|
||||
def __init__ (self, parent=None):
|
||||
super(UpdateDialog, self).__init__(parent)
|
||||
title = _('%(app)s update information') % dict(app=configuration.App)
|
||||
self.setWindowTitle(title)
|
||||
self.thread = UpdateThread()
|
||||
self.thread.finished.connect(self.update)
|
||||
|
||||
def reset (self):
|
||||
self.thread.reset()
|
||||
self.thread.start()
|
||||
self.setIcon(QtGui.QMessageBox.Information)
|
||||
self.setText(_('Checking for updates...'))
|
||||
|
||||
def update (self):
|
||||
result, value = self.thread.result, self.thread.value
|
||||
if result:
|
||||
if value is None:
|
||||
# no update available: display info
|
||||
text = _('Congratulations: the latest version '
|
||||
'%(app)s is installed.')
|
||||
attrs = dict(app=configuration.App)
|
||||
else:
|
||||
# display update link
|
||||
version, url = 'hulla', 'bulla'
|
||||
text = _('A new version %(version)s of %(app)s is '
|
||||
'available for <a href="%(url)s">download</a>.')
|
||||
attrs = dict(version=version, app=configuration.AppName,
|
||||
url=url)
|
||||
else:
|
||||
# value is an error message or None if UpdateThread has been
|
||||
# terminated
|
||||
if value is None:
|
||||
value = _('update thread has been terminated')
|
||||
self.setIcon(QtGui.QMessageBox.Warning)
|
||||
text = _('An error occured while checking for an '
|
||||
'update of %(app)s: %(error)s.')
|
||||
attrs = dict(error=value, app=configuration.AppName)
|
||||
self.setText(text % attrs)
|
||||
|
|
@ -1,5 +1,5 @@
|
|||
# -*- coding: iso-8859-1 -*-
|
||||
# Copyright (C) 2000-2010 Bastian Kleineidam
|
||||
# Copyright (C) 2010 Bastian Kleineidam
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
|
|
|
|||
Loading…
Reference in a new issue