forked from openlp/openlp
Added a dialog to edit metadata of Bibles, and additional language options.
bzr-revno: 1943 Fixes: https://launchpad.net/bugs/738697, https://launchpad.net/bugs/822363
This commit is contained in:
commit
93a72fd4d5
@ -55,6 +55,7 @@ from booknameform import BookNameForm
|
||||
from languageform import LanguageForm
|
||||
from bibleimportform import BibleImportForm
|
||||
from bibleupgradeform import BibleUpgradeForm
|
||||
from editbibleform import EditBibleForm
|
||||
|
||||
__all__ = [u'BookNameForm', u'LanguageForm', u'BibleImportForm',
|
||||
u'BibleUpgradeForm']
|
||||
u'BibleUpgradeForm', u'EditBibleForm']
|
||||
|
@ -415,7 +415,7 @@ class BibleUpgradeForm(OpenLPWizard):
|
||||
meta_data[meta[u'key']] = meta[u'value']
|
||||
if not meta[u'key'] == u'Version' and not meta[u'key'] == \
|
||||
u'dbversion':
|
||||
self.newbibles[number].create_meta(meta[u'key'],
|
||||
self.newbibles[number].save_meta(meta[u'key'],
|
||||
meta[u'value'])
|
||||
if meta[u'key'] == u'download source':
|
||||
webbible = True
|
||||
@ -455,7 +455,7 @@ class BibleUpgradeForm(OpenLPWizard):
|
||||
meta_data[u'download source'].lower())
|
||||
if bible and bible[u'language_id']:
|
||||
language_id = bible[u'language_id']
|
||||
self.newbibles[number].create_meta(u'language_id',
|
||||
self.newbibles[number].save_meta(u'language_id',
|
||||
language_id)
|
||||
else:
|
||||
language_id = self.newbibles[number].get_language(name)
|
||||
@ -574,7 +574,7 @@ class BibleUpgradeForm(OpenLPWizard):
|
||||
self.progressBar.maximum() - self.progressBar.value())
|
||||
else:
|
||||
self.success[number] = True
|
||||
self.newbibles[number].create_meta(u'Version', name)
|
||||
self.newbibles[number].save_meta(u'Version', name)
|
||||
self.incrementProgressBar(unicode(translate(
|
||||
'BiblesPlugin.UpgradeWizardForm',
|
||||
'Upgrading Bible %s of %s: "%s"\n'
|
||||
|
181
openlp/plugins/bibles/forms/editbibledialog.py
Normal file
181
openlp/plugins/bibles/forms/editbibledialog.py
Normal file
@ -0,0 +1,181 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# vim: autoindent shiftwidth=4 expandtab textwidth=80 tabstop=4 softtabstop=4
|
||||
|
||||
###############################################################################
|
||||
# OpenLP - Open Source Lyrics Projection #
|
||||
# --------------------------------------------------------------------------- #
|
||||
# Copyright (c) 2008-2012 Raoul Snyman #
|
||||
# Portions copyright (c) 2008-2012 Tim Bentley, Gerald Britton, Jonathan #
|
||||
# Corwin, Michael Gorven, Scott Guerrieri, Matthias Hub, Meinert Jordan, #
|
||||
# Armin Köhler, Joshua Miller, Stevan Pettit, Andreas Preikschat, Mattias #
|
||||
# Põldaru, Christian Richter, Philip Ridout, Simon Scudder, Jeffrey Smith, #
|
||||
# Maikel Stuivenberg, Martin Thompson, Jon Tibble, 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 #
|
||||
###############################################################################
|
||||
|
||||
from PyQt4 import QtCore, QtGui
|
||||
|
||||
from openlp.core.lib import build_icon, translate
|
||||
from openlp.core.lib.ui import create_button_box
|
||||
from openlp.plugins.bibles.lib import LanguageSelection, BibleStrings
|
||||
from openlp.plugins.bibles.lib.db import BiblesResourcesDB
|
||||
|
||||
|
||||
class Ui_EditBibleDialog(object):
|
||||
def setupUi(self, editBibleDialog):
|
||||
editBibleDialog.setObjectName(u'editBibleDialog')
|
||||
editBibleDialog.resize(520, 400)
|
||||
editBibleDialog.setWindowIcon(
|
||||
build_icon(u':/icon/openlp-logo-16x16.png'))
|
||||
editBibleDialog.setModal(True)
|
||||
self.dialogLayout = QtGui.QVBoxLayout(editBibleDialog)
|
||||
self.dialogLayout.setSpacing(8)
|
||||
self.dialogLayout.setContentsMargins(8, 8, 8, 8)
|
||||
self.dialogLayout.setObjectName(u'dialogLayout')
|
||||
self.bibleTabWidget = QtGui.QTabWidget(editBibleDialog)
|
||||
self.bibleTabWidget.setObjectName(u'BibleTabWidget')
|
||||
# Meta tab
|
||||
self.metaTab = QtGui.QWidget()
|
||||
self.metaTab.setObjectName(u'metaTab')
|
||||
self.metaTabLayout = QtGui.QVBoxLayout(self.metaTab)
|
||||
self.metaTabLayout.setObjectName(u'metaTabLayout')
|
||||
self.licenseDetailsGroupBox = QtGui.QGroupBox(self.metaTab)
|
||||
self.licenseDetailsGroupBox.setObjectName(u'licenseDetailsGroupBox')
|
||||
self.licenseDetailsLayout = QtGui.QFormLayout(
|
||||
self.licenseDetailsGroupBox)
|
||||
self.licenseDetailsLayout.setObjectName(u'licenseDetailsLayout')
|
||||
self.versionNameLabel = QtGui.QLabel(self.licenseDetailsGroupBox)
|
||||
self.versionNameLabel.setObjectName(u'versionNameLabel')
|
||||
self.versionNameEdit = QtGui.QLineEdit(self.licenseDetailsGroupBox)
|
||||
self.versionNameEdit.setObjectName(u'versionNameEdit')
|
||||
self.versionNameLabel.setBuddy(self.versionNameEdit)
|
||||
self.licenseDetailsLayout.addRow(self.versionNameLabel,
|
||||
self.versionNameEdit)
|
||||
self.copyrightLabel = QtGui.QLabel(self.licenseDetailsGroupBox)
|
||||
self.copyrightLabel.setObjectName(u'copyrightLabel')
|
||||
self.copyrightEdit = QtGui.QLineEdit(self.licenseDetailsGroupBox)
|
||||
self.copyrightEdit.setObjectName(u'copyrightEdit')
|
||||
self.copyrightLabel.setBuddy(self.copyrightEdit)
|
||||
self.licenseDetailsLayout.addRow(self.copyrightLabel,
|
||||
self.copyrightEdit)
|
||||
self.permissionsLabel = QtGui.QLabel(self.licenseDetailsGroupBox)
|
||||
self.permissionsLabel.setObjectName(u'permissionsLabel')
|
||||
self.permissionsEdit = QtGui.QLineEdit(self.licenseDetailsGroupBox)
|
||||
self.permissionsEdit.setObjectName(u'permissionsEdit')
|
||||
self.permissionsLabel.setBuddy(self.permissionsEdit)
|
||||
self.licenseDetailsLayout.addRow(self.permissionsLabel,
|
||||
self.permissionsEdit)
|
||||
self.metaTabLayout.addWidget(self.licenseDetailsGroupBox)
|
||||
self.languageSelectionGroupBox = QtGui.QGroupBox(self.metaTab)
|
||||
self.languageSelectionGroupBox.setObjectName(
|
||||
u'languageSelectionGroupBox')
|
||||
self.languageSelectionLayout = QtGui.QVBoxLayout(
|
||||
self.languageSelectionGroupBox)
|
||||
self.languageSelectionLabel = QtGui.QLabel(
|
||||
self.languageSelectionGroupBox)
|
||||
self.languageSelectionLabel.setObjectName(u'languageSelectionLabel')
|
||||
self.languageSelectionComboBox = QtGui.QComboBox(
|
||||
self.languageSelectionGroupBox)
|
||||
self.languageSelectionComboBox.setObjectName(
|
||||
u'languageSelectionComboBox')
|
||||
self.languageSelectionComboBox.addItems([u'', u'', u'', u''])
|
||||
self.languageSelectionLayout.addWidget(self.languageSelectionLabel)
|
||||
self.languageSelectionLayout.addWidget(self.languageSelectionComboBox)
|
||||
self.metaTabLayout.addWidget(self.languageSelectionGroupBox)
|
||||
self.metaTabLayout.addStretch()
|
||||
self.bibleTabWidget.addTab(self.metaTab, u'')
|
||||
# Book name tab
|
||||
self.bookNameTab = QtGui.QWidget()
|
||||
self.bookNameTab.setObjectName(u'bookNameTab')
|
||||
self.bookNameTabLayout = QtGui.QVBoxLayout(self.bookNameTab)
|
||||
self.bookNameTabLayout.setObjectName(u'bookNameTabLayout')
|
||||
self.bookNameNotice = QtGui.QLabel(self.bookNameTab)
|
||||
self.bookNameNotice.setObjectName(u'bookNameNotice')
|
||||
self.bookNameNotice.setWordWrap(True)
|
||||
self.bookNameTabLayout.addWidget(self.bookNameNotice)
|
||||
self.scrollArea = QtGui.QScrollArea(self.bookNameTab)
|
||||
self.scrollArea.setWidgetResizable(True)
|
||||
self.scrollArea.setObjectName(u'scrollArea')
|
||||
self.scrollArea.setHorizontalScrollBarPolicy(
|
||||
QtCore.Qt.ScrollBarAlwaysOff)
|
||||
self.bookNameWidget = QtGui.QWidget(self.scrollArea)
|
||||
self.bookNameWidget.setObjectName(u'bookNameWidget')
|
||||
self.bookNameWidgetLayout = QtGui.QFormLayout(self.bookNameWidget)
|
||||
self.bookNameWidgetLayout.setObjectName(u'bookNameWidgetLayout')
|
||||
self.bookNameLabel = {}
|
||||
self.bookNameEdit= {}
|
||||
for book in BiblesResourcesDB.get_books():
|
||||
self.bookNameLabel[book[u'abbreviation']] = QtGui.QLabel(
|
||||
self.bookNameWidget)
|
||||
self.bookNameLabel[book[u'abbreviation']].setObjectName(
|
||||
u'bookNameLabel[%s]' % book[u'abbreviation'])
|
||||
self.bookNameEdit[book[u'abbreviation']] = QtGui.QLineEdit(
|
||||
self.bookNameWidget)
|
||||
self.bookNameEdit[book[u'abbreviation']].setObjectName(
|
||||
u'bookNameEdit[%s]' % book[u'abbreviation'])
|
||||
self.bookNameWidgetLayout.addRow(
|
||||
self.bookNameLabel[book[u'abbreviation']],
|
||||
self.bookNameEdit[book[u'abbreviation']])
|
||||
self.scrollArea.setWidget(self.bookNameWidget)
|
||||
self.bookNameTabLayout.addWidget(self.scrollArea)
|
||||
self.bookNameTabLayout.addStretch()
|
||||
self.bibleTabWidget.addTab(self.bookNameTab, u'')
|
||||
# Last few bits
|
||||
self.dialogLayout.addWidget(self.bibleTabWidget)
|
||||
self.buttonBox = create_button_box(editBibleDialog, u'buttonBox',
|
||||
[u'cancel', u'save'])
|
||||
self.dialogLayout.addWidget(self.buttonBox)
|
||||
self.retranslateUi(editBibleDialog)
|
||||
QtCore.QMetaObject.connectSlotsByName(editBibleDialog)
|
||||
|
||||
def retranslateUi(self, editBibleDialog):
|
||||
self.booknames = BibleStrings().Booknames
|
||||
editBibleDialog.setWindowTitle(
|
||||
translate('BiblesPlugin.EditBibleForm', 'Bible Editor'))
|
||||
# Meta tab
|
||||
self.bibleTabWidget.setTabText(
|
||||
self.bibleTabWidget.indexOf(self.metaTab),
|
||||
translate('SongsPlugin.EditBibleForm', 'Meta Data'))
|
||||
self.licenseDetailsGroupBox.setTitle(
|
||||
translate('BiblesPlugin.EditBibleForm', 'License Details'))
|
||||
self.versionNameLabel.setText(
|
||||
translate('BiblesPlugin.EditBibleForm', 'Version name:'))
|
||||
self.copyrightLabel.setText(
|
||||
translate('BiblesPlugin.EditBibleForm', 'Copyright:'))
|
||||
self.permissionsLabel.setText(
|
||||
translate('BiblesPlugin.EditBibleForm', 'Permissions:'))
|
||||
self.languageSelectionGroupBox.setTitle(translate(
|
||||
'BiblesPlugin.EditBibleForm', 'Default Bible Language'))
|
||||
self.languageSelectionLabel.setText(
|
||||
translate('BiblesPlugin.EditBibleForm',
|
||||
'Book name language in search field, search results and on '
|
||||
'display:'))
|
||||
self.languageSelectionComboBox.setItemText(0,
|
||||
translate('BiblesPlugin.EditBibleForm', 'Global Settings'))
|
||||
self.languageSelectionComboBox.setItemText(LanguageSelection.Bible + 1,
|
||||
translate('BiblesPlugin.EditBibleForm', 'Bible Language'))
|
||||
self.languageSelectionComboBox.setItemText(
|
||||
LanguageSelection.Application + 1,
|
||||
translate('BiblesPlugin.EditBibleForm', 'Application Language'))
|
||||
self.languageSelectionComboBox.setItemText(
|
||||
LanguageSelection.English + 1,
|
||||
translate('BiblesPlugin.EditBibleForm', 'English'))
|
||||
# Book name tab
|
||||
self.bibleTabWidget.setTabText(
|
||||
self.bibleTabWidget.indexOf(self.bookNameTab),
|
||||
translate('SongsPlugin.EditBibleForm', 'Custom Book Names'))
|
||||
for book in BiblesResourcesDB.get_books():
|
||||
self.bookNameLabel[book[u'abbreviation']].setText(
|
||||
u'%s:' % unicode(self.booknames[book[u'abbreviation']]))
|
211
openlp/plugins/bibles/forms/editbibleform.py
Normal file
211
openlp/plugins/bibles/forms/editbibleform.py
Normal file
@ -0,0 +1,211 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# vim: autoindent shiftwidth=4 expandtab textwidth=80 tabstop=4 softtabstop=4
|
||||
|
||||
###############################################################################
|
||||
# OpenLP - Open Source Lyrics Projection #
|
||||
# --------------------------------------------------------------------------- #
|
||||
# Copyright (c) 2008-2012 Raoul Snyman #
|
||||
# Portions copyright (c) 2008-2012 Tim Bentley, Gerald Britton, Jonathan #
|
||||
# Corwin, Michael Gorven, Scott Guerrieri, Matthias Hub, Meinert Jordan, #
|
||||
# Armin Köhler, Joshua Miller, Stevan Pettit, Andreas Preikschat, Mattias #
|
||||
# Põldaru, Christian Richter, Philip Ridout, Simon Scudder, Jeffrey Smith, #
|
||||
# Maikel Stuivenberg, Martin Thompson, Jon Tibble, 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 re
|
||||
|
||||
from PyQt4 import QtGui
|
||||
|
||||
from openlp.core.lib import Receiver, translate
|
||||
from openlp.core.lib.ui import UiStrings, critical_error_message_box
|
||||
from editbibledialog import Ui_EditBibleDialog
|
||||
from openlp.plugins.bibles.lib import BibleStrings
|
||||
from openlp.plugins.bibles.lib.db import BiblesResourcesDB
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
class EditBibleForm(QtGui.QDialog, Ui_EditBibleDialog):
|
||||
"""
|
||||
Class to manage the editing of a bible
|
||||
"""
|
||||
log.info(u'%s EditBibleForm loaded', __name__)
|
||||
|
||||
def __init__(self, mediaitem, parent, manager):
|
||||
"""
|
||||
Constructor
|
||||
"""
|
||||
QtGui.QDialog.__init__(self, parent)
|
||||
self.mediaitem = mediaitem
|
||||
self.booknames = BibleStrings().Booknames
|
||||
self.setupUi(self)
|
||||
self.manager = manager
|
||||
|
||||
def loadBible(self, bible):
|
||||
"""
|
||||
Loads a bible.
|
||||
|
||||
``bible``
|
||||
The name of the bible.
|
||||
"""
|
||||
log.debug(u'Load Bible')
|
||||
self.bible = bible
|
||||
self.versionNameEdit.setText(
|
||||
self.manager.get_meta_data(self.bible, u'Version').value)
|
||||
self.copyrightEdit.setText(
|
||||
self.manager.get_meta_data(self.bible, u'Copyright').value)
|
||||
self.permissionsEdit.setText(
|
||||
self.manager.get_meta_data(self.bible, u'Permissions').value)
|
||||
bookname_language = self.manager.get_meta_data(self.bible,
|
||||
u'Bookname language')
|
||||
if bookname_language and bookname_language.value != u'None':
|
||||
self.languageSelectionComboBox.setCurrentIndex(
|
||||
int(bookname_language.value) + 1)
|
||||
self.books = {}
|
||||
self.webbible = self.manager.get_meta_data(self.bible,
|
||||
u'download source')
|
||||
if self.webbible:
|
||||
self.bookNameNotice.setText(translate('BiblesPlugin.EditBibleForm',
|
||||
'This is a Web Download Bible.\nIt is not possible to '
|
||||
'customize the Book Names.'))
|
||||
self.scrollArea.hide()
|
||||
else:
|
||||
self.bookNameNotice.setText(translate('BiblesPlugin.EditBibleForm',
|
||||
'To use the customized book names, "Bible language" must be '
|
||||
'selected on the Meta Data tab or, if "Global settings" is '
|
||||
'selected, on the Bible page in Configure OpenLP.'))
|
||||
for book in BiblesResourcesDB.get_books():
|
||||
self.books[book[u'abbreviation']] = self.manager.get_book_by_id(
|
||||
self.bible, book[u'id'])
|
||||
if self.books[book[u'abbreviation']] and not self.webbible:
|
||||
self.bookNameEdit[book[u'abbreviation']].setText(
|
||||
self.books[book[u'abbreviation']].name)
|
||||
else:
|
||||
# It is nessecary to remove the Widget otherwise there still
|
||||
# exists the vertical spacing in QFormLayout
|
||||
self.bookNameWidgetLayout.removeWidget(
|
||||
self.bookNameLabel[book[u'abbreviation']])
|
||||
self.bookNameLabel[book[u'abbreviation']].hide()
|
||||
self.bookNameWidgetLayout.removeWidget(
|
||||
self.bookNameEdit[book[u'abbreviation']])
|
||||
self.bookNameEdit[book[u'abbreviation']].hide()
|
||||
|
||||
def reject(self):
|
||||
"""
|
||||
Exit Dialog and do not save
|
||||
"""
|
||||
log.debug(u'BibleEditForm.reject')
|
||||
self.bible = None
|
||||
QtGui.QDialog.reject(self)
|
||||
|
||||
def accept(self):
|
||||
"""
|
||||
Exit Dialog and save data
|
||||
"""
|
||||
log.debug(u'BibleEditForm.accept')
|
||||
version = unicode(self.versionNameEdit.text())
|
||||
copyright = unicode(self.copyrightEdit.text())
|
||||
permissions = unicode(self.permissionsEdit.text())
|
||||
bookname_language = self.languageSelectionComboBox.currentIndex() - 1
|
||||
if bookname_language == -1:
|
||||
bookname_language = None
|
||||
if not self.validateMeta(version, copyright):
|
||||
return
|
||||
if not self.webbible:
|
||||
custom_names = {}
|
||||
for abbr, book in self.books.iteritems():
|
||||
if book:
|
||||
custom_names[abbr] = unicode(self.bookNameEdit[abbr].text())
|
||||
if book.name != custom_names[abbr]:
|
||||
if not self.validateBook(custom_names[abbr], abbr):
|
||||
return
|
||||
Receiver.send_message(u'openlp_process_events')
|
||||
Receiver.send_message(u'cursor_busy')
|
||||
self.manager.save_meta_data(self.bible, version, copyright, permissions,
|
||||
bookname_language)
|
||||
if not self.webbible:
|
||||
for abbr, book in self.books.iteritems():
|
||||
if book:
|
||||
if book.name != custom_names[abbr]:
|
||||
book.name = custom_names[abbr]
|
||||
self.manager.update_book(self.bible, book)
|
||||
self.bible = None
|
||||
Receiver.send_message(u'cursor_normal')
|
||||
QtGui.QDialog.accept(self)
|
||||
|
||||
def validateMeta(self, version, copyright):
|
||||
"""
|
||||
Validate the Meta before saving.
|
||||
"""
|
||||
if not version:
|
||||
self.versionNameEdit.setFocus()
|
||||
critical_error_message_box(UiStrings().EmptyField,
|
||||
translate('BiblesPlugin.BibleEditForm',
|
||||
'You need to specify a version name for your Bible.'))
|
||||
return False
|
||||
elif not copyright:
|
||||
self.copyrightEdit.setFocus()
|
||||
critical_error_message_box(UiStrings().EmptyField,
|
||||
translate('BiblesPlugin.BibleEditForm',
|
||||
'You need to set a copyright for your Bible. '
|
||||
'Bibles in the Public Domain need to be marked as such.'))
|
||||
return False
|
||||
elif self.manager.exists(version) and \
|
||||
self.manager.get_meta_data(self.bible, u'Version').value != \
|
||||
version:
|
||||
self.versionNameEdit.setFocus()
|
||||
critical_error_message_box(
|
||||
translate('BiblesPlugin.BibleEditForm', 'Bible Exists'),
|
||||
translate('BiblesPlugin.BibleEditForm',
|
||||
'This Bible already exists. Please import '
|
||||
'a different Bible or first delete the existing one.'))
|
||||
return False
|
||||
return True
|
||||
|
||||
def validateBook(self, new_bookname, abbreviation):
|
||||
"""
|
||||
Validate a book.
|
||||
"""
|
||||
book_regex = re.compile(u'[\d]*[^\d]+$')
|
||||
if not new_bookname:
|
||||
self.bookNameEdit[abbreviation].setFocus()
|
||||
critical_error_message_box(UiStrings().EmptyField,
|
||||
unicode(translate('BiblesPlugin.BibleEditForm',
|
||||
'You need to specify a book name for "%s".')) %
|
||||
self.booknames[abbreviation])
|
||||
return False
|
||||
elif not book_regex.match(new_bookname):
|
||||
self.bookNameEdit[abbreviation].setFocus()
|
||||
critical_error_message_box(UiStrings().EmptyField,
|
||||
unicode(translate('BiblesPlugin.BibleEditForm',
|
||||
'The book name "%s" is not correct.\nNumbers can only be used '
|
||||
'at the beginning and must\nbe followed by one or more '
|
||||
'non-numeric characters.')) % new_bookname)
|
||||
return False
|
||||
for abbr, book in self.books.iteritems():
|
||||
if book:
|
||||
if abbr == abbreviation:
|
||||
continue
|
||||
if unicode(self.bookNameEdit[abbr].text()) == new_bookname:
|
||||
self.bookNameEdit[abbreviation].setFocus()
|
||||
critical_error_message_box(
|
||||
translate('BiblesPlugin.BibleEditForm',
|
||||
'Duplicate Book Name'),
|
||||
unicode(translate('BiblesPlugin.BibleEditForm',
|
||||
'The Book Name "%s" has been entered more than once.'))
|
||||
% new_bookname)
|
||||
return False
|
||||
return True
|
@ -276,15 +276,16 @@ class BiblesTab(SettingsTab):
|
||||
'end marks may be defined.\nThey have to be separated by a '
|
||||
'vertical bar "|".\nPlease clear this edit line to use the '
|
||||
'default value.'))
|
||||
self.languageSelectionGroupBox.setTitle(translate('BiblesPlugin.BiblesTab',
|
||||
'Default Search Field Language'))
|
||||
self.languageSelectionGroupBox.setTitle(translate(
|
||||
'BiblesPlugin.BiblesTab', 'Default Bible Language'))
|
||||
self.languageSelectionLabel.setText(translate('BiblesPlugin.BiblesTab',
|
||||
'Book name language in search field:'))
|
||||
'Book name language in search field,\nsearch results and on '
|
||||
'display:'))
|
||||
self.languageSelectionComboBox.setItemText(LanguageSelection.Bible,
|
||||
translate('BiblesPlugin.BiblesTab', 'Bible language'))
|
||||
translate('BiblesPlugin.BiblesTab', 'Bible Language'))
|
||||
self.languageSelectionComboBox.setItemText(
|
||||
LanguageSelection.Application,
|
||||
translate('BiblesPlugin.BiblesTab', 'Application language'))
|
||||
translate('BiblesPlugin.BiblesTab', 'Application Language'))
|
||||
self.languageSelectionComboBox.setItemText(LanguageSelection.English,
|
||||
translate('BiblesPlugin.BiblesTab', 'English'))
|
||||
|
||||
|
@ -182,7 +182,7 @@ class BibleDB(QtCore.QObject, Manager):
|
||||
The actual Qt wizard form.
|
||||
"""
|
||||
self.wizard = wizard
|
||||
self.create_meta(u'dbversion', u'2')
|
||||
self.save_meta(u'dbversion', u'2')
|
||||
return self.name
|
||||
|
||||
def create_book(self, name, bk_ref_id, testament=1):
|
||||
@ -205,6 +205,16 @@ class BibleDB(QtCore.QObject, Manager):
|
||||
self.save_object(book)
|
||||
return book
|
||||
|
||||
def update_book(self, book):
|
||||
"""
|
||||
Update a book in the database.
|
||||
|
||||
``book``
|
||||
The book object
|
||||
"""
|
||||
log.debug(u'BibleDB.update_book("%s")', book.name)
|
||||
return self.save_object(book)
|
||||
|
||||
def delete_book(self, db_book):
|
||||
"""
|
||||
Delete a book from the database.
|
||||
@ -271,9 +281,9 @@ class BibleDB(QtCore.QObject, Manager):
|
||||
self.session.add(verse)
|
||||
return verse
|
||||
|
||||
def create_meta(self, key, value):
|
||||
def save_meta(self, key, value):
|
||||
"""
|
||||
Utility method to save BibleMeta objects in a Bible database.
|
||||
Utility method to save or update BibleMeta objects in a Bible database.
|
||||
|
||||
``key``
|
||||
The key for this instance.
|
||||
@ -284,7 +294,12 @@ class BibleDB(QtCore.QObject, Manager):
|
||||
if not isinstance(value, unicode):
|
||||
value = unicode(value)
|
||||
log.debug(u'BibleDB.save_meta("%s/%s")', key, value)
|
||||
self.save_object(BibleMeta.populate(key=key, value=value))
|
||||
meta = self.get_object(BibleMeta, key)
|
||||
if meta:
|
||||
meta.value = value
|
||||
self.save_object(meta)
|
||||
else:
|
||||
self.save_object(BibleMeta.populate(key=key, value=value))
|
||||
|
||||
def get_book(self, book):
|
||||
"""
|
||||
@ -471,7 +486,7 @@ class BibleDB(QtCore.QObject, Manager):
|
||||
return False
|
||||
language = BiblesResourcesDB.get_language(language)
|
||||
language_id = language[u'id']
|
||||
self.create_meta(u'language_id', language_id)
|
||||
self.save_meta(u'language_id', language_id)
|
||||
return language_id
|
||||
|
||||
def is_old_database(self):
|
||||
|
@ -401,16 +401,16 @@ class HTTPBible(BibleDB):
|
||||
self.wizard.incrementProgressBar(unicode(translate(
|
||||
'BiblesPlugin.HTTPBible',
|
||||
'Registering Bible and loading books...')))
|
||||
self.create_meta(u'download source', self.download_source)
|
||||
self.create_meta(u'download name', self.download_name)
|
||||
self.save_meta(u'download source', self.download_source)
|
||||
self.save_meta(u'download name', self.download_name)
|
||||
if self.proxy_server:
|
||||
self.create_meta(u'proxy server', self.proxy_server)
|
||||
self.save_meta(u'proxy server', self.proxy_server)
|
||||
if self.proxy_username:
|
||||
# Store the proxy userid.
|
||||
self.create_meta(u'proxy username', self.proxy_username)
|
||||
self.save_meta(u'proxy username', self.proxy_username)
|
||||
if self.proxy_password:
|
||||
# Store the proxy password.
|
||||
self.create_meta(u'proxy password', self.proxy_password)
|
||||
self.save_meta(u'proxy password', self.proxy_password)
|
||||
if self.download_source.lower() == u'crosswalk':
|
||||
handler = CWExtract(self.proxy_server)
|
||||
elif self.download_source.lower() == u'biblegateway':
|
||||
@ -429,7 +429,7 @@ class HTTPBible(BibleDB):
|
||||
self.download_source.lower())
|
||||
if bible[u'language_id']:
|
||||
language_id = bible[u'language_id']
|
||||
self.create_meta(u'language_id', language_id)
|
||||
self.save_meta(u'language_id', language_id)
|
||||
else:
|
||||
language_id = self.get_language(bible_name)
|
||||
if not language_id:
|
||||
|
@ -31,7 +31,6 @@ import os
|
||||
from PyQt4 import QtCore
|
||||
|
||||
from openlp.core.lib import Receiver, SettingsManager, translate
|
||||
from openlp.core.lib.ui import critical_error_message_box
|
||||
from openlp.core.utils import AppLocation, delete_file
|
||||
from openlp.plugins.bibles.lib import parse_reference, \
|
||||
get_reference_separator, LanguageSelection
|
||||
@ -141,7 +140,8 @@ class BibleManager(object):
|
||||
BibleDB class.
|
||||
"""
|
||||
log.debug(u'Reload bibles')
|
||||
files = SettingsManager.get_files(self.settingsSection, self.suffix)
|
||||
files = SettingsManager.get_files(self.settingsSection,
|
||||
self.suffix)
|
||||
if u'alternative_book_names.sqlite' in files:
|
||||
files.remove(u'alternative_book_names.sqlite')
|
||||
log.debug(u'Bible Files %s', files)
|
||||
@ -204,6 +204,27 @@ class BibleManager(object):
|
||||
self.db_cache[name] = importer
|
||||
return importer
|
||||
|
||||
def delete_bible(self, name):
|
||||
"""
|
||||
Delete a bible completly.
|
||||
|
||||
``name``
|
||||
The name of the bible.
|
||||
"""
|
||||
log.debug(u'BibleManager.delete_bible("%s")', name)
|
||||
files = SettingsManager.get_files(self.settingsSection,
|
||||
self.suffix)
|
||||
if u'alternative_book_names.sqlite' in files:
|
||||
files.remove(u'alternative_book_names.sqlite')
|
||||
for filename in files:
|
||||
bible = BibleDB(self.parent, path=self.path, file=filename)
|
||||
# Remove the bible files
|
||||
if name == bible.get_name():
|
||||
bible.session.close()
|
||||
if delete_file(os.path.join(self.path, filename)):
|
||||
return True
|
||||
return False
|
||||
|
||||
def get_bibles(self):
|
||||
"""
|
||||
Returns a dict with all available Bibles.
|
||||
@ -309,9 +330,13 @@ class BibleManager(object):
|
||||
'Import Wizard to install one or more Bibles.')
|
||||
})
|
||||
return None
|
||||
language_selection = QtCore.QSettings().value(
|
||||
self.settingsSection + u'/bookname language',
|
||||
QtCore.QVariant(0)).toInt()[0]
|
||||
language_selection = self.get_meta_data(bible, u'Bookname language')
|
||||
if language_selection:
|
||||
language_selection = int(language_selection.value)
|
||||
if language_selection is None or language_selection == -1:
|
||||
language_selection = QtCore.QSettings().value(
|
||||
self.settingsSection + u'/bookname language',
|
||||
QtCore.QVariant(0)).toInt()[0]
|
||||
reflist = parse_reference(versetext, self.db_cache[bible],
|
||||
language_selection, book_ref_id)
|
||||
if reflist:
|
||||
@ -344,6 +369,22 @@ class BibleManager(object):
|
||||
})
|
||||
return None
|
||||
|
||||
def get_language_selection(self, bible):
|
||||
"""
|
||||
Returns the language selection of a bible.
|
||||
|
||||
``bible``
|
||||
Unicode. The Bible to get the language selection from.
|
||||
"""
|
||||
log.debug(u'BibleManager.get_language_selection("%s")', bible)
|
||||
language_selection = self.get_meta_data(bible, u'Bookname language')
|
||||
if language_selection and language_selection.value != u'None':
|
||||
return int(language_selection.value)
|
||||
if language_selection is None or language_selection.value == u'None':
|
||||
return QtCore.QSettings().value(
|
||||
self.settingsSection + u'/bookname language',
|
||||
QtCore.QVariant(0)).toInt()[0]
|
||||
|
||||
def verse_search(self, bible, second_bible, text):
|
||||
"""
|
||||
Does a verse search for the given bible and text.
|
||||
@ -396,15 +437,18 @@ class BibleManager(object):
|
||||
})
|
||||
return None
|
||||
|
||||
def save_meta_data(self, bible, version, copyright, permissions):
|
||||
def save_meta_data(self, bible, version, copyright, permissions,
|
||||
bookname_language=None):
|
||||
"""
|
||||
Saves the bibles meta data.
|
||||
"""
|
||||
log.debug(u'save_meta data %s,%s, %s,%s',
|
||||
log.debug(u'save_meta data %s, %s, %s, %s',
|
||||
bible, version, copyright, permissions)
|
||||
self.db_cache[bible].create_meta(u'Version', version)
|
||||
self.db_cache[bible].create_meta(u'Copyright', copyright)
|
||||
self.db_cache[bible].create_meta(u'Permissions', permissions)
|
||||
self.db_cache[bible].save_meta(u'Version', version)
|
||||
self.db_cache[bible].save_meta(u'Copyright', copyright)
|
||||
self.db_cache[bible].save_meta(u'Permissions', permissions)
|
||||
self.db_cache[bible].save_meta(u'Bookname language',
|
||||
bookname_language)
|
||||
|
||||
def get_meta_data(self, bible, key):
|
||||
"""
|
||||
@ -412,6 +456,13 @@ class BibleManager(object):
|
||||
"""
|
||||
log.debug(u'get_meta %s,%s', bible, key)
|
||||
return self.db_cache[bible].get_object(BibleMeta, key)
|
||||
|
||||
def update_book(self, bible, book):
|
||||
"""
|
||||
Update a book of the bible.
|
||||
"""
|
||||
log.debug(u'BibleManager.update_book("%s", "%s")', bible, book.name)
|
||||
self.db_cache[bible].update_book(book)
|
||||
|
||||
def exists(self, name):
|
||||
"""
|
||||
|
@ -36,9 +36,10 @@ from openlp.core.lib.searchedit import SearchEdit
|
||||
from openlp.core.lib.ui import UiStrings, set_case_insensitive_completer, \
|
||||
create_horizontal_adjusting_combo_box, critical_error_message_box, \
|
||||
find_and_set_in_combo_box, build_icon
|
||||
from openlp.plugins.bibles.forms import BibleImportForm
|
||||
from openlp.plugins.bibles.forms import BibleImportForm, EditBibleForm
|
||||
from openlp.plugins.bibles.lib import LayoutStyle, DisplayStyle, \
|
||||
VerseReferenceList, get_reference_separator, LanguageSelection, BibleStrings
|
||||
VerseReferenceList, get_reference_separator, LanguageSelection, \
|
||||
BibleStrings
|
||||
from openlp.plugins.bibles.lib.db import BiblesResourcesDB
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
@ -109,8 +110,8 @@ class BibleMediaItem(MediaManagerItem):
|
||||
MediaManagerItem.requiredIcons(self)
|
||||
self.hasImportIcon = True
|
||||
self.hasNewIcon = False
|
||||
self.hasEditIcon = False
|
||||
self.hasDeleteIcon = False
|
||||
self.hasEditIcon = True
|
||||
self.hasDeleteIcon = True
|
||||
self.addToServiceItem = False
|
||||
|
||||
def addSearchTab(self, prefix, name):
|
||||
@ -352,10 +353,6 @@ class BibleMediaItem(MediaManagerItem):
|
||||
log.debug(u'bible manager initialise')
|
||||
self.plugin.manager.media = self
|
||||
self.loadBibles()
|
||||
bible = QtCore.QSettings().value(
|
||||
self.settingsSection + u'/quick bible', QtCore.QVariant(
|
||||
self.quickVersionComboBox.currentText())).toString()
|
||||
find_and_set_in_combo_box(self.quickVersionComboBox, bible)
|
||||
self.quickSearchEdit.setSearchTypes([
|
||||
(BibleSearch.Reference, u':/bibles/bibles_search_reference.png',
|
||||
translate('BiblesPlugin.MediaItem', 'Scripture Reference'),
|
||||
@ -397,6 +394,10 @@ class BibleMediaItem(MediaManagerItem):
|
||||
self.initialiseAdvancedBible(unicode(bible))
|
||||
elif len(bibles):
|
||||
self.initialiseAdvancedBible(bibles[0])
|
||||
bible = QtCore.QSettings().value(
|
||||
self.settingsSection + u'/quick bible', QtCore.QVariant(
|
||||
self.quickVersionComboBox.currentText())).toString()
|
||||
find_and_set_in_combo_box(self.quickVersionComboBox, bible)
|
||||
|
||||
def reloadBibles(self, process=False):
|
||||
log.debug(u'Reloading Bibles')
|
||||
@ -431,9 +432,7 @@ class BibleMediaItem(MediaManagerItem):
|
||||
book_data = book_data_temp
|
||||
self.advancedBookComboBox.clear()
|
||||
first = True
|
||||
language_selection = QtCore.QSettings().value(
|
||||
self.settingsSection + u'/bookname language',
|
||||
QtCore.QVariant(0)).toInt()[0]
|
||||
language_selection = self.plugin.manager.get_language_selection(bible)
|
||||
booknames = BibleStrings().Booknames
|
||||
for book in book_data:
|
||||
row = self.advancedBookComboBox.count()
|
||||
@ -505,9 +504,8 @@ class BibleMediaItem(MediaManagerItem):
|
||||
secondbook.book_reference_id:
|
||||
book_data_temp.append(book)
|
||||
book_data = book_data_temp
|
||||
language_selection = QtCore.QSettings().value(
|
||||
self.settingsSection + u'/bookname language',
|
||||
QtCore.QVariant(0)).toInt()[0]
|
||||
language_selection = self.plugin.manager.get_language_selection(
|
||||
bible)
|
||||
if language_selection == LanguageSelection.Bible:
|
||||
books = [book.name + u' ' for book in book_data]
|
||||
elif language_selection == LanguageSelection.Application:
|
||||
@ -533,6 +531,34 @@ class BibleMediaItem(MediaManagerItem):
|
||||
if self.import_wizard.exec_():
|
||||
self.reloadBibles()
|
||||
|
||||
def onEditClick(self):
|
||||
if self.quickTab.isVisible():
|
||||
bible = unicode(self.quickVersionComboBox.currentText())
|
||||
elif self.advancedTab.isVisible():
|
||||
bible = unicode(self.advancedVersionComboBox.currentText())
|
||||
if bible:
|
||||
self.editBibleForm = EditBibleForm(self, self.plugin.formparent,
|
||||
self.plugin.manager)
|
||||
self.editBibleForm.loadBible(bible)
|
||||
if self.editBibleForm.exec_():
|
||||
self.reloadBibles()
|
||||
|
||||
def onDeleteClick(self):
|
||||
if self.quickTab.isVisible():
|
||||
bible = unicode(self.quickVersionComboBox.currentText())
|
||||
elif self.advancedTab.isVisible():
|
||||
bible = unicode(self.advancedVersionComboBox.currentText())
|
||||
if bible:
|
||||
if QtGui.QMessageBox.question(self, UiStrings().ConfirmDelete,
|
||||
unicode(translate('BiblesPlugin.MediaItem',
|
||||
'Are you sure you want to delete "%s"?')) % bible,
|
||||
QtGui.QMessageBox.StandardButtons(QtGui.QMessageBox.Yes |
|
||||
QtGui.QMessageBox.No),
|
||||
QtGui.QMessageBox.Yes) == QtGui.QMessageBox.No:
|
||||
return
|
||||
self.plugin.manager.delete_bible(bible)
|
||||
self.reloadBibles()
|
||||
|
||||
def onSearchTabBarCurrentChanged(self, index):
|
||||
if index == 0:
|
||||
self.advancedTab.setVisible(False)
|
||||
@ -795,9 +821,21 @@ class BibleMediaItem(MediaManagerItem):
|
||||
second_permissions = self.plugin.manager.get_meta_data(
|
||||
second_bible, u'Permissions').value
|
||||
items = []
|
||||
language_selection = self.plugin.manager.get_language_selection(bible)
|
||||
for count, verse in enumerate(search_results):
|
||||
if language_selection == LanguageSelection.Bible:
|
||||
book = verse.book.name
|
||||
elif language_selection == LanguageSelection.Application:
|
||||
booknames = BibleStrings().Booknames
|
||||
data = BiblesResourcesDB.get_book_by_id(
|
||||
verse.book.book_reference_id)
|
||||
book = unicode(booknames[data[u'abbreviation']])
|
||||
elif language_selection == LanguageSelection.English:
|
||||
data = BiblesResourcesDB.get_book_by_id(
|
||||
verse.book.book_reference_id)
|
||||
book = data[u'name']
|
||||
data = {
|
||||
'book': QtCore.QVariant(verse.book.name),
|
||||
'book': QtCore.QVariant(book),
|
||||
'chapter': QtCore.QVariant(verse.chapter),
|
||||
'verse': QtCore.QVariant(verse.verse),
|
||||
'bible': QtCore.QVariant(bible),
|
||||
@ -819,12 +857,11 @@ class BibleMediaItem(MediaManagerItem):
|
||||
log.exception(u'The second_search_results does not have as '
|
||||
'many verses as the search_results.')
|
||||
break
|
||||
bible_text = u'%s %d%s%d (%s, %s)' % (verse.book.name,
|
||||
verse.chapter, verse_separator, verse.verse, version,
|
||||
second_version)
|
||||
bible_text = u'%s %d%s%d (%s, %s)' % (book, verse.chapter,
|
||||
verse_separator, verse.verse, version, second_version)
|
||||
else:
|
||||
bible_text = u'%s %d%s%d (%s)' % (verse.book.name,
|
||||
verse.chapter, verse_separator, verse.verse, version)
|
||||
bible_text = u'%s %d%s%d (%s)' % (book, verse.chapter,
|
||||
verse_separator, verse.verse, version)
|
||||
bible_verse = QtGui.QListWidgetItem(bible_text)
|
||||
bible_verse.setData(QtCore.Qt.UserRole, QtCore.QVariant(data))
|
||||
items.append(bible_verse)
|
||||
|
@ -122,7 +122,7 @@ class OSISBible(BibleDB):
|
||||
language_match.group(1))
|
||||
if language:
|
||||
language_id = language[u'id']
|
||||
self.create_meta(u'language_id', language_id)
|
||||
self.save_meta(u'language_id', language_id)
|
||||
continue
|
||||
match = self.verse_regex.search(file_record)
|
||||
if match:
|
||||
|
Loading…
Reference in New Issue
Block a user