forked from openlp/openlp
Merge in changes from lp:~raoul-snyman/openlp/biblesplugin
bzr-revno: 693
This commit is contained in:
commit
9be767a388
@ -66,13 +66,13 @@ class ImportWizardForm(QtGui.QWizard, Ui_BibleImportWizard):
|
||||
QtGui.QWizard.__init__(self, parent)
|
||||
self.setupUi(self)
|
||||
self.registerFields()
|
||||
self.web_bible_list = {}
|
||||
self.finishButton = self.button(QtGui.QWizard.FinishButton)
|
||||
self.cancelButton = self.button(QtGui.QWizard.CancelButton)
|
||||
self.biblemanager = biblemanager
|
||||
self.config = config
|
||||
self.bibleplugin = bibleplugin
|
||||
self.biblemanager.process_dialog(self)
|
||||
self.biblemanager.set_process_dialog(self)
|
||||
self.web_bible_list = {}
|
||||
self.loadWebBibles()
|
||||
QtCore.QObject.connect(self.LocationComboBox,
|
||||
QtCore.SIGNAL(u'currentIndexChanged(int)'),
|
||||
@ -89,6 +89,9 @@ class ImportWizardForm(QtGui.QWizard, Ui_BibleImportWizard):
|
||||
QtCore.QObject.connect(self.OpenSongBrowseButton,
|
||||
QtCore.SIGNAL(u'clicked()'),
|
||||
self.onOpenSongBrowseButtonClicked)
|
||||
QtCore.QObject.connect(self.cancelButton,
|
||||
QtCore.SIGNAL(u'clicked(bool)'),
|
||||
self.onCancelButtonClicked)
|
||||
QtCore.QObject.connect(self,
|
||||
QtCore.SIGNAL(u'currentIdChanged(int)'),
|
||||
self.onCurrentIdChanged)
|
||||
@ -192,6 +195,11 @@ class ImportWizardForm(QtGui.QWizard, Ui_BibleImportWizard):
|
||||
self.getFileName(self.trUtf8('Open OpenSong Bible'),
|
||||
self.OpenSongFileEdit)
|
||||
|
||||
def onCancelButtonClicked(self, checked):
|
||||
log.debug('Cancel button pressed!')
|
||||
if self.currentId() == 3:
|
||||
Receiver.send_message(u'openlpstopimport')
|
||||
|
||||
def onCurrentIdChanged(self, id):
|
||||
if id == 3:
|
||||
self.preImport()
|
||||
@ -237,11 +245,11 @@ class ImportWizardForm(QtGui.QWizard, Ui_BibleImportWizard):
|
||||
self.setField(u'opensong_file', u'')
|
||||
self.setField(u'web_location', 0)
|
||||
self.setField(u'web_biblename', self.BibleComboBox)
|
||||
self.setField(u'proxy_server',
|
||||
self.setField(u'proxy_server',
|
||||
self.config.get_config(u'proxy address', u''))
|
||||
self.setField(u'proxy_username',
|
||||
self.setField(u'proxy_username',
|
||||
self.config.get_config(u'proxy username',u''))
|
||||
self.setField(u'proxy_password',
|
||||
self.setField(u'proxy_password',
|
||||
self.config.get_config(u'proxy password',u''))
|
||||
self.setField(u'license_version', self.VersionNameEdit)
|
||||
self.setField(u'license_copyright', self.CopyrightEdit)
|
||||
@ -297,8 +305,7 @@ class ImportWizardForm(QtGui.QWizard, Ui_BibleImportWizard):
|
||||
Receiver.send_message(u'process_events')
|
||||
|
||||
def preImport(self):
|
||||
self.finishButton.setEnabled(False)
|
||||
self.cancelButton.setVisible(False)
|
||||
self.finishButton.setVisible(False)
|
||||
self.ImportProgressBar.setMinimum(0)
|
||||
self.ImportProgressBar.setMaximum(1188)
|
||||
self.ImportProgressBar.setValue(0)
|
||||
@ -352,13 +359,14 @@ class ImportWizardForm(QtGui.QWizard, Ui_BibleImportWizard):
|
||||
unicode(self.field(u'license_copyright').toString()),
|
||||
unicode(self.field(u'license_permission').toString())
|
||||
)
|
||||
self.ImportProgressLabel.setText(self.trUtf8('Finished import.'))
|
||||
else:
|
||||
self.ImportProgressLabel.setText(
|
||||
self.trUtf8('Your Bible import failed.'))
|
||||
self.ImportProgressBar.setValue(self.ImportProgressBar.maximum())
|
||||
|
||||
def postImport(self):
|
||||
self.ImportProgressLabel.setText(self.trUtf8('Finished import.'))
|
||||
self.finishButton.setEnabled(True)
|
||||
self.ImportProgressBar.setValue(self.ImportProgressBar.maximum())
|
||||
self.finishButton.setVisible(True)
|
||||
self.cancelButton.setVisible(False)
|
||||
Receiver.send_message(u'process_events')
|
||||
|
||||
|
@ -49,6 +49,7 @@ class BibleCSVImpl(BibleCommon):
|
||||
|
||||
def load_data(self, booksfile, versesfile, dialogobject):
|
||||
#Populate the Tables
|
||||
success = True
|
||||
fbooks = None
|
||||
try:
|
||||
fbooks = open(booksfile, 'r')
|
||||
@ -71,10 +72,12 @@ class BibleCSVImpl(BibleCommon):
|
||||
count = 0
|
||||
except:
|
||||
log.exception(u'Loading books from file failed')
|
||||
success = False
|
||||
finally:
|
||||
if fbooks:
|
||||
fbooks.close()
|
||||
|
||||
if not success:
|
||||
return False
|
||||
fverse = None
|
||||
try:
|
||||
fverse = open(versesfile, 'r')
|
||||
@ -104,6 +107,14 @@ class BibleCSVImpl(BibleCommon):
|
||||
self.bibledb.save_verses()
|
||||
except:
|
||||
log.exception(u'Loading verses from file failed')
|
||||
success = False
|
||||
finally:
|
||||
if fverse:
|
||||
fverse.close()
|
||||
if not self.loadbible:
|
||||
dialogobject.incrementProgressBar(u'Import canceled!')
|
||||
dialogobject.ImportProgressBar.setValue(
|
||||
dialogobject.ImportProgressBar.maximum())
|
||||
return False
|
||||
else:
|
||||
return success
|
||||
|
@ -91,6 +91,7 @@ class BibleOSISImpl():
|
||||
"""
|
||||
Stops the import of the Bible.
|
||||
"""
|
||||
log.debug('Stopping import!')
|
||||
self.loadbible = False
|
||||
|
||||
def load_data(self, osisfile_record, dialogobject=None):
|
||||
@ -116,19 +117,23 @@ class BibleOSISImpl():
|
||||
if detect_file:
|
||||
detect_file.close()
|
||||
osis = None
|
||||
success = True
|
||||
try:
|
||||
osis = codecs.open(osisfile_record, u'r', details['encoding'])
|
||||
last_chapter = 0
|
||||
testament = 1
|
||||
db_book = None
|
||||
for file_record in osis:
|
||||
if not self.loadbible:
|
||||
break
|
||||
match = self.verse_regex.search(file_record)
|
||||
if match:
|
||||
book = match.group(1)
|
||||
chapter = int(match.group(2))
|
||||
verse = int(match.group(3))
|
||||
verse_text = match.group(4)
|
||||
if not db_book or db_book.name != book:
|
||||
if not db_book or db_book.name != self.books[book][0]:
|
||||
log.debug('New book: "%s"', self.books[book][0])
|
||||
if book == u'Matt':
|
||||
testament += 1
|
||||
db_book = self.bibledb.create_book(
|
||||
@ -166,11 +171,19 @@ class BibleOSISImpl():
|
||||
.replace(u'</div>', u'')
|
||||
verse_text = self.spaces_regex.sub(u' ', verse_text)
|
||||
self.bibledb.add_verse(db_book.id, chapter, verse, verse_text)
|
||||
Receiver.send_message(u'process_events')
|
||||
self.bibledb.save_verses()
|
||||
dialogobject.incrementProgressBar(u'Finishing import...')
|
||||
except:
|
||||
log.exception(u'Loading bible from OSIS file failed')
|
||||
success = False
|
||||
finally:
|
||||
if osis:
|
||||
osis.close()
|
||||
|
||||
if not self.loadbible:
|
||||
dialogobject.incrementProgressBar(u'Import canceled!')
|
||||
dialogobject.ImportProgressBar.setValue(
|
||||
dialogobject.ImportProgressBar.maximum())
|
||||
return False
|
||||
else:
|
||||
return success
|
||||
|
@ -89,15 +89,22 @@ class BibleOpenSongImpl():
|
||||
if detect_file:
|
||||
detect_file.close()
|
||||
opensong_bible = None
|
||||
success = True
|
||||
try:
|
||||
opensong_bible = codecs.open(bible_file, u'r', details['encoding'])
|
||||
opensong = objectify.parse(opensong_bible)
|
||||
bible = opensong.getroot()
|
||||
for book in bible.b:
|
||||
if not self.loadbible:
|
||||
break
|
||||
dbbook = self.bibledb.create_book(book.attrib[u'n'],
|
||||
book.attrib[u'n'][:4])
|
||||
for chapter in book.c:
|
||||
if not self.loadbible:
|
||||
break
|
||||
for verse in chapter.v:
|
||||
if not self.loadbible:
|
||||
break
|
||||
self.bibledb.add_verse(dbbook.id, chapter.attrib[u'n'],
|
||||
verse.attrib[u'n'], verse.text)
|
||||
Receiver.send_message(u'process_events')
|
||||
@ -106,7 +113,15 @@ class BibleOpenSongImpl():
|
||||
self.bibledb.save_verses()
|
||||
except:
|
||||
log.exception(u'Loading bible from OpenSong file failed')
|
||||
success = False
|
||||
finally:
|
||||
if opensong_bible:
|
||||
opensong_bible.close()
|
||||
if not self.loadbible:
|
||||
dialogobject.incrementProgressBar(u'Import canceled!')
|
||||
dialogobject.ImportProgressBar.setValue(
|
||||
dialogobject.ImportProgressBar.maximum())
|
||||
return False
|
||||
else:
|
||||
return success
|
||||
|
||||
|
@ -155,7 +155,7 @@ class BibleManager(object):
|
||||
fbibles.close()
|
||||
log.debug(u'Bible Initialised')
|
||||
|
||||
def process_dialog(self, dialogobject):
|
||||
def set_process_dialog(self, dialogobject):
|
||||
"""
|
||||
Sets the reference to the dialog with the progress bar on it.
|
||||
|
||||
@ -246,8 +246,7 @@ class BibleManager(object):
|
||||
self.bible_db_cache[biblename] = nbible
|
||||
# Create the loader and pass in the database
|
||||
bcsv = BibleCSVImpl(nbible)
|
||||
bcsv.load_data(booksfile, versefile, self.dialogobject)
|
||||
return True
|
||||
return bcsv.load_data(booksfile, versefile, self.dialogobject)
|
||||
else:
|
||||
log.debug(u'register_csv_file_bible %s not created already exists',
|
||||
biblename)
|
||||
@ -268,9 +267,8 @@ class BibleManager(object):
|
||||
# Cache the database for use later
|
||||
self.bible_db_cache[biblename] = nbible
|
||||
# Create the loader and pass in the database
|
||||
bcsv = BibleOSISImpl(self.biblePath, nbible)
|
||||
bcsv.load_data(osisfile, self.dialogobject)
|
||||
return True
|
||||
bosis = BibleOSISImpl(self.biblePath, nbible)
|
||||
return bosis.load_data(osisfile, self.dialogobject)
|
||||
else:
|
||||
log.debug(
|
||||
u'register_OSIS_file_bible %s, %s not created already exists',
|
||||
|
@ -1 +1 @@
|
||||
1.9.0-692
|
||||
1.9.0-693
|
||||
|
Loading…
Reference in New Issue
Block a user