Prevent duplicate images

bzr-revno: 1509
Fixes: https://launchpad.net/bugs/772080
This commit is contained in:
Tim Bentley 2011-05-01 18:55:33 +01:00
commit da996844b7
5 changed files with 24 additions and 18 deletions

View File

@ -34,7 +34,7 @@ from PyQt4 import QtCore, QtGui
from openlp.core.lib import SettingsManager, OpenLPToolbar, ServiceItem, \
StringContent, build_icon, translate, Receiver, ListWidgetWithDnD
from openlp.core.lib.ui import UiStrings, context_menu_action, \
context_menu_separator
context_menu_separator, critical_error_message_box
log = logging.getLogger(__name__)
@ -333,7 +333,21 @@ class MediaManagerItem(QtGui.QWidget):
log.info(u'New files(s) %s', unicode(files))
if files:
Receiver.send_message(u'cursor_busy')
self.loadList(files)
names = []
for count in range(0, self.listView.count()):
names.append(self.listView.item(count).text())
newFiles = []
for file in files:
filename = os.path.split(unicode(file))[1]
if filename in names:
critical_error_message_box(
UiStrings().Duplicate,
unicode(translate('OpenLP.MediaManagerItem',
'Duplicate file name %s.\nFilename already exists in '
'list')) % filename)
else:
newFiles.append(file)
self.loadList(newFiles)
lastDir = os.path.split(unicode(files[0]))[0]
SettingsManager.set_last_dir(self.settingsSection, lastDir)
SettingsManager.set_list(self.settingsSection,

View File

@ -67,6 +67,7 @@ class UiStrings(object):
self.Default = unicode(translate('OpenLP.Ui', 'Default'))
self.Delete = translate('OpenLP.Ui', '&Delete')
self.DisplayStyle = translate('OpenLP.Ui', 'Display style:')
self.Duplicate = translate('OpenLP.Ui', 'Duplicate Error')
self.Edit = translate('OpenLP.Ui', '&Edit')
self.EmptyField = translate('OpenLP.Ui', 'Empty Field')
self.Error = translate('OpenLP.Ui', 'Error')
@ -124,6 +125,7 @@ class UiStrings(object):
self.Themes = translate('OpenLP.Ui', 'Themes', 'Plural')
self.Tools = translate('OpenLP.Ui', 'Tools')
self.Top = translate('OpenLP.Ui', 'Top')
self.UnsupportedFile = translate('OpenLP.Ui', 'Unsupported File')
self.VersePerSlide = translate('OpenLP.Ui', 'Verse Per Slide')
self.VersePerLine = translate('OpenLP.Ui', 'Verse Per Line')
self.Version = translate('OpenLP.Ui', 'Version')

View File

@ -108,7 +108,6 @@ class ImageMediaItem(MediaManagerItem):
self.settingsSection, self.getFileList())
def loadList(self, list, initialLoad=False):
Receiver.send_message(u'cursor_busy')
if not initialLoad:
self.parent.formparent.displayProgressBar(len(list))
for imageFile in list:
@ -127,7 +126,6 @@ class ImageMediaItem(MediaManagerItem):
item_name.setIcon(icon)
item_name.setData(QtCore.Qt.UserRole, QtCore.QVariant(imageFile))
self.listView.addItem(item_name)
Receiver.send_message(u'cursor_normal')
if not initialLoad:
self.parent.formparent.finishedProgressBar()

View File

@ -138,10 +138,8 @@ class MediaMediaItem(MediaManagerItem):
if not self.mediaStateWait(Phonon.StoppedState):
# Due to string freeze, borrow a message from presentations
# This will be corrected in 1.9.6
critical_error_message_box(
translate('PresentationPlugin.MediaItem', 'Unsupported File'),
unicode(translate('PresentationPlugin.MediaItem',
'Unsupported File')))
critical_error_message_box(UiStrings().UnsupportedFile,
UiStrings().UnsupportedFile)
return False
# File too big for processing
if os.path.getsize(filename) <= 52428800: # 50MiB
@ -152,15 +150,11 @@ class MediaMediaItem(MediaManagerItem):
# Due to string freeze, borrow a message from presentations
# This will be corrected in 1.9.6
self.mediaObject.stop()
critical_error_message_box(
translate('PresentationPlugin.MediaItem',
'Unsupported File'),
unicode(translate('PresentationPlugin.MediaItem',
'Unsupported File')))
critical_error_message_box(UiStrings().UnsupportedFile,
UiStrings().UnsupportedFile)
return False
self.mediaLength = self.mediaObject.totalTime() / 1000
self.mediaObject.stop()
service_item.media_length = self.mediaLength
service_item.media_length = self.mediaObject.totalTime() / 1000
service_item.add_capability(
ItemCapabilities.AllowsVariableStartTime)
service_item.title = unicode(self.plugin.nameStrings[u'singular'])

View File

@ -193,9 +193,7 @@ class PresentationMediaItem(MediaManagerItem):
if initialLoad:
icon = build_icon(u':/general/general_delete.png')
else:
critical_error_message_box(
translate('PresentationPlugin.MediaItem',
'Unsupported File'),
critical_error_message_box(UiStrings().UnsupportedFile,
translate('PresentationPlugin.MediaItem',
'This type of presentation is not supported.'))
continue