openlp/openlp/core/ui/firsttimeform.py

615 lines
30 KiB
Python
Raw Normal View History

2011-02-26 11:16:21 +00:00
# -*- coding: utf-8 -*-
2012-12-29 13:15:42 +00:00
# vim: autoindent shiftwidth=4 expandtab textwidth=120 tabstop=4 softtabstop=4
2011-02-26 11:16:21 +00:00
###############################################################################
# OpenLP - Open Source Lyrics Projection #
# --------------------------------------------------------------------------- #
2016-12-31 11:01:36 +00:00
# Copyright (c) 2008-2017 OpenLP Developers #
2011-02-26 11:16:21 +00:00
# --------------------------------------------------------------------------- #
# 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 #
###############################################################################
2013-02-01 20:36:27 +00:00
"""
This module contains the first time wizard.
"""
2011-02-26 15:19:43 +00:00
import logging
2011-09-17 22:33:03 +00:00
import os
2015-02-17 21:27:51 +00:00
import socket
2011-12-29 12:26:37 +00:00
import time
2013-07-07 14:41:43 +00:00
import urllib.request
import urllib.parse
import urllib.error
from configparser import ConfigParser, MissingSectionHeaderError, NoOptionError, NoSectionError
2011-03-10 19:48:15 +00:00
from tempfile import gettempdir
2011-02-26 15:19:43 +00:00
2015-11-07 00:49:40 +00:00
from PyQt5 import QtCore, QtWidgets
2011-02-26 11:16:21 +00:00
2014-11-01 10:38:33 +00:00
from openlp.core.common import Registry, RegistryProperties, AppLocation, Settings, check_directory_exists, \
translate, clean_button_text, trace_error_handler
from openlp.core.common.path import Path
2013-12-13 17:44:05 +00:00
from openlp.core.lib import PluginStatus, build_icon
from openlp.core.lib.ui import critical_error_message_box
2016-12-20 21:59:40 +00:00
from openlp.core.common.httputils import get_web_page, get_url_file_size, url_get_file, CONNECTION_TIMEOUT
from .firsttimewizard import UiFirstTimeWizard, FirstTimePage
2011-02-26 11:16:21 +00:00
2011-03-06 19:44:33 +00:00
log = logging.getLogger(__name__)
2011-02-26 15:19:43 +00:00
2013-02-01 20:36:27 +00:00
class ThemeScreenshotWorker(QtCore.QObject):
2011-12-29 12:26:37 +00:00
"""
This thread downloads a theme's screenshot
2011-12-29 12:26:37 +00:00
"""
2015-02-02 22:04:30 +00:00
screenshot_downloaded = QtCore.pyqtSignal(str, str, str)
finished = QtCore.pyqtSignal()
2015-02-02 19:25:34 +00:00
def __init__(self, themes_url, title, filename, sha256, screenshot):
"""
Set up the worker object
"""
self.was_download_cancelled = False
self.themes_url = themes_url
self.title = title
self.filename = filename
2015-02-02 19:25:34 +00:00
self.sha256 = sha256
self.screenshot = screenshot
2015-02-19 15:34:09 +00:00
socket.setdefaulttimeout(CONNECTION_TIMEOUT)
super(ThemeScreenshotWorker, self).__init__()
2011-12-29 12:26:37 +00:00
def run(self):
2013-02-01 20:36:27 +00:00
"""
Overridden method to run the thread.
"""
if self.was_download_cancelled:
return
try:
2016-05-20 16:22:06 +00:00
urllib.request.urlretrieve('{host}{name}'.format(host=self.themes_url, name=self.screenshot),
os.path.join(gettempdir(), 'openlp', self.screenshot))
# Signal that the screenshot has been downloaded
2015-02-02 19:25:34 +00:00
self.screenshot_downloaded.emit(self.title, self.filename, self.sha256)
except:
log.exception('Unable to download screenshot')
finally:
self.finished.emit()
@QtCore.pyqtSlot(bool)
def set_download_canceled(self, toggle):
"""
Externally set if the download was canceled
:param toggle: Set if the download was canceled or not
"""
self.was_download_cancelled = toggle
2011-12-29 12:26:37 +00:00
2015-11-07 00:49:40 +00:00
class FirstTimeForm(QtWidgets.QWizard, UiFirstTimeWizard, RegistryProperties):
2011-02-26 15:19:43 +00:00
"""
2013-05-11 17:28:42 +00:00
This is the Theme Import Wizard, which allows easy creation and editing of OpenLP themes.
2011-02-26 15:19:43 +00:00
"""
2013-08-31 18:17:38 +00:00
log.info('ThemeWizardForm loaded')
2011-02-26 11:16:21 +00:00
def __init__(self, parent=None):
2013-02-01 20:36:27 +00:00
"""
Create and set up the first time wizard.
"""
super(FirstTimeForm, self).__init__(parent)
2014-12-12 20:57:42 +00:00
self.web_access = True
self.web = ''
self.setup_ui(self)
def get_next_page_id(self):
"""
Returns the id of the next FirstTimePage to go to based on enabled plugins
"""
if FirstTimePage.Welcome < self.currentId() < FirstTimePage.Songs and self.songs_check_box.isChecked():
# If the songs plugin is enabled then go to the songs page
return FirstTimePage.Songs
elif FirstTimePage.Welcome < self.currentId() < FirstTimePage.Bibles and self.bible_check_box.isChecked():
# Otherwise, if the Bibles plugin is enabled then go to the Bibles page
return FirstTimePage.Bibles
elif FirstTimePage.Welcome < self.currentId() < FirstTimePage.Themes:
# Otherwise, if the current page is somewhere between the Welcome and the Themes pages, go to the themes
return FirstTimePage.Themes
else:
# If all else fails, go to the next page
return self.currentId() + 1
def nextId(self):
"""
Determine the next page in the Wizard to go to.
"""
self.application.process_events()
if self.currentId() == FirstTimePage.Download:
if not self.web_access:
return FirstTimePage.NoInternet
else:
return FirstTimePage.Plugins
elif self.currentId() == FirstTimePage.Plugins:
return self.get_next_page_id()
elif self.currentId() == FirstTimePage.Progress:
return -1
elif self.currentId() == FirstTimePage.NoInternet:
return FirstTimePage.Progress
elif self.currentId() == FirstTimePage.Themes:
self.application.set_busy_cursor()
while not all([thread.isFinished() for thread in self.theme_screenshot_threads]):
time.sleep(0.1)
self.application.process_events()
# Build the screenshot icons, as this can not be done in the thread.
self._build_theme_screenshots()
self.application.set_normal_cursor()
return FirstTimePage.Defaults
else:
return self.get_next_page_id()
2015-11-07 00:49:40 +00:00
def exec(self):
"""
Run the wizard.
"""
self.set_defaults()
2015-11-07 00:49:40 +00:00
return QtWidgets.QWizard.exec(self)
def initialize(self, screens):
"""
Set up the First Time Wizard
:param screens: The screens detected by OpenLP
"""
self.screens = screens
self.was_cancelled = False
self.theme_screenshot_threads = []
self.theme_screenshot_workers = []
self.has_run_wizard = False
def _download_index(self):
"""
Download the configuration file and kick off the theme screenshot download threads
"""
2011-02-26 11:16:21 +00:00
# check to see if we have web access
self.web_access = False
self.config = ConfigParser()
user_agent = 'OpenLP/' + Registry().get('application').applicationVersion()
self.application.process_events()
2015-01-13 19:03:05 +00:00
try:
2016-05-20 16:22:06 +00:00
web_config = get_web_page('{host}{name}'.format(host=self.web, name='download.cfg'),
header=('User-Agent', user_agent))
2015-01-13 19:03:05 +00:00
except (urllib.error.URLError, ConnectionError) as err:
2015-11-07 00:49:40 +00:00
msg = QtWidgets.QMessageBox()
2015-01-13 19:03:05 +00:00
title = translate('OpenLP.FirstTimeWizard', 'Network Error')
2016-05-20 16:22:06 +00:00
msg.setText('{title} {error}'.format(title=title,
error=err.code if hasattr(err, 'code') else ''))
2015-01-13 19:03:05 +00:00
msg.setInformativeText(translate('OpenLP.FirstTimeWizard',
'There was a network error attempting to '
2015-01-14 15:38:50 +00:00
'connect to retrieve initial configuration information'))
2015-01-13 19:03:05 +00:00
msg.setStandardButtons(msg.Ok)
2015-11-07 00:49:40 +00:00
ans = msg.exec()
2015-01-13 19:03:05 +00:00
web_config = False
if web_config:
2015-02-02 22:04:30 +00:00
files = web_config.read()
try:
2015-02-02 22:04:30 +00:00
self.config.read_string(files.decode())
self.web = self.config.get('general', 'base url')
self.songs_url = self.web + self.config.get('songs', 'directory') + '/'
self.bibles_url = self.web + self.config.get('bibles', 'directory') + '/'
self.themes_url = self.web + self.config.get('themes', 'directory') + '/'
self.web_access = True
except (NoSectionError, NoOptionError, MissingSectionHeaderError):
2016-12-24 09:10:13 +00:00
log.debug('A problem occurred while parsing the downloaded config file')
trace_error_handler(log)
2013-02-07 11:33:47 +00:00
self.update_screen_list_combo()
self.application.process_events()
self.downloading = translate('OpenLP.FirstTimeWizard', 'Downloading {name}...')
2014-11-26 09:04:09 +00:00
if self.has_run_wizard:
self.songs_check_box.setChecked(self.plugin_manager.get_plugin_by_name('songs').is_active())
self.bible_check_box.setChecked(self.plugin_manager.get_plugin_by_name('bibles').is_active())
self.presentation_check_box.setChecked(self.plugin_manager.get_plugin_by_name('presentations').is_active())
self.image_check_box.setChecked(self.plugin_manager.get_plugin_by_name('images').is_active())
self.media_check_box.setChecked(self.plugin_manager.get_plugin_by_name('media').is_active())
self.custom_check_box.setChecked(self.plugin_manager.get_plugin_by_name('custom').is_active())
self.song_usage_check_box.setChecked(self.plugin_manager.get_plugin_by_name('songusage').is_active())
self.alert_check_box.setChecked(self.plugin_manager.get_plugin_by_name('alerts').is_active())
self.application.set_normal_cursor()
2011-02-27 14:29:19 +00:00
# Sort out internet access for downloads
2013-02-09 14:13:38 +00:00
if self.web_access:
2013-08-31 18:17:38 +00:00
songs = self.config.get('songs', 'languages')
songs = songs.split(',')
2011-03-10 13:15:49 +00:00
for song in songs:
self.application.process_events()
2016-05-20 16:22:06 +00:00
title = self.config.get('songs_{song}'.format(song=song), 'title')
filename = self.config.get('songs_{song}'.format(song=song), 'filename')
sha256 = self.config.get('songs_{song}'.format(song=song), 'sha256', fallback='')
2015-11-07 00:49:40 +00:00
item = QtWidgets.QListWidgetItem(title, self.songs_list_widget)
2015-01-31 21:52:02 +00:00
item.setData(QtCore.Qt.UserRole, (filename, sha256))
2011-03-10 13:15:49 +00:00
item.setCheckState(QtCore.Qt.Unchecked)
item.setFlags(item.flags() | QtCore.Qt.ItemIsUserCheckable)
2013-08-31 18:17:38 +00:00
bible_languages = self.config.get('bibles', 'languages')
bible_languages = bible_languages.split(',')
2011-03-10 19:48:15 +00:00
for lang in bible_languages:
self.application.process_events()
2016-05-20 16:22:06 +00:00
language = self.config.get('bibles_{lang}'.format(lang=lang), 'title')
2015-11-07 00:49:40 +00:00
lang_item = QtWidgets.QTreeWidgetItem(self.bibles_tree_widget, [language])
2016-05-20 16:22:06 +00:00
bibles = self.config.get('bibles_{lang}'.format(lang=lang), 'translations')
2013-08-31 18:17:38 +00:00
bibles = bibles.split(',')
2011-03-10 13:15:49 +00:00
for bible in bibles:
self.application.process_events()
2016-05-20 16:22:06 +00:00
title = self.config.get('bible_{bible}'.format(bible=bible), 'title')
filename = self.config.get('bible_{bible}'.format(bible=bible), 'filename')
sha256 = self.config.get('bible_{bible}'.format(bible=bible), 'sha256', fallback='')
2015-11-07 00:49:40 +00:00
item = QtWidgets.QTreeWidgetItem(lang_item, [title])
2015-02-02 19:25:34 +00:00
item.setData(0, QtCore.Qt.UserRole, (filename, sha256))
2011-03-10 13:15:49 +00:00
item.setCheckState(0, QtCore.Qt.Unchecked)
item.setFlags(item.flags() | QtCore.Qt.ItemIsUserCheckable)
2013-05-11 17:41:26 +00:00
self.bibles_tree_widget.expandAll()
self.application.process_events()
# Download the theme screenshots
themes = self.config.get('themes', 'files').split(',')
for theme in themes:
2016-05-20 16:22:06 +00:00
title = self.config.get('theme_{theme}'.format(theme=theme), 'title')
filename = self.config.get('theme_{theme}'.format(theme=theme), 'filename')
sha256 = self.config.get('theme_{theme}'.format(theme=theme), 'sha256', fallback='')
screenshot = self.config.get('theme_{theme}'.format(theme=theme), 'screenshot')
2015-02-02 19:25:34 +00:00
worker = ThemeScreenshotWorker(self.themes_url, title, filename, sha256, screenshot)
self.theme_screenshot_workers.append(worker)
worker.screenshot_downloaded.connect(self.on_screenshot_downloaded)
thread = QtCore.QThread(self)
self.theme_screenshot_threads.append(thread)
thread.started.connect(worker.run)
worker.finished.connect(thread.quit)
worker.moveToThread(thread)
thread.start()
2015-02-19 15:34:09 +00:00
self.application.process_events()
def set_defaults(self):
"""
Set up display at start of theme edit.
"""
self.restart()
self.web = 'http://openlp.org/files/frw/'
self.cancel_button.clicked.connect(self.on_cancel_button_clicked)
self.no_internet_finish_button.clicked.connect(self.on_no_internet_finish_button_clicked)
self.no_internet_cancel_button.clicked.connect(self.on_no_internet_cancel_button_clicked)
self.currentIdChanged.connect(self.on_current_id_changed)
Registry().register_function('config_screen_changed', self.update_screen_list_combo)
self.no_internet_finish_button.setVisible(False)
self.no_internet_cancel_button.setVisible(False)
# Check if this is a re-run of the wizard.
self.has_run_wizard = Settings().value('core/has run wizard')
check_directory_exists(Path(gettempdir(), 'openlp'))
2011-02-26 20:52:26 +00:00
def update_screen_list_combo(self):
"""
The user changed screen resolution or enabled/disabled more screens, so
we need to update the combo box.
"""
self.display_combo_box.clear()
self.display_combo_box.addItems(self.screens.get_screen_list())
self.display_combo_box.setCurrentIndex(self.display_combo_box.count() - 1)
2013-05-11 17:41:26 +00:00
def on_current_id_changed(self, page_id):
2011-03-02 21:47:55 +00:00
"""
Detects Page changes and updates as appropriate.
2011-03-02 21:47:55 +00:00
"""
2013-05-11 17:41:26 +00:00
# Keep track of the page we are at. Triggering "Cancel" causes page_id to be a -1.
2013-02-03 19:23:12 +00:00
self.application.process_events()
2013-05-11 17:41:26 +00:00
if page_id != -1:
self.last_id = page_id
if page_id == FirstTimePage.Download:
self.back_button.setVisible(False)
self.next_button.setVisible(False)
# Set the no internet page text.
2013-05-11 17:41:26 +00:00
if self.has_run_wizard:
self.no_internet_label.setText(self.no_internet_text)
else:
self.no_internet_label.setText(self.no_internet_text + self.cancel_wizard_text)
self.application.set_busy_cursor()
self._download_index()
self.application.set_normal_cursor()
self.back_button.setVisible(False)
self.next_button.setVisible(True)
self.next()
2013-05-11 17:41:26 +00:00
elif page_id == FirstTimePage.Defaults:
self.theme_combo_box.clear()
for index in range(self.themes_list_widget.count()):
item = self.themes_list_widget.item(index)
2011-03-10 19:48:15 +00:00
if item.checkState() == QtCore.Qt.Checked:
2013-05-11 17:41:26 +00:00
self.theme_combo_box.addItem(item.text())
if self.has_run_wizard:
# Add any existing themes to list.
2013-02-02 07:34:42 +00:00
for theme in self.theme_manager.get_themes():
2013-05-11 17:41:26 +00:00
index = self.theme_combo_box.findText(theme)
if index == -1:
2013-05-11 17:41:26 +00:00
self.theme_combo_box.addItem(theme)
2013-08-31 18:17:38 +00:00
default_theme = Settings().value('themes/global theme')
# Pre-select the current default theme.
2013-05-11 17:41:26 +00:00
index = self.theme_combo_box.findText(default_theme)
self.theme_combo_box.setCurrentIndex(index)
elif page_id == FirstTimePage.NoInternet:
self.back_button.setVisible(False)
self.next_button.setVisible(False)
self.cancel_button.setVisible(False)
2013-05-11 17:28:42 +00:00
self.no_internet_finish_button.setVisible(True)
if self.has_run_wizard:
self.no_internet_cancel_button.setVisible(False)
else:
self.no_internet_cancel_button.setVisible(True)
elif page_id == FirstTimePage.Plugins:
self.back_button.setVisible(False)
2013-05-11 17:41:26 +00:00
elif page_id == FirstTimePage.Progress:
2013-02-03 19:23:12 +00:00
self.application.set_busy_cursor()
2013-04-29 18:42:29 +00:00
self._pre_wizard()
2013-05-11 18:11:52 +00:00
self._perform_wizard()
2013-03-14 22:22:18 +00:00
self._post_wizard()
2013-02-03 19:23:12 +00:00
self.application.set_normal_cursor()
2011-03-02 21:47:55 +00:00
2013-05-11 18:11:52 +00:00
def on_cancel_button_clicked(self):
"""
Process the triggering of the cancel button.
"""
self.was_cancelled = True
if self.theme_screenshot_workers:
for worker in self.theme_screenshot_workers:
worker.set_download_canceled(True)
# Was the thread created.
if self.theme_screenshot_threads:
while any([thread.isRunning() for thread in self.theme_screenshot_threads]):
time.sleep(0.1)
2013-02-03 19:23:12 +00:00
self.application.set_normal_cursor()
2015-02-02 19:25:34 +00:00
def on_screenshot_downloaded(self, title, filename, sha256):
"""
Add an item to the list when a theme has been downloaded
:param title: The title of the theme
:param filename: The filename of the theme
"""
2015-11-07 00:49:40 +00:00
item = QtWidgets.QListWidgetItem(title, self.themes_list_widget)
2015-02-02 19:25:34 +00:00
item.setData(QtCore.Qt.UserRole, (filename, sha256))
item.setCheckState(QtCore.Qt.Unchecked)
item.setFlags(item.flags() | QtCore.Qt.ItemIsUserCheckable)
2013-05-11 18:11:52 +00:00
def on_no_internet_finish_button_clicked(self):
"""
Process the triggering of the "Finish" button on the No Internet page.
"""
2013-02-03 19:23:12 +00:00
self.application.set_busy_cursor()
2013-05-11 18:11:52 +00:00
self._perform_wizard()
2013-02-03 19:23:12 +00:00
self.application.set_normal_cursor()
2013-08-31 18:17:38 +00:00
Settings().setValue('core/has run wizard', True)
self.close()
def on_no_internet_cancel_button_clicked(self):
"""
Process the triggering of the "Cancel" button on the No Internet page.
"""
self.was_cancelled = True
self.close()
2013-05-11 18:11:52 +00:00
def _build_theme_screenshots(self):
2011-12-29 12:26:37 +00:00
"""
2014-03-17 19:05:55 +00:00
This method builds the theme screenshots' icons for all items in the ``self.themes_list_widget``.
2011-12-29 12:26:37 +00:00
"""
2013-08-31 18:17:38 +00:00
themes = self.config.get('themes', 'files')
themes = themes.split(',')
for index, theme in enumerate(themes):
2016-05-20 16:22:06 +00:00
screenshot = self.config.get('theme_{theme}'.format(theme=theme), 'screenshot')
item = self.themes_list_widget.item(index)
2015-02-19 15:34:09 +00:00
if item:
item.setIcon(build_icon(os.path.join(gettempdir(), 'openlp', screenshot)))
2011-12-29 12:26:37 +00:00
2013-05-11 18:11:52 +00:00
def _download_progress(self, count, block_size):
2013-02-01 20:36:27 +00:00
"""
Calculate and display the download progress.
"""
2011-03-17 13:03:57 +00:00
increment = (count * block_size) - self.previous_size
2013-04-29 18:42:29 +00:00
self._increment_progress_bar(None, increment)
2011-03-17 13:03:57 +00:00
self.previous_size = count * block_size
2011-12-29 12:26:37 +00:00
2013-04-29 18:42:29 +00:00
def _increment_progress_bar(self, status_text, increment=1):
2011-03-11 10:20:09 +00:00
"""
Update the wizard progress page.
2014-03-17 19:05:55 +00:00
:param status_text: Current status information to display.
:param increment: The value to increment the progress bar by.
2011-03-11 10:20:09 +00:00
"""
if status_text:
2013-05-11 17:41:26 +00:00
self.progress_label.setText(status_text)
2011-03-11 10:20:09 +00:00
if increment > 0:
2013-05-11 17:41:26 +00:00
self.progress_bar.setValue(self.progress_bar.value() + increment)
2013-02-03 19:23:12 +00:00
self.application.process_events()
2011-03-11 10:20:09 +00:00
2013-04-29 18:42:29 +00:00
def _pre_wizard(self):
2011-03-11 10:20:09 +00:00
"""
Prepare the UI for the process.
"""
2011-06-09 22:03:30 +00:00
self.max_progress = 0
2013-05-11 17:41:26 +00:00
self.finish_button.setVisible(False)
2013-02-03 19:23:12 +00:00
self.application.process_events()
try:
# Loop through the songs list and increase for each selected item
for i in range(self.songs_list_widget.count()):
self.application.process_events()
item = self.songs_list_widget.item(i)
if item.checkState() == QtCore.Qt.Checked:
2015-02-08 18:38:47 +00:00
filename, sha256 = item.data(QtCore.Qt.UserRole)
2016-12-20 21:20:54 +00:00
size = get_url_file_size('{path}{name}'.format(path=self.songs_url, name=filename))
self.max_progress += size
# Loop through the Bibles list and increase for each selected item
2015-11-07 00:49:40 +00:00
iterator = QtWidgets.QTreeWidgetItemIterator(self.bibles_tree_widget)
while iterator.value():
self.application.process_events()
item = iterator.value()
if item.parent() and item.checkState(0) == QtCore.Qt.Checked:
2015-02-08 18:38:47 +00:00
filename, sha256 = item.data(0, QtCore.Qt.UserRole)
2016-12-20 21:20:54 +00:00
size = get_url_file_size('{path}{name}'.format(path=self.bibles_url, name=filename))
self.max_progress += size
iterator += 1
# Loop through the themes list and increase for each selected item
for i in range(self.themes_list_widget.count()):
self.application.process_events()
item = self.themes_list_widget.item(i)
if item.checkState() == QtCore.Qt.Checked:
2015-02-08 18:38:47 +00:00
filename, sha256 = item.data(QtCore.Qt.UserRole)
2016-12-20 21:20:54 +00:00
size = get_url_file_size('{path}{name}'.format(path=self.themes_url, name=filename))
self.max_progress += size
2015-01-31 21:52:02 +00:00
except urllib.error.URLError:
trace_error_handler(log)
critical_error_message_box(translate('OpenLP.FirstTimeWizard', 'Download Error'),
translate('OpenLP.FirstTimeWizard', 'There was a connection problem during '
'download, so further downloads will be skipped. Try to re-run the '
'First Time Wizard later.'))
self.max_progress = 0
self.web_access = None
2011-06-09 22:03:30 +00:00
if self.max_progress:
# Add on 2 for plugins status setting plus a "finished" point.
2013-02-04 21:26:27 +00:00
self.max_progress += 2
2013-05-11 17:41:26 +00:00
self.progress_bar.setValue(0)
self.progress_bar.setMinimum(0)
self.progress_bar.setMaximum(self.max_progress)
self.progress_page.setTitle(translate('OpenLP.FirstTimeWizard', 'Setting Up And Downloading'))
self.progress_page.setSubTitle(
2012-12-29 13:15:42 +00:00
translate('OpenLP.FirstTimeWizard', 'Please wait while OpenLP is set up and your data is downloaded.'))
2011-06-09 22:03:30 +00:00
else:
2013-05-11 17:41:26 +00:00
self.progress_bar.setVisible(False)
self.progress_page.setTitle(translate('OpenLP.FirstTimeWizard', 'Setting Up'))
2013-08-31 18:17:38 +00:00
self.progress_page.setSubTitle('Setup complete.')
self.repaint()
2013-02-03 19:23:12 +00:00
self.application.process_events()
# Try to give the wizard a chance to repaint itself
time.sleep(0.1)
2011-03-11 10:20:09 +00:00
2013-03-14 22:22:18 +00:00
def _post_wizard(self):
2011-03-11 10:20:09 +00:00
"""
Clean up the UI after the process has finished.
"""
2011-06-09 22:03:30 +00:00
if self.max_progress:
2013-05-11 17:41:26 +00:00
self.progress_bar.setValue(self.progress_bar.maximum())
if self.has_run_wizard:
2016-05-20 16:22:06 +00:00
text = translate('OpenLP.FirstTimeWizard',
'Download complete. Click the {button} button to return to OpenLP.'
2016-06-09 02:57:21 +00:00
).format(button=clean_button_text(self.buttonText(QtWidgets.QWizard.FinishButton)))
2016-05-20 16:22:06 +00:00
self.progress_label.setText(text)
else:
2016-05-20 16:22:06 +00:00
text = translate('OpenLP.FirstTimeWizard',
'Download complete. Click the {button} button to start OpenLP.'
).format(button=clean_button_text(self.buttonText(QtWidgets.QWizard.FinishButton)))
2016-06-08 20:41:21 +00:00
self.progress_label.setText(text)
2011-06-09 22:03:30 +00:00
else:
2013-05-11 17:41:26 +00:00
if self.has_run_wizard:
2016-05-20 16:22:06 +00:00
text = translate('OpenLP.FirstTimeWizard',
'Click the {button} button to return to OpenLP.'
).format(button=clean_button_text(self.buttonText(QtWidgets.QWizard.FinishButton)))
self.progress_label.setText(text)
else:
2016-05-20 16:22:06 +00:00
text = translate('OpenLP.FirstTimeWizard',
'Click the {button} button to start OpenLP.'
).format(button=clean_button_text(self.buttonText(QtWidgets.QWizard.FinishButton)))
2016-06-08 20:41:21 +00:00
self.progress_label.setText(text)
2013-05-11 17:41:26 +00:00
self.finish_button.setVisible(True)
self.finish_button.setEnabled(True)
2013-05-11 17:28:42 +00:00
self.cancel_button.setVisible(False)
2013-05-11 17:41:26 +00:00
self.next_button.setVisible(False)
2013-02-03 19:23:12 +00:00
self.application.process_events()
2011-03-11 10:20:09 +00:00
2013-05-11 18:11:52 +00:00
def _perform_wizard(self):
2011-03-11 10:20:09 +00:00
"""
Run the tasks in the wizard.
"""
# Set plugin states
2013-04-29 18:42:29 +00:00
self._increment_progress_bar(translate('OpenLP.FirstTimeWizard', 'Enabling selected plugins...'))
2013-08-31 18:17:38 +00:00
self._set_plugin_status(self.songs_check_box, 'songs/status')
self._set_plugin_status(self.bible_check_box, 'bibles/status')
self._set_plugin_status(self.presentation_check_box, 'presentations/status')
2013-08-31 18:17:38 +00:00
self._set_plugin_status(self.image_check_box, 'images/status')
self._set_plugin_status(self.media_check_box, 'media/status')
self._set_plugin_status(self.custom_check_box, 'custom/status')
self._set_plugin_status(self.song_usage_check_box, 'songusage/status')
self._set_plugin_status(self.alert_check_box, 'alerts/status')
2013-02-09 14:13:38 +00:00
if self.web_access:
if not self._download_selected():
critical_error_message_box(translate('OpenLP.FirstTimeWizard', 'Download Error'),
translate('OpenLP.FirstTimeWizard', 'There was a connection problem while '
'downloading, so further downloads will be skipped. Try to re-run '
'the First Time Wizard later.'))
2011-03-06 13:44:35 +00:00
# Set Default Display
2013-05-11 17:41:26 +00:00
if self.display_combo_box.currentIndex() != -1:
2013-08-31 18:17:38 +00:00
Settings().setValue('core/monitor', self.display_combo_box.currentIndex())
2013-05-11 17:41:26 +00:00
self.screens.set_current_display(self.display_combo_box.currentIndex())
2011-03-06 13:44:35 +00:00
# Set Global Theme
2013-05-11 17:41:26 +00:00
if self.theme_combo_box.currentIndex() != -1:
2013-08-31 18:17:38 +00:00
Settings().setValue('themes/global theme', self.theme_combo_box.currentText())
2011-02-26 16:51:00 +00:00
def _download_selected(self):
"""
Download selected songs, bibles and themes. Returns False on download error
"""
# Build directories for downloads
songs_destination = os.path.join(gettempdir(), 'openlp')
2017-08-01 20:59:41 +00:00
bibles_destination = str(AppLocation.get_section_data_path('bibles'))
themes_destination = str(AppLocation.get_section_data_path('themes'))
2015-02-17 21:27:51 +00:00
missed_files = []
# Download songs
for i in range(self.songs_list_widget.count()):
item = self.songs_list_widget.item(i)
if item.checkState() == QtCore.Qt.Checked:
2015-01-31 21:52:02 +00:00
filename, sha256 = item.data(QtCore.Qt.UserRole)
self._increment_progress_bar(self.downloading.format(name=filename), 0)
self.previous_size = 0
destination = os.path.join(songs_destination, str(filename))
2016-12-20 21:59:40 +00:00
if not url_get_file(self, '{path}{name}'.format(path=self.songs_url, name=filename),
2016-12-21 10:00:14 +00:00
destination, sha256):
2016-05-20 16:22:06 +00:00
missed_files.append('Song: {name}'.format(name=filename))
# Download Bibles
2015-11-07 00:49:40 +00:00
bibles_iterator = QtWidgets.QTreeWidgetItemIterator(self.bibles_tree_widget)
while bibles_iterator.value():
item = bibles_iterator.value()
if item.parent() and item.checkState(0) == QtCore.Qt.Checked:
2015-02-02 19:25:34 +00:00
bible, sha256 = item.data(0, QtCore.Qt.UserRole)
self._increment_progress_bar(self.downloading.format(name=bible), 0)
self.previous_size = 0
2016-12-20 21:59:40 +00:00
if not url_get_file(self, '{path}{name}'.format(path=self.bibles_url, name=bible),
2016-12-21 10:00:14 +00:00
os.path.join(bibles_destination, bible),
sha256):
2016-05-20 16:22:06 +00:00
missed_files.append('Bible: {name}'.format(name=bible))
bibles_iterator += 1
# Download themes
for i in range(self.themes_list_widget.count()):
item = self.themes_list_widget.item(i)
if item.checkState() == QtCore.Qt.Checked:
2015-02-02 19:25:34 +00:00
theme, sha256 = item.data(QtCore.Qt.UserRole)
self._increment_progress_bar(self.downloading.format(name=theme), 0)
self.previous_size = 0
2016-12-21 12:46:35 +00:00
if not url_get_file(self, '{path}{name}'.format(path=self.themes_url, name=theme),
os.path.join(themes_destination, theme),
sha256):
2016-05-20 16:22:06 +00:00
missed_files.append('Theme: {name}'.format(name=theme))
2015-02-17 21:27:51 +00:00
if missed_files:
file_list = ''
for entry in missed_files:
2016-07-01 21:17:20 +00:00
file_list += '{text}<br \\>'.format(text=entry)
2015-11-07 00:49:40 +00:00
msg = QtWidgets.QMessageBox()
msg.setIcon(QtWidgets.QMessageBox.Warning)
2015-02-17 21:27:51 +00:00
msg.setWindowTitle(translate('OpenLP.FirstTimeWizard', 'Network Error'))
msg.setText(translate('OpenLP.FirstTimeWizard', 'Unable to download some files'))
msg.setInformativeText(translate('OpenLP.FirstTimeWizard',
'The following files were not able to be '
2016-07-01 21:17:20 +00:00
'downloaded:<br \\>{text}'.format(text=file_list)))
2015-02-17 21:27:51 +00:00
msg.setStandardButtons(msg.Ok)
2015-11-07 00:49:40 +00:00
ans = msg.exec()
return True
2013-05-11 18:11:52 +00:00
def _set_plugin_status(self, field, tag):
2013-02-01 20:36:27 +00:00
"""
Set the status of a plugin.
"""
2012-12-29 13:15:42 +00:00
status = PluginStatus.Active if field.checkState() == QtCore.Qt.Checked else PluginStatus.Inactive
2014-03-20 19:10:31 +00:00
Settings().setValue(tag, status)