This commit is contained in:
Andreas Preikschat 2011-01-02 11:29:18 +01:00
commit cce440ba48
2 changed files with 40 additions and 14 deletions

View File

@ -41,7 +41,7 @@ class ImagePlugin(Plugin):
self.icon = build_icon(self.icon_path) self.icon = build_icon(self.icon_path)
def getMediaManagerItem(self): def getMediaManagerItem(self):
# Create the MediaManagerItem object # Create the MediaManagerItem object.
return ImageMediaItem(self, self, self.icon) return ImageMediaItem(self, self, self.icon)
def about(self): def about(self):

View File

@ -48,6 +48,7 @@ class ImageMediaItem(MediaManagerItem):
""" """
This is the custom media manager item for images. This is the custom media manager item for images.
""" """
# TODO: prevent adding an image twice
log.info(u'Image Media Item loaded') log.info(u'Image Media Item loaded')
def __init__(self, parent, plugin, icon): def __init__(self, parent, plugin, icon):
@ -166,29 +167,53 @@ class ImageMediaItem(MediaManagerItem):
service_item.add_capability(ItemCapabilities.AllowsAdditions) service_item.add_capability(ItemCapabilities.AllowsAdditions)
# force a nonexistent theme # force a nonexistent theme
service_item.theme = -1 service_item.theme = -1
missing_items = []
text = u''
for item in items: for item in items:
bitem = self.listView.item(item.row()) bitem = self.listView.item(item.row())
filename = unicode(bitem.data(QtCore.Qt.UserRole).toString()) filename = unicode(bitem.data(QtCore.Qt.UserRole).toString())
if os.path.exists(filename): if not os.path.exists(filename):
(path, name) = os.path.split(filename) missing_items.append(item)
service_item.add_from_image(filename, name) text += u'\n' + filename
# We have only one image, which is no longer present. for item in missing_items:
elif len(items) == 1: items.remove(item)
QtGui.QMessageBox.critical( # We cannot continue, as all images do not exist.
self, translate('ImagePlugin.MediaItem', if not items:
'Missing Image'), if len(missing_items) == 1:
QtGui.QMessageBox.critical(self,
translate('ImagePlugin.MediaItem', 'Missing Image'),
unicode(translate('ImagePlugin.MediaItem', unicode(translate('ImagePlugin.MediaItem',
'The image %s no longer exists.')) % filename) 'The image %s no longer exists.')) % text)
else:
QtGui.QMessageBox.critical(self,
translate('ImagePlugin.MediaItem', 'Missing Images'),
unicode(translate('ImagePlugin.MediaItem',
'The following images no longer exist: %s')) % text)
return False return False
# We have more than one item, but a file is missing. # We have missing as well as existing images. We ask what to do.
elif QtGui.QMessageBox.question(self, elif missing_items:
if len(missing_items) == 1 and QtGui.QMessageBox.question(self,
translate('ImagePlugin.MediaItem', 'Missing Image'), translate('ImagePlugin.MediaItem', 'Missing Image'),
unicode(translate('ImagePlugin.MediaItem', 'The image %s ' unicode(translate('ImagePlugin.MediaItem', 'The image %s '
'no longer exists. Do you want to add the other images ' 'no longer exists. Do you want to add the other images '
'anyway?')) % filename, 'anyway?')) % text,
QtGui.QMessageBox.StandardButtons(QtGui.QMessageBox.No | QtGui.QMessageBox.StandardButtons(QtGui.QMessageBox.No |
QtGui.QMessageBox.Yes)) == QtGui.QMessageBox.No: QtGui.QMessageBox.Yes)) == QtGui.QMessageBox.No:
return False return False
elif len(missing_items) > 1 and QtGui.QMessageBox.question(self,
translate('ImagePlugin.MediaItem', 'Missing Images'),
unicode(translate('ImagePlugin.MediaItem', 'The following '
'images no longer exist: %s\nDo you want to add the other '
'images anyway?')) % text,
QtGui.QMessageBox.StandardButtons(QtGui.QMessageBox.No |
QtGui.QMessageBox.Yes)) == QtGui.QMessageBox.No:
return False
# Continue with the existing images.
for item in items:
bitem = self.listView.item(item.row())
filename = unicode(bitem.data(QtCore.Qt.UserRole).toString())
(path, name) = os.path.split(filename)
service_item.add_from_image(filename, name)
return True return True
else: else:
return False return False
@ -198,6 +223,7 @@ class ImageMediaItem(MediaManagerItem):
self.parent.liveController.display.resetImage() self.parent.liveController.display.resetImage()
def onReplaceClick(self): def onReplaceClick(self):
# TODO: check if image exists
if check_item_selected(self.listView, if check_item_selected(self.listView,
translate('ImagePlugin.MediaItem', translate('ImagePlugin.MediaItem',
'You must select an image to replace the background with.')): 'You must select an image to replace the background with.')):