Deleting song items

This commit is contained in:
Jon Tibble 2011-02-14 02:54:24 +00:00
parent 71cbbfcbf2
commit 2316ab4ed4
2 changed files with 15 additions and 27 deletions

View File

@ -103,20 +103,22 @@ class SongMaintenanceForm(QtGui.QDialog, Ui_SongMaintenanceDialog):
else: else:
return -1 return -1
def _deleteItem(self, item_class, list_widget, reset_func, dlg_title, def _deleteItem(self, item_class, list_widget, reset_func, del_type):
del_text, err_text, sel_text): dlg_title = UiStrings.DeleteType % del_type
item_id = self._getCurrentItemId(list_widget) item_id = self._getCurrentItemId(list_widget)
if item_id != -1: if item_id != -1:
item = self.manager.get_object(item_class, item_id) item = self.manager.get_object(item_class, item_id)
if item and len(item.songs) == 0: if item and len(item.songs) == 0:
if critical_error_message_box(title=dlg_title, message=del_text, if critical_error_message_box(dlg_title,
parent=self, question=True) == QtGui.QMessageBox.Yes: SongStrings.SureDeleteType % del_type,
self, True) == QtGui.QMessageBox.Yes:
self.manager.delete_object(item_class, item.id) self.manager.delete_object(item_class, item.id)
reset_func() reset_func()
else: else:
critical_error_message_box(dlg_title, err_text) critical_error_message_box(dlg_title,
SongStrings.NoDeleteAssigned % del_type)
else: else:
critical_error_message_box(dlg_title, sel_text) critical_error_message_box(dlg_title, UiStrings.NISs)
def resetAuthors(self): def resetAuthors(self):
""" """
@ -440,39 +442,21 @@ class SongMaintenanceForm(QtGui.QDialog, Ui_SongMaintenanceDialog):
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,
UiStrings.DeleteType % SongStrings.Author, SongStrings.Author)
translate('SongsPlugin.SongMaintenanceForm',
'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.'),
translate('SongsPlugin.SongMaintenanceForm', 'No author selected!'))
def onTopicDeleteButtonClick(self): def onTopicDeleteButtonClick(self):
""" """
Delete the Book if the Book is not attached to any songs. Delete the Book if the Book is not attached to any songs.
""" """
self._deleteItem(Topic, self.topicsListWidget, self.resetTopics, self._deleteItem(Topic, self.topicsListWidget, self.resetTopics,
UiStrings.DeleteType % SongStrings.Topic, SongStrings.Topic)
translate('SongsPlugin.SongMaintenanceForm',
'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): def onBookDeleteButtonClick(self):
""" """
Delete the Book if the Book is not attached to any songs. Delete the Book if the Book is not attached to any songs.
""" """
self._deleteItem(Book, self.booksListWidget, self.resetBooks, self._deleteItem(Book, self.booksListWidget, self.resetBooks,
UiStrings.DeleteType % SongStrings.SongBook, SongStrings.SongBook)
translate('SongsPlugin.SongMaintenanceForm',
'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!'))
def onAuthorsListRowChanged(self, row): def onAuthorsListRowChanged(self, row):
""" """

View File

@ -39,8 +39,12 @@ class SongStrings(object):
AuthorUnknown = translate('OpenLP.Ui', 'Author Unknown') # Used in the UI. AuthorUnknown = translate('OpenLP.Ui', 'Author Unknown') # Used in the UI.
AuthorUnknownUnT = u'Author Unknown' # Used to populate the database. AuthorUnknownUnT = u'Author Unknown' # Used to populate the database.
CouldNotAdd = unicode(translate('OpenLP.Ui', 'Could not add your %s.')) CouldNotAdd = unicode(translate('OpenLP.Ui', 'Could not add your %s.'))
NoDeleteAssigned = unicode(translate('OpenLP.Ui', 'This %s cannot be '
'deleted as it is currently assigned to at least one song.'))
SongBook = translate('OpenLP.Ui', 'Song Book', 'Singular') SongBook = translate('OpenLP.Ui', 'Song Book', 'Singular')
SongBooks = translate('OpenLP.Ui', 'Song Books', 'Plural') SongBooks = translate('OpenLP.Ui', 'Song Books', 'Plural')
SureDeleteType = unicode(translate('OpenLP.Ui',
'Are you sure you want to delete the selected %s?'))
ThisTypeExists = unicode(translate('OpenLP.Ui', 'This %s already exists.')) ThisTypeExists = unicode(translate('OpenLP.Ui', 'This %s already exists.'))
Topic = translate('OpenLP.Ui', 'Topic', 'Singular') Topic = translate('OpenLP.Ui', 'Topic', 'Singular')
Topics = translate('OpenLP.Ui', 'Topics', 'Plural') Topics = translate('OpenLP.Ui', 'Topics', 'Plural')