From 1b536ab0c882707b0cfacba569ebb189c7e85118 Mon Sep 17 00:00:00 2001 From: andreas Date: Sat, 10 Jul 2010 19:02:42 +0200 Subject: [PATCH 1/9] Books, Topics and Authors redundancy imporvements. --- .../songs/forms/songmaintenanceform.py | 174 +++++++++++++----- 1 file changed, 127 insertions(+), 47 deletions(-) diff --git a/openlp/plugins/songs/forms/songmaintenanceform.py b/openlp/plugins/songs/forms/songmaintenanceform.py index 54a8d539f..116bb7843 100644 --- a/openlp/plugins/songs/forms/songmaintenanceform.py +++ b/openlp/plugins/songs/forms/songmaintenanceform.py @@ -97,6 +97,9 @@ class SongMaintenanceForm(QtGui.QDialog, Ui_SongMaintenanceDialog): QtGui.QMessageBox.critical(self, dlg_title, sel_text) def resetAuthors(self): + """ + Reloads the Authors list. + """ self.AuthorsListWidget.clear() authors = self.songmanager.get_all_objects(Author, Author.display_name) for author in authors: @@ -109,6 +112,9 @@ class SongMaintenanceForm(QtGui.QDialog, Ui_SongMaintenanceDialog): self.AuthorsListWidget.addItem(author_name) def resetTopics(self): + """ + Reloads the Topics list. + """ self.TopicsListWidget.clear() topics = self.songmanager.get_all_objects(Topic, Topic.name) for topic in topics: @@ -117,13 +123,89 @@ class SongMaintenanceForm(QtGui.QDialog, Ui_SongMaintenanceDialog): self.TopicsListWidget.addItem(topic_name) def resetBooks(self): + """ + Reloads the Books list. + """ self.BooksListWidget.clear() books = self.songmanager.get_all_objects(Book, Book.name) for book in books: - book_name = QtGui.QListWidgetItem(book.name) + book_name = QtGui.QListWidgetItem(u'%s (%s)' % (book.name, + book.publisher)) book_name.setData(QtCore.Qt.UserRole, QtCore.QVariant(book.id)) self.BooksListWidget.addItem(book_name) + def checkAuthor(self, new_author, edit=False): + """ + Returns True when the given Author is already in the list elsewise False. + """ + new_author_first_name = new_author.first_name + new_author_last_name = new_author.last_name + new_author_display_name = new_author.display_name + authors = self.songmanager.get_all_objects(Author) + author_exsists = False + for author in authors: + author_fist_name = author.first_name + author_last_name = author.last_name + author_display_name = author.display_name + if author_fist_name == new_author_first_name and \ + author_last_name == new_author_last_name and \ + author_display_name == new_author_display_name: + author_exsists = True + #If we edit an exsisting Author, we need to make sure that we do + #not return True when nothing has changed (because this would + #cause an error message later on) + if edit: + new_author_id = new_author.id + author_id = author.id + if new_author_id == author_id: + author_exsists = False + return author_exsists + + def checkTopic(self, new_topic, edit=False): + """ + Returns True when the given Topic is already in the list elsewise False. + """ + new_topic_name = new_topic.name + topics = self.songmanager.get_all_objects(Topic) + topic_exsists = False + for topic in topics: + topic_name = topic.name + if topic_name == new_topic_name: + topic_exsists = True + #If we edit an exsisting Topic, we need to make sure that we do + #not return True when nothing has changed (because this would + #cause an error message later on) + if edit: + new_topic_id = new_topic.id + topic_id = topic.id + if new_topic_id == topic_id: + topic_exsists = False + return topic_exsists + + def checkBook(self, new_book, edit=False): + """ + Returns True when the given Book is already in the list elsewise False. + """ + new_book_name = new_book.name + new_book_publisher = new_book.publisher + books = self.songmanager.get_all_objects(Book) + book_exsists = False + for book in books: + book_name = book.name + book_publisher = book.publisher + if book_publisher == new_book_publisher and \ + book_name == new_book_name: + book_exsists = True + #If we edit an exsisting Book, we need to make sure that we do + #not return True when nothing has changed (because this would + #cause an error message later on) + if edit: + new_book_id = new_book.id + book_id = book.id + if new_book_id == book_id: + book_exsists = False + return book_exsists + def onAuthorAddButtonClick(self): self.authorform.setAutoDisplayName(True) if self.authorform.exec_(): @@ -131,40 +213,40 @@ class SongMaintenanceForm(QtGui.QDialog, Ui_SongMaintenanceDialog): first_name=unicode(self.authorform.FirstNameEdit.text()), last_name=unicode(self.authorform.LastNameEdit.text()), display_name=unicode(self.authorform.DisplayEdit.text())) - if self.songmanager.save_object(author): + if self.checkAuthor(author) is False and \ + self.songmanager.save_object(author): self.resetAuthors() else: - QtGui.QMessageBox.critical( - self, translate('SongsPlugin.SongMaintenanceForm', - 'Error'), + QtGui.QMessageBox.critical(self, + translate('SongsPlugin.SongMaintenanceForm', 'Error'), translate('SongsPlugin.SongMaintenanceForm', - 'Couldn\'t add your author.')) + 'Could not add your author.')) def onTopicAddButtonClick(self): if self.topicform.exec_(): topic = Topic.populate(name=unicode(self.topicform.NameEdit.text())) - if self.songmanager.save_object(topic): + if self.checkTopic(topic) is False and \ + self.songmanager.save_object(topic): self.resetTopics() else: - QtGui.QMessageBox.critical( - self, translate('SongsPlugin.SongMaintenanceForm', - 'Error'), + QtGui.QMessageBox.critical(self, + translate('SongsPlugin.SongMaintenanceForm', 'Error'), translate('SongsPlugin.SongMaintenanceForm', - 'Couldn\'t add your topic.')) + 'Could not add your topic.')) def onBookAddButtonClick(self): if self.bookform.exec_(): book = Book.populate( name=unicode(self.bookform.NameEdit.text()), publisher=unicode(self.bookform.PublisherEdit.text())) - if self.songmanager.save_object(book): + if self.checkBook(book) is False and \ + self.songmanager.save_object(book): self.resetBooks() else: - QtGui.QMessageBox.critical( - self, translate('SongsPlugin.SongMaintenanceForm', - 'Error'), + QtGui.QMessageBox.critical(self, + translate('SongsPlugin.SongMaintenanceForm', 'Error'), translate('SongsPlugin.SongMaintenanceForm', - 'Couldn\'t add your book.')) + 'Could not add your book.')) def onAuthorEditButtonClick(self): author_id = self._getCurrentItemId(self.AuthorsListWidget) @@ -187,14 +269,14 @@ class SongMaintenanceForm(QtGui.QDialog, Ui_SongMaintenanceDialog): author.last_name = unicode(self.authorform.LastNameEdit.text()) author.display_name = unicode( self.authorform.DisplayEdit.text()) - if self.songmanager.save_object(author): + if self.checkAuthor(author, True) is False and \ + self.songmanager.save_object(author): self.resetAuthors() else: - QtGui.QMessageBox.critical( - self, translate('SongsPlugin.SongMaintenanceForm', - 'Error'), + QtGui.QMessageBox.critical(self, + translate('SongsPlugin.SongMaintenanceForm', 'Error'), translate('SongsPlugin.SongMaintenanceForm', - 'Couldn\'t save your author.')) + 'Could not save your author.')) def onTopicEditButtonClick(self): topic_id = self._getCurrentItemId(self.TopicsListWidget) @@ -203,14 +285,14 @@ class SongMaintenanceForm(QtGui.QDialog, Ui_SongMaintenanceDialog): self.topicform.NameEdit.setText(topic.name) if self.topicform.exec_(False): topic.name = unicode(self.topicform.NameEdit.text()) - if self.songmanager.save_object(topic): + if self.checkTopic(topic, True) is False and \ + self.songmanager.save_object(topic): self.resetTopics() else: - QtGui.QMessageBox.critical( - self, translate('SongsPlugin.SongMaintenanceForm', - 'Error'), + QtGui.QMessageBox.critical(self, + translate('SongsPlugin.SongMaintenanceForm', 'Error'), translate('SongsPlugin.SongMaintenanceForm', - 'Couldn\'t save your topic.')) + 'Could not save your topic.')) def onBookEditButtonClick(self): book_id = self._getCurrentItemId(self.BooksListWidget) @@ -221,14 +303,14 @@ class SongMaintenanceForm(QtGui.QDialog, Ui_SongMaintenanceDialog): if self.bookform.exec_(False): book.name = unicode(self.bookform.NameEdit.text()) book.publisher = unicode(self.bookform.PublisherEdit.text()) - if self.songmanager.save_object(book): + if self.checkBook(book, True) is False and \ + self.songmanager.save_object(book): self.resetBooks() else: - QtGui.QMessageBox.critical( - self, translate('SongsPlugin.SongMaintenanceForm', - 'Error'), + QtGui.QMessageBox.critical(self, + translate('SongsPlugin.SongMaintenanceForm', 'Error'), translate('SongsPlugin.SongMaintenanceForm', - 'Couldn\'t save your book.')) + 'Could not save your book.')) def onAuthorDeleteButtonClick(self): """ @@ -236,13 +318,12 @@ class SongMaintenanceForm(QtGui.QDialog, Ui_SongMaintenanceDialog): """ self._deleteItem(Author, self.AuthorsListWidget, self.resetAuthors, translate('SongsPlugin.SongMaintenanceForm', 'Delete Author'), - translate('SongsPlugin.SongMaintenanceForm', - 'Are you sure you want to delete the selected author?'), translate('SongsPlugin.SongMaintenanceForm', - 'This author can\'t be deleted, they are currently ' - 'assigned to at least one song.'), + 'Are you sure you want to delete the selected author?'), translate('SongsPlugin.SongMaintenanceForm', - 'No author selected!')) + 'This author ca not be deleted, they are currently ' + 'assigned to at least one song.'), + translate('SongsPlugin.SongMaintenanceForm', 'No author selected!')) def onTopicDeleteButtonClick(self): """ @@ -250,13 +331,12 @@ class SongMaintenanceForm(QtGui.QDialog, Ui_SongMaintenanceDialog): """ self._deleteItem(Topic, self.TopicsListWidget, self.resetTopics, translate('SongsPlugin.SongMaintenanceForm', 'Delete Topic'), - translate('SongsPlugin.SongMaintenanceForm', - 'Are you sure you want to delete the selected topic?'), - translate('SongsPlugin.SongMaintenanceForm', - 'This topic can\'t be deleted, it is currently ' - 'assigned to at least one song.'), translate('SongsPlugin.SongMaintenanceForm', - 'No topic selected!')) + 'Are you sure you want to delete the selected topic?'), + translate('SongsPlugin.SongMaintenanceForm', + 'This topic cannot be deleted, it is currently ' + 'assigned to at least one song.'), + translate('SongsPlugin.SongMaintenanceForm', 'No topic selected!')) def onBookDeleteButtonClick(self): """ @@ -265,8 +345,8 @@ class SongMaintenanceForm(QtGui.QDialog, Ui_SongMaintenanceDialog): self._deleteItem(Book, self.BooksListWidget, self.resetBooks, translate('SongsPlugin.SongMaintenanceForm', 'Delete Book'), translate('SongsPlugin.SongMaintenanceForm', - 'Are you sure you want to delete the selected book?'), - translate('SongsPlugin.SongMaintenanceForm', - 'This book can\'t be deleted, it is currently ' - 'assigned to at least one song.'), - translate('SongsPlugin.SongMaintenanceForm', u'No book selected!')) + 'Are you sure you want to delete the selected book?'), + translate('SongsPlugin.SongMaintenanceForm', + 'This book cannot be deleted, it is currently ' + 'assigned to at least one song.'), + translate('SongsPlugin.SongMaintenanceForm', 'No book selected!')) From 639ce2bfbcb341cd35916256ef5ce110f26243b0 Mon Sep 17 00:00:00 2001 From: andreas Date: Sat, 10 Jul 2010 19:30:01 +0200 Subject: [PATCH 2/9] fixed double whitespace --- openlp/plugins/songs/forms/songmaintenanceform.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/openlp/plugins/songs/forms/songmaintenanceform.py b/openlp/plugins/songs/forms/songmaintenanceform.py index 116bb7843..2ac5f93a7 100644 --- a/openlp/plugins/songs/forms/songmaintenanceform.py +++ b/openlp/plugins/songs/forms/songmaintenanceform.py @@ -134,7 +134,7 @@ class SongMaintenanceForm(QtGui.QDialog, Ui_SongMaintenanceDialog): book_name.setData(QtCore.Qt.UserRole, QtCore.QVariant(book.id)) self.BooksListWidget.addItem(book_name) - def checkAuthor(self, new_author, edit=False): + def checkAuthor(self, new_author, edit=False): """ Returns True when the given Author is already in the list elsewise False. """ @@ -182,7 +182,7 @@ class SongMaintenanceForm(QtGui.QDialog, Ui_SongMaintenanceDialog): topic_exsists = False return topic_exsists - def checkBook(self, new_book, edit=False): + def checkBook(self, new_book, edit=False): """ Returns True when the given Book is already in the list elsewise False. """ From d6fe2d1c9f18b35883a9dcf66124360d80391047 Mon Sep 17 00:00:00 2001 From: andreas Date: Sat, 10 Jul 2010 20:19:54 +0200 Subject: [PATCH 3/9] oppps... spelling --- .../songs/forms/songmaintenanceform.py | 24 +++++++++---------- 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/openlp/plugins/songs/forms/songmaintenanceform.py b/openlp/plugins/songs/forms/songmaintenanceform.py index 2ac5f93a7..2ba5e455d 100644 --- a/openlp/plugins/songs/forms/songmaintenanceform.py +++ b/openlp/plugins/songs/forms/songmaintenanceform.py @@ -142,7 +142,7 @@ class SongMaintenanceForm(QtGui.QDialog, Ui_SongMaintenanceDialog): new_author_last_name = new_author.last_name new_author_display_name = new_author.display_name authors = self.songmanager.get_all_objects(Author) - author_exsists = False + author_exists = False for author in authors: author_fist_name = author.first_name author_last_name = author.last_name @@ -150,7 +150,7 @@ class SongMaintenanceForm(QtGui.QDialog, Ui_SongMaintenanceDialog): if author_fist_name == new_author_first_name and \ author_last_name == new_author_last_name and \ author_display_name == new_author_display_name: - author_exsists = True + author_exists = True #If we edit an exsisting Author, we need to make sure that we do #not return True when nothing has changed (because this would #cause an error message later on) @@ -158,8 +158,8 @@ class SongMaintenanceForm(QtGui.QDialog, Ui_SongMaintenanceDialog): new_author_id = new_author.id author_id = author.id if new_author_id == author_id: - author_exsists = False - return author_exsists + author_exists = False + return author_exists def checkTopic(self, new_topic, edit=False): """ @@ -167,11 +167,11 @@ class SongMaintenanceForm(QtGui.QDialog, Ui_SongMaintenanceDialog): """ new_topic_name = new_topic.name topics = self.songmanager.get_all_objects(Topic) - topic_exsists = False + topic_exists = False for topic in topics: topic_name = topic.name if topic_name == new_topic_name: - topic_exsists = True + topic_exists = True #If we edit an exsisting Topic, we need to make sure that we do #not return True when nothing has changed (because this would #cause an error message later on) @@ -179,8 +179,8 @@ class SongMaintenanceForm(QtGui.QDialog, Ui_SongMaintenanceDialog): new_topic_id = new_topic.id topic_id = topic.id if new_topic_id == topic_id: - topic_exsists = False - return topic_exsists + topic_exists = False + return topic_exists def checkBook(self, new_book, edit=False): """ @@ -189,13 +189,13 @@ class SongMaintenanceForm(QtGui.QDialog, Ui_SongMaintenanceDialog): new_book_name = new_book.name new_book_publisher = new_book.publisher books = self.songmanager.get_all_objects(Book) - book_exsists = False + book_exists = False for book in books: book_name = book.name book_publisher = book.publisher if book_publisher == new_book_publisher and \ book_name == new_book_name: - book_exsists = True + book_exists = True #If we edit an exsisting Book, we need to make sure that we do #not return True when nothing has changed (because this would #cause an error message later on) @@ -203,8 +203,8 @@ class SongMaintenanceForm(QtGui.QDialog, Ui_SongMaintenanceDialog): new_book_id = new_book.id book_id = book.id if new_book_id == book_id: - book_exsists = False - return book_exsists + book_exists = False + return book_exists def onAuthorAddButtonClick(self): self.authorform.setAutoDisplayName(True) From ab179f8e1235b61caacb962f60351158288aab53 Mon Sep 17 00:00:00 2001 From: andreas Date: Sat, 10 Jul 2010 23:26:09 +0200 Subject: [PATCH 4/9] fixes for merge --- .../songs/forms/songmaintenanceform.py | 43 ++++++------------- 1 file changed, 12 insertions(+), 31 deletions(-) diff --git a/openlp/plugins/songs/forms/songmaintenanceform.py b/openlp/plugins/songs/forms/songmaintenanceform.py index 2ba5e455d..925e77de1 100644 --- a/openlp/plugins/songs/forms/songmaintenanceform.py +++ b/openlp/plugins/songs/forms/songmaintenanceform.py @@ -138,26 +138,18 @@ class SongMaintenanceForm(QtGui.QDialog, Ui_SongMaintenanceDialog): """ Returns True when the given Author is already in the list elsewise False. """ - new_author_first_name = new_author.first_name - new_author_last_name = new_author.last_name - new_author_display_name = new_author.display_name authors = self.songmanager.get_all_objects(Author) author_exists = False for author in authors: - author_fist_name = author.first_name - author_last_name = author.last_name - author_display_name = author.display_name - if author_fist_name == new_author_first_name and \ - author_last_name == new_author_last_name and \ - author_display_name == new_author_display_name: + if author.fist_name == new_author.first_name and \ + author.last_name == new_author.last_name and \ + author.display_name == new_author.display_name: author_exists = True #If we edit an exsisting Author, we need to make sure that we do #not return True when nothing has changed (because this would #cause an error message later on) if edit: - new_author_id = new_author.id - author_id = author.id - if new_author_id == author_id: + if new_author.id == author.id: author_exists = False return author_exists @@ -165,20 +157,16 @@ class SongMaintenanceForm(QtGui.QDialog, Ui_SongMaintenanceDialog): """ Returns True when the given Topic is already in the list elsewise False. """ - new_topic_name = new_topic.name topics = self.songmanager.get_all_objects(Topic) topic_exists = False for topic in topics: - topic_name = topic.name - if topic_name == new_topic_name: + if topic.name == new_topic.name: topic_exists = True #If we edit an exsisting Topic, we need to make sure that we do #not return True when nothing has changed (because this would #cause an error message later on) if edit: - new_topic_id = new_topic.id - topic_id = topic.id - if new_topic_id == topic_id: + if new_topic.id == topic.id: topic_exists = False return topic_exists @@ -186,23 +174,17 @@ class SongMaintenanceForm(QtGui.QDialog, Ui_SongMaintenanceDialog): """ Returns True when the given Book is already in the list elsewise False. """ - new_book_name = new_book.name - new_book_publisher = new_book.publisher books = self.songmanager.get_all_objects(Book) book_exists = False for book in books: - book_name = book.name - book_publisher = book.publisher - if book_publisher == new_book_publisher and \ - book_name == new_book_name: + if book.publisher == new_book.publisher and \ + book.name == new_book.name: book_exists = True #If we edit an exsisting Book, we need to make sure that we do #not return True when nothing has changed (because this would #cause an error message later on) if edit: - new_book_id = new_book.id - book_id = book.id - if new_book_id == book_id: + if new_book.id == book.id: book_exists = False return book_exists @@ -213,7 +195,7 @@ class SongMaintenanceForm(QtGui.QDialog, Ui_SongMaintenanceDialog): first_name=unicode(self.authorform.FirstNameEdit.text()), last_name=unicode(self.authorform.LastNameEdit.text()), display_name=unicode(self.authorform.DisplayEdit.text())) - if self.checkAuthor(author) is False and \ + if not self.checkAuthor(author) and \ self.songmanager.save_object(author): self.resetAuthors() else: @@ -225,7 +207,7 @@ class SongMaintenanceForm(QtGui.QDialog, Ui_SongMaintenanceDialog): def onTopicAddButtonClick(self): if self.topicform.exec_(): topic = Topic.populate(name=unicode(self.topicform.NameEdit.text())) - if self.checkTopic(topic) is False and \ + if not self.checkTopic(topic) and \ self.songmanager.save_object(topic): self.resetTopics() else: @@ -239,8 +221,7 @@ class SongMaintenanceForm(QtGui.QDialog, Ui_SongMaintenanceDialog): book = Book.populate( name=unicode(self.bookform.NameEdit.text()), publisher=unicode(self.bookform.PublisherEdit.text())) - if self.checkBook(book) is False and \ - self.songmanager.save_object(book): + if not self.checkBook(book) and self.songmanager.save_object(book): self.resetBooks() else: QtGui.QMessageBox.critical(self, From 931f572a4e4ce6da0f58410b116381b95b058857 Mon Sep 17 00:00:00 2001 From: andreas Date: Sat, 10 Jul 2010 23:39:54 +0200 Subject: [PATCH 5/9] spelling mistakes --- openlp/plugins/songs/forms/songmaintenanceform.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/openlp/plugins/songs/forms/songmaintenanceform.py b/openlp/plugins/songs/forms/songmaintenanceform.py index 925e77de1..f320e6883 100644 --- a/openlp/plugins/songs/forms/songmaintenanceform.py +++ b/openlp/plugins/songs/forms/songmaintenanceform.py @@ -145,7 +145,7 @@ class SongMaintenanceForm(QtGui.QDialog, Ui_SongMaintenanceDialog): author.last_name == new_author.last_name and \ author.display_name == new_author.display_name: author_exists = True - #If we edit an exsisting Author, we need to make sure that we do + #If we edit an existing Author, we need to make sure that we do #not return True when nothing has changed (because this would #cause an error message later on) if edit: @@ -162,7 +162,7 @@ class SongMaintenanceForm(QtGui.QDialog, Ui_SongMaintenanceDialog): for topic in topics: if topic.name == new_topic.name: topic_exists = True - #If we edit an exsisting Topic, we need to make sure that we do + #If we edit an existing Topic, we need to make sure that we do #not return True when nothing has changed (because this would #cause an error message later on) if edit: @@ -180,7 +180,7 @@ class SongMaintenanceForm(QtGui.QDialog, Ui_SongMaintenanceDialog): if book.publisher == new_book.publisher and \ book.name == new_book.name: book_exists = True - #If we edit an exsisting Book, we need to make sure that we do + #If we edit an existing Book, we need to make sure that we do #not return True when nothing has changed (because this would #cause an error message later on) if edit: @@ -302,7 +302,7 @@ class SongMaintenanceForm(QtGui.QDialog, Ui_SongMaintenanceDialog): translate('SongsPlugin.SongMaintenanceForm', 'Are you sure you want to delete the selected author?'), translate('SongsPlugin.SongMaintenanceForm', - 'This author ca not be deleted, they are currently ' + 'This author cannot be deleted, they are currently ' 'assigned to at least one song.'), translate('SongsPlugin.SongMaintenanceForm', 'No author selected!')) From 0623d2bb4e702491ea55797c012052b05901e05e Mon Sep 17 00:00:00 2001 From: andreas Date: Sat, 10 Jul 2010 23:44:43 +0200 Subject: [PATCH 6/9] fixes for merge --- openlp/plugins/songs/forms/songmaintenanceform.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/openlp/plugins/songs/forms/songmaintenanceform.py b/openlp/plugins/songs/forms/songmaintenanceform.py index f320e6883..32c1a6359 100644 --- a/openlp/plugins/songs/forms/songmaintenanceform.py +++ b/openlp/plugins/songs/forms/songmaintenanceform.py @@ -250,7 +250,7 @@ class SongMaintenanceForm(QtGui.QDialog, Ui_SongMaintenanceDialog): author.last_name = unicode(self.authorform.LastNameEdit.text()) author.display_name = unicode( self.authorform.DisplayEdit.text()) - if self.checkAuthor(author, True) is False and \ + if not self.checkAuthor(author, True) and \ self.songmanager.save_object(author): self.resetAuthors() else: @@ -266,8 +266,8 @@ class SongMaintenanceForm(QtGui.QDialog, Ui_SongMaintenanceDialog): self.topicform.NameEdit.setText(topic.name) if self.topicform.exec_(False): topic.name = unicode(self.topicform.NameEdit.text()) - if self.checkTopic(topic, True) is False and \ - self.songmanager.save_object(topic): + if not self.checkTopic(topic, True) and \ + self.songmanager.save_object(topic): self.resetTopics() else: QtGui.QMessageBox.critical(self, @@ -284,8 +284,8 @@ class SongMaintenanceForm(QtGui.QDialog, Ui_SongMaintenanceDialog): if self.bookform.exec_(False): book.name = unicode(self.bookform.NameEdit.text()) book.publisher = unicode(self.bookform.PublisherEdit.text()) - if self.checkBook(book, True) is False and \ - self.songmanager.save_object(book): + if not self.checkBook(book, True) and \ + self.songmanager.save_object(book): self.resetBooks() else: QtGui.QMessageBox.critical(self, From 488ead81626fc37a21717e8700107785c0264412 Mon Sep 17 00:00:00 2001 From: andreas Date: Sun, 11 Jul 2010 15:23:12 +0200 Subject: [PATCH 7/9] cleanup --- .../plugins/songs/forms/songmaintenanceform.py | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/openlp/plugins/songs/forms/songmaintenanceform.py b/openlp/plugins/songs/forms/songmaintenanceform.py index 32c1a6359..f9d6e253d 100644 --- a/openlp/plugins/songs/forms/songmaintenanceform.py +++ b/openlp/plugins/songs/forms/songmaintenanceform.py @@ -300,10 +300,10 @@ class SongMaintenanceForm(QtGui.QDialog, Ui_SongMaintenanceDialog): self._deleteItem(Author, self.AuthorsListWidget, self.resetAuthors, translate('SongsPlugin.SongMaintenanceForm', 'Delete Author'), translate('SongsPlugin.SongMaintenanceForm', - 'Are you sure you want to delete the selected author?'), + 'Are you sure you want to delete the selected author?'), translate('SongsPlugin.SongMaintenanceForm', - 'This author cannot be deleted, they are currently ' - 'assigned to at least one song.'), + 'This author cannot be deleted, they are currently ' + 'assigned to at least one song.'), translate('SongsPlugin.SongMaintenanceForm', 'No author selected!')) def onTopicDeleteButtonClick(self): @@ -313,10 +313,10 @@ class SongMaintenanceForm(QtGui.QDialog, Ui_SongMaintenanceDialog): self._deleteItem(Topic, self.TopicsListWidget, self.resetTopics, translate('SongsPlugin.SongMaintenanceForm', 'Delete Topic'), translate('SongsPlugin.SongMaintenanceForm', - 'Are you sure you want to delete the selected topic?'), + 'Are you sure you want to delete the selected topic?'), translate('SongsPlugin.SongMaintenanceForm', - 'This topic cannot be deleted, it is currently ' - 'assigned to at least one song.'), + 'This topic cannot be deleted, it is currently ' + 'assigned to at least one song.'), translate('SongsPlugin.SongMaintenanceForm', 'No topic selected!')) def onBookDeleteButtonClick(self): @@ -326,8 +326,8 @@ class SongMaintenanceForm(QtGui.QDialog, Ui_SongMaintenanceDialog): self._deleteItem(Book, self.BooksListWidget, self.resetBooks, translate('SongsPlugin.SongMaintenanceForm', 'Delete Book'), translate('SongsPlugin.SongMaintenanceForm', - 'Are you sure you want to delete the selected book?'), + 'Are you sure you want to delete the selected book?'), translate('SongsPlugin.SongMaintenanceForm', - 'This book cannot be deleted, it is currently ' - 'assigned to at least one song.'), + 'This book cannot be deleted, it is currently ' + 'assigned to at least one song.'), translate('SongsPlugin.SongMaintenanceForm', 'No book selected!')) From 75f9f809a829e365b3a0f1ec19a983b7b2481eda Mon Sep 17 00:00:00 2001 From: andreas Date: Mon, 12 Jul 2010 15:18:07 +0200 Subject: [PATCH 8/9] use database for checking --- .../songs/forms/songmaintenanceform.py | 163 +++++++++++------- 1 file changed, 98 insertions(+), 65 deletions(-) diff --git a/openlp/plugins/songs/forms/songmaintenanceform.py b/openlp/plugins/songs/forms/songmaintenanceform.py index f9d6e253d..d50bf747f 100644 --- a/openlp/plugins/songs/forms/songmaintenanceform.py +++ b/openlp/plugins/songs/forms/songmaintenanceform.py @@ -24,6 +24,7 @@ ############################################################################### from PyQt4 import QtGui, QtCore +from sqlalchemy.sql import and_ from openlp.core.lib import translate from openlp.plugins.songs.forms import AuthorsForm, TopicsForm, SongBookForm @@ -136,57 +137,74 @@ class SongMaintenanceForm(QtGui.QDialog, Ui_SongMaintenanceDialog): def checkAuthor(self, new_author, edit=False): """ - Returns True when the given Author is already in the list elsewise False. + Returns False when the given Author is already in the list elsewise + True. """ - authors = self.songmanager.get_all_objects(Author) - author_exists = False - for author in authors: - if author.fist_name == new_author.first_name and \ - author.last_name == new_author.last_name and \ - author.display_name == new_author.display_name: - author_exists = True - #If we edit an existing Author, we need to make sure that we do - #not return True when nothing has changed (because this would - #cause an error message later on) - if edit: - if new_author.id == author.id: - author_exists = False - return author_exists + 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 + # cause an error message later on). + if edit: + if authors[0].id == new_author.id: + return True + else: + return False + else: + return False + else: + return True def checkTopic(self, new_topic, edit=False): """ - Returns True when the given Topic is already in the list elsewise False. + Returns False when the given Topic is already in the list elsewise True. """ - topics = self.songmanager.get_all_objects(Topic) - topic_exists = False - for topic in topics: - if topic.name == new_topic.name: - topic_exists = True - #If we edit an existing Topic, we need to make sure that we do - #not return True when nothing has changed (because this would - #cause an error message later on) - if edit: - if new_topic.id == topic.id: - topic_exists = False - return topic_exists + topics = self.songmanager.get_all_objects_filtered(Topic, + Topic.name == new_topic.name + ) + if len(topics) > 0: + # If we edit an existing Topic, we need to make sure that we do + # not return False when nothing has changed (because this would + # cause an error message later on). + if edit: + if topics[0].id == new_topic.id: + return True + else: + return False + else: + return False + else: + return True def checkBook(self, new_book, edit=False): """ - Returns True when the given Book is already in the list elsewise False. + Returns False when the given Book is already in the list elsewise True. """ - books = self.songmanager.get_all_objects(Book) - book_exists = False - for book in books: - if book.publisher == new_book.publisher and \ - book.name == new_book.name: - book_exists = True - #If we edit an existing Book, we need to make sure that we do - #not return True when nothing has changed (because this would - #cause an error message later on) + books = self.songmanager.get_all_objects_filtered(Book, + 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 + # not return False when nothing has changed (because this would + # cause an error message later on). if edit: - if new_book.id == book.id: - book_exists = False - return book_exists + if books[0].id == new_book.id: + return True + else: + return False + else: + return False + else: + return True def onAuthorAddButtonClick(self): self.authorform.setAutoDisplayName(True) @@ -195,9 +213,9 @@ class SongMaintenanceForm(QtGui.QDialog, Ui_SongMaintenanceDialog): first_name=unicode(self.authorform.FirstNameEdit.text()), last_name=unicode(self.authorform.LastNameEdit.text()), display_name=unicode(self.authorform.DisplayEdit.text())) - if not self.checkAuthor(author) and \ - self.songmanager.save_object(author): - self.resetAuthors() + if self.checkAuthor(author): + if self.songmanager.save_object(author): + self.resetAuthors() else: QtGui.QMessageBox.critical(self, translate('SongsPlugin.SongMaintenanceForm', 'Error'), @@ -207,9 +225,9 @@ class SongMaintenanceForm(QtGui.QDialog, Ui_SongMaintenanceDialog): def onTopicAddButtonClick(self): if self.topicform.exec_(): topic = Topic.populate(name=unicode(self.topicform.NameEdit.text())) - if not self.checkTopic(topic) and \ - self.songmanager.save_object(topic): - self.resetTopics() + if self.checkTopic(topic): + if self.songmanager.save_object(topic): + self.resetTopics() else: QtGui.QMessageBox.critical(self, translate('SongsPlugin.SongMaintenanceForm', 'Error'), @@ -221,8 +239,9 @@ class SongMaintenanceForm(QtGui.QDialog, Ui_SongMaintenanceDialog): book = Book.populate( name=unicode(self.bookform.NameEdit.text()), publisher=unicode(self.bookform.PublisherEdit.text())) - if not self.checkBook(book) and self.songmanager.save_object(book): - self.resetBooks() + if self.checkBook(book): + if self.songmanager.save_object(book): + self.resetBooks() else: QtGui.QMessageBox.critical(self, translate('SongsPlugin.SongMaintenanceForm', 'Error'), @@ -233,27 +252,30 @@ class SongMaintenanceForm(QtGui.QDialog, Ui_SongMaintenanceDialog): author_id = self._getCurrentItemId(self.AuthorsListWidget) if author_id != -1: author = self.songmanager.get_object(Author, author_id) - # Just make sure none of the fields is None - if author.first_name is None: - author.first_name = u'' - if author.last_name is None: - author.last_name = u'' - if author.display_name is None: - author.display_name = u'' self.authorform.setAutoDisplayName(False) self.authorform.FirstNameEdit.setText(author.first_name) self.authorform.LastNameEdit.setText(author.last_name) self.authorform.DisplayEdit.setText(author.display_name) + # Save the author's first and last name as well as the display name + # for the case that they have to be restored. + temp_first_name = author.first_name + temp_last_name = author.last_name + temp_display_name = author.display_name if self.authorform.exec_(False): author.first_name = unicode( self.authorform.FirstNameEdit.text()) author.last_name = unicode(self.authorform.LastNameEdit.text()) author.display_name = unicode( self.authorform.DisplayEdit.text()) - if not self.checkAuthor(author, True) and \ - self.songmanager.save_object(author): - self.resetAuthors() + if self.checkAuthor(author, True): + if self.songmanager.save_object(author): + self.resetAuthors() else: + # We restore the author's old first and last name as well as + # his display name. + author.first_name = temp_first_name + author.last_name = temp_last_name + author.display_name = temp_display_name QtGui.QMessageBox.critical(self, translate('SongsPlugin.SongMaintenanceForm', 'Error'), translate('SongsPlugin.SongMaintenanceForm', @@ -264,12 +286,16 @@ class SongMaintenanceForm(QtGui.QDialog, Ui_SongMaintenanceDialog): if topic_id != -1: topic = self.songmanager.get_object(Topic, topic_id) self.topicform.NameEdit.setText(topic.name) + # Save the topic's name for the case that he has to be restored. + temp_name = topic.name if self.topicform.exec_(False): topic.name = unicode(self.topicform.NameEdit.text()) - if not self.checkTopic(topic, True) and \ - self.songmanager.save_object(topic): - self.resetTopics() + if self.checkTopic(topic, True): + if self.songmanager.save_object(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', @@ -281,13 +307,20 @@ class SongMaintenanceForm(QtGui.QDialog, Ui_SongMaintenanceDialog): book = self.songmanager.get_object(Book, book_id) self.bookform.NameEdit.setText(book.name) self.bookform.PublisherEdit.setText(book.publisher) + # Save the book's name and publisher for the case that they have to + # be restored. + temp_name = book.name + temp_publisher = book.publisher if self.bookform.exec_(False): book.name = unicode(self.bookform.NameEdit.text()) book.publisher = unicode(self.bookform.PublisherEdit.text()) - if not self.checkBook(book, True) and \ - self.songmanager.save_object(book): - self.resetBooks() + if self.checkBook(book, True): + if self.songmanager.save_object(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', From 46d561b320e3bd3f217a96c71954cf83ed893c2c Mon Sep 17 00:00:00 2001 From: Jon Tibble Date: Mon, 12 Jul 2010 15:32:48 +0100 Subject: [PATCH 9/9] Add saving current media plugin (Bug #596540) --- openlp/core/ui/advancedtab.py | 43 +++++++++++++++++++++++++---------- openlp/core/ui/mainwindow.py | 10 ++++++++ 2 files changed, 41 insertions(+), 12 deletions(-) diff --git a/openlp/core/ui/advancedtab.py b/openlp/core/ui/advancedtab.py index d2f0c22b5..b2efd92cd 100644 --- a/openlp/core/ui/advancedtab.py +++ b/openlp/core/ui/advancedtab.py @@ -53,22 +53,32 @@ class AdvancedTab(SettingsTab): self.leftLayout = QtGui.QVBoxLayout(self.leftWidget) self.leftLayout.setSpacing(8) self.leftLayout.setMargin(0) - self.recentGroupBox = QtGui.QGroupBox(self.leftWidget) - self.recentGroupBox.setObjectName(u'recentGroupBox') - self.recentGroupBox.setGeometry(QtCore.QRect(0, 0, 220, 57)) - self.recentGroupBox.setMaximumSize(QtCore.QSize(220, 57)) - self.recentLayout = QtGui.QHBoxLayout(self.recentGroupBox) + self.uiGroupBox = QtGui.QGroupBox(self.leftWidget) + self.uiGroupBox.setObjectName(u'uiGroupBox') + self.uiGroupBox.setMaximumWidth(260) + self.uiLayout = QtGui.QVBoxLayout(self.uiGroupBox) + self.uiLayout.setSpacing(8) + self.uiLayout.setMargin(6) + self.uiLayout.setObjectName(u'uiLayout') + self.recentLayout = QtGui.QHBoxLayout() self.recentLayout.setSpacing(8) - self.recentLayout.setMargin(6) + self.recentLayout.setMargin(0) self.recentLayout.setObjectName(u'recentLayout') - self.recentLabel = QtGui.QLabel(self.recentGroupBox) + self.recentLabel = QtGui.QLabel(self.uiGroupBox) self.recentLabel.setObjectName(u'recentLabel') self.recentLayout.addWidget(self.recentLabel) - self.recentSpinBox = QtGui.QSpinBox(self.recentGroupBox) - self.recentSpinBox.setMinimum(0) + self.recentSpinBox = QtGui.QSpinBox(self.uiGroupBox) self.recentSpinBox.setObjectName(u'recentSpinBox') + self.recentSpinBox.setMinimum(0) self.recentLayout.addWidget(self.recentSpinBox) - self.leftLayout.addWidget(self.recentGroupBox) + self.recentSpacer = QtGui.QSpacerItem(50, 20, + QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Minimum) + self.recentLayout.addItem(self.recentSpacer) + self.uiLayout.addLayout(self.recentLayout) + self.mediaPluginCheckBox = QtGui.QCheckBox(self.uiGroupBox) + self.mediaPluginCheckBox.setObjectName(u'mediaPluginCheckBox') + self.uiLayout.addWidget(self.mediaPluginCheckBox) + self.leftLayout.addWidget(self.uiGroupBox) # self.sharedDirGroupBox = QtGui.QGroupBox(self.leftWidget) # self.sharedDirGroupBox.setObjectName(u'sharedDirGroupBox') # self.sharedDirGroupBox.setGeometry(QtCore.QRect(0, 65, 500, 85)) @@ -108,6 +118,8 @@ class AdvancedTab(SettingsTab): # self.databaseLayout.setSpacing(8) # self.databaseLayout.setMargin(8) # self.rightLayout.addWidget(self.databaseGroupBox) +# self.rightSpacer = QtGui.QSpacerItem(20, 40, +# QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Expanding) # self.advancedTabLayout.addWidget(self.rightWidget) # QtCore.QObject.connect(self.sharedCheckBox, # QtCore.SIGNAL(u'stateChanged(int)'), self.onSharedCheckBoxChanged) @@ -116,9 +128,11 @@ class AdvancedTab(SettingsTab): """ Setup the interface translation strings. """ - self.recentGroupBox.setTitle(translate('AdvancedTab', 'Recent Files')) + self.uiGroupBox.setTitle(translate('AdvancedTab', 'UI Settings')) self.recentLabel.setText( - translate('AdvancedTab', 'Number of recent files to list:')) + translate('AdvancedTab', 'Number of recent files to display:')) + self.mediaPluginCheckBox.setText(translate('AdvancedTab', + 'Save currently selected media manager plugin')) # self.sharedDirGroupBox.setTitle( # translate('AdvancedTab', 'Central Data Store')) # self.sharedCheckBox.setText( @@ -140,6 +154,9 @@ class AdvancedTab(SettingsTab): u'max recent files', QtCore.QVariant(20)).toInt()[0]) self.recentSpinBox.setValue(settings.value(u'recent file count', QtCore.QVariant(4)).toInt()[0]) + self.mediaPluginCheckBox.setChecked( + settings.value(u'save current plugin', + QtCore.QVariant(False)).toBool()) settings.endGroup() def save(self): @@ -150,6 +167,8 @@ class AdvancedTab(SettingsTab): settings.beginGroup(self.settingsSection) settings.setValue(u'recent file count', QtCore.QVariant(self.recentSpinBox.value())) + settings.setValue(u'save current plugin', + QtCore.QVariant(self.mediaPluginCheckBox.isChecked())) settings.endGroup() def onSharedCheckBoxChanged(self, checked): diff --git a/openlp/core/ui/mainwindow.py b/openlp/core/ui/mainwindow.py index ccef8a5ea..ec34a483b 100644 --- a/openlp/core/ui/mainwindow.py +++ b/openlp/core/ui/mainwindow.py @@ -658,6 +658,12 @@ class MainWindow(QtGui.QMainWindow, Ui_MainWindow): log.info(u'Load Themes') self.ThemeManagerContents.loadThemes() log.info(u'Load data from Settings') + if QtCore.QSettings().value(u'advanced/save current plugin', + QtCore.QVariant(False)).toBool(): + savedPlugin = QtCore.QSettings().value( + u'advanced/current media plugin', QtCore.QVariant()).toInt()[0] + if savedPlugin != -1: + self.MediaToolBox.setCurrentIndex(savedPlugin) self.settingsForm.postSetUp() def setAutoLanguage(self, value): @@ -820,6 +826,10 @@ class MainWindow(QtGui.QMainWindow, Ui_MainWindow): """ # Clean temporary files used by services self.ServiceManagerContents.cleanUp() + if QtCore.QSettings().value(u'advanced/save current plugin', + QtCore.QVariant(False)).toBool(): + QtCore.QSettings().setValue(u'advanced/current media plugin', + QtCore.QVariant(self.MediaToolBox.currentIndex())) # Call the cleanup method to shutdown plugins. log.info(u'cleanup plugins') self.plugin_manager.finalise_plugins()