2012-03-12 05:48:14 +00:00
|
|
|
# -*- 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
|
2012-04-03 18:42:21 +00:00
|
|
|
import re
|
2012-03-12 05:48:14 +00:00
|
|
|
|
2012-04-03 18:42:21 +00:00
|
|
|
from PyQt4 import QtGui
|
2012-03-12 05:48:14 +00:00
|
|
|
|
2012-04-03 18:42:21 +00:00
|
|
|
from openlp.core.lib import Receiver, translate
|
2012-03-12 05:48:14 +00:00
|
|
|
from openlp.core.lib.ui import UiStrings, critical_error_message_box
|
|
|
|
from editbibledialog import Ui_EditBibleDialog
|
2012-03-21 20:57:07 +00:00
|
|
|
from openlp.plugins.bibles.lib import BibleStrings
|
2012-04-03 18:42:21 +00:00
|
|
|
from openlp.plugins.bibles.lib.db import BiblesResourcesDB
|
2012-03-12 05:48:14 +00:00
|
|
|
|
|
|
|
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
|
2012-04-21 22:29:08 +00:00
|
|
|
self.book_names = BibleStrings().BookNames
|
2012-03-12 05:48:14 +00:00
|
|
|
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(
|
2012-04-21 22:29:08 +00:00
|
|
|
self.manager.get_meta_data(self.bible, u'name').value)
|
2012-03-12 05:48:14 +00:00
|
|
|
self.copyrightEdit.setText(
|
2012-04-21 22:29:08 +00:00
|
|
|
self.manager.get_meta_data(self.bible, u'copyright').value)
|
2012-03-12 05:48:14 +00:00
|
|
|
self.permissionsEdit.setText(
|
2012-04-21 22:29:08 +00:00
|
|
|
self.manager.get_meta_data(self.bible, u'permissions').value)
|
|
|
|
book_name_language = self.manager.get_meta_data(self.bible,
|
|
|
|
u'book_name_language')
|
|
|
|
if book_name_language and book_name_language.value != u'None':
|
2012-03-12 05:48:14 +00:00
|
|
|
self.languageSelectionComboBox.setCurrentIndex(
|
2012-04-21 22:29:08 +00:00
|
|
|
int(book_name_language.value) + 1)
|
2012-03-12 05:48:14 +00:00
|
|
|
self.books = {}
|
2012-03-21 21:00:44 +00:00
|
|
|
self.webbible = self.manager.get_meta_data(self.bible,
|
|
|
|
u'download source')
|
2012-03-21 20:57:07 +00:00
|
|
|
if self.webbible:
|
|
|
|
self.bookNameNotice.setText(translate('BiblesPlugin.EditBibleForm',
|
2012-04-06 18:14:38 +00:00
|
|
|
'This is a Web Download Bible.\nIt is not possible to '
|
|
|
|
'customize the Book Names.'))
|
2012-04-05 18:31:15 +00:00
|
|
|
self.scrollArea.hide()
|
2012-03-21 20:57:07 +00:00
|
|
|
else:
|
|
|
|
self.bookNameNotice.setText(translate('BiblesPlugin.EditBibleForm',
|
2012-04-06 18:14:38 +00:00
|
|
|
'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.'))
|
2012-03-21 20:57:07 +00:00
|
|
|
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:
|
2012-04-11 17:39:15 +00:00
|
|
|
# It is nessecary to remove the Widget otherwise there still
|
|
|
|
# exists the vertical spacing in QFormLayout
|
2012-04-04 19:34:14 +00:00
|
|
|
self.bookNameWidgetLayout.removeWidget(
|
2012-03-21 20:57:07 +00:00
|
|
|
self.bookNameLabel[book[u'abbreviation']])
|
2012-04-11 17:39:15 +00:00
|
|
|
self.bookNameLabel[book[u'abbreviation']].hide()
|
2012-04-04 19:34:14 +00:00
|
|
|
self.bookNameWidgetLayout.removeWidget(
|
2012-03-21 20:57:07 +00:00
|
|
|
self.bookNameEdit[book[u'abbreviation']])
|
2012-04-11 17:39:15 +00:00
|
|
|
self.bookNameEdit[book[u'abbreviation']].hide()
|
2012-03-12 05:48:14 +00:00
|
|
|
|
|
|
|
def reject(self):
|
|
|
|
"""
|
|
|
|
Exit Dialog and do not save
|
|
|
|
"""
|
2012-04-12 20:58:11 +00:00
|
|
|
log.debug(u'BibleEditForm.reject')
|
2012-03-12 05:48:14 +00:00
|
|
|
self.bible = None
|
|
|
|
QtGui.QDialog.reject(self)
|
|
|
|
|
|
|
|
def accept(self):
|
|
|
|
"""
|
|
|
|
Exit Dialog and save data
|
|
|
|
"""
|
|
|
|
log.debug(u'BibleEditForm.accept')
|
2012-04-12 20:58:11 +00:00
|
|
|
version = unicode(self.versionNameEdit.text())
|
|
|
|
copyright = unicode(self.copyrightEdit.text())
|
|
|
|
permissions = unicode(self.permissionsEdit.text())
|
2012-04-21 22:29:08 +00:00
|
|
|
book_name_language = self.languageSelectionComboBox.currentIndex() - 1
|
|
|
|
if book_name_language == -1:
|
|
|
|
book_name_language = None
|
2012-04-12 20:58:11 +00:00
|
|
|
if not self.validateMeta(version, copyright):
|
2012-04-06 18:14:38 +00:00
|
|
|
return
|
|
|
|
if not self.webbible:
|
2012-03-21 20:57:07 +00:00
|
|
|
custom_names = {}
|
2012-03-12 05:48:14 +00:00
|
|
|
for abbr, book in self.books.iteritems():
|
|
|
|
if book:
|
2012-03-21 20:57:07 +00:00
|
|
|
custom_names[abbr] = unicode(self.bookNameEdit[abbr].text())
|
|
|
|
if book.name != custom_names[abbr]:
|
|
|
|
if not self.validateBook(custom_names[abbr], abbr):
|
2012-04-06 18:14:38 +00:00
|
|
|
return
|
|
|
|
Receiver.send_message(u'openlp_process_events')
|
|
|
|
Receiver.send_message(u'cursor_busy')
|
2012-04-12 20:58:11 +00:00
|
|
|
self.manager.save_meta_data(self.bible, version, copyright, permissions,
|
2012-04-21 22:29:08 +00:00
|
|
|
book_name_language)
|
2012-04-06 18:14:38 +00:00
|
|
|
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)
|
2012-03-12 05:48:14 +00:00
|
|
|
|
2012-04-21 22:29:08 +00:00
|
|
|
def validateMeta(self, name, copyright):
|
2012-03-12 05:48:14 +00:00
|
|
|
"""
|
2012-03-21 20:57:07 +00:00
|
|
|
Validate the Meta before saving.
|
2012-03-12 05:48:14 +00:00
|
|
|
"""
|
2012-04-21 22:29:08 +00:00
|
|
|
if not name:
|
2012-04-03 18:42:21 +00:00
|
|
|
self.versionNameEdit.setFocus()
|
2012-03-12 05:48:14 +00:00
|
|
|
critical_error_message_box(UiStrings().EmptyField,
|
|
|
|
translate('BiblesPlugin.BibleEditForm',
|
|
|
|
'You need to specify a version name for your Bible.'))
|
|
|
|
return False
|
2012-04-12 20:58:11 +00:00
|
|
|
elif not copyright:
|
2012-04-03 18:42:21 +00:00
|
|
|
self.copyrightEdit.setFocus()
|
2012-03-12 05:48:14 +00:00
|
|
|
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
|
2012-04-21 22:29:08 +00:00
|
|
|
elif self.manager.exists(name) and \
|
|
|
|
self.manager.get_meta_data(self.bible, u'name').value != \
|
|
|
|
name:
|
2012-04-03 18:42:21 +00:00
|
|
|
self.versionNameEdit.setFocus()
|
2012-03-12 05:48:14 +00:00
|
|
|
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
|
2012-03-21 20:57:07 +00:00
|
|
|
|
2012-04-21 22:29:08 +00:00
|
|
|
def validateBook(self, new_book_name, abbreviation):
|
2012-03-21 20:57:07 +00:00
|
|
|
"""
|
|
|
|
Validate a book.
|
|
|
|
"""
|
2012-04-03 18:42:21 +00:00
|
|
|
book_regex = re.compile(u'[\d]*[^\d]+$')
|
2012-04-21 22:29:08 +00:00
|
|
|
if not new_book_name:
|
2012-03-21 20:57:07 +00:00
|
|
|
self.bookNameEdit[abbreviation].setFocus()
|
|
|
|
critical_error_message_box(UiStrings().EmptyField,
|
|
|
|
unicode(translate('BiblesPlugin.BibleEditForm',
|
|
|
|
'You need to specify a book name for "%s".')) %
|
2012-04-21 22:29:08 +00:00
|
|
|
self.book_names[abbreviation])
|
2012-03-21 20:57:07 +00:00
|
|
|
return False
|
2012-04-21 22:29:08 +00:00
|
|
|
elif not book_regex.match(new_book_name):
|
2012-04-03 18:42:21 +00:00
|
|
|
self.bookNameEdit[abbreviation].setFocus()
|
|
|
|
critical_error_message_box(UiStrings().EmptyField,
|
|
|
|
unicode(translate('BiblesPlugin.BibleEditForm',
|
2012-04-06 18:14:38 +00:00
|
|
|
'The book name "%s" is not correct.\nNumbers can only be used '
|
|
|
|
'at the beginning and must\nbe followed by one or more '
|
2012-04-21 22:29:08 +00:00
|
|
|
'non-numeric characters.')) % new_book_name)
|
2012-04-03 18:42:21 +00:00
|
|
|
return False
|
2012-03-21 20:57:07 +00:00
|
|
|
for abbr, book in self.books.iteritems():
|
|
|
|
if book:
|
2012-04-03 18:42:21 +00:00
|
|
|
if abbr == abbreviation:
|
|
|
|
continue
|
2012-04-21 22:29:08 +00:00
|
|
|
if unicode(self.bookNameEdit[abbr].text()) == new_book_name:
|
2012-03-21 20:57:07 +00:00
|
|
|
self.bookNameEdit[abbreviation].setFocus()
|
|
|
|
critical_error_message_box(
|
|
|
|
translate('BiblesPlugin.BibleEditForm',
|
2012-04-06 18:14:38 +00:00
|
|
|
'Duplicate Book Name'),
|
2012-03-21 20:57:07 +00:00
|
|
|
unicode(translate('BiblesPlugin.BibleEditForm',
|
2012-04-06 18:14:38 +00:00
|
|
|
'The Book Name "%s" has been entered more than once.'))
|
2012-04-21 22:29:08 +00:00
|
|
|
% new_book_name)
|
2012-03-21 20:57:07 +00:00
|
|
|
return False
|
|
|
|
return True
|