From f53a6fddeb9d12e916fcc4880d92dceaa7b45a11 Mon Sep 17 00:00:00 2001 From: Tim Bentley Date: Sun, 11 Oct 2009 06:47:38 +0100 Subject: [PATCH] Latest Version checking added --- openlp.pyw | 3 +- openlp/core/ui/mainwindow.py | 16 +++++++++ openlp/core/utils/__init__.py | 1 + openlp/core/utils/latestversion.py | 57 ++++++++++++++++++++++++++++++ 4 files changed, 76 insertions(+), 1 deletion(-) create mode 100644 openlp/core/utils/latestversion.py diff --git a/openlp.pyw b/openlp.pyw index 941ae1e38..203137e1f 100755 --- a/openlp.pyw +++ b/openlp.pyw @@ -49,6 +49,7 @@ class OpenLP(QtGui.QApplication): """ Run the OpenLP application. """ + applicationVersion = u'1.9.0' #set the default string encoding try: sys.setappdefaultencoding(u'utf-8') @@ -58,7 +59,7 @@ class OpenLP(QtGui.QApplication): QtCore.QObject.connect(Receiver.get_receiver(), QtCore.SIGNAL(u'process_events'), self.processEvents) self.setApplicationName(u'OpenLP') - self.setApplicationVersion(u'1.9.0') + self.setApplicationVersion(applicationVersion) show_splash = str_to_bool(ConfigHelper.get_registry().get_value( u'general', u'show splash', True)) if show_splash: diff --git a/openlp/core/ui/mainwindow.py b/openlp/core/ui/mainwindow.py index 629269a28..e842412b8 100644 --- a/openlp/core/ui/mainwindow.py +++ b/openlp/core/ui/mainwindow.py @@ -33,6 +33,7 @@ from openlp.core.ui import AboutForm, SettingsForm, AlertForm, \ from openlp.core.lib import translate, RenderManager, PluginConfig, \ OpenLPDockWidget, SettingsManager, PluginManager, Receiver, \ buildIcon +from openlp.core.utils import LatestVersion class Ui_MainWindow(object): @@ -524,6 +525,21 @@ class MainWindow(QtGui.QMainWindow, Ui_MainWindow): self.ThemeManagerContents.loadThemes() log.info(u'Load data from Settings') self.settingsForm.postSetUp() + self.versionCheck() + + def versionCheck(self): + # We do not want this in development! + if log.isEnabledFor(logging.DEBUG): + applicationVersion = self.generalConfig.get_config(u'Application version', u'1.9.0') + version = LatestVersion(self.generalConfig).checkVersion(applicationVersion) + if applicationVersion != version: + QtGui.QMessageBox.question(None, + translate(u'mainWindow', u'OpenLP version Updated'), + translate(u'mainWindow', u'OpenLP version %s has been updated to version %s' + % (applicationVersion, version)), + QtGui.QMessageBox.StandardButtons(QtGui.QMessageBox.Ok), + QtGui.QMessageBox.Ok) + self.generalConfig.set_config(u'Application version', version) def getMonitorNumber(self): diff --git a/openlp/core/utils/__init__.py b/openlp/core/utils/__init__.py index 0b93ec30f..17a4f5785 100644 --- a/openlp/core/utils/__init__.py +++ b/openlp/core/utils/__init__.py @@ -24,5 +24,6 @@ from registry import Registry from confighelper import ConfigHelper +from latestversion import LatestVersion __all__ = ['Registry', 'ConfigHelper'] diff --git a/openlp/core/utils/latestversion.py b/openlp/core/utils/latestversion.py new file mode 100644 index 000000000..7abc957e8 --- /dev/null +++ b/openlp/core/utils/latestversion.py @@ -0,0 +1,57 @@ +# -*- coding: utf-8 -*- +# vim: autoindent shiftwidth=4 expandtab textwidth=80 tabstop=4 softtabstop=4 + +############################################################################### +# OpenLP - Open Source Lyrics Projection # +# --------------------------------------------------------------------------- # +# Copyright (c) 2008-2009 Raoul Snyman # +# Portions copyright (c) 2008-2009 Martin Thompson, Tim Bentley, Carsten # +# Tinggaard, Jon Tibble, Jonathan Corwin, Maikel Stuivenberg, Scott Guerrieri # +# --------------------------------------------------------------------------- # +# 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; version 2 of the License. # +# # +# 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., 59 # +# Temple Place, Suite 330, Boston, MA 02111-1307 USA # +############################################################################### + +import logging +import urllib2 +from datetime import datetime + + +class LatestVersion(object): + """ + """ + global log + log = logging.getLogger(u'LatestVersion') + log.info(u'Latest Version detector loaded') + + def __init__(self, config): + self.config = config + + def checkVersion(self, current_version): + version_string = current_version + lastTest = self.config.get_config(u'Application version Test', datetime.now().date()) + thisTest = unicode(datetime.now().date()) + self.config.set_config(u'Application version Test', thisTest) + if lastTest != thisTest: + print "Now check" + version_string = u'' + req = urllib2.Request(u'http://www.openlp.oeg/files/version.txt') + req.add_header(u'User-Agent', u'Mozilla/4.0 (compatible; MSIE 5.5; Windows NT)') + try: + handle = urllib2.urlopen(req, None, 1) + html = handle.read() + version_string = unicode(html).rstrip() + except IOError, e: + if hasattr(e, u'reason'): + log.exception(u'Reason for failure: %s', e.reason) + return version_string