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.weight = -9
|
||||||
self.icon_path = u':/plugins/plugin_bibles.png'
|
self.icon_path = u':/plugins/plugin_bibles.png'
|
||||||
self.icon = build_icon(self.icon_path)
|
self.icon = build_icon(self.icon_path)
|
||||||
#Register the bible Manager
|
# Register the bible Manager.
|
||||||
self.status = PluginStatus.Active
|
self.status = PluginStatus.Active
|
||||||
self.manager = None
|
self.manager = None
|
||||||
|
|
||||||
@ -62,7 +62,7 @@ class BiblePlugin(Plugin):
|
|||||||
return BiblesTab(self.name)
|
return BiblesTab(self.name)
|
||||||
|
|
||||||
def getMediaManagerItem(self):
|
def getMediaManagerItem(self):
|
||||||
# Create the BibleManagerItem object
|
# Create the BibleManagerItem object.
|
||||||
return BibleMediaItem(self, self.icon, self.name)
|
return BibleMediaItem(self, self.icon, self.name)
|
||||||
|
|
||||||
def addImportMenuItem(self, import_menu):
|
def addImportMenuItem(self, import_menu):
|
||||||
@ -71,7 +71,7 @@ class BiblePlugin(Plugin):
|
|||||||
import_menu.addAction(self.ImportBibleItem)
|
import_menu.addAction(self.ImportBibleItem)
|
||||||
self.ImportBibleItem.setText(
|
self.ImportBibleItem.setText(
|
||||||
translate('BiblePlugin', '&Bible'))
|
translate('BiblePlugin', '&Bible'))
|
||||||
# Signals and slots
|
# signals and slots
|
||||||
QtCore.QObject.connect(self.ImportBibleItem,
|
QtCore.QObject.connect(self.ImportBibleItem,
|
||||||
QtCore.SIGNAL(u'triggered()'), self.onBibleImportClick)
|
QtCore.SIGNAL(u'triggered()'), self.onBibleImportClick)
|
||||||
self.ImportBibleItem.setVisible(False)
|
self.ImportBibleItem.setVisible(False)
|
||||||
|
@ -129,8 +129,7 @@ class BibleMediaItem(MediaManagerItem):
|
|||||||
self.QuickClearLabel.setObjectName(u'QuickSearchLabel')
|
self.QuickClearLabel.setObjectName(u'QuickSearchLabel')
|
||||||
self.QuickLayout.addWidget(self.QuickClearLabel, 4, 0, 1, 1)
|
self.QuickLayout.addWidget(self.QuickClearLabel, 4, 0, 1, 1)
|
||||||
self.ClearQuickSearchComboBox = QtGui.QComboBox(self.QuickTab)
|
self.ClearQuickSearchComboBox = QtGui.QComboBox(self.QuickTab)
|
||||||
self.ClearQuickSearchComboBox.setObjectName(
|
self.ClearQuickSearchComboBox.setObjectName(u'ClearQuickSearchComboBox')
|
||||||
u'ClearQuickSearchComboBox')
|
|
||||||
self.QuickLayout.addWidget(self.ClearQuickSearchComboBox, 4, 1, 1, 2)
|
self.QuickLayout.addWidget(self.ClearQuickSearchComboBox, 4, 1, 1, 2)
|
||||||
self.QuickSearchButtonLayout = QtGui.QHBoxLayout()
|
self.QuickSearchButtonLayout = QtGui.QHBoxLayout()
|
||||||
self.QuickSearchButtonLayout.setMargin(0)
|
self.QuickSearchButtonLayout.setMargin(0)
|
||||||
@ -168,8 +167,7 @@ class BibleMediaItem(MediaManagerItem):
|
|||||||
self.AdvancedVersionComboBox.setObjectName(u'AdvancedVersionComboBox')
|
self.AdvancedVersionComboBox.setObjectName(u'AdvancedVersionComboBox')
|
||||||
self.AdvancedLayout.addWidget(self.AdvancedVersionComboBox, 0, 1, 1, 2)
|
self.AdvancedLayout.addWidget(self.AdvancedVersionComboBox, 0, 1, 1, 2)
|
||||||
self.AdvancedSecondBibleLabel = QtGui.QLabel(self.AdvancedTab)
|
self.AdvancedSecondBibleLabel = QtGui.QLabel(self.AdvancedTab)
|
||||||
self.AdvancedSecondBibleLabel.setObjectName(
|
self.AdvancedSecondBibleLabel.setObjectName(u'AdvancedSecondBibleLabel')
|
||||||
u'AdvancedSecondBibleLabel')
|
|
||||||
self.AdvancedLayout.addWidget(self.AdvancedSecondBibleLabel, 1, 0, 1, 1)
|
self.AdvancedLayout.addWidget(self.AdvancedSecondBibleLabel, 1, 0, 1, 1)
|
||||||
self.AdvancedSecondBibleComboBox = QtGui.QComboBox(self.AdvancedTab)
|
self.AdvancedSecondBibleComboBox = QtGui.QComboBox(self.AdvancedTab)
|
||||||
self.AdvancedSecondBibleComboBox.setSizeAdjustPolicy(
|
self.AdvancedSecondBibleComboBox.setSizeAdjustPolicy(
|
||||||
@ -223,8 +221,7 @@ class BibleMediaItem(MediaManagerItem):
|
|||||||
u'AdvancedSearchButtonLayout')
|
u'AdvancedSearchButtonLayout')
|
||||||
self.AdvancedSearchButtonSpacer = QtGui.QSpacerItem(40, 20,
|
self.AdvancedSearchButtonSpacer = QtGui.QSpacerItem(40, 20,
|
||||||
QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Minimum)
|
QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Minimum)
|
||||||
self.AdvancedSearchButtonLayout.addItem(
|
self.AdvancedSearchButtonLayout.addItem(self.AdvancedSearchButtonSpacer)
|
||||||
self.AdvancedSearchButtonSpacer)
|
|
||||||
self.AdvancedSearchButton = QtGui.QPushButton(self.AdvancedTab)
|
self.AdvancedSearchButton = QtGui.QPushButton(self.AdvancedTab)
|
||||||
self.AdvancedSearchButton.setObjectName(u'AdvancedSearchButton')
|
self.AdvancedSearchButton.setObjectName(u'AdvancedSearchButton')
|
||||||
self.AdvancedSearchButtonLayout.addWidget(self.AdvancedSearchButton)
|
self.AdvancedSearchButtonLayout.addWidget(self.AdvancedSearchButton)
|
||||||
@ -618,8 +615,7 @@ class BibleMediaItem(MediaManagerItem):
|
|||||||
else:
|
else:
|
||||||
self.AdvancedSearchButton.setEnabled(True)
|
self.AdvancedSearchButton.setEnabled(True)
|
||||||
self.AdvancedMessage.setText(u'')
|
self.AdvancedMessage.setText(u'')
|
||||||
self.adjustComboBox(1, self.chapters_from,
|
self.adjustComboBox(1, self.chapters_from, self.AdvancedFromChapter)
|
||||||
self.AdvancedFromChapter)
|
|
||||||
self.adjustComboBox(1, self.chapters_from, self.AdvancedToChapter)
|
self.adjustComboBox(1, self.chapters_from, self.AdvancedToChapter)
|
||||||
self.adjustComboBox(1, self.verses, self.AdvancedFromVerse)
|
self.adjustComboBox(1, self.verses, self.AdvancedFromVerse)
|
||||||
self.adjustComboBox(1, self.verses, self.AdvancedToVerse)
|
self.adjustComboBox(1, self.verses, self.AdvancedToVerse)
|
||||||
|
@ -97,7 +97,7 @@ class AuthorsForm(QtGui.QDialog, Ui_AuthorsDialog):
|
|||||||
if QtGui.QMessageBox.critical(
|
if QtGui.QMessageBox.critical(
|
||||||
self, translate('SongsPlugin.AuthorsForm', 'Error'),
|
self, translate('SongsPlugin.AuthorsForm', 'Error'),
|
||||||
translate('SongsPlugin.AuthorsForm',
|
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 '
|
'author, would you like me to combine the first and '
|
||||||
'last names for you?'),
|
'last names for you?'),
|
||||||
QtGui.QMessageBox.StandardButtons(
|
QtGui.QMessageBox.StandardButtons(
|
||||||
|
@ -430,7 +430,7 @@ class Ui_EditSongDialog(object):
|
|||||||
self.AuthorRemoveButton.setText(
|
self.AuthorRemoveButton.setText(
|
||||||
translate('SongsPlugin.EditSongForm', '&Remove'))
|
translate('SongsPlugin.EditSongForm', '&Remove'))
|
||||||
self.MaintenanceButton.setText(translate('SongsPlugin.EditSongForm',
|
self.MaintenanceButton.setText(translate('SongsPlugin.EditSongForm',
|
||||||
'&Manage Authors, Topics, Books'))
|
'&Manage Authors, Topics, Song Books'))
|
||||||
self.TopicGroupBox.setTitle(
|
self.TopicGroupBox.setTitle(
|
||||||
translate('SongsPlugin.EditSongForm', 'Topic'))
|
translate('SongsPlugin.EditSongForm', 'Topic'))
|
||||||
self.TopicAddButton.setText(
|
self.TopicAddButton.setText(
|
||||||
@ -441,7 +441,7 @@ class Ui_EditSongDialog(object):
|
|||||||
translate('SongsPlugin.EditSongForm', 'Song Book'))
|
translate('SongsPlugin.EditSongForm', 'Song Book'))
|
||||||
self.SongTabWidget.setTabText(
|
self.SongTabWidget.setTabText(
|
||||||
self.SongTabWidget.indexOf(self.AuthorsTab),
|
self.SongTabWidget.indexOf(self.AuthorsTab),
|
||||||
translate('SongsPlugin.EditSongForm', 'Authors, Topics && Book'))
|
translate('SongsPlugin.EditSongForm', 'Authors, Topics && Song Book'))
|
||||||
self.ThemeGroupBox.setTitle(
|
self.ThemeGroupBox.setTitle(
|
||||||
translate('SongsPlugin.EditSongForm', 'Theme'))
|
translate('SongsPlugin.EditSongForm', 'Theme'))
|
||||||
self.ThemeAddButton.setText(
|
self.ThemeAddButton.setText(
|
||||||
|
@ -68,7 +68,7 @@ class Ui_SongBookDialog(object):
|
|||||||
|
|
||||||
def retranslateUi(self, SongBookDialog):
|
def retranslateUi(self, SongBookDialog):
|
||||||
SongBookDialog.setWindowTitle(
|
SongBookDialog.setWindowTitle(
|
||||||
translate('SongsPlugin.SongBookForm', 'Edit Book'))
|
translate('SongsPlugin.SongBookForm', 'Song Book Maintenance'))
|
||||||
self.NameLabel.setText(translate('SongsPlugin.SongBookForm', '&Name:'))
|
self.NameLabel.setText(translate('SongsPlugin.SongBookForm', '&Name:'))
|
||||||
self.PublisherLabel.setText(
|
self.PublisherLabel.setText(
|
||||||
translate('SongsPlugin.SongBookForm', '&Publisher:'))
|
translate('SongsPlugin.SongBookForm', '&Publisher:'))
|
||||||
|
@ -217,7 +217,7 @@ class Ui_SongMaintenanceDialog(object):
|
|||||||
self.TypeListWidget.item(1).setText(
|
self.TypeListWidget.item(1).setText(
|
||||||
translate('SongsPlugin.SongMaintenanceForm', 'Topics'))
|
translate('SongsPlugin.SongMaintenanceForm', 'Topics'))
|
||||||
self.TypeListWidget.item(2).setText(
|
self.TypeListWidget.item(2).setText(
|
||||||
translate('SongsPlugin.SongMaintenanceForm', 'Books/Hymnals'))
|
translate('SongsPlugin.SongMaintenanceForm', 'Song Books'))
|
||||||
self.AuthorAddButton.setText(
|
self.AuthorAddButton.setText(
|
||||||
translate('SongsPlugin.SongMaintenanceForm', '&Add'))
|
translate('SongsPlugin.SongMaintenanceForm', '&Add'))
|
||||||
self.AuthorEditButton.setText(
|
self.AuthorEditButton.setText(
|
||||||
|
@ -26,9 +26,9 @@
|
|||||||
from PyQt4 import QtGui, QtCore
|
from PyQt4 import QtGui, QtCore
|
||||||
from sqlalchemy.sql import and_
|
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.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
|
from songmaintenancedialog import Ui_SongMaintenanceDialog
|
||||||
|
|
||||||
class SongMaintenanceForm(QtGui.QDialog, Ui_SongMaintenanceDialog):
|
class SongMaintenanceForm(QtGui.QDialog, Ui_SongMaintenanceDialog):
|
||||||
@ -140,13 +140,10 @@ class SongMaintenanceForm(QtGui.QDialog, Ui_SongMaintenanceDialog):
|
|||||||
Returns False if the given Author is already in the list otherwise
|
Returns False if the given Author is already in the list otherwise
|
||||||
True.
|
True.
|
||||||
"""
|
"""
|
||||||
authors = self.songmanager.get_all_objects_filtered(Author,
|
authors = self.songmanager.get_all_objects_filtered(Author,
|
||||||
and_(
|
and_(Author.first_name == new_author.first_name,
|
||||||
Author.first_name == new_author.first_name,
|
Author.last_name == new_author.last_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 len(authors) > 0:
|
||||||
# If we edit an existing 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 False when nothing has changed (because this would
|
# not return False when nothing has changed (because this would
|
||||||
@ -186,7 +183,7 @@ class SongMaintenanceForm(QtGui.QDialog, Ui_SongMaintenanceDialog):
|
|||||||
Returns False if the given Book is already in the list otherwise True.
|
Returns False if the given Book is already in the list otherwise True.
|
||||||
"""
|
"""
|
||||||
books = self.songmanager.get_all_objects_filtered(Book,
|
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))
|
Book.publisher == new_book.publisher))
|
||||||
if len(books) > 0:
|
if len(books) > 0:
|
||||||
# If we edit an existing Book, we need to make sure that we do
|
# If we edit an existing Book, we need to make sure that we do
|
||||||
@ -212,11 +209,16 @@ class SongMaintenanceForm(QtGui.QDialog, Ui_SongMaintenanceDialog):
|
|||||||
if self.checkAuthor(author):
|
if self.checkAuthor(author):
|
||||||
if self.songmanager.save_object(author):
|
if self.songmanager.save_object(author):
|
||||||
self.resetAuthors()
|
self.resetAuthors()
|
||||||
|
else:
|
||||||
|
QtGui.QMessageBox.critical(self,
|
||||||
|
translate('SongsPlugin.SongMaintenanceForm', 'Error'),
|
||||||
|
translate('SongsPlugin.SongMaintenanceForm',
|
||||||
|
'Could not add your author.'))
|
||||||
else:
|
else:
|
||||||
QtGui.QMessageBox.critical(self,
|
QtGui.QMessageBox.critical(self,
|
||||||
translate('SongsPlugin.SongMaintenanceForm', 'Error'),
|
translate('SongsPlugin.SongMaintenanceForm', 'Error'),
|
||||||
translate('SongsPlugin.SongMaintenanceForm',
|
translate('SongsPlugin.SongMaintenanceForm',
|
||||||
'Could not add your author.'))
|
'This author already exists.'))
|
||||||
|
|
||||||
def onTopicAddButtonClick(self):
|
def onTopicAddButtonClick(self):
|
||||||
if self.topicform.exec_():
|
if self.topicform.exec_():
|
||||||
@ -224,25 +226,34 @@ class SongMaintenanceForm(QtGui.QDialog, Ui_SongMaintenanceDialog):
|
|||||||
if self.checkTopic(topic):
|
if self.checkTopic(topic):
|
||||||
if self.songmanager.save_object(topic):
|
if self.songmanager.save_object(topic):
|
||||||
self.resetTopics()
|
self.resetTopics()
|
||||||
|
else:
|
||||||
|
QtGui.QMessageBox.critical(self,
|
||||||
|
translate('SongsPlugin.SongMaintenanceForm', 'Error'),
|
||||||
|
translate('SongsPlugin.SongMaintenanceForm',
|
||||||
|
'Could not add your topic.'))
|
||||||
else:
|
else:
|
||||||
QtGui.QMessageBox.critical(self,
|
QtGui.QMessageBox.critical(self,
|
||||||
translate('SongsPlugin.SongMaintenanceForm', 'Error'),
|
translate('SongsPlugin.SongMaintenanceForm', 'Error'),
|
||||||
translate('SongsPlugin.SongMaintenanceForm',
|
translate('SongsPlugin.SongMaintenanceForm',
|
||||||
'Could not add your topic.'))
|
'This topic already exists.'))
|
||||||
|
|
||||||
def onBookAddButtonClick(self):
|
def onBookAddButtonClick(self):
|
||||||
if self.bookform.exec_():
|
if self.bookform.exec_():
|
||||||
book = Book.populate(
|
book = Book.populate(name=unicode(self.bookform.NameEdit.text()),
|
||||||
name=unicode(self.bookform.NameEdit.text()),
|
|
||||||
publisher=unicode(self.bookform.PublisherEdit.text()))
|
publisher=unicode(self.bookform.PublisherEdit.text()))
|
||||||
if self.checkBook(book):
|
if self.checkBook(book):
|
||||||
if self.songmanager.save_object(book):
|
if self.songmanager.save_object(book):
|
||||||
self.resetBooks()
|
self.resetBooks()
|
||||||
|
else:
|
||||||
|
QtGui.QMessageBox.critical(self,
|
||||||
|
translate('SongsPlugin.SongMaintenanceForm', 'Error'),
|
||||||
|
translate('SongsPlugin.SongMaintenanceForm',
|
||||||
|
'Could not add your book.'))
|
||||||
else:
|
else:
|
||||||
QtGui.QMessageBox.critical(self,
|
QtGui.QMessageBox.critical(self,
|
||||||
translate('SongsPlugin.SongMaintenanceForm', 'Error'),
|
translate('SongsPlugin.SongMaintenanceForm', 'Error'),
|
||||||
translate('SongsPlugin.SongMaintenanceForm',
|
translate('SongsPlugin.SongMaintenanceForm',
|
||||||
'Could not add your book.'))
|
'This book already exists.'))
|
||||||
|
|
||||||
def onAuthorEditButtonClick(self):
|
def onAuthorEditButtonClick(self):
|
||||||
author_id = self._getCurrentItemId(self.AuthorsListWidget)
|
author_id = self._getCurrentItemId(self.AuthorsListWidget)
|
||||||
@ -266,6 +277,24 @@ class SongMaintenanceForm(QtGui.QDialog, Ui_SongMaintenanceDialog):
|
|||||||
if self.checkAuthor(author, True):
|
if self.checkAuthor(author, True):
|
||||||
if self.songmanager.save_object(author):
|
if self.songmanager.save_object(author):
|
||||||
self.resetAuthors()
|
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:
|
else:
|
||||||
# We restore the author's old first and last name as well as
|
# We restore the author's old first and last name as well as
|
||||||
# his display name.
|
# his display name.
|
||||||
@ -275,7 +304,8 @@ class SongMaintenanceForm(QtGui.QDialog, Ui_SongMaintenanceDialog):
|
|||||||
QtGui.QMessageBox.critical(self,
|
QtGui.QMessageBox.critical(self,
|
||||||
translate('SongsPlugin.SongMaintenanceForm', 'Error'),
|
translate('SongsPlugin.SongMaintenanceForm', 'Error'),
|
||||||
translate('SongsPlugin.SongMaintenanceForm',
|
translate('SongsPlugin.SongMaintenanceForm',
|
||||||
'Could not save your author.'))
|
'Could not save your modified author, because he '
|
||||||
|
'already exists.'))
|
||||||
|
|
||||||
def onTopicEditButtonClick(self):
|
def onTopicEditButtonClick(self):
|
||||||
topic_id = self._getCurrentItemId(self.TopicsListWidget)
|
topic_id = self._getCurrentItemId(self.TopicsListWidget)
|
||||||
@ -289,13 +319,30 @@ class SongMaintenanceForm(QtGui.QDialog, Ui_SongMaintenanceDialog):
|
|||||||
if self.checkTopic(topic, True):
|
if self.checkTopic(topic, True):
|
||||||
if self.songmanager.save_object(topic):
|
if self.songmanager.save_object(topic):
|
||||||
self.resetTopics()
|
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:
|
else:
|
||||||
# We restore the topics's old name.
|
# We restore the topics's old name.
|
||||||
topic.name = temp_name
|
topic.name = temp_name
|
||||||
QtGui.QMessageBox.critical(self,
|
QtGui.QMessageBox.critical(self,
|
||||||
translate('SongsPlugin.SongMaintenanceForm', 'Error'),
|
translate('SongsPlugin.SongMaintenanceForm', 'Error'),
|
||||||
translate('SongsPlugin.SongMaintenanceForm',
|
translate('SongsPlugin.SongMaintenanceForm',
|
||||||
'Could not save your topic.'))
|
'Could not save your modified topic, because it '
|
||||||
|
'already exists.'))
|
||||||
|
|
||||||
def onBookEditButtonClick(self):
|
def onBookEditButtonClick(self):
|
||||||
book_id = self._getCurrentItemId(self.BooksListWidget)
|
book_id = self._getCurrentItemId(self.BooksListWidget)
|
||||||
@ -313,18 +360,89 @@ class SongMaintenanceForm(QtGui.QDialog, Ui_SongMaintenanceDialog):
|
|||||||
if self.checkBook(book, True):
|
if self.checkBook(book, True):
|
||||||
if self.songmanager.save_object(book):
|
if self.songmanager.save_object(book):
|
||||||
self.resetBooks()
|
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:
|
else:
|
||||||
# We restore the book's old name and publisher.
|
# We restore the book's old name and publisher.
|
||||||
book.name = temp_name
|
book.name = temp_name
|
||||||
book.publisher = temp_publisher
|
book.publisher = temp_publisher
|
||||||
QtGui.QMessageBox.critical(self,
|
|
||||||
translate('SongsPlugin.SongMaintenanceForm', 'Error'),
|
def mergeAuthors(self, old_author):
|
||||||
translate('SongsPlugin.SongMaintenanceForm',
|
'''
|
||||||
'Could not save your book.'))
|
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):
|
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,
|
self._deleteItem(Author, self.AuthorsListWidget, self.resetAuthors,
|
||||||
translate('SongsPlugin.SongMaintenanceForm', 'Delete Author'),
|
translate('SongsPlugin.SongMaintenanceForm', 'Delete Author'),
|
||||||
@ -337,7 +455,7 @@ class SongMaintenanceForm(QtGui.QDialog, Ui_SongMaintenanceDialog):
|
|||||||
|
|
||||||
def onTopicDeleteButtonClick(self):
|
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,
|
self._deleteItem(Topic, self.TopicsListWidget, self.resetTopics,
|
||||||
translate('SongsPlugin.SongMaintenanceForm', 'Delete Topic'),
|
translate('SongsPlugin.SongMaintenanceForm', 'Delete Topic'),
|
||||||
@ -350,7 +468,7 @@ class SongMaintenanceForm(QtGui.QDialog, Ui_SongMaintenanceDialog):
|
|||||||
|
|
||||||
def onBookDeleteButtonClick(self):
|
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,
|
self._deleteItem(Book, self.BooksListWidget, self.resetBooks,
|
||||||
translate('SongsPlugin.SongMaintenanceForm', 'Delete Book'),
|
translate('SongsPlugin.SongMaintenanceForm', 'Delete Book'),
|
||||||
|
Loading…
Reference in New Issue
Block a user