openlp/openlp/core/ui/firsttimeform.py

568 lines
27 KiB
Python
Raw Normal View History

2011-02-26 11:16:21 +00:00
# -*- coding: utf-8 -*-
2019-04-13 13:00:22 +00:00
##########################################################################
# OpenLP - Open Source Lyrics Projection #
# ---------------------------------------------------------------------- #
2022-02-01 10:10:57 +00:00
# Copyright (c) 2008-2022 OpenLP Developers #
2019-04-13 13:00:22 +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, either version 3 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, see <https://www.gnu.org/licenses/>. #
##########################################################################
2013-02-01 20:36:27 +00:00
"""
This module contains the first time wizard.
"""
import json
2011-02-26 15:19:43 +00:00
import logging
2011-12-29 12:26:37 +00:00
import time
2013-07-07 14:41:43 +00:00
import urllib.error
2017-12-28 08:27:44 +00:00
import urllib.parse
import urllib.request
from pathlib import Path
2011-03-10 19:48:15 +00:00
from tempfile import gettempdir
2011-02-26 15:19:43 +00:00
2021-08-25 21:14:19 +00:00
from PyQt5 import QtCore, QtWidgets, QtGui
2011-02-26 11:16:21 +00:00
from openlp.core.api.deploy import get_latest_size, download_and_check
2019-03-08 21:25:16 +00:00
from openlp.core.common import trace_error_handler
2017-10-07 07:05:07 +00:00
from openlp.core.common.applocation import AppLocation
from openlp.core.common.httputils import DownloadWorker, download_file, get_url_file_size, get_web_page
2017-10-07 07:05:07 +00:00
from openlp.core.common.i18n import translate
2017-10-23 22:09:57 +00:00
from openlp.core.common.mixins import RegistryProperties
from openlp.core.common.path import create_paths
2017-10-23 22:09:57 +00:00
from openlp.core.common.registry import Registry
from openlp.core.lib import build_icon
from openlp.core.lib.plugin import PluginStatus
from openlp.core.lib.ui import critical_error_message_box
from openlp.core.threading import get_thread_worker, is_thread_finished, run_thread
2018-10-02 04:39:42 +00:00
from openlp.core.ui.firsttimewizard import FirstTimePage, UiFirstTimeWizard
from openlp.core.ui.icons import UiIcons
from openlp.core.widgets.widgets import ProxyDialog
2018-10-02 04:39:42 +00:00
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 ThemeListWidgetItem(QtWidgets.QListWidgetItem):
2011-12-29 12:26:37 +00:00
"""
Subclass a QListWidgetItem to allow dynamic loading of thumbnails from an online resource
2011-12-29 12:26:37 +00:00
"""
def __init__(self, themes_url, sample_theme_data, ftw, *args, **kwargs):
super().__init__(*args, **kwargs)
title = sample_theme_data['title']
thumbnail = sample_theme_data['thumbnail']
self.file_name = sample_theme_data['file_name']
self.sha256 = sample_theme_data['sha256']
self.setIcon(UiIcons().picture) # Set a place holder icon whilst the thumbnails download
self.setText(title)
self.setToolTip(title)
worker = DownloadWorker(themes_url, thumbnail)
worker.download_failed.connect(self._on_download_failed)
worker.download_succeeded.connect(self._on_thumbnail_downloaded)
2019-02-21 21:29:00 +00:00
thread_name = 'thumbnail_download_{thumbnail}'.format(thumbnail=thumbnail)
run_thread(worker, thread_name)
2019-02-15 22:34:53 +00:00
ftw.thumbnail_download_threads.append(thread_name)
def _on_download_failed(self):
"""
Set an icon to indicate that the thumbnail download has failed.
:rtype: None
2013-02-01 20:36:27 +00:00
"""
self.setIcon(UiIcons().exception)
def _on_thumbnail_downloaded(self, thumbnail_path):
"""
Load the thumbnail as the icon when it has downloaded.
:param Path thumbnail_path: Path to the file to use as a thumbnail
:rtype: None
"""
self.setIcon(build_icon(thumbnail_path))
2011-12-29 12:26:37 +00:00
2019-02-15 20:22:02 +00:00
2015-11-07 00:49:40 +00:00
class FirstTimeForm(QtWidgets.QWizard, UiFirstTimeWizard, RegistryProperties):
2011-02-26 15:19:43 +00:00
"""
This is the FirstTimeWizard, designed to help new users to get up and running quickly.
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.
"""
2021-08-25 21:14:19 +00:00
super(FirstTimeForm, self).__init__(parent, QtCore.Qt.WindowSystemMenuHint | QtCore.Qt.WindowTitleHint |
QtCore.Qt.WindowCloseButtonHint)
2020-01-06 21:15:11 +00:00
self.has_web_access = True
2014-12-12 20:57:42 +00:00
self.web = ''
2020-01-06 21:15:11 +00:00
self.is_index_downloaded = False
self.setup_ui(self)
self.customButtonClicked.connect(self._on_custom_button_clicked)
self.themes_list_widget.itemSelectionChanged.connect(self.on_themes_list_widget_selection_changed)
self.themes_deselect_all_button.clicked.connect(self.themes_list_widget.clearSelection)
self.themes_select_all_button.clicked.connect(self.themes_list_widget.selectAll)
2021-08-25 21:14:19 +00:00
self.setOption(QtWidgets.QWizard.HaveHelpButton, True)
self.helpRequested.connect(self.provide_help)
def provide_help(self):
"""
Provide help within the wizard by opening the appropriate page of the openlp manual in the user's browser
"""
QtGui.QDesktopServices.openUrl(QtCore.QUrl("https://manual.openlp.org/wizard.html"))
def get_next_page_id(self):
"""
Returns the id of the next FirstTimePage to go to based on enabled plugins
"""
if FirstTimePage.Remote < 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.Remote < 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.Remote < 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:
2020-01-06 21:15:11 +00:00
if not self.has_web_access:
return FirstTimePage.NoInternet
else:
return FirstTimePage.Remote
elif self.currentId() == FirstTimePage.Progress:
return -1
elif self.currentId() == FirstTimePage.NoInternet:
return FirstTimePage.Progress
return self.get_next_page_id()
2015-11-07 00:49:40 +00:00
def exec(self):
"""
Run the wizard.
"""
self.set_defaults()
return super().exec()
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.thumbnail_download_threads = []
self.has_run_wizard = False
def _download_index(self):
"""
Download the configuration file and kick off the theme screenshot download threads
"""
2020-01-06 21:15:11 +00:00
# Check if the index file has already been downloaded
if self.is_index_downloaded:
return
2011-02-26 11:16:21 +00:00
# check to see if we have web access
2020-01-06 21:15:11 +00:00
self.has_web_access = False
self.config = ''
web_config = None
2020-01-06 21:15:11 +00:00
user_agent = 'OpenLP/' + QtWidgets.QApplication.applicationVersion()
self.application.process_events()
2015-01-13 19:03:05 +00:00
try:
web_config = get_web_page('{host}{name}'.format(host=self.web, name='download_3.0.json'),
2017-09-19 16:48:34 +00:00
headers={'User-Agent': user_agent})
2019-02-15 20:47:09 +00:00
except ConnectionError:
2017-09-19 16:48:34 +00:00
QtWidgets.QMessageBox.critical(self, translate('OpenLP.FirstTimeWizard', 'Network Error'),
translate('OpenLP.FirstTimeWizard', 'There was a network error attempting '
'to connect to retrieve initial configuration information'),
QtWidgets.QMessageBox.Ok)
if web_config and self._parse_config(web_config):
2020-01-06 21:15:11 +00:00
self.has_web_access = True
self.application.process_events()
self.downloading = translate('OpenLP.FirstTimeWizard', 'Downloading {name}...')
2020-01-06 21:15:11 +00:00
self.is_index_downloaded = True
def _parse_config(self, web_config):
try:
config = json.loads(web_config)
meta = config['_meta']
self.web = meta['base_url']
self.songs_url = self.web + meta['songs_dir'] + '/'
self.bibles_url = self.web + meta['bibles_dir'] + '/'
self.themes_url = self.web + meta['themes_dir'] + '/'
for song in config['songs'].values():
self.application.process_events()
item = QtWidgets.QListWidgetItem(song['title'], self.songs_list_widget)
item.setData(QtCore.Qt.UserRole, (song['file_name'], song['sha256']))
2011-03-10 13:15:49 +00:00
item.setCheckState(QtCore.Qt.Unchecked)
item.setFlags(item.flags() | QtCore.Qt.ItemIsUserCheckable)
for lang in config['bibles'].values():
self.application.process_events()
lang_item = QtWidgets.QTreeWidgetItem(self.bibles_tree_widget, [lang['title']])
for translation in lang['translations'].values():
self.application.process_events()
item = QtWidgets.QTreeWidgetItem(lang_item, [translation['title']])
item.setData(0, QtCore.Qt.UserRole, (translation['file_name'], translation['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()
for theme in config['themes'].values():
ThemeListWidgetItem(self.themes_url, theme, self, self.themes_list_widget)
2015-02-19 15:34:09 +00:00
self.application.process_events()
except Exception:
log.exception('Unable to parse sample config file %s', web_config)
QtWidgets.QMessageBox.critical(self, translate('OpenLP.FirstTimeWizard', 'Invalid index file'),
translate('OpenLP.FirstTimeWizard',
'OpenLP was unable to read the resource index file. '
'Please try again later.'))
return False
return True
def set_defaults(self):
"""
Set up display at start of theme edit.
"""
self.restart()
2019-02-15 20:56:15 +00:00
self.web = 'https://get.openlp.org/ftw/'
self.currentIdChanged.connect(self.on_current_id_changed)
Registry().register_function('config_screen_changed', self.screen_selection_widget.load)
# Check if this is a re-run of the wizard.
self.has_run_wizard = self.settings.value('core/has run wizard')
2017-10-07 07:05:07 +00:00
create_paths(Path(gettempdir(), 'openlp'))
self.theme_combo_box.clear()
self.remote_page.can_download_remote = False
self.button(QtWidgets.QWizard.CustomButton1).setVisible(False)
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())
2020-10-19 07:18:26 +00:00
# temp fix for #677 when we have an error
try:
self.media_check_box.setChecked(self.plugin_manager.get_plugin_by_name('media').is_active())
except Exception:
self.media_check_box.setEnabled(False)
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())
# Add any existing themes to list.
self.theme_combo_box.insertSeparator(0)
self.theme_combo_box.addItems(sorted(self.theme_manager.get_theme_names()))
default_theme = self.settings.value('themes/global theme')
# Pre-select the current default theme.
index = self.theme_combo_box.findText(default_theme)
self.theme_combo_box.setCurrentIndex(index)
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
"""
back_button = self.button(QtWidgets.QWizard.BackButton)
cancel_button = self.button(QtWidgets.QWizard.CancelButton)
internet_settings_button = self.button(QtWidgets.QWizard.CustomButton1)
next_button = self.button(QtWidgets.QWizard.NextButton)
back_button.setVisible(True)
next_button.setVisible(True)
internet_settings_button.setVisible(False)
2013-02-03 19:23:12 +00:00
self.application.process_events()
if page_id == FirstTimePage.SampleOption:
internet_settings_button.setVisible(True)
elif page_id == FirstTimePage.Download:
back_button.setVisible(False)
next_button.setVisible(False)
self.application.set_busy_cursor()
self._download_index()
self.application.set_normal_cursor()
self.next()
2013-05-11 17:41:26 +00:00
elif page_id == FirstTimePage.NoInternet:
next_button.setVisible(False)
cancel_button.setVisible(False)
internet_settings_button.setVisible(True)
2013-05-11 17:41:26 +00:00
elif page_id == FirstTimePage.Progress:
back_button.setVisible(False)
next_button.setVisible(False)
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
def accept(self):
"""
Called when the user clicks 'Finish'. Reimplement it to to save the plugin status
:rtype: None
"""
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')
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')
self.screen_selection_widget.save()
if self.theme_combo_box.currentIndex() != -1:
self.settings.setValue('themes/global theme', self.theme_combo_box.currentText())
Registry().remove_function('config_screen_changed', self.screen_selection_widget.load)
super().accept()
def reject(self):
"""
Called when the user clicks the cancel button. Reimplement it to clean up the threads.
:rtype: None
"""
self.was_cancelled = True
for thread_name in self.thumbnail_download_threads:
worker = get_thread_worker(thread_name)
if worker:
worker.cancel_download()
# Was the thread created.
if self.thumbnail_download_threads:
while any([not is_thread_finished(thread_name) for thread_name in self.thumbnail_download_threads]):
2020-10-20 11:32:48 +00:00
self.application.process_events()
time.sleep(0.1)
2013-02-03 19:23:12 +00:00
self.application.set_normal_cursor()
Registry().remove_function('config_screen_changed', self.screen_selection_widget.load)
super().reject()
def _on_custom_button_clicked(self, which):
"""
Slot to handle the a click on one of the wizards custom buttons.
:param int QtWidgets.QWizard which: The button pressed
:rtype: None
"""
# Internet settings button
if which == QtWidgets.QWizard.CustomButton1:
proxy_dialog = ProxyDialog(self)
proxy_dialog.retranslate_ui()
proxy_dialog.exec()
2019-03-09 06:58:52 +00:00
def on_projectors_check_box_clicked(self):
# When clicking projectors_check box, change the visibility setting for Projectors panel.
if self.settings.value('projector/show after wizard'):
self.settings.setValue('projector/show after wizard', False)
2019-03-09 06:58:52 +00:00
else:
self.settings.setValue('projector/show after wizard', True)
2019-03-09 06:58:52 +00:00
def on_themes_list_widget_selection_changed(self):
"""
Update the `theme_combo_box` with the selected items
:rtype: None
"""
existing_themes = []
if self.theme_manager:
existing_themes = self.theme_manager.get_theme_names()
for list_index in range(self.themes_list_widget.count()):
item = self.themes_list_widget.item(list_index)
if item.text() not in existing_themes:
cbox_index = self.theme_combo_box.findText(item.text())
if item.isSelected() and cbox_index == -1:
self.theme_combo_box.insertItem(0, item.text())
elif not item.isSelected() and cbox_index != -1:
self.theme_combo_box.removeItem(cbox_index)
2018-01-13 23:24:26 +00:00
def update_progress(self, count, block_size):
2013-02-01 20:36:27 +00:00
"""
2018-01-13 23:24:26 +00:00
Calculate and display the download progress. This method is called by download_file().
2013-02-01 20:36:27 +00:00
"""
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
self.button(QtWidgets.QWizard.FinishButton).setEnabled(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 item in self.themes_list_widget.selectedItems():
2019-02-21 21:29:00 +00:00
size = get_url_file_size('{url}{file}'.format(url=self.themes_url, file=item.file_name))
self.max_progress += size
# If we're downloading the remote, add it in here too
if self.remote_page.can_download_remote:
self.max_progress += get_latest_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
2020-01-06 21:15:11 +00:00
self.has_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 \'{finish_button}\' button to return to OpenLP.')
else:
2016-05-20 16:22:06 +00:00
text = translate('OpenLP.FirstTimeWizard',
'Download complete. Click the \'{finish_button}\' button to start OpenLP.')
2011-06-09 22:03:30 +00:00
else:
2013-05-11 17:41:26 +00:00
if self.has_run_wizard:
text = translate('OpenLP.FirstTimeWizard', 'Click the \'{finish_button}\' button to return to OpenLP.')
else:
text = translate('OpenLP.FirstTimeWizard', 'Click the \'{finish_button}\' button to start OpenLP.')
self.progress_label.setText(text.format(finish_button=self.finish_button_text))
self.button(QtWidgets.QWizard.FinishButton).setEnabled(True)
self.button(QtWidgets.QWizard.CancelButton).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.
"""
2020-01-06 21:15:11 +00:00
if self.has_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-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
2017-12-17 04:29:53 +00:00
songs_destination_path = Path(gettempdir(), 'openlp')
bibles_destination_path = AppLocation.get_section_data_path('bibles')
themes_destination_path = 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
2017-12-17 04:29:53 +00:00
destination = songs_destination_path / str(filename)
2018-01-04 06:01:35 +00:00
if not download_file(self, '{path}{name}'.format(path=self.songs_url, name=filename),
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
2018-01-04 06:01:35 +00:00
if not download_file(self, '{path}{name}'.format(path=self.bibles_url, name=bible),
bibles_destination_path / bible, sha256):
2016-05-20 16:22:06 +00:00
missed_files.append('Bible: {name}'.format(name=bible))
bibles_iterator += 1
# Download themes
for item in self.themes_list_widget.selectedItems():
self._increment_progress_bar(self.downloading.format(name=item.file_name), 0)
self.previous_size = 0
2019-02-21 21:29:00 +00:00
if not download_file(self, '{url}{file}'.format(url=self.themes_url, file=item.file_name),
themes_destination_path / item.file_name, item.sha256):
2020-05-07 05:19:20 +00:00
missed_files.append('Theme: {name}'.format(name=item.file_name))
# Remote
if self.remote_page.can_download_remote:
self._increment_progress_bar(self.downloading.format(name='Web Remote'), 0)
self.previous_size = 0
remote_version = download_and_check(self, can_update_range=False)
if remote_version:
self.settings.setValue('api/download version', remote_version)
else:
missed_files.append('Web Remote')
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)
2017-10-07 07:05:07 +00:00
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
self.settings.setValue(tag, status)