From 6f51b68824162a5a43d880d145cee5d48ef351aa Mon Sep 17 00:00:00 2001 From: Tim Bentley Date: Sat, 13 Nov 2010 07:30:34 +0000 Subject: [PATCH 1/5] Sort theme --- openlp/core/ui/thememanager.py | 1 + 1 file changed, 1 insertion(+) diff --git a/openlp/core/ui/thememanager.py b/openlp/core/ui/thememanager.py index 2f060b12f..1b349a1e4 100644 --- a/openlp/core/ui/thememanager.py +++ b/openlp/core/ui/thememanager.py @@ -462,6 +462,7 @@ class ThemeManager(QtGui.QWidget): self.themelist = [] self.themeListWidget.clear() dirList = os.listdir(self.path) + dirList.sort() for name in dirList: if name.endswith(u'.png'): # check to see file is in theme root directory From 8ed5bb883e428d0486d1a291ff1b3a6ac40ff342 Mon Sep 17 00:00:00 2001 From: Raoul Snyman Date: Tue, 16 Nov 2010 08:19:23 +0200 Subject: [PATCH 2/5] Added a "re-index" tool for songs. --- openlp/core/lib/db.py | 37 +++++++++++++++++++++ openlp/plugins/songs/songsplugin.py | 51 +++++++++++++++++++++++++++++ 2 files changed, 88 insertions(+) diff --git a/openlp/core/lib/db.py b/openlp/core/lib/db.py index e59a9737b..0dc138abc 100644 --- a/openlp/core/lib/db.py +++ b/openlp/core/lib/db.py @@ -158,6 +158,27 @@ class Manager(object): log.exception(u'Object save failed') return False + def save_objects(self, object_list, commit=True): + """ + Save a list of objects to the database + + ``object_list`` + The list of objects to save + + ``commit`` + Commit the session with this object + """ + try: + self.session.add_all(object_list) + if commit: + self.session.commit() + self.is_dirty = True + return True + except InvalidRequestError: + self.session.rollback() + log.exception(u'Object list save failed') + return False + def get_object(self, object_class, key=None): """ Return the details of an object @@ -207,6 +228,22 @@ class Manager(object): return query.order_by(order_by_ref).all() return query.all() + def get_object_count(self, object_class, filter_clause=None): + """ + Returns a count of the number of objects in the database. + + ``object_class`` + The type of objects to return. + + ``filter_clause`` + The filter governing selection of objects to return. Defaults to + None. + """ + query = self.session.query(object_class) + if filter_clause is not None: + query = query.filter(filter_clause) + return query.count() + def delete_object(self, object_class, key): """ Delete an object from the database diff --git a/openlp/plugins/songs/songsplugin.py b/openlp/plugins/songs/songsplugin.py index dea60cdc0..615f284c2 100644 --- a/openlp/plugins/songs/songsplugin.py +++ b/openlp/plugins/songs/songsplugin.py @@ -25,6 +25,7 @@ ############################################################################### import logging +import re from PyQt4 import QtCore, QtGui @@ -55,6 +56,7 @@ class SongsPlugin(Plugin): self.manager = Manager(u'songs', init_schema) self.icon_path = u':/plugins/plugin_songs.png' self.icon = build_icon(self.icon_path) + self.whitespace = re.compile(r'\W+') def getSettingsTab(self): visible_name = self.getString(StringContent.VisibleName) @@ -63,6 +65,7 @@ class SongsPlugin(Plugin): def initialise(self): log.info(u'Songs Initialising') Plugin.initialise(self) + self.toolsReindexItem.setVisible(True) self.mediaItem.displayResultsSong( self.manager.get_all_objects(Song, order_by_ref=Song.search_title)) @@ -106,6 +109,52 @@ class SongsPlugin(Plugin): # No menu items for now. pass + def addToolsMenuItem(self, tools_menu): + """ + Give the alerts plugin the opportunity to add items to the + **Tools** menu. + + ``tools_menu`` + The actual **Tools** menu item, so that your actions can + use it as their parent. + """ + log.info(u'add tools menu') + self.toolsReindexItem = QtGui.QAction(tools_menu) + self.toolsReindexItem.setIcon(build_icon(u':/plugins/plugin_songs.png')) + self.toolsReindexItem.setObjectName(u'toolsReindexItem') + self.toolsReindexItem.setText(translate('SongsPlugin', '&Reindex Songs')) + self.toolsReindexItem.setStatusTip( + translate('SongsPlugin', 'Rsindex the songs database to improve ' + 'searching and ordering.')) + #self.toolsReindexItem.setShortcut(u'F7') + tools_menu.addAction(self.toolsReindexItem) + QtCore.QObject.connect(self.toolsReindexItem, + QtCore.SIGNAL(u'triggered()'), self.onToolsReindexItemTriggered) + self.toolsReindexItem.setVisible(False) + + def onToolsReindexItemTriggered(self): + """ + Rebuild the search title of each song. + """ + maxSongs = self.manager.get_object_count(Song) + progressDialog = QtGui.QProgressDialog( + translate('SongsPlugin', 'Reindexing songs...'), + translate('SongsPlugin', 'Cancel'), + 0, maxSongs + 1, self.formparent) + progressDialog.setWindowModality(QtCore.Qt.WindowModal) + songs = self.manager.get_all_objects(Song) + counter = 0 + for song in songs: + counter += 1 + song.search_title = self.whitespace.sub(u' ', song.title.lower()) +\ + u' ' + self.whitespace.sub(u' ', song.alternate_title.lower()) + progressDialog.setValue(counter) + self.manager.save_objects(songs) + counter += 1 + progressDialog.setValue(counter) + self.mediaItem.displayResultsSong( + self.manager.get_all_objects(Song, order_by_ref=Song.search_title)) + def onSongImportItemClicked(self): if self.mediaItem: self.mediaItem.onImportClick() @@ -206,4 +255,6 @@ class SongsPlugin(Plugin): """ log.info(u'Songs Finalising') self.manager.finalise() + self.toolsReindexItem.setVisible(False) Plugin.finalise(self) + From 59f47a5e1f544d9a1c633c24b03e7568bc66cd99 Mon Sep 17 00:00:00 2001 From: Raoul Snyman Date: Tue, 16 Nov 2010 08:20:39 +0200 Subject: [PATCH 3/5] Fix the spelling. --- openlp/plugins/songs/songsplugin.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/openlp/plugins/songs/songsplugin.py b/openlp/plugins/songs/songsplugin.py index 615f284c2..c3b75ff28 100644 --- a/openlp/plugins/songs/songsplugin.py +++ b/openlp/plugins/songs/songsplugin.py @@ -122,9 +122,9 @@ class SongsPlugin(Plugin): self.toolsReindexItem = QtGui.QAction(tools_menu) self.toolsReindexItem.setIcon(build_icon(u':/plugins/plugin_songs.png')) self.toolsReindexItem.setObjectName(u'toolsReindexItem') - self.toolsReindexItem.setText(translate('SongsPlugin', '&Reindex Songs')) + self.toolsReindexItem.setText(translate('SongsPlugin', '&Re-index Songs')) self.toolsReindexItem.setStatusTip( - translate('SongsPlugin', 'Rsindex the songs database to improve ' + translate('SongsPlugin', 'Re-index the songs database to improve ' 'searching and ordering.')) #self.toolsReindexItem.setShortcut(u'F7') tools_menu.addAction(self.toolsReindexItem) From 689cddf3e47572cfaeb77229ce900d6a6fdcb140 Mon Sep 17 00:00:00 2001 From: Raoul Snyman Date: Tue, 16 Nov 2010 11:29:46 +0200 Subject: [PATCH 4/5] Removed an unnecessary line. --- openlp/plugins/songs/songsplugin.py | 1 - 1 file changed, 1 deletion(-) diff --git a/openlp/plugins/songs/songsplugin.py b/openlp/plugins/songs/songsplugin.py index c3b75ff28..87a652f71 100644 --- a/openlp/plugins/songs/songsplugin.py +++ b/openlp/plugins/songs/songsplugin.py @@ -126,7 +126,6 @@ class SongsPlugin(Plugin): self.toolsReindexItem.setStatusTip( translate('SongsPlugin', 'Re-index the songs database to improve ' 'searching and ordering.')) - #self.toolsReindexItem.setShortcut(u'F7') tools_menu.addAction(self.toolsReindexItem) QtCore.QObject.connect(self.toolsReindexItem, QtCore.SIGNAL(u'triggered()'), self.onToolsReindexItemTriggered) From aadc913ba19a4d2eb1c3813483aea864eda9abc6 Mon Sep 17 00:00:00 2001 From: Raoul Snyman Date: Tue, 16 Nov 2010 19:12:11 +0200 Subject: [PATCH 5/5] Fix a bug where a null field would cause an exception. --- openlp/plugins/songs/songsplugin.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/openlp/plugins/songs/songsplugin.py b/openlp/plugins/songs/songsplugin.py index 87a652f71..338179037 100644 --- a/openlp/plugins/songs/songsplugin.py +++ b/openlp/plugins/songs/songsplugin.py @@ -145,6 +145,10 @@ class SongsPlugin(Plugin): counter = 0 for song in songs: counter += 1 + if song.title is None: + song.title = u'' + if song.alternate_title is None: + song.alternate_title = u'' song.search_title = self.whitespace.sub(u' ', song.title.lower()) +\ u' ' + self.whitespace.sub(u' ', song.alternate_title.lower()) progressDialog.setValue(counter)