From 5e0ab4a7f6d8a06855e7b9803294cbdeecd049d7 Mon Sep 17 00:00:00 2001 From: Jon Tibble Date: Wed, 16 Jun 2010 02:23:57 +0100 Subject: [PATCH] Fix lack of feedback for edit and delete --- openlp/core/lib/mediamanageritem.py | 17 +++++++++++++++-- openlp/plugins/custom/lib/mediaitem.py | 16 ++++++++++++---- openlp/plugins/images/lib/mediaitem.py | 12 ++++++++---- openlp/plugins/media/lib/mediaitem.py | 9 ++++++--- openlp/plugins/presentations/lib/mediaitem.py | 8 ++++++-- openlp/plugins/songs/lib/mediaitem.py | 17 ++++++++++++----- 6 files changed, 59 insertions(+), 20 deletions(-) diff --git a/openlp/core/lib/mediamanageritem.py b/openlp/core/lib/mediamanageritem.py index 92efd152c..8df8bded9 100644 --- a/openlp/core/lib/mediamanageritem.py +++ b/openlp/core/lib/mediamanageritem.py @@ -325,6 +325,19 @@ class MediaManagerItem(QtGui.QWidget): """ pass + def checkItemSelected(self, message): + """ + Check if a list item is selected so an action may be performed on it + + ``message`` + The message to give the user if no item is selected + """ + if not self.ListView.selectedIndexes(): + QtGui.QMessageBox.information(self, + self.trUtf8('No Items Selected'), message) + return False + return True + def onFileClick(self): files = QtGui.QFileDialog.getOpenFileNames( self, self.OnNewPrompt, @@ -392,7 +405,7 @@ class MediaManagerItem(QtGui.QWidget): if not self.ListView.selectedIndexes() and not self.remoteTriggered: QtGui.QMessageBox.information(self, self.trUtf8('No Items Selected'), - self.trUtf8('You must select one or more items.')) + self.trUtf8('You must select one or more items to preview.')) else: log.debug(self.PluginNameShort + u' Preview requested') service_item = self.buildServiceItem() @@ -404,7 +417,7 @@ class MediaManagerItem(QtGui.QWidget): if not self.ListView.selectedIndexes(): QtGui.QMessageBox.information(self, self.trUtf8('No Items Selected'), - self.trUtf8('You must select one or more items.')) + self.trUtf8('You must select one or more items to send live.')) else: log.debug(self.PluginNameShort + u' Live requested') service_item = self.buildServiceItem() diff --git a/openlp/plugins/custom/lib/mediaitem.py b/openlp/plugins/custom/lib/mediaitem.py index 581334410..4cbf25476 100644 --- a/openlp/plugins/custom/lib/mediaitem.py +++ b/openlp/plugins/custom/lib/mediaitem.py @@ -115,16 +115,24 @@ class CustomMediaItem(MediaManagerItem): self.parent.edit_custom_form.exec_() def onEditClick(self): - item = self.ListView.currentItem() - if item: + """ + Edit a custom item + """ + if self.checkItemSelected(translate(u'CustomPlugin.MediaItem', + u'You must select an item to edit.')): + item = self.ListView.currentItem() item_id = (item.data(QtCore.Qt.UserRole)).toInt()[0] self.parent.edit_custom_form.loadCustom(item_id, False) self.parent.edit_custom_form.exec_() self.initialise() def onDeleteClick(self): - item = self.ListView.currentItem() - if item: + """ + Remove a custom item from the list and database + """ + if self.checkItemSelected(translate(u'CustomPlugin.MediaItem', + u'You must select an item to delete.')): + item = self.ListView.currentItem() item_id = (item.data(QtCore.Qt.UserRole)).toInt()[0] self.parent.custommanager.delete_custom(item_id) row = self.ListView.row(item) diff --git a/openlp/plugins/images/lib/mediaitem.py b/openlp/plugins/images/lib/mediaitem.py index 6e791badd..0ab86f3f7 100644 --- a/openlp/plugins/images/lib/mediaitem.py +++ b/openlp/plugins/images/lib/mediaitem.py @@ -116,14 +116,18 @@ class ImageMediaItem(MediaManagerItem): self.PageLayout.addWidget(self.ImageWidget) def onDeleteClick(self): - items = self.ListView.selectedIndexes() - if items: + """ + Remove an image item from the list + """ + if self.checkItemSelected(translate(u'ImagePlugin.MediaItem', + u'You must select an item to delete.')): + items = self.ListView.selectedIndexes() for item in items: text = self.ListView.item(item.row()) if text: try: - os.remove( - os.path.join(self.servicePath, unicode(text.text()))) + os.remove(os.path.join(self.servicePath, + unicode(text.text()))) except OSError: #if not present do not worry pass diff --git a/openlp/plugins/media/lib/mediaitem.py b/openlp/plugins/media/lib/mediaitem.py index fd397a35f..60bc190dc 100644 --- a/openlp/plugins/media/lib/mediaitem.py +++ b/openlp/plugins/media/lib/mediaitem.py @@ -137,8 +137,12 @@ class MediaMediaItem(MediaManagerItem): self.settingsSection)) def onDeleteClick(self): - item = self.ListView.currentItem() - if item: + """ + Remove a media item from the list + """ + if self.checkItemSelected(translate(u'MediaPlugin.MediaItem', + u'You must select an item to delete.')): + item = self.ListView.currentItem() row = self.ListView.row(item) self.ListView.takeItem(row) SettingsManager.set_list(self.settingsSection, @@ -152,4 +156,3 @@ class MediaMediaItem(MediaManagerItem): item_name.setIcon(build_icon(img)) item_name.setData(QtCore.Qt.UserRole, QtCore.QVariant(file)) self.ListView.addItem(item_name) - diff --git a/openlp/plugins/presentations/lib/mediaitem.py b/openlp/plugins/presentations/lib/mediaitem.py index be2cecff4..51e2db23b 100644 --- a/openlp/plugins/presentations/lib/mediaitem.py +++ b/openlp/plugins/presentations/lib/mediaitem.py @@ -174,8 +174,12 @@ class PresentationMediaItem(MediaManagerItem): self.ListView.addItem(item_name) def onDeleteClick(self): - item = self.ListView.currentItem() - if item: + """ + Remove a presentation item from the list + """ + if self.checkItemSelected(translate(u'PresentationPlugin.MediaItem', + u'You must select an item to delete.')): + item = self.ListView.currentItem() row = self.ListView.row(item) self.ListView.takeItem(row) SettingsManager.set_list(self.settingsSection, diff --git a/openlp/plugins/songs/lib/mediaitem.py b/openlp/plugins/songs/lib/mediaitem.py index d6f2f5ce8..60faaa826 100644 --- a/openlp/plugins/songs/lib/mediaitem.py +++ b/openlp/plugins/songs/lib/mediaitem.py @@ -275,15 +275,23 @@ class SongMediaItem(MediaManagerItem): self.edit_song_form.exec_() def onEditClick(self): - item = self.ListView.currentItem() - if item: + """ + Edit a song + """ + if self.checkItemSelected(translate(u'SongsPlugin.MediaItem', + u'You must select an item to edit.')): + item = self.ListView.currentItem() item_id = (item.data(QtCore.Qt.UserRole)).toInt()[0] self.edit_song_form.loadSong(item_id, False) self.edit_song_form.exec_() def onDeleteClick(self): - items = self.ListView.selectedIndexes() - if items: + """ + Remove a song from the list and database + """ + if self.checkItemSelected(translate(u'SongsPlugin.MediaItem', + u'You must select an item to delete.')): + items = self.ListView.selectedIndexes() if len(items) == 1: del_message = translate(u'SongsPlugin.MediaItem', u'Delete song?') @@ -371,4 +379,3 @@ class SongMediaItem(MediaManagerItem): song.title, author_audit, song.copyright, song.ccli_number ] return True -