diff --git a/openlp/plugins/remotes/deploy.py b/openlp/plugins/remotes/deploy.py index 1ffbe45ff..505858976 100644 --- a/openlp/plugins/remotes/deploy.py +++ b/openlp/plugins/remotes/deploy.py @@ -25,7 +25,7 @@ import zipfile import urllib.error from openlp.core.common import AppLocation, Registry -from openlp.core.common.httputils import url_get_file, get_web_page +from openlp.core.common.httputils import url_get_file, get_web_page, get_url_file_size def deploy_zipfile(app_root, zip_name): @@ -71,6 +71,8 @@ def download_and_check(callback=None): Download the web site and deploy it. """ sha256, version = download_sha256() + file_size = get_url_file_size('https://get.openlp.org/webclient/site.zip') + callback.setRange(0, file_size) if url_get_file(callback, '{host}{name}'.format(host='https://get.openlp.org/webclient/', name='site.zip'), os.path.join(AppLocation.get_section_data_path('remotes'), 'site.zip'), sha256=sha256): diff --git a/openlp/plugins/remotes/remoteplugin.py b/openlp/plugins/remotes/remoteplugin.py index 8658cf60c..1d6c02aec 100644 --- a/openlp/plugins/remotes/remoteplugin.py +++ b/openlp/plugins/remotes/remoteplugin.py @@ -23,8 +23,10 @@ import logging import os +from PyQt5 import QtCore, QtWidgets + from openlp.core.api.http import register_endpoint -from openlp.core.common import AppLocation, Registry, OpenLPMixin, check_directory_exists +from openlp.core.common import AppLocation, Registry, Settings, OpenLPMixin, check_directory_exists from openlp.core.lib import Plugin, StringContent, translate, build_icon from openlp.plugins.remotes.endpoint import remote_endpoint from openlp.plugins.remotes.deploy import download_and_check, download_sha256 @@ -59,6 +61,7 @@ class RemotesPlugin(Plugin, OpenLPMixin): check_directory_exists(os.path.join(AppLocation.get_section_data_path('remotes'), 'assets')) check_directory_exists(os.path.join(AppLocation.get_section_data_path('remotes'), 'images')) check_directory_exists(os.path.join(AppLocation.get_section_data_path('remotes'), 'static')) + check_directory_exists(os.path.join(AppLocation.get_section_data_path('remotes'), 'static', 'index')) check_directory_exists(os.path.join(AppLocation.get_section_data_path('remotes'), 'templates')) @staticmethod @@ -91,10 +94,13 @@ class RemotesPlugin(Plugin, OpenLPMixin): Import web site code if active """ self.application.process_events() - download_and_check() + progress = Progress(self) + progress.forceShow() + download_and_check(progress) self.application.process_events() + progress.close() + Settings().setValue('remotes/download version', Registry().set_flag('website_version')) - @staticmethod def website_version(self): """ Download and save the website version and sha256 @@ -104,3 +110,41 @@ class RemotesPlugin(Plugin, OpenLPMixin): Registry().set_flag('website_sha256', sha256) Registry().set_flag('website_version', version) Registry().execute('set_website_version') + + +class Progress(QtWidgets.QProgressDialog): + """ + Local class to handle download display based and supporting httputils:get_web_page + """ + def __init__(self, parent): + super(Progress, self).__init__(parent.main_window) + self.parent = parent + self.setWindowModality(QtCore.Qt.WindowModal) + self.setWindowTitle(translate('OpenLP.Ui', 'Importing Website')) + self.setLabelText(translate('OpenLP.Ui', 'Starting import...')) + self.setCancelButton(None) + self.setRange(0, 1) + self.setMinimumDuration(0) + self.was_cancelled = False + self.previous_size = 0 + + def _download_progress(self, count, block_size): + """ + Calculate and display the download progress. + """ + increment = (count * block_size) - self.previous_size + self._increment_progress_bar(None, increment) + self.previous_size = count * block_size + + def _increment_progress_bar(self, status_text, increment=1): + """ + Update the wizard progress page. + + :param status_text: Current status information to display. + :param increment: The value to increment the progress bar by. + """ + if status_text: + self.setText(status_text) + if increment > 0: + self.setValue(self.value() + increment) + self.parent.application.process_events()