Add Author Search to Song Plugin

This commit is contained in:
Tim Bentley 2009-06-21 18:45:59 +01:00
parent c0df49e551
commit 3c255076f9
3 changed files with 39 additions and 21 deletions

View File

@ -60,8 +60,8 @@ class SongManager():
metadata.create_all()
log.debug(u'Song Initialised')
def process_dialog(self, dialogobject):
self.dialogobject = dialogobject
# def process_dialog(self, dialogobject):
# self.dialogobject = dialogobject
def get_songs(self):
"""
@ -81,6 +81,12 @@ class SongManager():
"""
return self.session.query(Song).filter(Song.search_lyrics.like(u'%' + keywords + u'%')).order_by(Song.search_lyrics.asc()).all()
def get_song_from_author(self, keywords):
"""
Searches the song authors for keywords.
"""
return self.session.query(Author).filter(Author.display_name.like(u'%' + keywords + u'%')).order_by(Author.display_name.asc()).all()
def get_song(self, id=None):
"""
Returns the details of a song

View File

@ -160,8 +160,25 @@ class SongMediaItem(MediaManagerItem):
self.SearchTypeComboBox.addItem(translate(u'SongMediaItem', u'Lyrics'))
self.SearchTypeComboBox.addItem(translate(u'SongMediaItem', u'Authors'))
def displayResults(self, searchresults):
log.debug(u'display results')
def onSearchTextButtonClick(self):
search_keywords = unicode(self.SearchTextEdit.displayText())
search_results = []
search_type = self.SearchTypeComboBox.currentIndex()
if search_type == 0:
log.debug(u'Titles Search')
search_results = self.parent.songmanager.search_song_title(search_keywords)
self.displayResultsSong(search_results)
elif search_type == 1:
log.debug(u'Lyrics Search')
search_results = self.parent.songmanager.search_song_lyrics(search_keywords)
self.displayResultsSong(search_results)
elif search_type == 2:
log.debug(u'Authors Search')
search_results = self.parent.songmanager.get_song_from_author(search_keywords)
self.displayResultsAuthor(search_results)
def displayResultsSong(self, searchresults):
log.debug(u'display results Song')
self.SongListWidget.clear()
#log.debug(u'Records returned from search %s", len(searchresults))
for song in searchresults:
@ -175,6 +192,16 @@ class SongMediaItem(MediaManagerItem):
song_name.setData(QtCore.Qt.UserRole, QtCore.QVariant(song.id))
self.SongListWidget.addItem(song_name)
def displayResultsAuthor(self, searchresults):
log.debug(u'display results Author')
self.SongListWidget.clear()
for author in searchresults:
for song in author.songs:
song_detail = unicode(u'%s (%s)' % (unicode(author.display_name), unicode(song.title)))
song_name = QtGui.QListWidgetItem(song_detail)
song_name.setData(QtCore.Qt.UserRole, QtCore.QVariant(song.id))
self.SongListWidget.addItem(song_name)
def onClearTextButtonClick(self):
"""
Clear the search text.
@ -188,21 +215,6 @@ class SongMediaItem(MediaManagerItem):
if len(text) > search_length:
self.onSearchTextButtonClick()
def onSearchTextButtonClick(self):
search_keywords = unicode(self.SearchTextEdit.displayText())
search_results = []
search_type = self.SearchTypeComboBox.currentIndex()
if search_type == 0:
log.debug(u'Titles Search')
search_results = self.parent.songmanager.search_song_title(search_keywords)
elif search_type == 1:
log.debug(u'Lyrics Search')
search_results = self.parent.songmanager.search_song_lyrics(search_keywords)
elif search_type == 2:
log.debug(u'Authors Search')
#searchresults = self.songmanager.get_song_from_author(searchtext)
self.displayResults(search_results)
def onSongNewClick(self):
self.edit_song_form.newSong()
self.edit_song_form.exec_()

View File

@ -103,7 +103,7 @@ class SongsPlugin(Plugin):
QtCore.QObject.connect(self.ExportOpenSongItem, QtCore.SIGNAL(u'triggered()'), self.onExportOpenSongItemClicked)
def initialise(self):
self.media_item.displayResults(self.songmanager.get_songs())
self.media_item.displayResultsSong(self.songmanager.get_songs())
def onImportOpenlp1ItemClick(self):
self.openlp_import_form.show()
@ -136,4 +136,4 @@ class SongsPlugin(Plugin):
self.media_item.onSongLiveClick()
if event.event_type == EventType.LoadSongList :
log.debug(u'Load Load Song List Item received')
self.media_item.displayResults(self.songmanager.get_songs())
self.media_item.displayResults(self.songmanager.get_songs())