From 2316ab4ed47bba894c9c31bd71ba17947e8da418 Mon Sep 17 00:00:00 2001 From: Jon Tibble Date: Mon, 14 Feb 2011 02:54:24 +0000 Subject: [PATCH] Deleting song items --- .../songs/forms/songmaintenanceform.py | 38 ++++++------------- openlp/plugins/songs/lib/ui.py | 4 ++ 2 files changed, 15 insertions(+), 27 deletions(-) diff --git a/openlp/plugins/songs/forms/songmaintenanceform.py b/openlp/plugins/songs/forms/songmaintenanceform.py index 41f3e4237..ffea2ffa6 100644 --- a/openlp/plugins/songs/forms/songmaintenanceform.py +++ b/openlp/plugins/songs/forms/songmaintenanceform.py @@ -103,20 +103,22 @@ class SongMaintenanceForm(QtGui.QDialog, Ui_SongMaintenanceDialog): else: return -1 - def _deleteItem(self, item_class, list_widget, reset_func, dlg_title, - del_text, err_text, sel_text): + def _deleteItem(self, item_class, list_widget, reset_func, del_type): + dlg_title = UiStrings.DeleteType % del_type item_id = self._getCurrentItemId(list_widget) if item_id != -1: item = self.manager.get_object(item_class, item_id) if item and len(item.songs) == 0: - if critical_error_message_box(title=dlg_title, message=del_text, - parent=self, question=True) == QtGui.QMessageBox.Yes: + if critical_error_message_box(dlg_title, + SongStrings.SureDeleteType % del_type, + self, True) == QtGui.QMessageBox.Yes: self.manager.delete_object(item_class, item.id) reset_func() else: - critical_error_message_box(dlg_title, err_text) + critical_error_message_box(dlg_title, + SongStrings.NoDeleteAssigned % del_type) else: - critical_error_message_box(dlg_title, sel_text) + critical_error_message_box(dlg_title, UiStrings.NISs) 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. """ self._deleteItem(Author, self.authorsListWidget, self.resetAuthors, - UiStrings.DeleteType % 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!')) + SongStrings.Author) def onTopicDeleteButtonClick(self): """ Delete the Book if the Book is not attached to any songs. """ self._deleteItem(Topic, self.topicsListWidget, self.resetTopics, - UiStrings.DeleteType % 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!')) + SongStrings.Topic) def onBookDeleteButtonClick(self): """ Delete the Book if the Book is not attached to any songs. """ self._deleteItem(Book, self.booksListWidget, self.resetBooks, - UiStrings.DeleteType % 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!')) + SongStrings.SongBook) def onAuthorsListRowChanged(self, row): """ diff --git a/openlp/plugins/songs/lib/ui.py b/openlp/plugins/songs/lib/ui.py index 0203c166e..e16835ba3 100644 --- a/openlp/plugins/songs/lib/ui.py +++ b/openlp/plugins/songs/lib/ui.py @@ -39,8 +39,12 @@ class SongStrings(object): AuthorUnknown = translate('OpenLP.Ui', 'Author Unknown') # Used in the UI. AuthorUnknownUnT = u'Author Unknown' # Used to populate the database. 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') 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.')) Topic = translate('OpenLP.Ui', 'Topic', 'Singular') Topics = translate('OpenLP.Ui', 'Topics', 'Plural')