diff --git a/openlp/plugins/bibles/forms/bibleimportform.py b/openlp/plugins/bibles/forms/bibleimportform.py index 57a38538f..a85230611 100644 --- a/openlp/plugins/bibles/forms/bibleimportform.py +++ b/openlp/plugins/bibles/forms/bibleimportform.py @@ -30,6 +30,7 @@ import csv import logging import os import os.path +import re from PyQt4 import QtCore, QtGui @@ -471,6 +472,7 @@ class BibleImportForm(OpenLPWizard): license_version = unicode(self.field(u'license_version').toString()) license_copyright = \ unicode(self.field(u'license_copyright').toString()) + path = AppLocation.get_section_data_path(u'bibles/bibles') if not license_version: critical_error_message_box(UiStrings().EmptyField, translate('BiblesPlugin.ImportWizardForm', @@ -492,10 +494,32 @@ class BibleImportForm(OpenLPWizard): 'a different Bible or first delete the existing one.')) self.versionNameEdit.setFocus() return False + elif os.path.exists(os.path.join(path, self.clean_filename( + license_version))): + critical_error_message_box( + translate('BiblesPlugin.ImportWizardForm', 'Bible Exists'), + 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 if self.currentPage() == self.progressPage: return True + def clean_filename(self, old_filename): + """ + Clean up the version name of the Bible and convert it into a valid + file name. + + ``old_filename`` + The "dirty" file name or version name. + """ + if not isinstance(old_filename, unicode): + old_filename = unicode(old_filename, u'utf-8') + old_filename = re.sub(r'[^\w]+', u'_', old_filename).strip(u'_') + return old_filename + u'.sqlite' + def onWebSourceComboBoxIndexChanged(self, index): """ Setup the list of Bibles when you select a different source on the web diff --git a/openlp/plugins/bibles/forms/biblereimportform.py b/openlp/plugins/bibles/forms/biblereimportform.py index 48af1c558..5895f710a 100644 --- a/openlp/plugins/bibles/forms/biblereimportform.py +++ b/openlp/plugins/bibles/forms/biblereimportform.py @@ -310,7 +310,7 @@ class BibleReImportForm(OpenLPWizard): the wizard is progressing with its task. """ OpenLPWizard.addProgressPage(self) - self.progressLayout.setContentsMargins(48, 30, 48, 30) + self.progressLayout.setContentsMargins(48, 48, 48, 30) self.progressLabelAfter = QtGui.QLabel(self.progressPage) self.progressLabelAfter.setObjectName(u'progressLabelAfter') self.progressLayout.addWidget(self.progressLabelAfter) @@ -663,22 +663,23 @@ class BibleReImportForm(OpenLPWizard): elif success == False and self.checkBox[number].checkState() == 2: failed_import += 1 if failed_import > 0: - failed_import_text = u' And ' + unicode(failed_import) + \ - u' reimport fails.' + failed_import_text = unicode(translate( + 'BiblesPlugin.ReImportWizardForm', + ' - %s reimport fail')) % failed_import else: failed_import_text = u'' if successful_import > 0: if include_webbible: self.progressLabel.setText(unicode( translate('BiblesPlugin.ReImportWizardForm', 'Reimport %s ' - 'bibles successful.%s\nPlease note, that verses from ' + 'bible(s) successful%s.\nPlease note, that verses from ' 'webbibles will be downloaded\non demand and thus an ' 'internet connection is required.')) % (successful_import, failed_import_text)) else: self.progressLabel.setText(unicode( translate('BiblesPlugin.ReImportWizardForm', 'Reimport %s ' - 'bibles successful.%s')) % (successful_import, + 'bible(s) successful.%s')) % (successful_import, failed_import_text)) self.deleteCheckBox.setVisible(1) bibles = u'' diff --git a/openlp/plugins/bibles/forms/booknameform.py b/openlp/plugins/bibles/forms/booknameform.py index 58603226c..b8bdbb493 100644 --- a/openlp/plugins/bibles/forms/booknameform.py +++ b/openlp/plugins/bibles/forms/booknameform.py @@ -56,8 +56,7 @@ class BookNameForm(QDialog, Ui_BookNameDialog): def exec_(self, name): items = [] self.requestComboBox.addItem(u'') - self.requestLabel.setText( - translate('BiblesPlugin.BookNameForm', name)) + self.requestLabel.setText(name) items = BiblesResourcesDB.get_books() for item in items: self.requestComboBox.addItem(item[u'name']) diff --git a/openlp/plugins/bibles/lib/mediaitem.py b/openlp/plugins/bibles/lib/mediaitem.py index 1b7bf90ce..ec65a37d0 100644 --- a/openlp/plugins/bibles/lib/mediaitem.py +++ b/openlp/plugins/bibles/lib/mediaitem.py @@ -311,11 +311,11 @@ class BibleMediaItem(MediaManagerItem): self.reloadBibles() def onReImportClick(self): - if not hasattr(self, u'import_wizard'): - self.import_wizard = BibleReImportForm(self, self.parent.manager, + if not hasattr(self, u'reimport_wizard'): + self.reimport_wizard = BibleReImportForm(self, self.parent.manager, self.parent) # If the import was not cancelled then reload. - if self.import_wizard.exec_(): + if self.reimport_wizard.exec_(): self.reloadBibles() def loadBibles(self): diff --git a/openlp/plugins/bibles/resources/bibles_resources.sqlite b/openlp/plugins/bibles/resources/bibles_resources.sqlite index 23c89b5df..4645fcf9c 100644 Binary files a/openlp/plugins/bibles/resources/bibles_resources.sqlite and b/openlp/plugins/bibles/resources/bibles_resources.sqlite differ