forked from openlp/openlp
Head
This commit is contained in:
commit
6b73c842cb
@ -92,7 +92,7 @@ class MediaManagerItem(QtGui.QWidget):
|
||||
"""
|
||||
QtGui.QWidget.__init__(self, parent)
|
||||
self.hide()
|
||||
self.whitespace = re.compile(r'\W+', re.UNICODE)
|
||||
self.whitespace = re.compile(r'[\W_]+', re.UNICODE)
|
||||
self.plugin = plugin
|
||||
visible_title = self.plugin.getString(StringContent.VisibleName)
|
||||
self.title = unicode(visible_title[u'title'])
|
||||
|
@ -300,6 +300,12 @@ class Plugin(QtCore.QObject):
|
||||
if self.mediaItem:
|
||||
self.mediadock.remove_dock(self.mediaItem)
|
||||
|
||||
def appStartup(self):
|
||||
"""
|
||||
Perform tasks on application starup
|
||||
"""
|
||||
pass
|
||||
|
||||
def usesTheme(self, theme):
|
||||
"""
|
||||
Called to find out if a plugin is currently using a theme.
|
||||
|
@ -655,7 +655,7 @@ class MainWindow(QtGui.QMainWindow, Ui_MainWindow):
|
||||
# Give all the plugins a chance to perform some tasks at startup
|
||||
Receiver.send_message(u'openlp_process_events')
|
||||
for plugin in self.pluginManager.plugins:
|
||||
if plugin.isActive() and hasattr(plugin, u'appStartup'):
|
||||
if plugin.isActive():
|
||||
Receiver.send_message(u'openlp_process_events')
|
||||
plugin.appStartup()
|
||||
Receiver.send_message(u'openlp_process_events')
|
||||
|
@ -132,6 +132,7 @@ class PluginForm(QtGui.QDialog, Ui_PluginViewDialog):
|
||||
Receiver.send_message(u'cursor_busy')
|
||||
self.activePlugin.toggleStatus(PluginStatus.Active)
|
||||
Receiver.send_message(u'cursor_normal')
|
||||
self.activePlugin.appStartup()
|
||||
else:
|
||||
self.activePlugin.toggleStatus(PluginStatus.Inactive)
|
||||
status_text = unicode(
|
||||
|
@ -106,7 +106,7 @@ class ScreenList(object):
|
||||
"""
|
||||
# Do not log at start up.
|
||||
if changed_screen != -1:
|
||||
log.info(u'screen_count_changed %d' % number)
|
||||
log.info(u'screen_count_changed %d' % self.desktop.numScreens())
|
||||
# Remove unplugged screens.
|
||||
for screen in copy.deepcopy(self.screen_list):
|
||||
if screen[u'number'] == self.desktop.numScreens():
|
||||
|
@ -115,6 +115,8 @@ class BibleUpgradeForm(OpenLPWizard):
|
||||
self.stop_import_flag = True
|
||||
if not self.currentPage() == self.progressPage:
|
||||
self.done(QtGui.QDialog.Rejected)
|
||||
else:
|
||||
self.postWizard()
|
||||
|
||||
def onCurrentIdChanged(self, pageId):
|
||||
"""
|
||||
@ -127,14 +129,6 @@ class BibleUpgradeForm(OpenLPWizard):
|
||||
elif self.page(pageId) == self.selectPage and self.maxBibles == 0:
|
||||
self.next()
|
||||
|
||||
def onFinishButton(self):
|
||||
"""
|
||||
Some cleanup while finishing
|
||||
"""
|
||||
for number, filename in enumerate(self.files):
|
||||
if number in self.success and self.success[number] == True:
|
||||
delete_file(os.path.join(self.path, filename[0]))
|
||||
|
||||
def onBackupBrowseButtonClicked(self):
|
||||
"""
|
||||
Show the file open dialog for the OSIS file.
|
||||
@ -180,8 +174,6 @@ class BibleUpgradeForm(OpenLPWizard):
|
||||
"""
|
||||
Set up the signals used in the bible importer.
|
||||
"""
|
||||
QtCore.QObject.connect(self.finishButton,
|
||||
QtCore.SIGNAL(u'clicked()'), self.onFinishButton)
|
||||
QtCore.QObject.connect(self.backupBrowseButton,
|
||||
QtCore.SIGNAL(u'clicked()'), self.onBackupBrowseButtonClicked)
|
||||
QtCore.QObject.connect(self.noBackupCheckBox,
|
||||
@ -536,7 +528,7 @@ class BibleUpgradeForm(OpenLPWizard):
|
||||
"""
|
||||
Perform the actual upgrade.
|
||||
"""
|
||||
include_webbible = False
|
||||
self.include_webbible = False
|
||||
proxy_server = None
|
||||
if self.maxBibles == 0:
|
||||
self.progressLabel.setText(
|
||||
@ -578,19 +570,19 @@ class BibleUpgradeForm(OpenLPWizard):
|
||||
name = unicode(self.versionNameEdit[biblenumber].text())
|
||||
self.newbibles[number] = BibleDB(self.mediaItem, path=self.path,
|
||||
name=name)
|
||||
self.newbibles[number].register(self.plugin.upgrade_wizard)
|
||||
metadata = oldbible.get_metadata()
|
||||
webbible = False
|
||||
meta_data = {}
|
||||
for meta in metadata:
|
||||
meta_data[meta[u'key']] = meta[u'value']
|
||||
if not meta[u'key'] == u'Version':
|
||||
if not meta[u'key'] == u'Version' and not meta[u'key'] == \
|
||||
u'dbversion':
|
||||
self.newbibles[number].create_meta(meta[u'key'],
|
||||
meta[u'value'])
|
||||
else:
|
||||
self.newbibles[number].create_meta(meta[u'key'], name)
|
||||
if meta[u'key'] == u'download source':
|
||||
webbible = True
|
||||
include_webbible = True
|
||||
self.include_webbible = True
|
||||
if meta.has_key(u'proxy server'):
|
||||
proxy_server = meta[u'proxy server']
|
||||
if webbible:
|
||||
@ -606,8 +598,7 @@ class BibleUpgradeForm(OpenLPWizard):
|
||||
u'name: "%s" failed' % (
|
||||
meta_data[u'download source'],
|
||||
meta_data[u'download name']))
|
||||
delete_database(self.path,
|
||||
clean_filename(self.newbibles[number].get_name()))
|
||||
delete_database(self.path, clean_filename(name))
|
||||
del self.newbibles[number]
|
||||
critical_error_message_box(
|
||||
translate('BiblesPlugin.UpgradeWizardForm',
|
||||
@ -626,7 +617,7 @@ class BibleUpgradeForm(OpenLPWizard):
|
||||
bible = BiblesResourcesDB.get_webbible(
|
||||
meta_data[u'download name'],
|
||||
meta_data[u'download source'].lower())
|
||||
if bible[u'language_id']:
|
||||
if bible and bible[u'language_id']:
|
||||
language_id = bible[u'language_id']
|
||||
self.newbibles[number].create_meta(u'language_id',
|
||||
language_id)
|
||||
@ -634,8 +625,7 @@ class BibleUpgradeForm(OpenLPWizard):
|
||||
language_id = self.newbibles[number].get_language(name)
|
||||
if not language_id:
|
||||
log.warn(u'Upgrading from "%s" failed' % filename[0])
|
||||
delete_database(self.path,
|
||||
clean_filename(self.newbibles[number].get_name()))
|
||||
delete_database(self.path, clean_filename(name))
|
||||
del self.newbibles[number]
|
||||
self.incrementProgressBar(unicode(translate(
|
||||
'BiblesPlugin.UpgradeWizardForm',
|
||||
@ -661,8 +651,7 @@ class BibleUpgradeForm(OpenLPWizard):
|
||||
u'name: "%s" aborted by user' % (
|
||||
meta_data[u'download source'],
|
||||
meta_data[u'download name']))
|
||||
delete_database(self.path,
|
||||
clean_filename(self.newbibles[number].get_name()))
|
||||
delete_database(self.path, clean_filename(name))
|
||||
del self.newbibles[number]
|
||||
bible_failed = True
|
||||
break
|
||||
@ -693,8 +682,7 @@ class BibleUpgradeForm(OpenLPWizard):
|
||||
language_id = self.newbibles[number].get_language(name)
|
||||
if not language_id:
|
||||
log.warn(u'Upgrading books from "%s" failed' % name)
|
||||
delete_database(self.path,
|
||||
clean_filename(self.newbibles[number].get_name()))
|
||||
delete_database(self.path, clean_filename(name))
|
||||
del self.newbibles[number]
|
||||
self.incrementProgressBar(unicode(translate(
|
||||
'BiblesPlugin.UpgradeWizardForm',
|
||||
@ -720,8 +708,7 @@ class BibleUpgradeForm(OpenLPWizard):
|
||||
if not book_ref_id:
|
||||
log.warn(u'Upgrading books from %s " '\
|
||||
'failed - aborted by user' % name)
|
||||
delete_database(self.path,
|
||||
clean_filename(self.newbibles[number].get_name()))
|
||||
delete_database(self.path, clean_filename(name))
|
||||
del self.newbibles[number]
|
||||
bible_failed = True
|
||||
break
|
||||
@ -744,6 +731,8 @@ class BibleUpgradeForm(OpenLPWizard):
|
||||
Receiver.send_message(u'openlp_process_events')
|
||||
self.newbibles[number].session.commit()
|
||||
if not bible_failed:
|
||||
self.newbibles[number].create_meta(u'Version', name)
|
||||
delete_file(os.path.join(self.path, filename[0]))
|
||||
self.incrementProgressBar(unicode(translate(
|
||||
'BiblesPlugin.UpgradeWizardForm',
|
||||
'Upgrading Bible %s of %s: "%s"\n'
|
||||
@ -756,10 +745,13 @@ class BibleUpgradeForm(OpenLPWizard):
|
||||
'Upgrading Bible %s of %s: "%s"\nFailed')) %
|
||||
(number + 1, self.maxBibles, name),
|
||||
self.progressBar.maximum() - self.progressBar.value())
|
||||
delete_database(self.path,
|
||||
clean_filename(name))
|
||||
delete_database(self.path, clean_filename(name))
|
||||
number += 1
|
||||
self.mediaItem.reloadBibles()
|
||||
|
||||
def postWizard(self):
|
||||
"""
|
||||
Clean up the UI after the import has finished.
|
||||
"""
|
||||
successful_import = 0
|
||||
failed_import = 0
|
||||
for number, filename in enumerate(self.files):
|
||||
@ -774,7 +766,7 @@ class BibleUpgradeForm(OpenLPWizard):
|
||||
else:
|
||||
failed_import_text = u''
|
||||
if successful_import > 0:
|
||||
if include_webbible:
|
||||
if self.include_webbible:
|
||||
self.progressLabel.setText(unicode(
|
||||
translate('BiblesPlugin.UpgradeWizardForm', 'Upgrading '
|
||||
'Bible(s): %s successful%s\nPlease note, that verses from '
|
||||
@ -790,3 +782,4 @@ class BibleUpgradeForm(OpenLPWizard):
|
||||
self.progressLabel.setText(
|
||||
translate('BiblesPlugin.UpgradeWizardForm', 'Upgrade '
|
||||
'failed.'))
|
||||
OpenLPWizard.postWizard(self)
|
||||
|
@ -109,7 +109,7 @@ class BGExtract(object):
|
||||
try:
|
||||
clean_verse_num = int(str(raw_verse_num))
|
||||
except ValueError:
|
||||
log.exception(u'Illegal verse number in %s %s %s:%s',
|
||||
log.warn(u'Illegal verse number in %s %s %s:%s',
|
||||
version, bookname, chapter, unicode(raw_verse_num))
|
||||
if clean_verse_num:
|
||||
verse_text = raw_verse_num.next
|
||||
@ -139,16 +139,17 @@ class BGExtract(object):
|
||||
"""
|
||||
log.debug(u'BGExtract.get_books_from_http("%s")', version)
|
||||
url_params = urllib.urlencode(
|
||||
{u'search': 'Bible-List', u'version': u'%s' % version})
|
||||
reference_url = u'http://www.biblegateway.com/passage/?%s' % url_params
|
||||
{u'action': 'getVersionInfo', u'vid': u'%s' % version})
|
||||
reference_url = u'http://www.biblegateway.com/versions/?%s#books' % \
|
||||
url_params
|
||||
page = get_web_page(reference_url)
|
||||
if not page:
|
||||
send_error_message(u'download')
|
||||
return None
|
||||
page_source = page.read()
|
||||
page_source = unicode(page_source, 'utf8')
|
||||
page_source_temp = re.search(u'<table id="booklist".*?>.*?</table>', \
|
||||
page_source, re.DOTALL)
|
||||
page_source_temp = re.search(u'<table .*?class="infotable".*?>.*?'\
|
||||
u'</table>', page_source, re.DOTALL)
|
||||
if page_source_temp:
|
||||
soup = page_source_temp.group(0)
|
||||
else:
|
||||
@ -156,15 +157,17 @@ class BGExtract(object):
|
||||
try:
|
||||
soup = BeautifulSoup(soup)
|
||||
except HTMLParseError:
|
||||
log.exception(u'BeautifulSoup could not parse the Bible page.')
|
||||
log.error(u'BeautifulSoup could not parse the Bible page.')
|
||||
send_error_message(u'parse')
|
||||
return None
|
||||
if not soup:
|
||||
send_error_message(u'parse')
|
||||
return None
|
||||
Receiver.send_message(u'openlp_process_events')
|
||||
content = soup.find(u'table', {u'id': u'booklist'})
|
||||
content = soup.find(u'table', {u'class': u'infotable'})
|
||||
content = content.findAll(u'tr')
|
||||
if not content:
|
||||
log.exception(u'No books found in the Biblegateway response.')
|
||||
log.error(u'No books found in the Biblegateway response.')
|
||||
send_error_message(u'parse')
|
||||
return None
|
||||
books = []
|
||||
@ -199,9 +202,10 @@ class BSExtract(object):
|
||||
"""
|
||||
log.debug(u'BSExtract.get_bible_chapter("%s", "%s", "%s")', version,
|
||||
bookname, chapter)
|
||||
urlversion = urllib.quote(version.encode("utf-8"))
|
||||
urlbookname = urllib.quote(bookname.encode("utf-8"))
|
||||
chapter_url = u'http://m.bibleserver.com/text/%s/%s%s' % \
|
||||
(version, urlbookname, chapter)
|
||||
chapter_url = u'http://m.bibleserver.com/text/%s/%s%d' % \
|
||||
(urlversion, urlbookname, chapter)
|
||||
header = (u'Accept-Language', u'en')
|
||||
soup = get_soup_for_bible_ref(chapter_url, header)
|
||||
if not soup:
|
||||
@ -209,7 +213,7 @@ class BSExtract(object):
|
||||
Receiver.send_message(u'openlp_process_events')
|
||||
content = soup.find(u'div', u'content')
|
||||
if not content:
|
||||
log.exception(u'No verses found in the Bibleserver response.')
|
||||
log.error(u'No verses found in the Bibleserver response.')
|
||||
send_error_message(u'parse')
|
||||
return None
|
||||
content = content.find(u'div').findAll(u'div')
|
||||
@ -230,14 +234,15 @@ class BSExtract(object):
|
||||
The version of the Bible like NIV for New International Version
|
||||
"""
|
||||
log.debug(u'BSExtract.get_books_from_http("%s")', version)
|
||||
urlversion = urllib.quote(version.encode("utf-8"))
|
||||
chapter_url = u'http://m.bibleserver.com/overlay/selectBook?'\
|
||||
'translation=%s' % (version)
|
||||
'translation=%s' % (urlversion)
|
||||
soup = get_soup_for_bible_ref(chapter_url)
|
||||
if not soup:
|
||||
return None
|
||||
content = soup.find(u'ul')
|
||||
if not content:
|
||||
log.exception(u'No books found in the Bibleserver response.')
|
||||
log.error(u'No books found in the Bibleserver response.')
|
||||
send_error_message(u'parse')
|
||||
return None
|
||||
content = content.findAll(u'li')
|
||||
@ -281,7 +286,7 @@ class CWExtract(object):
|
||||
Receiver.send_message(u'openlp_process_events')
|
||||
htmlverses = soup.findAll(u'span', u'versetext')
|
||||
if not htmlverses:
|
||||
log.debug(u'No verses found in the CrossWalk response.')
|
||||
log.error(u'No verses found in the CrossWalk response.')
|
||||
send_error_message(u'parse')
|
||||
return None
|
||||
verses = {}
|
||||
@ -333,7 +338,7 @@ class CWExtract(object):
|
||||
content = soup.find(u'div', {u'class': u'Body'})
|
||||
content = content.find(u'ul', {u'class': u'parent'})
|
||||
if not content:
|
||||
log.exception(u'No books found in the Crosswalk response.')
|
||||
log.error(u'No books found in the Crosswalk response.')
|
||||
send_error_message(u'parse')
|
||||
return None
|
||||
content = content.findAll(u'li')
|
||||
|
@ -772,7 +772,7 @@ 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,
|
||||
bible_text = u'%s %d%s%d (%s, %s)' % (verse.book.name,
|
||||
verse.chapter, verse_separator, verse.verse, version,
|
||||
second_version)
|
||||
else:
|
||||
@ -830,7 +830,7 @@ class BibleMediaItem(MediaManagerItem):
|
||||
bible_text = u''
|
||||
# If we are 'Verse Per Line' then force a new line.
|
||||
elif self.settings.layout_style == LayoutStyle.VersePerLine:
|
||||
bible_text = u'%s %s %s\n' % (bible_text, verse_text, text)
|
||||
bible_text = u'%s%s %s\n' % (bible_text, verse_text, text)
|
||||
# We have to be 'Continuous'.
|
||||
else:
|
||||
bible_text = u'%s %s %s\n' % (bible_text, verse_text, text)
|
||||
|
Binary file not shown.
@ -32,6 +32,9 @@ from openlp.core.lib import translate
|
||||
from db import Author
|
||||
from ui import SongStrings
|
||||
|
||||
WHITESPACE = re.compile(r'[\W_]+', re.UNICODE)
|
||||
APOSTROPHE = re.compile(u'[\'`’ʻ′]', re.UNICODE)
|
||||
|
||||
class VerseType(object):
|
||||
"""
|
||||
VerseType provides an enumeration for the tags that may be associated
|
||||
@ -246,6 +249,12 @@ def retrieve_windows_encoding(recommendation=None):
|
||||
return None
|
||||
return filter(lambda item: item[1] == choice[0], encodings)[0][0]
|
||||
|
||||
def clean_string(string):
|
||||
"""
|
||||
Strips punctuation from the passed string to assist searching
|
||||
"""
|
||||
return WHITESPACE.sub(u' ', APOSTROPHE.sub(u'', string)).lower()
|
||||
|
||||
def clean_song(manager, song):
|
||||
"""
|
||||
Cleans the search title, rebuilds the search lyrics, adds a default author
|
||||
@ -262,9 +271,8 @@ def clean_song(manager, song):
|
||||
if song.alternate_title is None:
|
||||
song.alternate_title = u''
|
||||
song.alternate_title = song.alternate_title.strip()
|
||||
whitespace = re.compile(r'\W+', re.UNICODE)
|
||||
song.search_title = (whitespace.sub(u' ', song.title).strip() + u'@' +
|
||||
whitespace.sub(u' ', song.alternate_title).strip()).strip().lower()
|
||||
song.search_title = clean_string(song.title) + u'@' + \
|
||||
clean_string(song.alternate_title)
|
||||
# Only do this, if we the song is a 1.9.4 song (or older).
|
||||
if song.lyrics.find(u'<lyrics language="en">') != -1:
|
||||
# Remove the old "language" attribute from lyrics tag (prior to 1.9.5).
|
||||
@ -273,8 +281,8 @@ def clean_song(manager, song):
|
||||
song.lyrics = song.lyrics.replace(
|
||||
u'<lyrics language="en">', u'<lyrics>')
|
||||
verses = SongXML().get_verses(song.lyrics)
|
||||
lyrics = u' '.join([whitespace.sub(u' ', verse[1]) for verse in verses])
|
||||
song.search_lyrics = lyrics.lower()
|
||||
song.search_lyrics = u' '.join([clean_string(verse[1])
|
||||
for verse in verses])
|
||||
# We need a new and clean SongXML instance.
|
||||
sxml = SongXML()
|
||||
# Rebuild the song's verses, to remove any wrong verse names (for
|
||||
@ -316,6 +324,11 @@ def clean_song(manager, song):
|
||||
if order not in compare_order:
|
||||
song.verse_order = u''
|
||||
break
|
||||
else:
|
||||
verses = SongXML().get_verses(song.lyrics)
|
||||
song.search_lyrics = u' '.join([clean_string(verse[1])
|
||||
for verse in verses])
|
||||
|
||||
# The song does not have any author, add one.
|
||||
if not song.authors:
|
||||
name = SongStrings.AuthorUnknown
|
||||
|
@ -38,7 +38,8 @@ from openlp.core.lib.searchedit import SearchEdit
|
||||
from openlp.core.lib.ui import UiStrings
|
||||
from openlp.plugins.songs.forms import EditSongForm, SongMaintenanceForm, \
|
||||
SongImportForm, SongExportForm
|
||||
from openlp.plugins.songs.lib import OpenLyrics, SongXML, VerseType
|
||||
from openlp.plugins.songs.lib import OpenLyrics, SongXML, VerseType, \
|
||||
clean_string
|
||||
from openlp.plugins.songs.lib.db import Author, Song
|
||||
from openlp.plugins.songs.lib.ui import SongStrings
|
||||
|
||||
@ -181,13 +182,14 @@ class SongMediaItem(MediaManagerItem):
|
||||
elif search_type == SongSearch.Titles:
|
||||
log.debug(u'Titles Search')
|
||||
search_results = self.plugin.manager.get_all_objects(Song,
|
||||
Song.search_title.like(u'%' + self.whitespace.sub(u' ',
|
||||
search_keywords.lower()) + u'%'))
|
||||
Song.search_title.like(u'%' + clean_string(search_keywords) +
|
||||
u'%'))
|
||||
self.displayResultsSong(search_results)
|
||||
elif search_type == SongSearch.Lyrics:
|
||||
log.debug(u'Lyrics Search')
|
||||
search_results = self.plugin.manager.get_all_objects(Song,
|
||||
Song.search_lyrics.like(u'%' + search_keywords.lower() + u'%'))
|
||||
Song.search_lyrics.like(u'%' + clean_string(search_keywords) +
|
||||
u'%'))
|
||||
self.displayResultsSong(search_results)
|
||||
elif search_type == SongSearch.Authors:
|
||||
log.debug(u'Authors Search')
|
||||
@ -198,16 +200,16 @@ class SongMediaItem(MediaManagerItem):
|
||||
elif search_type == SongSearch.Themes:
|
||||
log.debug(u'Theme Search')
|
||||
search_results = self.plugin.manager.get_all_objects(Song,
|
||||
Song.theme_name.like(u'%' + self.whitespace.sub(u' ',
|
||||
search_keywords) + u'%'))
|
||||
Song.theme_name.like(u'%' + search_keywords + u'%'))
|
||||
self.displayResultsSong(search_results)
|
||||
self.check_search_result()
|
||||
|
||||
def searchEntire(self, search_keywords):
|
||||
return self.plugin.manager.get_all_objects(Song,
|
||||
or_(Song.search_title.like(u'%' + self.whitespace.sub(u' ',
|
||||
search_keywords.lower()) + u'%'),
|
||||
Song.search_lyrics.like(u'%' + search_keywords.lower() + u'%'),
|
||||
or_(Song.search_title.like(u'%' + clean_string(search_keywords)
|
||||
+ u'%'),
|
||||
Song.search_lyrics.like(u'%' + clean_string(search_keywords)
|
||||
+ u'%'),
|
||||
Song.comments.like(u'%' + search_keywords.lower() + u'%')))
|
||||
|
||||
def onSongListLoad(self):
|
||||
|
Loading…
Reference in New Issue
Block a user