Remote bible search. Kludgy and probably broken something or going to conflict. Also tweaked Remote web interface

This commit is contained in:
Jonathan Corwin 2011-05-14 22:25:22 +01:00
parent 75414d2ba8
commit 357d34a4d8
8 changed files with 155 additions and 79 deletions

View File

@ -481,14 +481,18 @@ class MediaManagerItem(QtGui.QWidget):
log.debug(u'%s Live requested', self.plugin.name)
item = None
if item_id:
item = QtGui.QListWidgetItem()
item.setData(QtCore.Qt.UserRole, QtCore.QVariant(item_id))
item = self.createItemFromId(item_id)
serviceItem = self.buildServiceItem(item)
if serviceItem:
if not item_id:
serviceItem.from_plugin = True
self.parent.liveController.addServiceItem(serviceItem)
def createItemFromId(self, item_id):
item = QtGui.QListWidgetItem()
item.setData(QtCore.Qt.UserRole, QtCore.QVariant(item_id))
return item
def onAddClick(self):
"""
Add a selected item to the current service

View File

@ -1,4 +1,4 @@
# -*- coding: utf-8 -*-
# -*- coding: utf-8 -*-
# vim: autoindent shiftwidth=4 expandtab textwidth=80 tabstop=4 softtabstop=4
###############################################################################
@ -323,7 +323,7 @@ class BibleDB(QtCore.QObject, Manager):
"""
return self.get_all_objects(Book, order_by_ref=Book.id)
def get_verses(self, reference_list):
def get_verses(self, reference_list, show_error=True):
"""
This is probably the most used function. It retrieves the list of
verses based on the user's query.
@ -360,11 +360,12 @@ class BibleDB(QtCore.QObject, Manager):
verse_list.extend(verses)
else:
log.debug(u'OpenLP failed to find book %s', book)
critical_error_message_box(
translate('BiblesPlugin', 'No Book Found'),
translate('BiblesPlugin', 'No matching book '
'could be found in this Bible. Check that you have '
'spelled the name of the book correctly.'))
if show_error:
critical_error_message_box(
translate('BiblesPlugin', 'No Book Found'),
translate('BiblesPlugin', 'No matching book '
'could be found in this Bible. Check that you have '
'spelled the name of the book correctly.'))
return verse_list
def verse_search(self, text):

View File

@ -425,7 +425,7 @@ class HTTPBible(BibleDB):
self.create_meta(u'proxy password', self.proxy_password)
return True
def get_verses(self, reference_list):
def get_verses(self, reference_list, show_error=True):
"""
A reimplementation of the ``BibleDB.get_verses`` method, this one is
specifically for web Bibles. It first checks to see if the particular
@ -453,11 +453,12 @@ class HTTPBible(BibleDB):
if not db_book:
book_details = HTTPBooks.get_book(book)
if not book_details:
critical_error_message_box(
translate('BiblesPlugin', 'No Book Found'),
translate('BiblesPlugin', 'No matching '
'book could be found in this Bible. Check that you '
'have spelled the name of the book correctly.'))
if show_error:
critical_error_message_box(
translate('BiblesPlugin', 'No Book Found'),
translate('BiblesPlugin', 'No matching '
'book could be found in this Bible. Check that you '
'have spelled the name of the book correctly.'))
return []
db_book = self.create_book(book_details[u'name'],
book_details[u'abbreviation'],
@ -480,7 +481,7 @@ class HTTPBible(BibleDB):
Receiver.send_message(u'openlp_process_events')
Receiver.send_message(u'cursor_normal')
Receiver.send_message(u'openlp_process_events')
return BibleDB.get_verses(self, reference_list)
return BibleDB.get_verses(self, reference_list, show_error)
def get_chapter(self, book, chapter):
"""

View File

@ -231,7 +231,7 @@ class BibleManager(object):
bible, book, chapter)
return self.db_cache[bible].get_verse_count(book, chapter)
def get_verses(self, bible, versetext):
def get_verses(self, bible, versetext, show_error=True):
"""
Parses a scripture reference, fetches the verses from the Bible
specified, and returns a list of ``Verse`` objects.
@ -252,32 +252,34 @@ class BibleManager(object):
"""
log.debug(u'BibleManager.get_verses("%s", "%s")', bible, versetext)
if not bible:
Receiver.send_message(u'openlp_information_message', {
u'title': translate('BiblesPlugin.BibleManager',
'No Bibles Available'),
u'message': translate('BiblesPlugin.BibleManager',
'There are no Bibles currently installed. Please use the '
'Import Wizard to install one or more Bibles.')
})
if show_error:
Receiver.send_message(u'openlp_information_message', {
u'title': translate('BiblesPlugin.BibleManager',
'No Bibles Available'),
u'message': translate('BiblesPlugin.BibleManager',
'There are no Bibles currently installed. Please use the '
'Import Wizard to install one or more Bibles.')
})
return None
reflist = parse_reference(versetext)
if reflist:
return self.db_cache[bible].get_verses(reflist)
return self.db_cache[bible].get_verses(reflist, show_error)
else:
Receiver.send_message(u'openlp_information_message', {
u'title': translate('BiblesPlugin.BibleManager',
'Scripture Reference Error'),
u'message': translate('BiblesPlugin.BibleManager',
'Your scripture reference is either not supported by OpenLP '
'or is invalid. Please make sure your reference conforms to '
'one of the following patterns:\n\n'
'Book Chapter\n'
'Book Chapter-Chapter\n'
'Book Chapter:Verse-Verse\n'
'Book Chapter:Verse-Verse,Verse-Verse\n'
'Book Chapter:Verse-Verse,Chapter:Verse-Verse\n'
'Book Chapter:Verse-Chapter:Verse')
})
if show_message:
Receiver.send_message(u'openlp_information_message', {
u'title': translate('BiblesPlugin.BibleManager',
'Scripture Reference Error'),
u'message': translate('BiblesPlugin.BibleManager',
'Your scripture reference is either not supported by OpenLP '
'or is invalid. Please make sure your reference conforms to '
'one of the following patterns:\n\n'
'Book Chapter\n'
'Book Chapter-Chapter\n'
'Book Chapter:Verse-Verse\n'
'Book Chapter:Verse-Verse,Verse-Verse\n'
'Book Chapter:Verse-Verse,Chapter:Verse-Verse\n'
'Book Chapter:Verse-Chapter:Verse')
})
return None
def verse_search(self, bible, second_bible, text):

View File

@ -590,7 +590,7 @@ class BibleMediaItem(MediaManagerItem):
item_second_bible = self._decodeQtObject(bitem, 'second_bible')
if item_second_bible and second_bible or not item_second_bible and \
not second_bible:
self.displayResults(bible, second_bible)
self.displayResults(bible, second_bible, self_search_results)
elif critical_error_message_box(
message=translate('BiblePlugin.MediaItem',
'You cannot combine single and dual Bible verse search results. '
@ -601,6 +601,18 @@ class BibleMediaItem(MediaManagerItem):
self.displayResults(bible, second_bible)
def displayResults(self, bible, second_bible=u''):
"""
Displays the search results in the media manager. All data needed for
further action is saved for/in each row.
"""
items = self.buildDisplayResults(bible, second_bible, self.search_results)
for bible_verse in items:
self.listView.addItem(bible_verse)
self.listView.selectAll()
self.search_results = {}
self.second_search_results = {}
def buildDisplayResults(self, bible, second_bible, search_results):
"""
Displays the search results in the media manager. All data needed for
further action is saved for/in each row.
@ -620,7 +632,8 @@ class BibleMediaItem(MediaManagerItem):
second_bible, u'Copyright').value
second_permissions = self.parent.manager.get_meta_data(
second_bible, u'Permissions').value
for count, verse in enumerate(self.search_results):
items = []
for count, verse in enumerate(search_results):
data = {
'book': QtCore.QVariant(verse.book.name),
'chapter': QtCore.QVariant(verse.chapter),
@ -652,10 +665,8 @@ class BibleMediaItem(MediaManagerItem):
verse.chapter, verse_separator, verse.verse, version)
bible_verse = QtGui.QListWidgetItem(bible_text)
bible_verse.setData(QtCore.Qt.UserRole, QtCore.QVariant(data))
self.listView.addItem(bible_verse)
self.listView.selectAll()
self.search_results = {}
self.second_search_results = {}
items.append(bible_verse)
return items
def _decodeQtObject(self, bitem, key):
reference = bitem.data(QtCore.Qt.UserRole)
@ -672,7 +683,10 @@ class BibleMediaItem(MediaManagerItem):
service item's title.
"""
log.debug(u'generating slide data')
items = self.listView.selectedIndexes()
if item:
items = item
else:
items = self.listView.selectedItems()
if len(items) == 0:
return False
bible_text = u''
@ -681,8 +695,7 @@ class BibleMediaItem(MediaManagerItem):
raw_slides = []
raw_title = []
verses = VerseReferenceList()
for item in items:
bitem = self.listView.item(item.row())
for bitem in items:
book = self._decodeQtObject(bitem, 'book')
chapter = int(self._decodeQtObject(bitem, 'chapter'))
verse = int(self._decodeQtObject(bitem, 'verse'))
@ -716,11 +729,11 @@ class BibleMediaItem(MediaManagerItem):
else:
bible_text = u'%s %s %s\n' % (bible_text, verse_text, text)
if not old_item:
start_item = item
elif self.checkTitle(item, old_item):
start_item = bitem
elif self.checkTitle(bitem, old_item):
raw_title.append(self.formatTitle(start_item, old_item))
start_item = item
old_item = item
start_item = bitem
old_item = bitem
old_chapter = chapter
# Add footer
service_item.raw_footer.append(verses.format_verses())
@ -728,7 +741,7 @@ class BibleMediaItem(MediaManagerItem):
verses.add_version(second_version, second_copyright,
second_permissions)
service_item.raw_footer.append(verses.format_versions())
raw_title.append(self.formatTitle(start_item, item))
raw_title.append(self.formatTitle(start_item, bitem))
# If there are no more items we check whether we have to add bible_text.
if bible_text:
raw_slides.append(bible_text.lstrip())
@ -751,9 +764,9 @@ class BibleMediaItem(MediaManagerItem):
[service_item.add_from_text(slide[:30], slide) for slide in raw_slides]
return True
def formatTitle(self, start_item, old_item):
def formatTitle(self, start_bitem, old_bitem):
"""
This methode is called, when we have to change the title, because
This method is called, when we have to change the title, because
we are at the end of a verse range. E. g. if we want to add
Genesis 1:1-6 as well as Daniel 2:14.
@ -765,10 +778,8 @@ class BibleMediaItem(MediaManagerItem):
"""
verse_separator = get_reference_match(u'sep_v_display')
range_separator = get_reference_match(u'sep_r_display')
old_bitem = self.listView.item(old_item.row())
old_chapter = self._decodeQtObject(old_bitem, 'chapter')
old_verse = self._decodeQtObject(old_bitem, 'verse')
start_bitem = self.listView.item(start_item.row())
start_book = self._decodeQtObject(start_bitem, 'book')
start_chapter = self._decodeQtObject(start_bitem, 'chapter')
start_verse = self._decodeQtObject(start_bitem, 'verse')
@ -789,9 +800,9 @@ class BibleMediaItem(MediaManagerItem):
range_separator + old_chapter + verse_separator + old_verse
return u'%s %s (%s)' % (start_book, verse_range, bibles)
def checkTitle(self, item, old_item):
def checkTitle(self, bitem, old_bitem):
"""
This methode checks if we are at the end of an verse range. If that is
This method checks if we are at the end of an verse range. If that is
the case, we return True, otherwise False. E. g. if we added
Genesis 1:1-6, but the next verse is Daniel 2:14, we return True.
@ -802,13 +813,11 @@ class BibleMediaItem(MediaManagerItem):
The item we were previously dealing with.
"""
# Get all the necessary meta data.
bitem = self.listView.item(item.row())
book = self._decodeQtObject(bitem, 'book')
chapter = int(self._decodeQtObject(bitem, 'chapter'))
verse = int(self._decodeQtObject(bitem, 'verse'))
bible = self._decodeQtObject(bitem, 'bible')
second_bible = self._decodeQtObject(bitem, 'second_bible')
old_bitem = self.listView.item(old_item.row())
old_book = self._decodeQtObject(old_bitem, 'book')
old_chapter = int(self._decodeQtObject(old_bitem, 'chapter'))
old_verse = int(self._decodeQtObject(old_bitem, 'verse'))
@ -868,3 +877,32 @@ class BibleMediaItem(MediaManagerItem):
QtCore.QSettings().setValue(
self.settingsSection + u'/verse layout style',
QtCore.QVariant(self.settings.layout_style))
def hasSearch(self):
"""
Returns whether this plugin supports the search method
"""
return True
def search(self, string):
"""
Search for some Bible verses (by reference).
"""
bible = unicode(self.quickVersionComboBox.currentText())
search_results = self.parent.manager.get_verses(bible, string, False)
results = []
if search_results:
versetext = u''
for verse in search_results:
if versetext:
versetext += u' '
versetext += verse.text
results.append([string, versetext])
return results
def createItemFromId(self, item_id):
item = QtGui.QListWidgetItem()
bible = unicode(self.quickVersionComboBox.currentText())
search_results = self.parent.manager.get_verses(bible, item_id, False)
items = self.buildDisplayResults(bible, u'', search_results)
return items

View File

@ -51,34 +51,42 @@
<div data-role="header">
<a href="#" data-rel="back" data-icon="arrow-l">Back</a>
<h1>Service Manager</h1>
</div>
<a href="#" id="service-refresh" data-role="button" data-icon="refresh">Refresh</a>
</div>
<div data-role="content">
<div class="ui-grid-c">
<div class="ui-block-a"><a href="#" id="service-blank" data-role="button" data-icon="blank">Blank</a></div>
<div class="ui-block-b"><a href="#" id="service-unblank" data-role="button" data-icon="unblank">Unblank</a></div>
<div class="ui-block-c"><a href="#" id="service-previous" data-role="button" data-icon="arrow-l">Previous</a></div>
<div class="ui-block-d"><a href="#" id="service-next" data-role="button" data-icon="arrow-r" data-iconpos="right">Next</a></div>
</div>
<ul data-role="listview" data-inset="true">
</ul>
</div>
<div data-role="footer" data-theme="b" class="ui-bar">
<a href="#" id="service-blank" data-role="button" data-icon="blank">Blank</a>
<a href="#" id="service-unblank" data-role="button" data-icon="unblank">Unblank</a>
<a href="#" id="service-refresh" data-role="button" data-icon="refresh">Refresh</a>
<a href="#" id="service-previous" data-role="button" data-icon="arrow-l">Previous</a>
<a href="#" id="service-next" data-role="button" data-icon="arrow-r" data-iconpos="right">Next</a>
<a href="#" id="service-previousslide" data-role="button" data-icon="arrow-l">Previous Slide</a>
<a href="#" class="ui-btn-right" id="service-nextslide" data-role="button" data-icon="arrow-r" data-iconpos="right">Next Slide</a>
</div>
</div>
<div data-role="page" id="slide-controller">
<div data-role="header">
<a href="#" data-rel="back" data-icon="arrow-l">Back</a>
<h1>Slide Controller</h1>
<a href="#" id="controller-refresh" data-role="button" data-icon="refresh">Refresh</a>
</div>
<div data-role="content">
<div class="ui-grid-c">
<div class="ui-block-a"><a href="#" id="controller-blank" data-role="button" data-icon="blank">Blank</a></div>
<div class="ui-block-d"><a href="#" id="controller-unblank" data-role="button" data-icon="unblank">Unblank</a></div>
<div class="ui-block-c"><a href="#" id="controller-previous" data-role="button" data-icon="arrow-l">Previous</a></div>
<div class="ui-block-d"><a href="#" id="controller-next" data-role="button" data-icon="arrow-r" data-iconpos="right">Next</a></div>
</div>
<ul data-role="listview" data-inset="true">
</ul>
</div>
</div>
<div data-role="footer" data-theme="b" class="ui-bar">
<a href="#" id="controller-blank" data-role="button" data-icon="blank">Blank</a>
<a href="#" id="controller-unblank" data-role="button" data-icon="unblank">Unblank</a>
<a href="#" id="controller-refresh" data-role="button" data-icon="refresh">Refresh</a>
<a href="#" id="controller-previous" data-role="button" data-icon="arrow-l">Previous</a>
<a href="#" id="controller-next" data-role="button" data-icon="arrow-r" data-iconpos="right">Next</a>
<a href="#" id="controller-prevsong" data-role="button" data-icon="arrow-l">Previous Song</a>
<a href="#" class="ui-btn-right" id="controller-nextsong" data-role="button" data-icon="arrow-r" data-iconpos="right">Next Song</a>
</div>
</div>
<div data-role="page" id="alerts">
@ -101,8 +109,12 @@
</div>
<div data-role="content">
<div data-role="fieldcontain">
<label for="search-text">Search:</label>
<input type="text" name="search-text" id="search-text" value="" />
<label for="search-plugin">Search:</label>
<select name="search-plugin" id="search-plugin" data-native-menu="false"></select>
</div>
<div data-role="fieldcontain">
<label for="search-text">For:</label>
<input type="search" name="search-text" id="search-text" value="" />
</div>
<a href="#" id="search-submit" data-role="button">Search</a>
<ul data-role="listview" data-inset="true">

View File

@ -39,6 +39,19 @@ window.OpenLP = {
}
return $(targ);
},
searchPlugins: function (event) {
$.getJSON(
"/api/plugin/search",
function (data, status) {
var select = $("#search-plugin");
select.html("");
$.each(data.results.items, function (idx, value) {
select.append("<option value='" + value + "'>" + value + "</option>");
});
select.selectmenu("refresh");
}
);
},
loadService: function (event) {
$.getJSON(
"/api/service/list",
@ -193,7 +206,7 @@ window.OpenLP = {
search: function (event) {
var text = JSON.stringify({"request": {"text": $("#search-text").val()}});
$.getJSON(
"/api/Songs/search",
"/api/" + $("#search-plugin").val() + "/search",
{"data": text},
function (data, status) {
var ul = $("#search > div[data-role=content] > ul[data-role=listview]");
@ -220,9 +233,9 @@ window.OpenLP = {
var id = slide.attr("value");
var text = JSON.stringify({"request": {"id": id}});
$.getJSON(
"/api/Songs/live",
"/api/" + $("#search-plugin").val() + "/live",
{"data": text})
window.location.replace('/#slide-controller');
$.mobile.changePage("slide-controller");
return false;
}
@ -234,6 +247,8 @@ $("#service-next").live("click", OpenLP.nextItem);
$("#service-previous").live("click", OpenLP.previousItem);
$("#service-blank").live("click", OpenLP.blankDisplay);
$("#service-unblank").live("click", OpenLP.unblankDisplay);
$("#service-nextslide").live("click", OpenLP.nextSlide);
$("#service-previousslide").live("click", OpenLP.previousSlide);
// Slide Controller
$("#slide-controller").live("pagebeforeshow", OpenLP.loadController);
$("#controller-refresh").live("click", OpenLP.loadController);
@ -241,11 +256,14 @@ $("#controller-next").live("click", OpenLP.nextSlide);
$("#controller-previous").live("click", OpenLP.previousSlide);
$("#controller-blank").live("click", OpenLP.blankDisplay);
$("#controller-unblank").live("click", OpenLP.unblankDisplay);
$("#controller-nextsong").live("click", OpenLP.nextItem);
$("#controller-previoussong").live("click", OpenLP.previousItem);
// Alerts
$("#alert-submit").live("click", OpenLP.showAlert);
// Search
$("#search-submit").live("click", OpenLP.search);
// Poll the server twice a second to get any updates.
OpenLP.searchPlugins();
$.ajaxSetup({ cache: false });
setInterval("OpenLP.pollServer();", 500);
OpenLP.pollServer();

View File

@ -458,7 +458,7 @@ class HttpConnection(object):
for plugin in self.parent.parent.pluginManager.plugins:
media_item = plugin.mediaItem
if media_item and media_item.hasSearch():
searches.append(plugin.Name)
searches.append(plugin.name)
return HttpResponse(
json.dumps({u'results': {u'items': searches}}),
{u'Content-Type': u'application/json'})