← Back to team overview

openlp-core team mailing list archive

[Merge] lp:~googol-hush/openlp/trivial into lp:openlp

 

googol has proposed merging lp:~googol-hush/openlp/trivial into lp:openlp.

Requested reviews:
  Raoul Snyman (raoul-snyman): error in logic
  Tim Bentley (trb143)
  Jon Tibble (meths)


- changed error messages
- name standardisation (now: song book or song books)
- Added message box providing the possibility to merge to books/authors/topics
-- 
https://code.launchpad.net/~googol-hush/openlp/trivial/+merge/30285
Your team OpenLP Core is subscribed to branch lp:openlp.
=== modified file 'openlp/plugins/bibles/bibleplugin.py'
--- openlp/plugins/bibles/bibleplugin.py	2010-07-12 21:11:00 +0000
+++ openlp/plugins/bibles/bibleplugin.py	2010-07-19 15:06:22 +0000
@@ -40,7 +40,7 @@
         self.weight = -9
         self.icon_path = u':/plugins/plugin_bibles.png'
         self.icon = build_icon(self.icon_path)
-        #Register the bible Manager
+        # Register the bible Manager.
         self.status = PluginStatus.Active
         self.manager = None
 
@@ -62,7 +62,7 @@
         return BiblesTab(self.name)
 
     def getMediaManagerItem(self):
-        # Create the BibleManagerItem object
+        # Create the BibleManagerItem object.
         return BibleMediaItem(self, self.icon, self.name)
 
     def addImportMenuItem(self, import_menu):
@@ -71,7 +71,7 @@
         import_menu.addAction(self.ImportBibleItem)
         self.ImportBibleItem.setText(
             translate('BiblePlugin', '&Bible'))
-        # Signals and slots
+        # signals and slots
         QtCore.QObject.connect(self.ImportBibleItem,
             QtCore.SIGNAL(u'triggered()'), self.onBibleImportClick)
         self.ImportBibleItem.setVisible(False)

=== modified file 'openlp/plugins/bibles/lib/mediaitem.py'
--- openlp/plugins/bibles/lib/mediaitem.py	2010-07-08 13:50:06 +0000
+++ openlp/plugins/bibles/lib/mediaitem.py	2010-07-19 15:06:22 +0000
@@ -129,8 +129,7 @@
         self.QuickClearLabel.setObjectName(u'QuickSearchLabel')
         self.QuickLayout.addWidget(self.QuickClearLabel, 4, 0, 1, 1)
         self.ClearQuickSearchComboBox = QtGui.QComboBox(self.QuickTab)
-        self.ClearQuickSearchComboBox.setObjectName(
-            u'ClearQuickSearchComboBox')
+        self.ClearQuickSearchComboBox.setObjectName(u'ClearQuickSearchComboBox')
         self.QuickLayout.addWidget(self.ClearQuickSearchComboBox, 4, 1, 1, 2)
         self.QuickSearchButtonLayout = QtGui.QHBoxLayout()
         self.QuickSearchButtonLayout.setMargin(0)
@@ -168,8 +167,7 @@
         self.AdvancedVersionComboBox.setObjectName(u'AdvancedVersionComboBox')
         self.AdvancedLayout.addWidget(self.AdvancedVersionComboBox, 0, 1, 1, 2)
         self.AdvancedSecondBibleLabel = QtGui.QLabel(self.AdvancedTab)
-        self.AdvancedSecondBibleLabel.setObjectName(
-            u'AdvancedSecondBibleLabel')
+        self.AdvancedSecondBibleLabel.setObjectName(u'AdvancedSecondBibleLabel')
         self.AdvancedLayout.addWidget(self.AdvancedSecondBibleLabel, 1, 0, 1, 1)
         self.AdvancedSecondBibleComboBox = QtGui.QComboBox(self.AdvancedTab)
         self.AdvancedSecondBibleComboBox.setSizeAdjustPolicy(
@@ -223,8 +221,7 @@
             u'AdvancedSearchButtonLayout')
         self.AdvancedSearchButtonSpacer = QtGui.QSpacerItem(40, 20,
             QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Minimum)
-        self.AdvancedSearchButtonLayout.addItem(
-            self.AdvancedSearchButtonSpacer)
+        self.AdvancedSearchButtonLayout.addItem(self.AdvancedSearchButtonSpacer)
         self.AdvancedSearchButton = QtGui.QPushButton(self.AdvancedTab)
         self.AdvancedSearchButton.setObjectName(u'AdvancedSearchButton')
         self.AdvancedSearchButtonLayout.addWidget(self.AdvancedSearchButton)
@@ -618,8 +615,7 @@
         else:
             self.AdvancedSearchButton.setEnabled(True)
             self.AdvancedMessage.setText(u'')
-            self.adjustComboBox(1, self.chapters_from,
-                self.AdvancedFromChapter)
+            self.adjustComboBox(1, self.chapters_from, self.AdvancedFromChapter)
             self.adjustComboBox(1, self.chapters_from, self.AdvancedToChapter)
             self.adjustComboBox(1, self.verses, self.AdvancedFromVerse)
             self.adjustComboBox(1, self.verses, self.AdvancedToVerse)

=== modified file 'openlp/plugins/songs/forms/authorsform.py'
--- openlp/plugins/songs/forms/authorsform.py	2010-06-22 14:34:03 +0000
+++ openlp/plugins/songs/forms/authorsform.py	2010-07-19 15:06:22 +0000
@@ -97,7 +97,7 @@
             if QtGui.QMessageBox.critical(
                     self, translate('SongsPlugin.AuthorsForm', 'Error'),
                     translate('SongsPlugin.AuthorsForm',
-                        'You haven\'t set a display name for the '
+                        'You have not set a display name for the '
                         'author, would you like me to combine the first and '
                         'last names for you?'),
                     QtGui.QMessageBox.StandardButtons(

=== modified file 'openlp/plugins/songs/forms/editsongdialog.py'
--- openlp/plugins/songs/forms/editsongdialog.py	2010-07-16 12:31:47 +0000
+++ openlp/plugins/songs/forms/editsongdialog.py	2010-07-19 15:06:22 +0000
@@ -430,7 +430,7 @@
         self.AuthorRemoveButton.setText(
             translate('SongsPlugin.EditSongForm', '&Remove'))
         self.MaintenanceButton.setText(translate('SongsPlugin.EditSongForm',
-            '&Manage Authors, Topics, Books'))
+            '&Manage Authors, Topics, Song Books'))
         self.TopicGroupBox.setTitle(
             translate('SongsPlugin.EditSongForm', 'Topic'))
         self.TopicAddButton.setText(
@@ -441,7 +441,7 @@
             translate('SongsPlugin.EditSongForm', 'Song Book'))
         self.SongTabWidget.setTabText(
             self.SongTabWidget.indexOf(self.AuthorsTab),
-            translate('SongsPlugin.EditSongForm', 'Authors, Topics && Book'))
+            translate('SongsPlugin.EditSongForm', 'Authors, Topics && Song Book'))
         self.ThemeGroupBox.setTitle(
             translate('SongsPlugin.EditSongForm', 'Theme'))
         self.ThemeAddButton.setText(

=== modified file 'openlp/plugins/songs/forms/songbookdialog.py'
--- openlp/plugins/songs/forms/songbookdialog.py	2010-06-22 14:34:03 +0000
+++ openlp/plugins/songs/forms/songbookdialog.py	2010-07-19 15:06:22 +0000
@@ -68,7 +68,7 @@
 
     def retranslateUi(self, SongBookDialog):
         SongBookDialog.setWindowTitle(
-            translate('SongsPlugin.SongBookForm', 'Edit Book'))
+            translate('SongsPlugin.SongBookForm', 'Song Book Maintenance'))
         self.NameLabel.setText(translate('SongsPlugin.SongBookForm', '&Name:'))
         self.PublisherLabel.setText(
             translate('SongsPlugin.SongBookForm', '&Publisher:'))

=== modified file 'openlp/plugins/songs/forms/songmaintenancedialog.py'
--- openlp/plugins/songs/forms/songmaintenancedialog.py	2010-06-18 19:55:45 +0000
+++ openlp/plugins/songs/forms/songmaintenancedialog.py	2010-07-19 15:06:22 +0000
@@ -217,7 +217,7 @@
         self.TypeListWidget.item(1).setText(
             translate('SongsPlugin.SongMaintenanceForm', 'Topics'))
         self.TypeListWidget.item(2).setText(
-            translate('SongsPlugin.SongMaintenanceForm', 'Books/Hymnals'))
+            translate('SongsPlugin.SongMaintenanceForm', 'Song Books'))
         self.AuthorAddButton.setText(
             translate('SongsPlugin.SongMaintenanceForm', '&Add'))
         self.AuthorEditButton.setText(

=== modified file 'openlp/plugins/songs/forms/songmaintenanceform.py'
--- openlp/plugins/songs/forms/songmaintenanceform.py	2010-07-16 18:53:49 +0000
+++ openlp/plugins/songs/forms/songmaintenanceform.py	2010-07-19 15:06:22 +0000
@@ -26,9 +26,9 @@
 from PyQt4 import QtGui, QtCore
 from sqlalchemy.sql import and_
 
-from openlp.core.lib import translate
+from openlp.core.lib import Receiver, translate
 from openlp.plugins.songs.forms import AuthorsForm, TopicsForm, SongBookForm
-from openlp.plugins.songs.lib.db import Author, Book, Topic
+from openlp.plugins.songs.lib.db import Author, Book, Topic, Song
 from songmaintenancedialog import Ui_SongMaintenanceDialog
 
 class SongMaintenanceForm(QtGui.QDialog, Ui_SongMaintenanceDialog):
@@ -140,13 +140,10 @@
         Returns False if the given Author is already in the list otherwise
         True.
         """
-        authors = self.songmanager.get_all_objects_filtered(Author, 
-            and_(
-                Author.first_name == new_author.first_name, 
-                Author.last_name == new_author.last_name, 
-                Author.display_name == new_author.display_name
-                )
-            )
+        authors = self.songmanager.get_all_objects_filtered(Author,
+            and_(Author.first_name == new_author.first_name,
+                Author.last_name == new_author.last_name,
+                Author.display_name == new_author.display_name))
         if len(authors) > 0:
             # If we edit an existing Author, we need to make sure that we do
             # not return False when nothing has changed (because this would
@@ -186,7 +183,7 @@
         Returns False if the given Book is already in the list otherwise True.
         """
         books = self.songmanager.get_all_objects_filtered(Book,
-            and_(Book.name == new_book.name, 
+            and_(Book.name == new_book.name,
                 Book.publisher == new_book.publisher))
         if len(books) > 0:
             # If we edit an existing Book, we need to make sure that we do
@@ -212,11 +209,16 @@
             if self.checkAuthor(author):
                 if self.songmanager.save_object(author):
                     self.resetAuthors()
+                else:
+                    QtGui.QMessageBox.critical(self,
+                        translate('SongsPlugin.SongMaintenanceForm', 'Error'),
+                        translate('SongsPlugin.SongMaintenanceForm',
+                        'Could not add your author.'))
             else:
                 QtGui.QMessageBox.critical(self,
                     translate('SongsPlugin.SongMaintenanceForm', 'Error'),
                     translate('SongsPlugin.SongMaintenanceForm',
-                    'Could not add your author.'))
+                    'This author already exists.'))
 
     def onTopicAddButtonClick(self):
         if self.topicform.exec_():
@@ -224,25 +226,34 @@
             if self.checkTopic(topic):
                 if self.songmanager.save_object(topic):
                     self.resetTopics()
+                else:
+                    QtGui.QMessageBox.critical(self,
+                        translate('SongsPlugin.SongMaintenanceForm', 'Error'),
+                        translate('SongsPlugin.SongMaintenanceForm',
+                        'Could not add your topic.'))
             else:
                 QtGui.QMessageBox.critical(self,
                     translate('SongsPlugin.SongMaintenanceForm', 'Error'),
                     translate('SongsPlugin.SongMaintenanceForm',
-                    'Could not add your topic.'))
+                    'This topic already exists.'))
 
     def onBookAddButtonClick(self):
         if self.bookform.exec_():
-            book = Book.populate(
-                name=unicode(self.bookform.NameEdit.text()),
+            book = Book.populate(name=unicode(self.bookform.NameEdit.text()),
                 publisher=unicode(self.bookform.PublisherEdit.text()))
             if self.checkBook(book):
                 if self.songmanager.save_object(book):
                     self.resetBooks()
+                else:
+                    QtGui.QMessageBox.critical(self,
+                        translate('SongsPlugin.SongMaintenanceForm', 'Error'),
+                        translate('SongsPlugin.SongMaintenanceForm',
+                        'Could not add your book.'))
             else:
                 QtGui.QMessageBox.critical(self,
                     translate('SongsPlugin.SongMaintenanceForm', 'Error'),
                     translate('SongsPlugin.SongMaintenanceForm',
-                    'Could not add your book.'))
+                    'This book already exists.'))
 
     def onAuthorEditButtonClick(self):
         author_id = self._getCurrentItemId(self.AuthorsListWidget)
@@ -266,6 +277,24 @@
                 if self.checkAuthor(author, True):
                     if self.songmanager.save_object(author):
                         self.resetAuthors()
+                        Receiver.send_message(u'songs_load_list')
+                    else:
+                        QtGui.QMessageBox.critical(self,
+                            translate('SongsPlugin.SongMaintenanceForm',
+                            'Error'),
+                            translate('SongsPlugin.SongMaintenanceForm',
+                            'Could not save your changes.'))
+                elif QtGui.QMessageBox.critical(self,
+                    translate('SongsPlugin.SongMaintenanceForm', 'Error'),
+                    translate('SongsPlugin.SongMaintenanceForm', 'The author %s'
+                    ' already exists. Would you like to make songs with author '
+                    '%s use the existing author %s?' % (author.display_name,
+                    temp_display_name, author.display_name)),
+                    QtGui.QMessageBox.StandardButtons(QtGui.QMessageBox.No |
+                    QtGui.QMessageBox.Yes)) == QtGui.QMessageBox.Yes:
+                    self.mergeAuthors(author)
+                    self.resetAuthors()
+                    Receiver.send_message(u'songs_load_list')
                 else:
                     # We restore the author's old first and last name as well as
                     # his display name.
@@ -275,7 +304,8 @@
                     QtGui.QMessageBox.critical(self,
                         translate('SongsPlugin.SongMaintenanceForm', 'Error'),
                         translate('SongsPlugin.SongMaintenanceForm',
-                        'Could not save your author.'))
+                        'Could not save your modified author, because he '
+                        'already exists.'))
 
     def onTopicEditButtonClick(self):
         topic_id = self._getCurrentItemId(self.TopicsListWidget)
@@ -289,13 +319,30 @@
                 if self.checkTopic(topic, True):
                     if self.songmanager.save_object(topic):
                         self.resetTopics()
+                    else:
+                        QtGui.QMessageBox.critical(self,
+                            translate('SongsPlugin.SongMaintenanceForm',
+                            'Error'),
+                            translate('SongsPlugin.SongMaintenanceForm',
+                            'Could not save your changes.'))
+                elif QtGui.QMessageBox.critical(self,
+                    translate('SongsPlugin.SongMaintenanceForm', 'Error'),
+                    translate('SongsPlugin.SongMaintenanceForm', 'The topic %s '
+                    'already exists. Would you like to make songs with topic %s'
+                    ' use the existing topic %s?' % (topic.name, temp_name,
+                    topic.name)),
+                    QtGui.QMessageBox.StandardButtons(QtGui.QMessageBox.No |
+                    QtGui.QMessageBox.Yes)) == QtGui.QMessageBox.Yes:
+                    self.mergeTopics(topic)
+                    self.resetTopics()
                 else:
                     # We restore the topics's old name.
                     topic.name = temp_name
                     QtGui.QMessageBox.critical(self,
                         translate('SongsPlugin.SongMaintenanceForm', 'Error'),
                         translate('SongsPlugin.SongMaintenanceForm',
-                        'Could not save your topic.'))
+                        'Could not save your modified topic, because it '
+                        'already exists.'))
 
     def onBookEditButtonClick(self):
         book_id = self._getCurrentItemId(self.BooksListWidget)
@@ -313,18 +360,89 @@
                 if self.checkBook(book, True):
                     if self.songmanager.save_object(book):
                         self.resetBooks()
+                    else:
+                        QtGui.QMessageBox.critical(self,
+                            translate('SongsPlugin.SongMaintenanceForm',
+                            'Error'),
+                            translate('SongsPlugin.SongMaintenanceForm',
+                            'Could not save your changes.'))
+                elif QtGui.QMessageBox.critical(self,
+                    translate('SongsPlugin.SongMaintenanceForm', 'Error'),
+                    translate('SongsPlugin.SongMaintenanceForm', 'The book %s '
+                    'already exists. Would you like to make songs with book %s '
+                    'use the existing book %s?' % (book.name, temp_name,
+                    book.name)),
+                    QtGui.QMessageBox.StandardButtons(QtGui.QMessageBox.No |
+                    QtGui.QMessageBox.Yes)) == QtGui.QMessageBox.Yes:
+                    self.mergeBooks(book)
+                    self.resetBooks()
                 else:
                     # We restore the book's old name and publisher.
                     book.name = temp_name
                     book.publisher = temp_publisher
-                    QtGui.QMessageBox.critical(self,
-                        translate('SongsPlugin.SongMaintenanceForm', 'Error'),
-                        translate('SongsPlugin.SongMaintenanceForm',
-                        'Could not save your book.'))
+
+    def mergeAuthors(self, old_author):
+        '''
+        Merges two authors into one author.
+        
+        ``old_author``
+            The author which will be deleted afterwards.
+        '''
+        existing_author = self.songmanager.get_object_filtered(Author,
+            and_(Author.first_name == old_author.first_name,
+                Author.last_name == old_author.last_name, 
+                Author.display_name == old_author.display_name))
+        songs = self.songmanager.get_all_objects_filtered(Song,
+            Song.authors.contains(old_author))
+        for song in songs:
+            # We check if the song has already existing_author as author. If
+            # that is not the case we add it.
+            if existing_author not in song.authors:
+                song.authors.append(existing_author)
+            song.authors.remove(old_author)
+            self.songmanager.save_object(song)
+        self.songmanager.delete_object(Author, old_author.id)
+
+    def mergeTopics(self, old_topic):
+        '''
+        Merges two topics into one topic.
+        
+        ``old_topic``
+            The topic which will be deleted afterwards.
+        '''
+        existing_topic = self.songmanager.get_object_filtered(Topic,
+            Topic.name == old_topic.name)
+        songs = self.songmanager.get_all_objects_filtered(Song,
+            Song.topics.contains(old_topic))
+        for song in songs:
+            # We check if the song has already existing_topic as topic. If that
+            # is not the case we add it.
+            if existing_topic not in song.topics:
+                song.topics.append(existing_topic)
+            song.topics.remove(old_topic)
+            self.songmanager.save_object(song)
+        self.songmanager.delete_object(Topic, old_topic.id)
+
+    def mergeBooks(self, old_book):
+        '''
+        Merges two books into one book.
+        
+        ``old_book``
+            The book which will be deleted afterwards.
+        '''
+        existing_book = self.songmanager.get_object_filtered(Book,
+            and_(Book.name == old_book.name,
+                Book.publisher == old_book.publisher))
+        songs = self.songmanager.get_all_objects_filtered(Song,
+            Song.song_book_id == old_book.id)
+        for song in songs:
+            song.song_book_id = existing_book.id
+            self.songmanager.save_object(song)
+        self.songmanager.delete_object(Book, old_book.id)
 
     def onAuthorDeleteButtonClick(self):
         """
-        Delete the author if the author is not attached to any songs
+        Delete the author if the author is not attached to any songs.
         """
         self._deleteItem(Author, self.AuthorsListWidget, self.resetAuthors,
             translate('SongsPlugin.SongMaintenanceForm', 'Delete Author'),
@@ -337,7 +455,7 @@
 
     def onTopicDeleteButtonClick(self):
         """
-        Delete the Book is the Book is not attached to any songs
+        Delete the Book is the Book is not attached to any songs.
         """
         self._deleteItem(Topic, self.TopicsListWidget, self.resetTopics,
             translate('SongsPlugin.SongMaintenanceForm', 'Delete Topic'),
@@ -350,7 +468,7 @@
 
     def onBookDeleteButtonClick(self):
         """
-        Delete the Book is the Book is not attached to any songs
+        Delete the Book is the Book is not attached to any songs.
         """
         self._deleteItem(Book, self.BooksListWidget, self.resetBooks,
             translate('SongsPlugin.SongMaintenanceForm', 'Delete Book'),


Follow ups