forked from openlp/openlp
HEAD r1887
This commit is contained in:
commit
e359f764b4
@ -199,6 +199,10 @@ class Manager(object):
|
||||
urlquote(unicode(settings.value(u'db password').toString())),
|
||||
urlquote(unicode(settings.value(u'db hostname').toString())),
|
||||
urlquote(unicode(settings.value(u'db database').toString())))
|
||||
if db_type == u'mysql':
|
||||
db_encoding = unicode(
|
||||
settings.value(u'db encoding', u'utf8').toString())
|
||||
self.db_url += u'?charset=%s' % urlquote(db_encoding)
|
||||
settings.endGroup()
|
||||
if upgrade_mod:
|
||||
db_ver, up_ver = upgrade_db(self.db_url, upgrade_mod)
|
||||
|
@ -43,7 +43,7 @@ from openlp.plugins.songs.forms import EditSongForm, SongMaintenanceForm, \
|
||||
SongImportForm, SongExportForm
|
||||
from openlp.plugins.songs.lib import OpenLyrics, SongXML, VerseType, \
|
||||
clean_string
|
||||
from openlp.plugins.songs.lib.db import Author, Song, MediaFile
|
||||
from openlp.plugins.songs.lib.db import Author, Song, Book, MediaFile
|
||||
from openlp.plugins.songs.lib.ui import SongStrings
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
@ -56,7 +56,8 @@ class SongSearch(object):
|
||||
Titles = 2
|
||||
Lyrics = 3
|
||||
Authors = 4
|
||||
Themes = 5
|
||||
Books = 5
|
||||
Themes = 6
|
||||
|
||||
|
||||
class SongMediaItem(MediaManagerItem):
|
||||
@ -158,6 +159,8 @@ class SongMediaItem(MediaManagerItem):
|
||||
translate('SongsPlugin.MediaItem', 'Lyrics')),
|
||||
(SongSearch.Authors, u':/songs/song_search_author.png',
|
||||
SongStrings.Authors),
|
||||
(SongSearch.Books, u':/songs/song_book_edit.png',
|
||||
SongStrings.SongBooks),
|
||||
(SongSearch.Themes, u':/slides/slide_theme.png', UiStrings().Themes)
|
||||
])
|
||||
self.searchTextEdit.setCurrentSearchType(QtCore.QSettings().value(
|
||||
@ -196,6 +199,19 @@ class SongMediaItem(MediaManagerItem):
|
||||
Author.display_name.like(u'%' + search_keywords + u'%'),
|
||||
Author.display_name.asc())
|
||||
self.displayResultsAuthor(search_results)
|
||||
elif search_type == SongSearch.Books:
|
||||
log.debug(u'Books Search')
|
||||
search_results = self.plugin.manager.get_all_objects(Book,
|
||||
Book.name.like(u'%' + search_keywords + u'%'),
|
||||
Book.name.asc())
|
||||
song_number = False
|
||||
if not search_results:
|
||||
search_keywords = search_keywords.rpartition(' ')
|
||||
search_results = self.plugin.manager.get_all_objects(Book,
|
||||
Book.name.like(u'%' + search_keywords[0] + u'%'),
|
||||
Book.name.asc())
|
||||
song_number = re.sub(r'[^0-9]', u'', search_keywords[2])
|
||||
self.displayResultsBook(search_results, song_number)
|
||||
elif search_type == SongSearch.Themes:
|
||||
log.debug(u'Theme Search')
|
||||
search_results = self.plugin.manager.get_all_objects(Song,
|
||||
@ -270,6 +286,25 @@ class SongMediaItem(MediaManagerItem):
|
||||
song_name.setData(QtCore.Qt.UserRole, QtCore.QVariant(song.id))
|
||||
self.listView.addItem(song_name)
|
||||
|
||||
def displayResultsBook(self, searchresults, song_number=False):
|
||||
log.debug(u'display results Book')
|
||||
self.listView.clear()
|
||||
for book in searchresults:
|
||||
songs = sorted(book.songs, key=lambda song: int(
|
||||
re.sub(r'[^0-9]', u' ', song.song_number).partition(' ')[0])
|
||||
if len(re.sub(r'[^\w]', ' ', song.song_number)) else 0)
|
||||
for song in songs:
|
||||
# Do not display temporary songs
|
||||
if song.temporary:
|
||||
continue
|
||||
if song_number and not song_number in song.song_number:
|
||||
continue
|
||||
song_detail = u'%s - %s (%s)' % (book.name, song.song_number,
|
||||
song.title)
|
||||
song_name = QtGui.QListWidgetItem(song_detail)
|
||||
song_name.setData(QtCore.Qt.UserRole, QtCore.QVariant(song.id))
|
||||
self.listView.addItem(song_name)
|
||||
|
||||
def onClearTextButtonClick(self):
|
||||
"""
|
||||
Clear the search text.
|
||||
|
Loading…
Reference in New Issue
Block a user