diff --git a/openlp/plugins/bibles/forms/bibleimportform.py b/openlp/plugins/bibles/forms/bibleimportform.py index 749f1f938..e99fd1d7c 100644 --- a/openlp/plugins/bibles/forms/bibleimportform.py +++ b/openlp/plugins/bibles/forms/bibleimportform.py @@ -99,6 +99,9 @@ class BibleImportForm(QtGui.QWizard, Ui_BibleImportWizard): QtCore.QObject.connect(self.OpenSongBrowseButton, QtCore.SIGNAL(u'clicked()'), self.onOpenSongBrowseButtonClicked) + QtCore.QObject.connect(self.OLP1FileButton, + QtCore.SIGNAL(u'clicked()'), + self.onOLP1FileButtonClicked) QtCore.QObject.connect(self.cancelButton, QtCore.SIGNAL(u'clicked(bool)'), self.onCancelButtonClicked) @@ -123,7 +126,7 @@ class BibleImportForm(QtGui.QWizard, Ui_BibleImportWizard): elif self.currentId() == 1: # Select page if self.field(u'source_format').toInt()[0] == BibleFormat.OSIS: - if self.field(u'osis_location').toString() == u'': + if not self.field(u'osis_location').toString(): QtGui.QMessageBox.critical(self, translate('BiblesPlugin.ImportWizardForm', 'Invalid Bible Location'), @@ -162,9 +165,21 @@ class BibleImportForm(QtGui.QWizard, Ui_BibleImportWizard): 'file to import.')) self.OpenSongFileEdit.setFocus() return False + elif self.field(u'source_format').toInt()[0] == BibleFormat.OLP1: + if not self.field(u'OLP1_location').toString(): + QtGui.QMessageBox.critical(self, + translate('BiblesPlugin.ImportWizardForm', + 'Invalid Bible Location'), + translate('BiblesPlugin.ImportWizardForm', + 'You need to specify a file to import your ' + 'Bible from.')) + self.OLP1LocationEdit.setFocus() + return False return True elif self.currentId() == 2: # License details + if self.field(u'source_format').toInt()[0] == BibleFormat.OLP1: + return True license_version = unicode(self.field(u'license_version').toString()) license_copyright = \ unicode(self.field(u'license_copyright').toString()) @@ -244,6 +259,14 @@ class BibleImportForm(QtGui.QWizard, Ui_BibleImportWizard): translate('BiblesPlugin.ImportWizardForm', 'Open OpenSong Bible'), self.OpenSongFileEdit) + def onOLP1FileButtonClicked(self): + """ + Show the file open dialog for the openlp.org 1.x file. + """ + self.getFileName( + translate('BiblesPlugin.ImportWizardForm', + 'Open openlp.org 1.x Bible'), self.OLP1LocationEdit) + def onCancelButtonClicked(self, checked): """ Stop the import on pressing the cancel button. @@ -279,6 +302,8 @@ class BibleImportForm(QtGui.QWizard, Ui_BibleImportWizard): u'proxy_username', self.UsernameEdit) self.SelectPage.registerField( u'proxy_password', self.PasswordEdit) + self.SelectPage.registerField( + u'OLP1_location', self.OLP1LocationEdit) self.LicenseDetailsPage.registerField( u'license_version', self.VersionNameEdit) self.LicenseDetailsPage.registerField( @@ -306,6 +331,7 @@ class BibleImportForm(QtGui.QWizard, Ui_BibleImportWizard): settings.value(u'proxy username', QtCore.QVariant(u''))) self.setField(u'proxy_password', settings.value(u'proxy password', QtCore.QVariant(u''))) + self.setField(u'OLP1_location', QtCore.QVariant('')) self.setField(u'license_version', QtCore.QVariant(self.VersionNameEdit.text())) self.setField(u'license_copyright', @@ -442,6 +468,12 @@ class BibleImportForm(QtGui.QWizard, Ui_BibleImportWizard): unicode(self.field(u'proxy_username').toString()), proxy_password=unicode(self.field(u'proxy_password').toString()) ) + elif bible_type == BibleFormat.OLP1: + # Import an openlp.org 1.x bible. + importer = self.manager.import_bible(BibleFormat.OLP1, + name=license_version, + filename=unicode(self.field(u'OLP1_location').toString()) + ) if importer.do_import(): self.manager.save_meta_data(license_version, license_version, license_copyright, license_permissions) diff --git a/openlp/plugins/bibles/forms/bibleimportwizard.py b/openlp/plugins/bibles/forms/bibleimportwizard.py index 304e9fb0f..c7498d88c 100644 --- a/openlp/plugins/bibles/forms/bibleimportwizard.py +++ b/openlp/plugins/bibles/forms/bibleimportwizard.py @@ -38,6 +38,7 @@ class Ui_BibleImportWizard(object): QtGui.QWizard.IndependentPages | QtGui.QWizard.NoBackButtonOnStartPage | QtGui.QWizard.NoBackButtonOnLastPage) + # Welcome page self.WelcomePage = QtGui.QWizardPage() self.WelcomePage.setPixmap(QtGui.QWizard.WatermarkPixmap, QtGui.QPixmap(u':/wizards/wizard_importbible.bmp')) @@ -61,6 +62,7 @@ class Ui_BibleImportWizard(object): QtGui.QSizePolicy.Minimum, QtGui.QSizePolicy.Expanding) self.WelcomeLayout.addItem(spacerItem1) BibleImportWizard.addPage(self.WelcomePage) + # Select page self.SelectPage = QtGui.QWizardPage() self.SelectPage.setObjectName(u'SelectPage') self.selectPageLayout = QtGui.QVBoxLayout(self.SelectPage) @@ -79,6 +81,7 @@ class Ui_BibleImportWizard(object): self.FormatComboBox.addItem(u'') self.FormatComboBox.addItem(u'') self.FormatComboBox.addItem(u'') + self.FormatComboBox.addItem(u'') self.FormatSelectLayout.addWidget(self.FormatComboBox) spacerItem2 = QtGui.QSpacerItem(40, 20, QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Minimum) @@ -86,6 +89,7 @@ class Ui_BibleImportWizard(object): self.selectPageLayout.addLayout(self.FormatSelectLayout) self.FormatWidget = QtGui.QStackedWidget(self.SelectPage) self.FormatWidget.setObjectName(u'FormatWidget') + generalIcon = build_icon(u':/general/general_open.png') self.OsisPage = QtGui.QWidget() self.OsisPage.setObjectName(u'OsisPage') self.OsisLayout = QtGui.QFormLayout(self.OsisPage) @@ -106,7 +110,6 @@ class Ui_BibleImportWizard(object): self.OsisLocationLayout.addWidget(self.OSISLocationEdit) self.OsisFileButton = QtGui.QToolButton(self.OsisPage) self.OsisFileButton.setMaximumSize(QtCore.QSize(32, 16777215)) - generalIcon = build_icon(u':/general/general_open.png') self.OsisFileButton.setIcon(generalIcon) self.OsisFileButton.setObjectName(u'OsisFileButton') self.OsisLocationLayout.addWidget(self.OsisFileButton) @@ -251,8 +254,35 @@ class Ui_BibleImportWizard(object): self.WebDownloadTabWidget.addTab(self.ProxyServerTab, u'') self.WebDownloadLayout.addWidget(self.WebDownloadTabWidget) self.FormatWidget.addWidget(self.WebDownloadPage) + self.OLP1Page = QtGui.QWidget() + self.OLP1Page.setObjectName(u'OLP1Page') + self.OLP1Layout = QtGui.QFormLayout(self.OLP1Page) + self.OLP1Layout.setFieldGrowthPolicy( + QtGui.QFormLayout.ExpandingFieldsGrow) + self.OLP1Layout.setMargin(0) + self.OLP1Layout.setSpacing(8) + self.OLP1Layout.setObjectName(u'OLP1Layout') + self.OLP1LocationLabel = QtGui.QLabel(self.OLP1Page) + self.OLP1LocationLabel.setObjectName(u'OLP1LocationLabel') + self.OLP1Layout.setWidget(1, QtGui.QFormLayout.LabelRole, + self.OLP1LocationLabel) + self.OLP1LocationLayout = QtGui.QHBoxLayout() + self.OLP1LocationLayout.setSpacing(8) + self.OLP1LocationLayout.setObjectName(u'OLP1LocationLayout') + self.OLP1LocationEdit = QtGui.QLineEdit(self.OLP1Page) + self.OLP1LocationEdit.setObjectName(u'OLP1LocationEdit') + self.OLP1LocationLayout.addWidget(self.OLP1LocationEdit) + self.OLP1FileButton = QtGui.QToolButton(self.OLP1Page) + self.OLP1FileButton.setMaximumSize(QtCore.QSize(32, 16777215)) + self.OLP1FileButton.setIcon(generalIcon) + self.OLP1FileButton.setObjectName(u'OLP1FileButton') + self.OLP1LocationLayout.addWidget(self.OLP1FileButton) + self.OLP1Layout.setLayout(1, QtGui.QFormLayout.FieldRole, + self.OLP1LocationLayout) + self.FormatWidget.addWidget(self.OLP1Page) self.selectPageLayout.addWidget(self.FormatWidget) BibleImportWizard.addPage(self.SelectPage) + # License page self.LicenseDetailsPage = QtGui.QWizardPage() self.LicenseDetailsPage.setObjectName(u'LicenseDetailsPage') self.LicenseDetailsLayout = QtGui.QFormLayout(self.LicenseDetailsPage) @@ -284,6 +314,7 @@ class Ui_BibleImportWizard(object): self.LicenseDetailsLayout.setWidget(2, QtGui.QFormLayout.FieldRole, self.PermissionsEdit) BibleImportWizard.addPage(self.LicenseDetailsPage) + # Progress page self.ImportPage = QtGui.QWizardPage() self.ImportPage.setObjectName(u'ImportPage') self.ImportLayout = QtGui.QVBoxLayout(self.ImportPage) @@ -311,19 +342,19 @@ class Ui_BibleImportWizard(object): BibleImportWizard.setWindowTitle( translate('BiblesPlugin.ImportWizardForm', 'Bible Import Wizard')) self.TitleLabel.setText( - u'%s' % \ + u'%s' % translate('BiblesPlugin.ImportWizardForm', - 'Welcome to the Bible Import Wizard')) + 'Welcome to the Bible Import Wizard')) self.InformationLabel.setText( 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.')) + '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.')) self.SelectPage.setTitle(translate('BiblesPlugin.ImportWizardForm', 'Select Import Source')) self.SelectPage.setSubTitle( translate('BiblesPlugin.ImportWizardForm', - 'Select the import format, and where to import from.')) + 'Select the import format, and where to import from.')) self.FormatLabel.setText( translate('BiblesPlugin.ImportWizardForm', 'Format:')) self.FormatComboBox.setItemText(0, @@ -334,6 +365,10 @@ class Ui_BibleImportWizard(object): translate('BiblesPlugin.ImportWizardForm', 'OpenSong')) self.FormatComboBox.setItemText(3, translate('BiblesPlugin.ImportWizardForm', 'Web Download')) + self.FormatComboBox.setItemText(4, + translate('BiblesPlugin.ImportWizardForm', 'openlp.org 1.x')) + self.OLP1LocationLabel.setText( + translate('BiblesPlugin.ImportWizardForm', 'File location:')) self.OsisLocationLabel.setText( translate('BiblesPlugin.ImportWizardForm', 'File location:')) self.BooksLocationLabel.setText( @@ -362,12 +397,12 @@ class Ui_BibleImportWizard(object): self.WebDownloadTabWidget.setTabText( self.WebDownloadTabWidget.indexOf(self.ProxyServerTab), translate('BiblesPlugin.ImportWizardForm', - 'Proxy Server (Optional)')) + 'Proxy Server (Optional)')) self.LicenseDetailsPage.setTitle( translate('BiblesPlugin.ImportWizardForm', 'License Details')) self.LicenseDetailsPage.setSubTitle( translate('BiblesPlugin.ImportWizardForm', - 'Set up the Bible\'s license details.')) + 'Set up the Bible\'s license details.')) self.VersionNameLabel.setText( translate('BiblesPlugin.ImportWizardForm', 'Version name:')) self.CopyrightLabel.setText( @@ -378,7 +413,7 @@ class Ui_BibleImportWizard(object): translate('BiblesPlugin.ImportWizardForm', 'Importing')) self.ImportPage.setSubTitle( translate('BiblesPlugin.ImportWizardForm', - 'Please wait while your Bible is imported.')) + 'Please wait while your Bible is imported.')) self.ImportProgressLabel.setText( translate('BiblesPlugin.ImportWizardForm', 'Ready.')) self.ImportProgressBar.setFormat(u'%p%') diff --git a/openlp/plugins/bibles/lib/db.py b/openlp/plugins/bibles/lib/db.py index 9852ed16b..cdc81d408 100644 --- a/openlp/plugins/bibles/lib/db.py +++ b/openlp/plugins/bibles/lib/db.py @@ -231,7 +231,7 @@ class BibleDB(QtCore.QObject, Manager): def create_chapter(self, book_id, chapter, textlist): """ - Add a chapter and it's verses to a book. + Add a chapter and its verses to a book. ``book_id`` The id of the book being appended. diff --git a/openlp/plugins/bibles/lib/manager.py b/openlp/plugins/bibles/lib/manager.py index 6b4d7c800..737822016 100644 --- a/openlp/plugins/bibles/lib/manager.py +++ b/openlp/plugins/bibles/lib/manager.py @@ -33,9 +33,10 @@ from openlp.core.utils import AppLocation from openlp.plugins.bibles.lib import parse_reference from openlp.plugins.bibles.lib.db import BibleDB, BibleMeta +from csvbible import CSVBible +from olp1 import OpenLP1Bible from opensong import OpenSongBible from osis import OSISBible -from csvbible import CSVBible from http import HTTPBible log = logging.getLogger(__name__) @@ -61,6 +62,7 @@ class BibleFormat(object): CSV = 1 OpenSong = 2 WebDownload = 3 + OLP1 = 4 @staticmethod def get_class(format): @@ -78,6 +80,8 @@ class BibleFormat(object): return OpenSongBible elif format == BibleFormat.WebDownload: return HTTPBible + elif format == BibleFormat.OLP1: + return OpenLP1Bible else: return None @@ -90,7 +94,8 @@ class BibleFormat(object): BibleFormat.OSIS, BibleFormat.CSV, BibleFormat.OpenSong, - BibleFormat.WebDownload + BibleFormat.WebDownload, + BibleFormat.OLP1 ] diff --git a/openlp/plugins/bibles/lib/olp1.py b/openlp/plugins/bibles/lib/olp1.py new file mode 100755 index 000000000..c0106a980 --- /dev/null +++ b/openlp/plugins/bibles/lib/olp1.py @@ -0,0 +1,87 @@ +# -*- coding: utf-8 -*- +# vim: autoindent shiftwidth=4 expandtab textwidth=80 tabstop=4 softtabstop=4 + +############################################################################### +# OpenLP - Open Source Lyrics Projection # +# --------------------------------------------------------------------------- # +# Copyright (c) 2008-2010 Raoul Snyman # +# Portions copyright (c) 2008-2010 Tim Bentley, Jonathan Corwin, Michael # +# Gorven, Scott Guerrieri, Meinert Jordan, Andreas Preikschat, Christian # +# Richter, Philip Ridout, Maikel Stuivenberg, Martin Thompson, Jon Tibble, # +# Carsten Tinggaard, Frode Woldsund # +# --------------------------------------------------------------------------- # +# 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 # +############################################################################### + +import logging +import sqlite + +#from openlp.core.lib import Receiver, translate +from openlp.core.lib import translate +from db import BibleDB + +log = logging.getLogger(__name__) + +class OpenLP1Bible(BibleDB): + """ + This class provides the OpenLPv1 bible importer. + """ + def __init__(self, parent, **kwargs): + """ + Constructor. + """ + log.debug(__name__) + BibleDB.__init__(self, parent, **kwargs) + if 'filename' not in kwargs: + raise KeyError(u'You have to supply a file name to import from.') + self.filename = kwargs['filename'] +# QtCore.QObject.connect(Receiver.get_receiver(), +# QtCore.SIGNAL(u'bibles_stop_import'), self.stop_import) + + def do_import(self): + """ + Imports an openlp.org v1 bible. + """ + # TODO: stop_import_flag + # TODO: update progress bar + connection = None + cursor = None + self.wizard.incrementProgressBar(u'Preparing for import...') + try: + connection = sqlite.connect(self.filename) + cursor = connection.cursor() + except: + return False + # Import books. + cursor.execute(u'SELECT id, testament_id, name, abbreviation FROM book') + books = cursor.fetchall() + for book in books: + testament_id = int(book[1]) + name = unicode(book[2], u'cp1252') + abbreviation = unicode(book[3], u'cp1252') + self.create_book(name, abbreviation, testament_id) + self.session.commit() + # Import chapters/verses. + cursor.execute(u'SELECT id, book_id, chapter, verse, text || \'\' AS ' + 'text FROM verse') + verses = cursor.fetchall() + for verse in verses: + book_id = int(verse[1]) + chapter = int(verse[2]) + verse_number = int(verse[3]) + text = unicode(verse[4], u'cp1252') + self.create_verse(book_id, chapter, verse_number, text) + self.session.commit() + return True + diff --git a/openlp/plugins/bibles/lib/opensong.py b/openlp/plugins/bibles/lib/opensong.py index f1d3efd74..8644a9f47 100644 --- a/openlp/plugins/bibles/lib/opensong.py +++ b/openlp/plugins/bibles/lib/opensong.py @@ -89,8 +89,8 @@ class OpenSongBible(BibleDB): Receiver.send_message(u'openlp_process_events') self.wizard.incrementProgressBar( QtCore.QString('%s %s %s' % ( - translate('BiblesPlugin.Opensong', 'Importing'), - db_book.name, chapter.attrib[u'n']))) + translate('BiblesPlugin.Opensong', 'Importing'), + db_book.name, chapter.attrib[u'n']))) self.session.commit() except IOError: log.exception(u'Loading bible from OpenSong file failed')