openlp/openlp/plugins/bibles/forms/bibleimportform.py

583 lines
31 KiB
Python
Raw Normal View History

# -*- coding: utf-8 -*-
2013-01-01 16:33:41 +00:00
# vim: autoindent shiftwidth=4 expandtab textwidth=120 tabstop=4 softtabstop=4
###############################################################################
# OpenLP - Open Source Lyrics Projection #
# --------------------------------------------------------------------------- #
2012-12-29 20:56:56 +00:00
# Copyright (c) 2008-2013 Raoul Snyman #
# Portions copyright (c) 2008-2013 Tim Bentley, Gerald Britton, Jonathan #
# Corwin, Samuel Findlay, Michael Gorven, Scott Guerrieri, Matthias Hub, #
2012-11-11 21:16:14 +00:00
# Meinert Jordan, Armin Köhler, Erik Lundin, Edwin Lunando, Brian T. Meyer. #
2012-10-21 13:16:22 +00:00
# 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 #
###############################################################################
2011-01-13 17:55:29 +00:00
"""
The bible import functions for OpenLP
"""
import logging
import os
from PyQt4 import QtCore, QtGui
2013-02-05 08:05:28 +00:00
from openlp.core.lib import Settings, UiStrings, translate
2010-06-18 01:26:01 +00:00
from openlp.core.lib.db import delete_database
from openlp.core.lib.ui import critical_error_message_box
2011-02-12 02:43:13 +00:00
from openlp.core.ui.wizard import OpenLPWizard, WizardStrings
from openlp.core.utils import AppLocation, get_locale_key
from openlp.plugins.bibles.lib.manager import BibleFormat
2011-05-03 17:09:30 +00:00
from openlp.plugins.bibles.lib.db import BiblesResourcesDB, clean_filename
2010-02-27 15:31:23 +00:00
log = logging.getLogger(__name__)
class WebDownload(object):
2011-01-13 17:55:29 +00:00
"""
Provides an enumeration for the web bible types available to OpenLP.
"""
Unknown = -1
Crosswalk = 0
BibleGateway = 1
Bibleserver = 2
2011-02-18 03:15:09 +00:00
Names = [u'Crosswalk', u'BibleGateway', u'Bibleserver']
2011-01-13 17:55:29 +00:00
class BibleImportForm(OpenLPWizard):
"""
2013-04-18 17:45:14 +00:00
This is the Bible Import Wizard, which allows easy importing of Bibles into OpenLP from other formats like OSIS,
CSV and OpenSong.
"""
log.info(u'BibleImportForm loaded')
2013-04-18 17:45:14 +00:00
def __init__(self, parent, manager, bible_plugin):
"""
Instantiate the wizard, and run any extra setup we need to.
``parent``
The QWidget-derived parent of the wizard.
``manager``
The Bible manager.
2013-04-18 17:45:14 +00:00
``bible_plugin``
The Bible plugin.
"""
2011-01-13 17:55:29 +00:00
self.manager = manager
self.web_bible_list = {}
2013-07-18 19:00:37 +00:00
super(BibleImportForm, self).__init__(
parent, bible_plugin, u'bibleImportWizard', u':/wizards/wizard_importbible.bmp')
2011-01-13 17:55:29 +00:00
def setupUi(self, image):
"""
Set up the UI for the bible wizard.
"""
2013-07-18 19:49:44 +00:00
super(BibleImportForm, self).setupUi(image)
2013-03-07 11:15:10 +00:00
self.formatComboBox.currentIndexChanged.connect(self.onCurrentIndexChanged)
def onCurrentIndexChanged(self, index):
"""
Called when the format combo box's index changed. We have to check if
the import is available and accordingly to disable or enable the next
button.
"""
self.selectStack.setCurrentIndex(index)
2011-01-13 17:55:29 +00:00
2013-03-14 22:22:18 +00:00
def custom_init(self):
2011-01-13 17:55:29 +00:00
"""
Perform any custom initialisation for bible importing.
"""
2010-02-04 17:38:21 +00:00
self.manager.set_process_dialog(self)
self.loadWebBibles()
self.restart()
self.selectStack.setCurrentIndex(0)
2011-01-13 17:55:29 +00:00
2013-03-14 22:22:18 +00:00
def custom_signals(self):
2011-01-13 17:55:29 +00:00
"""
Set up the signals used in the bible importer.
"""
self.webSourceComboBox.currentIndexChanged.connect(self.onWebSourceComboBoxIndexChanged)
self.osisBrowseButton.clicked.connect(self.onOsisBrowseButtonClicked)
self.csvBooksButton.clicked.connect(self.onCsvBooksBrowseButtonClicked)
self.csvVersesButton.clicked.connect(self.onCsvVersesBrowseButtonClicked)
self.openSongBrowseButton.clicked.connect(self.onOpenSongBrowseButtonClicked)
2013-03-14 22:22:18 +00:00
def add_custom_pages(self):
"""
2011-01-13 17:55:29 +00:00
Add the bible import specific wizard pages.
"""
2011-01-13 17:55:29 +00:00
# Select Page
self.selectPage = QtGui.QWizardPage()
self.selectPage.setObjectName(u'SelectPage')
self.selectPageLayout = QtGui.QVBoxLayout(self.selectPage)
self.selectPageLayout.setObjectName(u'SelectPageLayout')
self.formatLayout = QtGui.QFormLayout()
self.formatLayout.setObjectName(u'FormatLayout')
self.formatLabel = QtGui.QLabel(self.selectPage)
self.formatLabel.setObjectName(u'FormatLabel')
self.formatComboBox = QtGui.QComboBox(self.selectPage)
2013-04-20 17:36:18 +00:00
self.formatComboBox.addItems([u'', u'', u'', u''])
2011-01-13 17:55:29 +00:00
self.formatComboBox.setObjectName(u'FormatComboBox')
self.formatLayout.addRow(self.formatLabel, self.formatComboBox)
2013-01-01 16:33:41 +00:00
self.spacer = QtGui.QSpacerItem(10, 0, QtGui.QSizePolicy.Fixed, QtGui.QSizePolicy.Minimum)
2011-02-03 20:12:06 +00:00
self.formatLayout.setItem(1, QtGui.QFormLayout.LabelRole, self.spacer)
2011-01-13 17:55:29 +00:00
self.selectPageLayout.addLayout(self.formatLayout)
self.selectStack = QtGui.QStackedLayout()
self.selectStack.setObjectName(u'SelectStack')
self.osisWidget = QtGui.QWidget(self.selectPage)
self.osisWidget.setObjectName(u'OsisWidget')
self.osisLayout = QtGui.QFormLayout(self.osisWidget)
self.osisLayout.setMargin(0)
self.osisLayout.setObjectName(u'OsisLayout')
self.osisFileLabel = QtGui.QLabel(self.osisWidget)
self.osisFileLabel.setObjectName(u'OsisFileLabel')
self.osisFileLayout = QtGui.QHBoxLayout()
self.osisFileLayout.setObjectName(u'OsisFileLayout')
self.osisFileEdit = QtGui.QLineEdit(self.osisWidget)
self.osisFileEdit.setObjectName(u'OsisFileEdit')
self.osisFileLayout.addWidget(self.osisFileEdit)
self.osisBrowseButton = QtGui.QToolButton(self.osisWidget)
2013-03-07 08:05:43 +00:00
self.osisBrowseButton.setIcon(self.open_icon)
2011-01-13 17:55:29 +00:00
self.osisBrowseButton.setObjectName(u'OsisBrowseButton')
self.osisFileLayout.addWidget(self.osisBrowseButton)
self.osisLayout.addRow(self.osisFileLabel, self.osisFileLayout)
2011-02-03 20:12:06 +00:00
self.osisLayout.setItem(1, QtGui.QFormLayout.LabelRole, self.spacer)
2011-01-13 17:55:29 +00:00
self.selectStack.addWidget(self.osisWidget)
self.csvWidget = QtGui.QWidget(self.selectPage)
self.csvWidget.setObjectName(u'CsvWidget')
self.csvLayout = QtGui.QFormLayout(self.csvWidget)
self.csvLayout.setMargin(0)
self.csvLayout.setObjectName(u'CsvLayout')
self.csvBooksLabel = QtGui.QLabel(self.csvWidget)
self.csvBooksLabel.setObjectName(u'CsvBooksLabel')
self.csvBooksLayout = QtGui.QHBoxLayout()
self.csvBooksLayout.setObjectName(u'CsvBooksLayout')
self.csvBooksEdit = QtGui.QLineEdit(self.csvWidget)
self.csvBooksEdit.setObjectName(u'CsvBooksEdit')
self.csvBooksLayout.addWidget(self.csvBooksEdit)
self.csvBooksButton = QtGui.QToolButton(self.csvWidget)
2013-03-07 08:05:43 +00:00
self.csvBooksButton.setIcon(self.open_icon)
2011-01-13 17:55:29 +00:00
self.csvBooksButton.setObjectName(u'CsvBooksButton')
self.csvBooksLayout.addWidget(self.csvBooksButton)
self.csvLayout.addRow(self.csvBooksLabel, self.csvBooksLayout)
self.csvVersesLabel = QtGui.QLabel(self.csvWidget)
self.csvVersesLabel.setObjectName(u'CsvVersesLabel')
self.csvVersesLayout = QtGui.QHBoxLayout()
self.csvVersesLayout.setObjectName(u'CsvVersesLayout')
self.csvVersesEdit = QtGui.QLineEdit(self.csvWidget)
self.csvVersesEdit.setObjectName(u'CsvVersesEdit')
self.csvVersesLayout.addWidget(self.csvVersesEdit)
self.csvVersesButton = QtGui.QToolButton(self.csvWidget)
2013-03-07 08:05:43 +00:00
self.csvVersesButton.setIcon(self.open_icon)
2011-01-13 17:55:29 +00:00
self.csvVersesButton.setObjectName(u'CsvVersesButton')
self.csvVersesLayout.addWidget(self.csvVersesButton)
self.csvLayout.addRow(self.csvVersesLabel, self.csvVersesLayout)
2011-02-03 20:12:06 +00:00
self.csvLayout.setItem(3, QtGui.QFormLayout.LabelRole, self.spacer)
2011-01-13 17:55:29 +00:00
self.selectStack.addWidget(self.csvWidget)
self.openSongWidget = QtGui.QWidget(self.selectPage)
self.openSongWidget.setObjectName(u'OpenSongWidget')
self.openSongLayout = QtGui.QFormLayout(self.openSongWidget)
self.openSongLayout.setMargin(0)
self.openSongLayout.setObjectName(u'OpenSongLayout')
self.openSongFileLabel = QtGui.QLabel(self.openSongWidget)
self.openSongFileLabel.setObjectName(u'OpenSongFileLabel')
self.openSongFileLayout = QtGui.QHBoxLayout()
self.openSongFileLayout.setObjectName(u'OpenSongFileLayout')
self.openSongFileEdit = QtGui.QLineEdit(self.openSongWidget)
self.openSongFileEdit.setObjectName(u'OpenSongFileEdit')
self.openSongFileLayout.addWidget(self.openSongFileEdit)
self.openSongBrowseButton = QtGui.QToolButton(self.openSongWidget)
2013-03-07 08:05:43 +00:00
self.openSongBrowseButton.setIcon(self.open_icon)
2011-01-13 17:55:29 +00:00
self.openSongBrowseButton.setObjectName(u'OpenSongBrowseButton')
self.openSongFileLayout.addWidget(self.openSongBrowseButton)
2013-01-01 16:33:41 +00:00
self.openSongLayout.addRow(self.openSongFileLabel, self.openSongFileLayout)
2011-02-03 20:12:06 +00:00
self.openSongLayout.setItem(1, QtGui.QFormLayout.LabelRole, self.spacer)
2011-01-13 17:55:29 +00:00
self.selectStack.addWidget(self.openSongWidget)
self.webTabWidget = QtGui.QTabWidget(self.selectPage)
self.webTabWidget.setObjectName(u'WebTabWidget')
self.webBibleTab = QtGui.QWidget()
self.webBibleTab.setObjectName(u'WebBibleTab')
self.webBibleLayout = QtGui.QFormLayout(self.webBibleTab)
self.webBibleLayout.setObjectName(u'WebBibleLayout')
self.webSourceLabel = QtGui.QLabel(self.webBibleTab)
self.webSourceLabel.setObjectName(u'WebSourceLabel')
2013-01-01 16:33:41 +00:00
self.webBibleLayout.setWidget(0, QtGui.QFormLayout.LabelRole, self.webSourceLabel)
2011-01-13 17:55:29 +00:00
self.webSourceComboBox = QtGui.QComboBox(self.webBibleTab)
self.webSourceComboBox.setObjectName(u'WebSourceComboBox')
self.webSourceComboBox.addItems([u'', u'', u''])
2013-01-01 16:33:41 +00:00
self.webBibleLayout.setWidget(0, QtGui.QFormLayout.FieldRole, self.webSourceComboBox)
2011-01-13 17:55:29 +00:00
self.webTranslationLabel = QtGui.QLabel(self.webBibleTab)
self.webTranslationLabel.setObjectName(u'webTranslationLabel')
2013-01-01 16:33:41 +00:00
self.webBibleLayout.setWidget(1, QtGui.QFormLayout.LabelRole, self.webTranslationLabel)
2011-01-13 17:55:29 +00:00
self.webTranslationComboBox = QtGui.QComboBox(self.webBibleTab)
2013-01-01 16:33:41 +00:00
self.webTranslationComboBox.setSizeAdjustPolicy(QtGui.QComboBox.AdjustToContents)
2011-01-13 17:55:29 +00:00
self.webTranslationComboBox.setObjectName(u'WebTranslationComboBox')
2013-01-01 16:33:41 +00:00
self.webBibleLayout.setWidget(1, QtGui.QFormLayout.FieldRole, self.webTranslationComboBox)
2011-01-13 17:55:29 +00:00
self.webTabWidget.addTab(self.webBibleTab, u'')
self.webProxyTab = QtGui.QWidget()
self.webProxyTab.setObjectName(u'WebProxyTab')
self.webProxyLayout = QtGui.QFormLayout(self.webProxyTab)
self.webProxyLayout.setObjectName(u'WebProxyLayout')
self.webServerLabel = QtGui.QLabel(self.webProxyTab)
self.webServerLabel.setObjectName(u'WebServerLabel')
2013-01-01 16:33:41 +00:00
self.webProxyLayout.setWidget(0, QtGui.QFormLayout.LabelRole, self.webServerLabel)
2011-01-13 17:55:29 +00:00
self.webServerEdit = QtGui.QLineEdit(self.webProxyTab)
self.webServerEdit.setObjectName(u'WebServerEdit')
2013-01-01 16:33:41 +00:00
self.webProxyLayout.setWidget(0, QtGui.QFormLayout.FieldRole, self.webServerEdit)
2011-01-13 17:55:29 +00:00
self.webUserLabel = QtGui.QLabel(self.webProxyTab)
self.webUserLabel.setObjectName(u'WebUserLabel')
2013-01-01 16:33:41 +00:00
self.webProxyLayout.setWidget(1, QtGui.QFormLayout.LabelRole, self.webUserLabel)
2011-01-13 17:55:29 +00:00
self.webUserEdit = QtGui.QLineEdit(self.webProxyTab)
self.webUserEdit.setObjectName(u'WebUserEdit')
2013-01-01 16:33:41 +00:00
self.webProxyLayout.setWidget(1, QtGui.QFormLayout.FieldRole, self.webUserEdit)
2011-01-13 17:55:29 +00:00
self.webPasswordLabel = QtGui.QLabel(self.webProxyTab)
self.webPasswordLabel.setObjectName(u'WebPasswordLabel')
2013-01-01 16:33:41 +00:00
self.webProxyLayout.setWidget(2, QtGui.QFormLayout.LabelRole, self.webPasswordLabel)
2011-01-13 17:55:29 +00:00
self.webPasswordEdit = QtGui.QLineEdit(self.webProxyTab)
self.webPasswordEdit.setObjectName(u'WebPasswordEdit')
2013-01-01 16:33:41 +00:00
self.webProxyLayout.setWidget(2, QtGui.QFormLayout.FieldRole, self.webPasswordEdit)
2011-01-13 17:55:29 +00:00
self.webTabWidget.addTab(self.webProxyTab, u'')
self.selectStack.addWidget(self.webTabWidget)
self.selectPageLayout.addLayout(self.selectStack)
self.addPage(self.selectPage)
# License Page
self.licenseDetailsPage = QtGui.QWizardPage()
self.licenseDetailsPage.setObjectName(u'LicenseDetailsPage')
self.licenseDetailsLayout = QtGui.QFormLayout(self.licenseDetailsPage)
self.licenseDetailsLayout.setObjectName(u'LicenseDetailsLayout')
self.versionNameLabel = QtGui.QLabel(self.licenseDetailsPage)
self.versionNameLabel.setObjectName(u'VersionNameLabel')
2013-01-01 16:33:41 +00:00
self.licenseDetailsLayout.setWidget(0, QtGui.QFormLayout.LabelRole, self.versionNameLabel)
2011-01-13 17:55:29 +00:00
self.versionNameEdit = QtGui.QLineEdit(self.licenseDetailsPage)
self.versionNameEdit.setObjectName(u'VersionNameEdit')
2013-01-01 16:33:41 +00:00
self.licenseDetailsLayout.setWidget(0, QtGui.QFormLayout.FieldRole, self.versionNameEdit)
2011-01-13 17:55:29 +00:00
self.copyrightLabel = QtGui.QLabel(self.licenseDetailsPage)
self.copyrightLabel.setObjectName(u'CopyrightLabel')
2013-01-01 16:33:41 +00:00
self.licenseDetailsLayout.setWidget(1, QtGui.QFormLayout.LabelRole, self.copyrightLabel)
2011-01-13 17:55:29 +00:00
self.copyrightEdit = QtGui.QLineEdit(self.licenseDetailsPage)
self.copyrightEdit.setObjectName(u'CopyrightEdit')
2013-01-01 16:33:41 +00:00
self.licenseDetailsLayout.setWidget(1, QtGui.QFormLayout.FieldRole, self.copyrightEdit)
2011-01-13 17:55:29 +00:00
self.permissionsLabel = QtGui.QLabel(self.licenseDetailsPage)
self.permissionsLabel.setObjectName(u'PermissionsLabel')
self.licenseDetailsLayout.setWidget(2, QtGui.QFormLayout.LabelRole,
self.permissionsLabel)
self.permissionsEdit = QtGui.QLineEdit(self.licenseDetailsPage)
self.permissionsEdit.setObjectName(u'PermissionsEdit')
2013-01-01 16:33:41 +00:00
self.licenseDetailsLayout.setWidget(2, QtGui.QFormLayout.FieldRole, self.permissionsEdit)
2011-01-13 17:55:29 +00:00
self.addPage(self.licenseDetailsPage)
def retranslateUi(self):
2010-12-08 23:40:28 +00:00
"""
2011-01-13 17:55:29 +00:00
Allow for localisation of the bible import wizard.
2010-12-08 23:40:28 +00:00
"""
2013-01-01 16:33:41 +00:00
self.setWindowTitle(translate('BiblesPlugin.ImportWizardForm', 'Bible Import Wizard'))
2013-03-07 08:05:43 +00:00
self.title_label.setText(WizardStrings.HeaderStyle %
2011-02-16 03:06:34 +00:00
translate('OpenLP.Ui', 'Welcome to the Bible Import Wizard'))
2013-03-07 08:05:43 +00:00
self.information_label.setText(
2011-02-16 03:06:34 +00:00
translate('BiblesPlugin.ImportWizardForm',
'This wizard will help you to import Bibles from a variety of '
'formats. Click the next button below to start the process by '
'selecting a format to import from.'))
2011-02-12 02:43:13 +00:00
self.selectPage.setTitle(WizardStrings.ImportSelect)
self.selectPage.setSubTitle(WizardStrings.ImportSelectLong)
self.formatLabel.setText(WizardStrings.FormatLabel)
2011-02-13 01:09:04 +00:00
self.formatComboBox.setItemText(BibleFormat.OSIS, WizardStrings.OSIS)
self.formatComboBox.setItemText(BibleFormat.CSV, WizardStrings.CSV)
self.formatComboBox.setItemText(BibleFormat.OpenSong, WizardStrings.OS)
self.formatComboBox.setItemText(BibleFormat.WebDownload,
2011-01-13 17:55:29 +00:00
translate('BiblesPlugin.ImportWizardForm', 'Web Download'))
2013-01-01 16:33:41 +00:00
self.osisFileLabel.setText(translate('BiblesPlugin.ImportWizardForm', 'Bible file:'))
self.csvBooksLabel.setText(translate('BiblesPlugin.ImportWizardForm', 'Books file:'))
self.csvVersesLabel.setText(translate('BiblesPlugin.ImportWizardForm', 'Verses file:'))
self.openSongFileLabel.setText(translate('BiblesPlugin.ImportWizardForm', 'Bible file:'))
self.webSourceLabel.setText(translate('BiblesPlugin.ImportWizardForm', 'Location:'))
2011-02-18 03:15:09 +00:00
self.webSourceComboBox.setItemText(WebDownload.Crosswalk,
2011-01-13 17:55:29 +00:00
translate('BiblesPlugin.ImportWizardForm', 'Crosswalk'))
2011-02-18 03:15:09 +00:00
self.webSourceComboBox.setItemText(WebDownload.BibleGateway,
2011-01-13 17:55:29 +00:00
translate('BiblesPlugin.ImportWizardForm', 'BibleGateway'))
2011-02-18 03:15:09 +00:00
self.webSourceComboBox.setItemText(WebDownload.Bibleserver,
2011-01-13 17:55:29 +00:00
translate('BiblesPlugin.ImportWizardForm', 'Bibleserver'))
2013-01-01 16:33:41 +00:00
self.webTranslationLabel.setText(translate('BiblesPlugin.ImportWizardForm', 'Bible:'))
self.webTabWidget.setTabText(self.webTabWidget.indexOf(self.webBibleTab),
2011-01-13 17:55:29 +00:00
translate('BiblesPlugin.ImportWizardForm', 'Download Options'))
2013-01-01 16:33:41 +00:00
self.webServerLabel.setText(translate('BiblesPlugin.ImportWizardForm', 'Server:'))
self.webUserLabel.setText(translate('BiblesPlugin.ImportWizardForm', 'Username:'))
self.webPasswordLabel.setText(translate('BiblesPlugin.ImportWizardForm', 'Password:'))
self.webTabWidget.setTabText(self.webTabWidget.indexOf(self.webProxyTab),
2011-01-13 17:55:29 +00:00
translate('BiblesPlugin.ImportWizardForm',
'Proxy Server (Optional)'))
self.licenseDetailsPage.setTitle(
translate('BiblesPlugin.ImportWizardForm', 'License Details'))
2013-01-01 16:33:41 +00:00
self.licenseDetailsPage.setSubTitle(translate('BiblesPlugin.ImportWizardForm',
2011-01-13 17:55:29 +00:00
'Set up the Bible\'s license details.'))
2013-01-01 16:33:41 +00:00
self.versionNameLabel.setText(translate('BiblesPlugin.ImportWizardForm', 'Version name:'))
self.copyrightLabel.setText(translate('BiblesPlugin.ImportWizardForm', 'Copyright:'))
self.permissionsLabel.setText(translate('BiblesPlugin.ImportWizardForm', 'Permissions:'))
2013-03-07 08:05:43 +00:00
self.progress_page.setTitle(WizardStrings.Importing)
self.progress_page.setSubTitle(translate('BiblesPlugin.ImportWizardForm',
2011-01-13 17:55:29 +00:00
'Please wait while your Bible is imported.'))
2013-03-07 08:05:43 +00:00
self.progress_label.setText(WizardStrings.Ready)
self.progress_bar.setFormat(u'%p%')
2011-01-13 17:55:29 +00:00
# Align all QFormLayouts towards each other.
labelWidth = max(self.formatLabel.minimumSizeHint().width(),
self.osisFileLabel.minimumSizeHint().width(),
self.csvBooksLabel.minimumSizeHint().width(),
self.csvVersesLabel.minimumSizeHint().width(),
2013-04-15 21:31:04 +00:00
self.openSongFileLabel.minimumSizeHint().width())
2013-01-01 16:33:41 +00:00
self.spacer.changeSize(labelWidth, 0, QtGui.QSizePolicy.Fixed, QtGui.QSizePolicy.Fixed)
2010-12-08 23:40:28 +00:00
def validateCurrentPage(self):
"""
Validate the current page before moving on to the next page.
"""
2013-03-07 08:05:43 +00:00
if self.currentPage() == self.welcome_page:
return True
elif self.currentPage() == self.selectPage:
2012-05-19 09:13:32 +00:00
if self.field(u'source_format') == BibleFormat.OSIS:
2012-05-19 15:10:05 +00:00
if not self.field(u'osis_location'):
2013-01-01 16:33:41 +00:00
critical_error_message_box(UiStrings().NFSs, WizardStrings.YouSpecifyFile % WizardStrings.OSIS)
self.osisFileEdit.setFocus()
return False
2012-05-19 09:13:32 +00:00
elif self.field(u'source_format') == BibleFormat.CSV:
2012-05-19 15:10:05 +00:00
if not self.field(u'csv_booksfile'):
2013-01-01 16:33:41 +00:00
critical_error_message_box(UiStrings().NFSs, translate('BiblesPlugin.ImportWizardForm',
'You need to specify a file with books of the Bible to use in the import.'))
self.csvBooksEdit.setFocus()
return False
2012-05-19 15:10:05 +00:00
elif not self.field(u'csv_versefile'):
critical_error_message_box(UiStrings().NFSs,
2010-06-21 18:28:36 +00:00
translate('BiblesPlugin.ImportWizardForm',
2013-01-01 16:33:41 +00:00
'You need to specify a file of Bible verses to import.'))
self.csvVersesEdit.setFocus()
return False
2013-01-01 16:33:41 +00:00
elif self.field(u'source_format') == BibleFormat.OpenSong:
2012-05-19 15:10:05 +00:00
if not self.field(u'opensong_file'):
2013-01-01 16:33:41 +00:00
critical_error_message_box(UiStrings().NFSs, WizardStrings.YouSpecifyFile % WizardStrings.OS)
2010-12-08 17:18:12 +00:00
self.openSongFileEdit.setFocus()
return False
2013-01-01 16:33:41 +00:00
elif self.field(u'source_format') == BibleFormat.WebDownload:
self.versionNameEdit.setText(self.webTranslationComboBox.currentText())
return True
return True
elif self.currentPage() == self.licenseDetailsPage:
2012-05-19 15:10:05 +00:00
license_version = self.field(u'license_version')
license_copyright = self.field(u'license_copyright')
path = AppLocation.get_section_data_path(u'bibles')
if not license_version:
critical_error_message_box(UiStrings().EmptyField,
2013-01-01 16:33:41 +00:00
translate('BiblesPlugin.ImportWizardForm', 'You need to specify a version name for your Bible.'))
2010-12-08 17:18:12 +00:00
self.versionNameEdit.setFocus()
2009-12-16 20:52:44 +00:00
return False
elif not license_copyright:
critical_error_message_box(UiStrings().EmptyField,
2013-01-01 16:33:41 +00:00
translate('BiblesPlugin.ImportWizardForm', 'You need to set a copyright for your Bible. '
'Bibles in the Public Domain need to be marked as such.'))
2010-12-08 17:18:12 +00:00
self.copyrightEdit.setFocus()
2009-12-16 20:52:44 +00:00
return False
elif self.manager.exists(license_version):
2013-01-01 16:33:41 +00:00
critical_error_message_box(translate('BiblesPlugin.ImportWizardForm', 'Bible Exists'),
2010-06-21 18:28:36 +00:00
translate('BiblesPlugin.ImportWizardForm',
2013-01-01 16:33:41 +00:00
'This Bible already exists. Please import a different Bible or first delete the existing one.'))
2010-12-08 17:18:12 +00:00
self.versionNameEdit.setFocus()
return False
2011-05-03 17:09:30 +00:00
elif os.path.exists(os.path.join(path, clean_filename(
license_version))):
critical_error_message_box(
translate('BiblesPlugin.ImportWizardForm', 'Bible Exists'),
2013-01-01 16:33:41 +00:00
translate('BiblesPlugin.ImportWizardForm', 'This Bible already exists. Please import '
'a different Bible or first delete the existing one.'))
self.versionNameEdit.setFocus()
return False
return True
2013-03-07 08:05:43 +00:00
if self.currentPage() == self.progress_page:
return True
2011-01-13 17:55:29 +00:00
def onWebSourceComboBoxIndexChanged(self, index):
"""
Setup the list of Bibles when you select a different source on the web
download page.
``index``
The index of the combo box.
"""
self.webTranslationComboBox.clear()
bibles = self.web_bible_list[index].keys()
bibles.sort(key=get_locale_key)
self.webTranslationComboBox.addItems(bibles)
def onOsisBrowseButtonClicked(self):
"""
Show the file open dialog for the OSIS file.
"""
2013-03-07 08:05:43 +00:00
self.get_file_name(WizardStrings.OpenTypeFile % WizardStrings.OSIS, self.osisFileEdit, u'last directory import')
2011-04-14 20:33:02 +00:00
2011-01-27 16:45:23 +00:00
def onCsvBooksBrowseButtonClicked(self):
"""
Show the file open dialog for the books CSV file.
"""
2013-03-07 08:05:43 +00:00
self.get_file_name(WizardStrings.OpenTypeFile % WizardStrings.CSV, self.csvBooksEdit, u'last directory import',
2013-01-18 20:35:30 +00:00
u'%s (*.csv)' % translate('BiblesPlugin.ImportWizardForm', 'CSV File'))
2009-12-16 20:52:44 +00:00
def onCsvVersesBrowseButtonClicked(self):
"""
Show the file open dialog for the verses CSV file.
"""
2013-03-07 08:05:43 +00:00
self.get_file_name(WizardStrings.OpenTypeFile % WizardStrings.CSV, self.csvVersesEdit, u'last directory import',
2013-01-18 20:35:30 +00:00
u'%s (*.csv)' % translate('BiblesPlugin.ImportWizardForm', 'CSV File'))
2009-12-16 20:52:44 +00:00
def onOpenSongBrowseButtonClicked(self):
"""
Show the file open dialog for the OpenSong file.
"""
2013-03-07 08:05:43 +00:00
self.get_file_name(WizardStrings.OpenTypeFile % WizardStrings.OS, self.openSongFileEdit, u'last directory import')
2009-12-16 20:52:44 +00:00
2013-03-07 11:42:56 +00:00
def register_fields(self):
2011-01-13 17:55:29 +00:00
"""
Register the bible import wizard fields.
"""
2010-12-09 16:53:48 +00:00
self.selectPage.registerField(u'source_format', self.formatComboBox)
self.selectPage.registerField(u'osis_location', self.osisFileEdit)
self.selectPage.registerField(u'csv_booksfile', self.csvBooksEdit)
self.selectPage.registerField(u'csv_versefile', self.csvVersesEdit)
2010-12-09 16:53:48 +00:00
self.selectPage.registerField(u'opensong_file', self.openSongFileEdit)
self.selectPage.registerField(u'web_location', self.webSourceComboBox)
2013-01-01 16:33:41 +00:00
self.selectPage.registerField(u'web_biblename', self.webTranslationComboBox)
self.selectPage.registerField(u'proxy_server', self.webServerEdit)
self.selectPage.registerField(u'proxy_username', self.webUserEdit)
self.selectPage.registerField(u'proxy_password', self.webPasswordEdit)
2013-01-01 16:33:41 +00:00
self.licenseDetailsPage.registerField(u'license_version', self.versionNameEdit)
self.licenseDetailsPage.registerField(u'license_copyright', self.copyrightEdit)
self.licenseDetailsPage.registerField(u'license_permissions', self.permissionsEdit)
def setDefaults(self):
2011-01-13 17:55:29 +00:00
"""
Set default values for the wizard pages.
"""
2012-05-17 15:13:09 +00:00
settings = Settings()
2013-03-19 19:43:22 +00:00
settings.beginGroup(self.plugin.settings_section)
self.restart()
2013-03-07 08:05:43 +00:00
self.finish_button.setVisible(False)
self.cancel_button.setVisible(True)
2012-05-17 15:13:09 +00:00
self.setField(u'source_format', 0)
self.setField(u'osis_location', '')
self.setField(u'csv_booksfile', '')
self.setField(u'csv_versefile', '')
self.setField(u'opensong_file', '')
self.setField(u'web_location', WebDownload.Crosswalk)
2013-01-01 16:33:41 +00:00
self.setField(u'web_biblename', self.webTranslationComboBox.currentIndex())
self.setField(u'proxy_server', settings.value(u'proxy address'))
self.setField(u'proxy_username', settings.value(u'proxy username'))
self.setField(u'proxy_password', settings.value(u'proxy password'))
2012-05-17 15:13:09 +00:00
self.setField(u'license_version', self.versionNameEdit.text())
self.setField(u'license_copyright', self.copyrightEdit.text())
self.setField(u'license_permissions', self.permissionsEdit.text())
2011-01-13 17:55:29 +00:00
self.onWebSourceComboBoxIndexChanged(WebDownload.Crosswalk)
2010-04-28 14:17:42 +00:00
settings.endGroup()
def loadWebBibles(self):
2009-12-16 20:52:44 +00:00
"""
2011-01-13 17:55:29 +00:00
Load the lists of Crosswalk, BibleGateway and Bibleserver bibles.
2009-12-16 20:52:44 +00:00
"""
2011-01-13 17:55:29 +00:00
# Load Crosswalk Bibles.
self.loadBibleResource(WebDownload.Crosswalk)
# Load BibleGateway Bibles.
self.loadBibleResource(WebDownload.BibleGateway)
# Load and Bibleserver Bibles.
self.loadBibleResource(WebDownload.Bibleserver)
2011-01-13 17:55:29 +00:00
def loadBibleResource(self, download_type):
2011-01-13 17:55:29 +00:00
"""
Loads a web bible from bible_resources.sqlite.
2011-01-13 17:55:29 +00:00
``download_type``
The WebDownload type e.g. bibleserver.
2011-01-13 17:55:29 +00:00
"""
self.web_bible_list[download_type] = {}
2013-01-01 16:33:41 +00:00
bibles = BiblesResourcesDB.get_webbibles(WebDownload.Names[download_type])
for bible in bibles:
2011-05-03 20:34:39 +00:00
version = bible[u'name']
name = bible[u'abbreviation']
2011-05-03 20:34:39 +00:00
self.web_bible_list[download_type][version] = name.strip()
def pre_wizard(self):
2010-12-06 19:30:04 +00:00
"""
Prepare the UI for the import.
"""
2013-07-18 19:49:44 +00:00
super(BibleImportForm, self).pre_wizard()
2012-05-19 09:13:32 +00:00
bible_type = self.field(u'source_format')
if bible_type == BibleFormat.WebDownload:
2013-03-07 08:05:43 +00:00
self.progress_label.setText(translate('BiblesPlugin.ImportWizardForm', 'Registering Bible...'))
else:
2013-03-07 08:05:43 +00:00
self.progress_label.setText(WizardStrings.StartingImport)
2013-02-03 19:23:12 +00:00
self.application.process_events()
2011-01-13 17:55:29 +00:00
def performWizard(self):
2010-12-06 19:30:04 +00:00
"""
Perform the actual import.
"""
2012-05-19 09:13:32 +00:00
bible_type = self.field(u'source_format')
2012-05-19 15:10:05 +00:00
license_version = self.field(u'license_version')
license_copyright = self.field(u'license_copyright')
license_permissions = self.field(u'license_permissions')
2010-03-19 22:08:06 +00:00
importer = None
if bible_type == BibleFormat.OSIS:
# Import an OSIS bible.
2010-03-19 22:08:06 +00:00
importer = self.manager.import_bible(BibleFormat.OSIS,
name=license_version,
2012-05-19 15:10:05 +00:00
filename=self.field(u'osis_location')
)
elif bible_type == BibleFormat.CSV:
# Import a CSV bible.
importer = self.manager.import_bible(BibleFormat.CSV,
name=license_version,
2012-05-19 15:10:05 +00:00
booksfile=self.field(u'csv_booksfile'),
versefile=self.field(u'csv_versefile')
)
elif bible_type == BibleFormat.OpenSong:
# Import an OpenSong bible.
2010-03-19 22:08:06 +00:00
importer = self.manager.import_bible(BibleFormat.OpenSong,
name=license_version,
2012-05-19 15:10:05 +00:00
filename=self.field(u'opensong_file')
)
elif bible_type == BibleFormat.WebDownload:
# Import a bible from the web.
2013-03-07 08:05:43 +00:00
self.progress_bar.setMaximum(1)
2012-05-19 09:13:32 +00:00
download_location = self.field(u'web_location')
2012-05-17 18:57:01 +00:00
bible_version = self.webTranslationComboBox.currentText()
2011-02-18 03:15:09 +00:00
bible = self.web_bible_list[download_location][bible_version]
importer = self.manager.import_bible(
2011-01-27 16:45:23 +00:00
BibleFormat.WebDownload, name=license_version,
2011-02-18 03:15:09 +00:00
download_source=WebDownload.Names[download_location],
2010-03-21 20:33:57 +00:00
download_name=bible,
2012-05-19 15:10:05 +00:00
proxy_server=self.field(u'proxy_server'),
proxy_username=self.field(u'proxy_username'),
proxy_password=self.field(u'proxy_password')
)
if importer.do_import(license_version):
self.manager.save_meta_data(license_version, license_version,
license_copyright, license_permissions)
2010-02-04 17:38:21 +00:00
self.manager.reload_bibles()
if bible_type == BibleFormat.WebDownload:
2013-03-07 08:05:43 +00:00
self.progress_label.setText(
2013-01-01 16:33:41 +00:00
translate('BiblesPlugin.ImportWizardForm', 'Registered Bible. Please note, that verses will be '
'downloaded on\ndemand and thus an internet connection is required.'))
else:
2013-03-07 08:05:43 +00:00
self.progress_label.setText(WizardStrings.FinishedImport)
else:
2013-03-07 08:05:43 +00:00
self.progress_label.setText(translate('BiblesPlugin.ImportWizardForm', 'Your Bible import failed.'))
del self.manager.db_cache[importer.name]
2013-03-19 19:43:22 +00:00
delete_database(self.plugin.settings_section, importer.file)