forked from openlp/openlp
Cleanups and song data merging
bzr-revno: 952
This commit is contained in:
commit
a266a54641
@ -40,7 +40,7 @@ class BiblePlugin(Plugin):
|
||||
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 @@ class BiblePlugin(Plugin):
|
||||
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 @@ class BiblePlugin(Plugin):
|
||||
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)
|
||||
|
@ -129,8 +129,7 @@ class BibleMediaItem(MediaManagerItem):
|
||||
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 @@ class BibleMediaItem(MediaManagerItem):
|
||||
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 @@ class BibleMediaItem(MediaManagerItem):
|
||||
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 @@ class BibleMediaItem(MediaManagerItem):
|
||||
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)
|
||||
|
@ -97,7 +97,7 @@ class AuthorsForm(QtGui.QDialog, Ui_AuthorsDialog):
|
||||
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(
|
||||
|
@ -430,7 +430,7 @@ class Ui_EditSongDialog(object):
|
||||
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 @@ class Ui_EditSongDialog(object):
|
||||
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(
|
||||
|
@ -68,7 +68,7 @@ class Ui_SongBookDialog(object):
|
||||
|
||||
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:'))
|
||||
|
@ -217,7 +217,7 @@ class Ui_SongMaintenanceDialog(object):
|
||||
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(
|
||||
|
@ -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):
|
||||
@ -141,12 +141,9 @@ class SongMaintenanceForm(QtGui.QDialog, Ui_SongMaintenanceDialog):
|
||||
True.
|
||||
"""
|
||||
authors = self.songmanager.get_all_objects_filtered(Author,
|
||||
and_(
|
||||
Author.first_name == new_author.first_name,
|
||||
and_(Author.first_name == new_author.first_name,
|
||||
Author.last_name == new_author.last_name,
|
||||
Author.display_name == new_author.display_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
|
||||
@ -217,6 +214,11 @@ class SongMaintenanceForm(QtGui.QDialog, Ui_SongMaintenanceDialog):
|
||||
translate('SongsPlugin.SongMaintenanceForm', 'Error'),
|
||||
translate('SongsPlugin.SongMaintenanceForm',
|
||||
'Could not add your author.'))
|
||||
else:
|
||||
QtGui.QMessageBox.critical(self,
|
||||
translate('SongsPlugin.SongMaintenanceForm', 'Error'),
|
||||
translate('SongsPlugin.SongMaintenanceForm',
|
||||
'This author already exists.'))
|
||||
|
||||
def onTopicAddButtonClick(self):
|
||||
if self.topicform.exec_():
|
||||
@ -229,11 +231,15 @@ class SongMaintenanceForm(QtGui.QDialog, Ui_SongMaintenanceDialog):
|
||||
translate('SongsPlugin.SongMaintenanceForm', 'Error'),
|
||||
translate('SongsPlugin.SongMaintenanceForm',
|
||||
'Could not add your topic.'))
|
||||
else:
|
||||
QtGui.QMessageBox.critical(self,
|
||||
translate('SongsPlugin.SongMaintenanceForm', 'Error'),
|
||||
translate('SongsPlugin.SongMaintenanceForm',
|
||||
'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):
|
||||
@ -243,6 +249,11 @@ class SongMaintenanceForm(QtGui.QDialog, Ui_SongMaintenanceDialog):
|
||||
translate('SongsPlugin.SongMaintenanceForm', 'Error'),
|
||||
translate('SongsPlugin.SongMaintenanceForm',
|
||||
'Could not add your book.'))
|
||||
else:
|
||||
QtGui.QMessageBox.critical(self,
|
||||
translate('SongsPlugin.SongMaintenanceForm', 'Error'),
|
||||
translate('SongsPlugin.SongMaintenanceForm',
|
||||
'This book already exists.'))
|
||||
|
||||
def onAuthorEditButtonClick(self):
|
||||
author_id = self._getCurrentItemId(self.AuthorsListWidget)
|
||||
@ -266,6 +277,24 @@ class SongMaintenanceForm(QtGui.QDialog, Ui_SongMaintenanceDialog):
|
||||
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 @@ class SongMaintenanceForm(QtGui.QDialog, Ui_SongMaintenanceDialog):
|
||||
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 @@ class SongMaintenanceForm(QtGui.QDialog, Ui_SongMaintenanceDialog):
|
||||
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 @@ class SongMaintenanceForm(QtGui.QDialog, Ui_SongMaintenanceDialog):
|
||||
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 @@ class SongMaintenanceForm(QtGui.QDialog, Ui_SongMaintenanceDialog):
|
||||
|
||||
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 @@ class SongMaintenanceForm(QtGui.QDialog, Ui_SongMaintenanceDialog):
|
||||
|
||||
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'),
|
||||
|
Loading…
Reference in New Issue
Block a user