Correct Version to Mainwindow communications.

bzr-revno: 2424
This commit is contained in:
Tim Bentley 2014-10-21 22:03:31 +01:00
commit d6dc19ae5e
4 changed files with 89 additions and 19 deletions

View File

@ -154,7 +154,8 @@ class OpenLP(OpenLPMixin, QtGui.QApplication):
self.main_window.first_time() self.main_window.first_time()
update_check = Settings().value('core/update check') update_check = Settings().value('core/update check')
if update_check: if update_check:
VersionThread(self.main_window).start() version = VersionThread(self.main_window)
version.start()
self.main_window.is_display_blank() self.main_window.is_display_blank()
self.main_window.app_startup() self.main_window.app_startup()
return self.exec_() return self.exec_()

View File

@ -490,7 +490,6 @@ class MainWindow(QtGui.QMainWindow, Ui_MainWindow, RegistryProperties):
self.header_section = 'SettingsImport' self.header_section = 'SettingsImport'
self.recent_files = [] self.recent_files = []
self.timer_id = 0 self.timer_id = 0
self.timer_version_id = 0
self.new_data_path = None self.new_data_path = None
self.copy_data = False self.copy_data = False
Settings().set_up_default_values() Settings().set_up_default_values()
@ -536,7 +535,7 @@ class MainWindow(QtGui.QMainWindow, Ui_MainWindow, RegistryProperties):
self.application.set_busy_cursor() self.application.set_busy_cursor()
# Simple message boxes # Simple message boxes
Registry().register_function('theme_update_global', self.default_theme_changed) Registry().register_function('theme_update_global', self.default_theme_changed)
Registry().register_function('openlp_version_check', self.version_notice) QtCore.QObject.connect(self, QtCore.SIGNAL('openlp_version_check'), self.version_notice)
Registry().register_function('config_screen_changed', self.screen_changed) Registry().register_function('config_screen_changed', self.screen_changed)
Registry().register_function('bootstrap_post_set_up', self.bootstrap_post_set_up) Registry().register_function('bootstrap_post_set_up', self.bootstrap_post_set_up)
# Reset the cursor # Reset the cursor
@ -585,12 +584,15 @@ class MainWindow(QtGui.QMainWindow, Ui_MainWindow, RegistryProperties):
""" """
Notifies the user that a newer version of OpenLP is available. Notifies the user that a newer version of OpenLP is available.
Triggered by delay thread and cannot display popup. Triggered by delay thread and cannot display popup.
:param version: The Version to be displayed.
""" """
log.debug('version_notice') log.debug('version_notice')
version_text = translate('OpenLP.MainWindow', 'Version %s of OpenLP is now available for download (you are ' version_text = translate('OpenLP.MainWindow', 'Version %s of OpenLP is now available for download (you are '
'currently running version %s). \n\nYou can download the latest version from ' 'currently running version %s). \n\nYou can download the latest version from '
'http://openlp.org/.') 'http://openlp.org/.')
self.version_text = version_text % (version, get_application_version()['full']) QtGui.QMessageBox.question(self, translate('OpenLP.MainWindow', 'OpenLP Version Updated'),
version_text % (version, get_application_version()[u'full']))
def show(self): def show(self):
""" """
@ -604,7 +606,6 @@ class MainWindow(QtGui.QMainWindow, Ui_MainWindow, RegistryProperties):
self.open_cmd_line_files() self.open_cmd_line_files()
elif Settings().value(self.general_settings_section + '/auto open'): elif Settings().value(self.general_settings_section + '/auto open'):
self.service_manager_contents.load_last_file() self.service_manager_contents.load_last_file()
self.timer_version_id = self.startTimer(1000)
view_mode = Settings().value('%s/view mode' % self.general_settings_section) view_mode = Settings().value('%s/view mode' % self.general_settings_section)
if view_mode == 'default': if view_mode == 'default':
self.mode_default_item.setChecked(True) self.mode_default_item.setChecked(True)
@ -1304,17 +1305,6 @@ class MainWindow(QtGui.QMainWindow, Ui_MainWindow, RegistryProperties):
self.timer_id = 0 self.timer_id = 0
self.load_progress_bar.hide() self.load_progress_bar.hide()
self.application.process_events() self.application.process_events()
if event.timerId() == self.timer_version_id:
self.timer_version_id = 0
# Has the thread passed some data to be displayed so display it and stop all waiting
if hasattr(self, 'version_text'):
QtGui.QMessageBox.question(self, translate('OpenLP.MainWindow', 'OpenLP Version Updated'),
self.version_text)
else:
# the thread has not confirmed it is running or it has not yet sent any data so lets keep waiting
if not hasattr(self, 'version_update_running') or self.version_update_running:
self.timer_version_id = self.startTimer(1000)
self.application.process_events()
def set_new_data_path(self, new_data_path): def set_new_data_path(self, new_data_path):
""" """

View File

@ -97,6 +97,16 @@ class VersionThread(QtCore.QThread):
A special Qt thread class to fetch the version of OpenLP from the website. A special Qt thread class to fetch the version of OpenLP from the website.
This is threaded so that it doesn't affect the loading time of OpenLP. This is threaded so that it doesn't affect the loading time of OpenLP.
""" """
def __init__(self, main_window):
"""
Constructor for the thread class.
:param main_window: The main window Object.
"""
log.debug("VersionThread - Initialise")
super(VersionThread, self).__init__(None)
self.main_window = main_window
def run(self): def run(self):
""" """
Run the thread. Run the thread.
@ -105,8 +115,9 @@ class VersionThread(QtCore.QThread):
log.debug('Version thread - run') log.debug('Version thread - run')
app_version = get_application_version() app_version = get_application_version()
version = check_latest_version(app_version) version = check_latest_version(app_version)
log.debug("Versions %s and %s " % (LooseVersion(str(version)), LooseVersion(str(app_version['full']))))
if LooseVersion(str(version)) > LooseVersion(str(app_version['full'])): if LooseVersion(str(version)) > LooseVersion(str(app_version['full'])):
Registry().execute('openlp_version_check', '%s' % version) self.main_window.emit(QtCore.SIGNAL('openlp_version_check'), '%s' % version)
class HTTPRedirectHandlerFixed(urllib.request.HTTPRedirectHandler): class HTTPRedirectHandlerFixed(urllib.request.HTTPRedirectHandler):
@ -216,8 +227,6 @@ def check_latest_version(current_version):
this_test = str(datetime.now().date()) this_test = str(datetime.now().date())
settings.setValue('last version test', this_test) settings.setValue('last version test', this_test)
settings.endGroup() settings.endGroup()
# Tell the main window whether there will ever be data to display
Registry().get('main_window').version_update_running = last_test != this_test
if last_test != this_test: if last_test != this_test:
if current_version['build']: if current_version['build']:
req = urllib.request.Request('http://www.openlp.org/files/nightly_version.txt') req = urllib.request.Request('http://www.openlp.org/files/nightly_version.txt')

View File

@ -0,0 +1,70 @@
# -*- coding: utf-8 -*-
# vim: autoindent shiftwidth=4 expandtab textwidth=120 tabstop=4 softtabstop=4
###############################################################################
# OpenLP - Open Source Lyrics Projection #
# --------------------------------------------------------------------------- #
# Copyright (c) 2008-2014 Raoul Snyman #
# Portions copyright (c) 2008-2014 Tim Bentley, Gerald Britton, Jonathan #
# Corwin, Samuel Findlay, Michael Gorven, Scott Guerrieri, Matthias Hub, #
# Meinert Jordan, Armin Köhler, Erik Lundin, Edwin Lunando, Brian T. Meyer. #
# Joshua Miller, Stevan Pettit, Andreas Preikschat, Mattias Põldaru, #
# Christian Richter, Philip Ridout, Simon Scudder, Jeffrey Smith, #
# Maikel Stuivenberg, Martin Thompson, Jon Tibble, Dave Warnock, #
# Frode Woldsund, Martin Zibricky, Patrick Zimmermann #
# --------------------------------------------------------------------------- #
# 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 #
###############################################################################
"""
Package to test the openlp.core.utils.actions package.
"""
from unittest import TestCase
from openlp.core.common.settings import Settings
from openlp.core.utils import VersionThread, get_application_version
from tests.functional import MagicMock, patch
from tests.helpers.testmixin import TestMixin
class TestInitFunctions(TestMixin, TestCase):
def setUp(self):
"""
Create an instance and a few example actions.
"""
self.build_settings()
def tearDown(self):
"""
Clean up
"""
self.destroy_settings()
def version_thread_triggered_test(self):
"""
Test the version thread call does not trigger UI
:return:
"""
# GIVEN: a equal version setup and the data is not today.
mocked_main_window = MagicMock()
Settings().setValue('core/last version test', '1950-04-01')
# WHEN: We check to see if the version is different .
with patch('PyQt4.QtCore.QThread'),\
patch('openlp.core.utils.get_application_version') as mocked_get_application_version:
mocked_get_application_version.return_value = \
{'version': '1.0.0', 'build': '', 'full': '2.0.4'}
version_thread = VersionThread(mocked_main_window)
version_thread.run()
# THEN: If the version has changed the main window is notified
self.assertTrue(mocked_main_window.emit.called, 'The main windows should have been notified')