forked from openlp/openlp
Fix review comments and cleanups
This commit is contained in:
parent
c9c0904c31
commit
644706a62a
@ -51,6 +51,9 @@ class ListWidgetWithDnD(QtGui.QListWidget):
|
||||
"""
|
||||
self.setAcceptDrops(True)
|
||||
self.setDragDropMode(QtGui.QAbstractItemView.DragDrop)
|
||||
QtCore.QObject.connect(Receiver.get_receiver(),
|
||||
QtCore.SIGNAL(u'%s_dnd' % self.mimeDataText),
|
||||
self.parent().loadFile)
|
||||
|
||||
def mouseMoveEvent(self, event):
|
||||
"""
|
||||
@ -71,7 +74,7 @@ class ListWidgetWithDnD(QtGui.QListWidget):
|
||||
drag.start(QtCore.Qt.CopyAction)
|
||||
|
||||
def dragEnterEvent(self, event):
|
||||
if event.mimeData().hasUrls:
|
||||
if event.mimeData().hasUrls():
|
||||
event.accept()
|
||||
else:
|
||||
event.ignore()
|
||||
@ -93,9 +96,15 @@ class ListWidgetWithDnD(QtGui.QListWidget):
|
||||
if event.mimeData().hasUrls():
|
||||
event.setDropAction(QtCore.Qt.CopyAction)
|
||||
event.accept()
|
||||
files = []
|
||||
for url in event.mimeData().urls():
|
||||
if os.path.isfile(url.toLocalFile()):
|
||||
Receiver.send_message(u'%s_dnd' % self.mimeDataText,
|
||||
url.toLocalFile())
|
||||
localFile = unicode(url.toLocalFile())
|
||||
if os.path.isfile(localFile):
|
||||
files.append(localFile)
|
||||
elif os.path.isdir(localFile):
|
||||
listing = os.listdir(localFile)
|
||||
for file in listing:
|
||||
files.append(os.path.join(localFile,file))
|
||||
Receiver.send_message(u'%s_dnd' % self.mimeDataText,files)
|
||||
else:
|
||||
event.ignore()
|
||||
|
@ -341,25 +341,31 @@ class MediaManagerItem(QtGui.QWidget):
|
||||
self.validateAndLoad(files)
|
||||
Receiver.send_message(u'cursor_normal')
|
||||
|
||||
def loadFile(self, filename):
|
||||
def loadFile(self, files):
|
||||
"""
|
||||
Turn file from Drag and Drop into a array so the Validate code
|
||||
can runn it.
|
||||
Turn file from Drag and Drop into an array so the Validate code
|
||||
can run it.
|
||||
|
||||
``filename``
|
||||
The file to be loaded
|
||||
``files``
|
||||
The list of files to be loaded
|
||||
"""
|
||||
filename = unicode(filename)
|
||||
type = filename.split(u'.')[-1]
|
||||
if type.lower() not in self.onNewFileMasks:
|
||||
critical_error_message_box(
|
||||
translate('OpenLP.MediaManagerItem',
|
||||
'Invalid File Type'),
|
||||
unicode(translate('OpenLP.MediaManagerItem',
|
||||
'Invalid File %s.\nSuffix not supported'))
|
||||
% filename)
|
||||
else:
|
||||
self.validateAndLoad([filename])
|
||||
newFiles = []
|
||||
errorShown = False
|
||||
for file in files:
|
||||
type = file.split(u'.')[-1]
|
||||
if type.lower() not in self.onNewFileMasks:
|
||||
if not errorShown:
|
||||
critical_error_message_box(
|
||||
translate('OpenLP.MediaManagerItem',
|
||||
'Invalid File Type'),
|
||||
unicode(translate('OpenLP.MediaManagerItem',
|
||||
'Invalid File %s.\nSuffix not supported'))
|
||||
% file)
|
||||
errorShown = True
|
||||
else:
|
||||
newFiles.append(file)
|
||||
if file:
|
||||
self.validateAndLoad(newFiles)
|
||||
|
||||
def validateAndLoad(self, files):
|
||||
"""
|
||||
@ -373,14 +379,11 @@ class MediaManagerItem(QtGui.QWidget):
|
||||
for count in range(0, self.listView.count()):
|
||||
names.append(self.listView.item(count).text())
|
||||
newFiles = []
|
||||
duplicatesFound = False
|
||||
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 filename %s.\nThis filename is already in '
|
||||
'the list')) % filename)
|
||||
duplicatesFound = True
|
||||
else:
|
||||
newFiles.append(file)
|
||||
self.loadList(newFiles)
|
||||
@ -388,6 +391,11 @@ class MediaManagerItem(QtGui.QWidget):
|
||||
SettingsManager.set_last_dir(self.settingsSection, lastDir)
|
||||
SettingsManager.set_list(self.settingsSection,
|
||||
self.settingsSection, self.getFileList())
|
||||
if duplicatesFound:
|
||||
critical_error_message_box(
|
||||
UiStrings().Duplicate,
|
||||
unicode(translate('OpenLP.MediaManagerItem',
|
||||
'Duplicate files found on import and ignored.')))
|
||||
|
||||
def contextMenu(self, point):
|
||||
item = self.listView.itemAt(point)
|
||||
|
@ -54,8 +54,6 @@ class ImageMediaItem(MediaManagerItem):
|
||||
QtCore.SIGNAL(u'live_theme_changed'), self.liveThemeChanged)
|
||||
# Allow DnD from the desktop
|
||||
self.listView.activateDnD()
|
||||
QtCore.QObject.connect(Receiver.get_receiver(),
|
||||
QtCore.SIGNAL(u'images_dnd'), self.loadFile)
|
||||
|
||||
def retranslateUi(self):
|
||||
self.onNewPrompt = translate('ImagePlugin.MediaItem',
|
||||
|
@ -63,8 +63,6 @@ class MediaMediaItem(MediaManagerItem):
|
||||
self.createPhonon)
|
||||
# Allow DnD from the desktop
|
||||
self.listView.activateDnD()
|
||||
QtCore.QObject.connect(Receiver.get_receiver(),
|
||||
QtCore.SIGNAL(u'media_dnd'), self.loadFile)
|
||||
|
||||
def retranslateUi(self):
|
||||
self.onNewPrompt = translate('MediaPlugin.MediaItem', 'Select Media')
|
||||
|
@ -60,8 +60,6 @@ class PresentationMediaItem(MediaManagerItem):
|
||||
QtCore.SIGNAL(u'mediaitem_presentation_rebuild'), self.rebuild)
|
||||
# Allow DnD from the desktop
|
||||
self.listView.activateDnD()
|
||||
QtCore.QObject.connect(Receiver.get_receiver(),
|
||||
QtCore.SIGNAL(u'presentations_dnd'), self.loadFile)
|
||||
|
||||
def retranslateUi(self):
|
||||
"""
|
||||
|
Loading…
Reference in New Issue
Block a user