forked from openlp/openlp
some fixes - improve error handling with duplicate book names
This commit is contained in:
parent
770fe855ee
commit
800510f2f8
@ -28,7 +28,7 @@
|
|||||||
from PyQt4 import QtCore, QtGui
|
from PyQt4 import QtCore, QtGui
|
||||||
|
|
||||||
from openlp.core.lib import build_icon, translate
|
from openlp.core.lib import build_icon, translate
|
||||||
from openlp.core.lib.ui import UiStrings, create_accept_reject_button_box
|
from openlp.core.lib.ui import create_accept_reject_button_box
|
||||||
from openlp.plugins.bibles.lib import LanguageSelection, BibleStrings
|
from openlp.plugins.bibles.lib import LanguageSelection, BibleStrings
|
||||||
from openlp.plugins.bibles.lib.db import BiblesResourcesDB
|
from openlp.plugins.bibles.lib.db import BiblesResourcesDB
|
||||||
|
|
||||||
@ -36,7 +36,7 @@ from openlp.plugins.bibles.lib.db import BiblesResourcesDB
|
|||||||
class Ui_EditBibleDialog(object):
|
class Ui_EditBibleDialog(object):
|
||||||
def setupUi(self, editBibleDialog):
|
def setupUi(self, editBibleDialog):
|
||||||
editBibleDialog.setObjectName(u'editBibleDialog')
|
editBibleDialog.setObjectName(u'editBibleDialog')
|
||||||
editBibleDialog.resize(650, 400)
|
editBibleDialog.resize(600, 400)
|
||||||
editBibleDialog.setWindowIcon(
|
editBibleDialog.setWindowIcon(
|
||||||
build_icon(u':/icon/openlp-logo-16x16.png'))
|
build_icon(u':/icon/openlp-logo-16x16.png'))
|
||||||
editBibleDialog.setModal(True)
|
editBibleDialog.setModal(True)
|
||||||
|
@ -26,16 +26,15 @@
|
|||||||
###############################################################################
|
###############################################################################
|
||||||
|
|
||||||
import logging
|
import logging
|
||||||
|
import re
|
||||||
|
|
||||||
from PyQt4 import QtCore, QtGui
|
from PyQt4 import QtGui
|
||||||
|
|
||||||
from openlp.core.lib import PluginStatus, Receiver, MediaType, translate, \
|
from openlp.core.lib import Receiver, translate
|
||||||
create_separated_list
|
|
||||||
from openlp.core.lib.ui import UiStrings, critical_error_message_box
|
from openlp.core.lib.ui import UiStrings, critical_error_message_box
|
||||||
from openlp.core.utils import AppLocation
|
|
||||||
from editbibledialog import Ui_EditBibleDialog
|
from editbibledialog import Ui_EditBibleDialog
|
||||||
from openlp.plugins.bibles.lib import BibleStrings
|
from openlp.plugins.bibles.lib import BibleStrings
|
||||||
from openlp.plugins.bibles.lib.db import BibleDB, BibleMeta, BiblesResourcesDB
|
from openlp.plugins.bibles.lib.db import BiblesResourcesDB
|
||||||
|
|
||||||
log = logging.getLogger(__name__)
|
log = logging.getLogger(__name__)
|
||||||
|
|
||||||
@ -89,9 +88,8 @@ class EditBibleForm(QtGui.QDialog, Ui_EditBibleDialog):
|
|||||||
self.scrollArea.setParent(None)
|
self.scrollArea.setParent(None)
|
||||||
else:
|
else:
|
||||||
self.bookNameNotice.setText(translate('BiblesPlugin.EditBibleForm',
|
self.bookNameNotice.setText(translate('BiblesPlugin.EditBibleForm',
|
||||||
'You could customize the Book Names of this Bible.\nTo use '
|
'To use the customized Book Names, choose the option "Bible '
|
||||||
'the Book Names below, you have to choose the option "Bible '
|
'language"\nin general settings or explicit for this Bible.'))
|
||||||
'language" in general settings or explicit for this Bible.'))
|
|
||||||
for book in BiblesResourcesDB.get_books():
|
for book in BiblesResourcesDB.get_books():
|
||||||
self.books[book[u'abbreviation']] = self.manager.get_book_by_id(
|
self.books[book[u'abbreviation']] = self.manager.get_book_by_id(
|
||||||
self.bible, book[u'id'])
|
self.bible, book[u'id'])
|
||||||
@ -125,12 +123,12 @@ class EditBibleForm(QtGui.QDialog, Ui_EditBibleDialog):
|
|||||||
self.permissions = unicode(self.permissionsEdit.text())
|
self.permissions = unicode(self.permissionsEdit.text())
|
||||||
self.bookname_language = \
|
self.bookname_language = \
|
||||||
self.languageSelectionComboBox.currentIndex()-1
|
self.languageSelectionComboBox.currentIndex()-1
|
||||||
|
for error in self.validate_error:
|
||||||
|
self.changeBackgroundColor(error, 'white')
|
||||||
if not self.validateMeta():
|
if not self.validateMeta():
|
||||||
save = False
|
save = False
|
||||||
if not self.webbible and save:
|
if not self.webbible and save:
|
||||||
custom_names = {}
|
custom_names = {}
|
||||||
for error in self.validate_error:
|
|
||||||
self.changeBackgroundColor(error, 'white')
|
|
||||||
for abbr, book in self.books.iteritems():
|
for abbr, book in self.books.iteritems():
|
||||||
if book:
|
if book:
|
||||||
custom_names[abbr] = unicode(self.bookNameEdit[abbr].text())
|
custom_names[abbr] = unicode(self.bookNameEdit[abbr].text())
|
||||||
@ -139,6 +137,8 @@ class EditBibleForm(QtGui.QDialog, Ui_EditBibleDialog):
|
|||||||
save = False
|
save = False
|
||||||
break
|
break
|
||||||
if save:
|
if save:
|
||||||
|
Receiver.send_message(u'openlp_process_events')
|
||||||
|
Receiver.send_message(u'cursor_busy')
|
||||||
self.manager.save_meta_data(self.bible, self.version,
|
self.manager.save_meta_data(self.bible, self.version,
|
||||||
self.copyright, self.permissions, self.bookname_language)
|
self.copyright, self.permissions, self.bookname_language)
|
||||||
if not self.webbible:
|
if not self.webbible:
|
||||||
@ -148,6 +148,7 @@ class EditBibleForm(QtGui.QDialog, Ui_EditBibleDialog):
|
|||||||
book.name = custom_names[abbr]
|
book.name = custom_names[abbr]
|
||||||
self.manager.update_book(self.bible, book)
|
self.manager.update_book(self.bible, book)
|
||||||
self.bible = None
|
self.bible = None
|
||||||
|
Receiver.send_message(u'cursor_normal')
|
||||||
QtGui.QDialog.accept(self)
|
QtGui.QDialog.accept(self)
|
||||||
|
|
||||||
def validateMeta(self):
|
def validateMeta(self):
|
||||||
@ -155,27 +156,33 @@ class EditBibleForm(QtGui.QDialog, Ui_EditBibleDialog):
|
|||||||
Validate the Meta before saving.
|
Validate the Meta before saving.
|
||||||
"""
|
"""
|
||||||
if not self.version:
|
if not self.version:
|
||||||
|
self.changeBackgroundColor(self.versionNameEdit, 'red')
|
||||||
|
self.validate_error = [self.versionNameEdit]
|
||||||
|
self.versionNameEdit.setFocus()
|
||||||
critical_error_message_box(UiStrings().EmptyField,
|
critical_error_message_box(UiStrings().EmptyField,
|
||||||
translate('BiblesPlugin.BibleEditForm',
|
translate('BiblesPlugin.BibleEditForm',
|
||||||
'You need to specify a version name for your Bible.'))
|
'You need to specify a version name for your Bible.'))
|
||||||
self.versionNameEdit.setFocus()
|
|
||||||
return False
|
return False
|
||||||
elif not self.copyright:
|
elif not self.copyright:
|
||||||
|
self.changeBackgroundColor(self.copyrightEdit, 'red')
|
||||||
|
self.validate_error = [self.copyrightEdit]
|
||||||
|
self.copyrightEdit.setFocus()
|
||||||
critical_error_message_box(UiStrings().EmptyField,
|
critical_error_message_box(UiStrings().EmptyField,
|
||||||
translate('BiblesPlugin.BibleEditForm',
|
translate('BiblesPlugin.BibleEditForm',
|
||||||
'You need to set a copyright for your Bible. '
|
'You need to set a copyright for your Bible. '
|
||||||
'Bibles in the Public Domain need to be marked as such.'))
|
'Bibles in the Public Domain need to be marked as such.'))
|
||||||
self.copyrightEdit.setFocus()
|
|
||||||
return False
|
return False
|
||||||
elif self.manager.exists(self.version) and \
|
elif self.manager.exists(self.version) and \
|
||||||
self.manager.get_meta_data(self.bible, u'Version').value != \
|
self.manager.get_meta_data(self.bible, u'Version').value != \
|
||||||
self.version:
|
self.version:
|
||||||
|
self.changeBackgroundColor(self.versionNameEdit, 'red')
|
||||||
|
self.validate_error = [self.versionNameEdit]
|
||||||
|
self.versionNameEdit.setFocus()
|
||||||
critical_error_message_box(
|
critical_error_message_box(
|
||||||
translate('BiblesPlugin.BibleEditForm', 'Bible Exists'),
|
translate('BiblesPlugin.BibleEditForm', 'Bible Exists'),
|
||||||
translate('BiblesPlugin.BibleEditForm',
|
translate('BiblesPlugin.BibleEditForm',
|
||||||
'This Bible already exists. Please import '
|
'This Bible already exists. Please import '
|
||||||
'a different Bible or first delete the existing one.'))
|
'a different Bible or first delete the existing one.'))
|
||||||
self.versionNameEdit.setFocus()
|
|
||||||
return False
|
return False
|
||||||
return True
|
return True
|
||||||
|
|
||||||
@ -183,6 +190,7 @@ class EditBibleForm(QtGui.QDialog, Ui_EditBibleDialog):
|
|||||||
"""
|
"""
|
||||||
Validate a book.
|
Validate a book.
|
||||||
"""
|
"""
|
||||||
|
book_regex = re.compile(u'[\d]*[^\d]+$')
|
||||||
if not new_bookname:
|
if not new_bookname:
|
||||||
self.changeBackgroundColor(self.bookNameEdit[abbreviation], 'red')
|
self.changeBackgroundColor(self.bookNameEdit[abbreviation], 'red')
|
||||||
self.validate_error = [self.bookNameEdit[abbreviation]]
|
self.validate_error = [self.bookNameEdit[abbreviation]]
|
||||||
@ -192,9 +200,21 @@ class EditBibleForm(QtGui.QDialog, Ui_EditBibleDialog):
|
|||||||
'You need to specify a book name for "%s".')) %
|
'You need to specify a book name for "%s".')) %
|
||||||
self.booknames[abbreviation])
|
self.booknames[abbreviation])
|
||||||
return False
|
return False
|
||||||
|
elif not book_regex.match(new_bookname):
|
||||||
|
self.changeBackgroundColor(self.bookNameEdit[abbreviation], 'red')
|
||||||
|
self.validate_error = [self.bookNameEdit[abbreviation]]
|
||||||
|
self.bookNameEdit[abbreviation].setFocus()
|
||||||
|
critical_error_message_box(UiStrings().EmptyField,
|
||||||
|
unicode(translate('BiblesPlugin.BibleEditForm',
|
||||||
|
'The book name "%s" is not correct.\nDecimal digits only could '
|
||||||
|
'be used at the beginning and\nmust be followed by one or more '
|
||||||
|
'non-digit characters')) % new_bookname)
|
||||||
|
return False
|
||||||
for abbr, book in self.books.iteritems():
|
for abbr, book in self.books.iteritems():
|
||||||
if book:
|
if book:
|
||||||
if book.name == new_bookname:
|
if abbr == abbreviation:
|
||||||
|
continue
|
||||||
|
if unicode(self.bookNameEdit[abbr].text()) == new_bookname:
|
||||||
self.changeBackgroundColor(self.bookNameEdit[abbreviation],
|
self.changeBackgroundColor(self.bookNameEdit[abbreviation],
|
||||||
'red')
|
'red')
|
||||||
self.bookNameEdit[abbreviation].setFocus()
|
self.bookNameEdit[abbreviation].setFocus()
|
||||||
|
@ -327,6 +327,10 @@ class BibleManager(object):
|
|||||||
'Import Wizard to install one or more Bibles.')
|
'Import Wizard to install one or more Bibles.')
|
||||||
})
|
})
|
||||||
return None
|
return None
|
||||||
|
language_selection = self.get_meta_data(bible, u'Bookname language')
|
||||||
|
if language_selection:
|
||||||
|
language_selection = int(language_selection.value)
|
||||||
|
if language_selection == None or language_selection == -1:
|
||||||
language_selection = QtCore.QSettings().value(
|
language_selection = QtCore.QSettings().value(
|
||||||
self.settingsSection + u'/bookname language',
|
self.settingsSection + u'/bookname language',
|
||||||
QtCore.QVariant(0)).toInt()[0]
|
QtCore.QVariant(0)).toInt()[0]
|
||||||
@ -415,7 +419,7 @@ class BibleManager(object):
|
|||||||
return None
|
return None
|
||||||
|
|
||||||
def save_meta_data(self, bible, version, copyright, permissions,
|
def save_meta_data(self, bible, version, copyright, permissions,
|
||||||
bookname_language):
|
bookname_language=-1):
|
||||||
"""
|
"""
|
||||||
Saves the bibles meta data.
|
Saves the bibles meta data.
|
||||||
"""
|
"""
|
||||||
|
@ -433,7 +433,7 @@ class BibleMediaItem(MediaManagerItem):
|
|||||||
bible, u'Bookname language')
|
bible, u'Bookname language')
|
||||||
if language_selection:
|
if language_selection:
|
||||||
language_selection = int(language_selection.value)
|
language_selection = int(language_selection.value)
|
||||||
if not language_selection or language_selection == -1:
|
if language_selection == None or language_selection == -1:
|
||||||
language_selection = QtCore.QSettings().value(
|
language_selection = QtCore.QSettings().value(
|
||||||
self.settingsSection + u'/bookname language',
|
self.settingsSection + u'/bookname language',
|
||||||
QtCore.QVariant(0)).toInt()[0]
|
QtCore.QVariant(0)).toInt()[0]
|
||||||
@ -508,6 +508,11 @@ class BibleMediaItem(MediaManagerItem):
|
|||||||
secondbook.book_reference_id:
|
secondbook.book_reference_id:
|
||||||
book_data_temp.append(book)
|
book_data_temp.append(book)
|
||||||
book_data = book_data_temp
|
book_data = book_data_temp
|
||||||
|
language_selection = self.plugin.manager.get_meta_data(
|
||||||
|
bible, u'Bookname language')
|
||||||
|
if language_selection:
|
||||||
|
language_selection = int(language_selection.value)
|
||||||
|
if language_selection == None or language_selection == -1:
|
||||||
language_selection = QtCore.QSettings().value(
|
language_selection = QtCore.QSettings().value(
|
||||||
self.settingsSection + u'/bookname language',
|
self.settingsSection + u'/bookname language',
|
||||||
QtCore.QVariant(0)).toInt()[0]
|
QtCore.QVariant(0)).toInt()[0]
|
||||||
|
Loading…
Reference in New Issue
Block a user