Implemented drag&drop from external directly into an image group

This commit is contained in:
Arjan Schrijver 2013-01-29 14:21:07 +01:00
parent 34455239ef
commit 42a75e545e
6 changed files with 39 additions and 29 deletions

View File

@ -335,7 +335,7 @@ class MediaManagerItem(QtGui.QWidget):
self.validateAndLoad(files) self.validateAndLoad(files)
Receiver.send_message(u'cursor_normal') Receiver.send_message(u'cursor_normal')
def loadFile(self, files): def loadFile(self, data):
""" """
Turn file from Drag and Drop into an array so the Validate code can run it. Turn file from Drag and Drop into an array so the Validate code can run it.
@ -344,7 +344,7 @@ class MediaManagerItem(QtGui.QWidget):
""" """
new_files = [] new_files = []
error_shown = False error_shown = False
for file in files: for file in data['files']:
type = file.split(u'.')[-1] type = file.split(u'.')[-1]
if type.lower() not in self.onNewFileMasks: if type.lower() not in self.onNewFileMasks:
if not error_shown: if not error_shown:
@ -354,7 +354,7 @@ class MediaManagerItem(QtGui.QWidget):
else: else:
new_files.append(file) new_files.append(file)
if new_files: if new_files:
self.validateAndLoad(new_files) self.validateAndLoad(new_files, data['target'])
def dndMoveInternal(self, target): def dndMoveInternal(self, target):
""" """
@ -362,7 +362,7 @@ class MediaManagerItem(QtGui.QWidget):
""" """
pass pass
def validateAndLoad(self, files): def validateAndLoad(self, files, target_group=None):
""" """
Process a list for files either from the File Dialog or from Drag and Process a list for files either from the File Dialog or from Drag and
Drop Drop
@ -385,8 +385,9 @@ class MediaManagerItem(QtGui.QWidget):
files_added = True files_added = True
full_list.append(file) full_list.append(file)
if full_list and files_added: if full_list and files_added:
if target_group is None:
self.listView.clear() self.listView.clear()
self.loadList(full_list) self.loadList(full_list, target_group)
last_dir = os.path.split(unicode(files[0]))[0] last_dir = os.path.split(unicode(files[0]))[0]
Settings().setValue(self.settingsSection + u'/last directory', last_dir) Settings().setValue(self.settingsSection + u'/last directory', last_dir)
if duplicates_found: if duplicates_found:
@ -415,7 +416,7 @@ class MediaManagerItem(QtGui.QWidget):
count += 1 count += 1
return file_list return file_list
def loadList(self, list): def loadList(self, list, target_group):
raise NotImplementedError(u'MediaManagerItem.loadList needs to be defined by the plugin') raise NotImplementedError(u'MediaManagerItem.loadList needs to be defined by the plugin')
def onNewClick(self): def onNewClick(self):

View File

@ -120,7 +120,7 @@ class TreeWidgetWithDnD(QtGui.QTreeWidget):
listing = os.listdir(localFile) listing = os.listdir(localFile)
for file in listing: for file in listing:
files.append(os.path.join(localFile, file)) files.append(os.path.join(localFile, file))
Receiver.send_message(u'%s_dnd' % self.mimeDataText, files) Receiver.send_message(u'%s_dnd' % self.mimeDataText, {'files':files, 'target':self.itemAt(event.pos())})
elif self.allowInternalDnD: elif self.allowInternalDnD:
event.setDropAction(QtCore.Qt.CopyAction) event.setDropAction(QtCore.Qt.CopyAction)
event.accept() event.accept()

View File

@ -99,7 +99,7 @@ class CustomMediaItem(MediaManagerItem):
self.searchTextEdit.setCurrentSearchType(Settings().value( u'%s/last search type' % self.settingsSection)) self.searchTextEdit.setCurrentSearchType(Settings().value( u'%s/last search type' % self.settingsSection))
self.config_updated() self.config_updated()
def loadList(self, custom_slides): def loadList(self, custom_slides, target_group=None):
# Sort out what custom we want to select after loading the list. # Sort out what custom we want to select after loading the list.
self.saveAutoSelectId() self.saveAutoSelectId()
self.listView.clear() self.listView.clear()

View File

@ -239,22 +239,31 @@ class ImageMediaItem(MediaManagerItem):
self.main_window.finishedProgressBar() self.main_window.finishedProgressBar()
Receiver.send_message(u'cursor_normal') Receiver.send_message(u'cursor_normal')
def loadList(self, images, initialLoad=False): def loadList(self, images, target_group=None, initialLoad=False):
""" """
Add new images to the database. This method is called when adding images using the Add button or DnD. Add new images to the database. This method is called when adding images using the Add button or DnD.
""" """
if target_group is None:
# Ask which group the images should be saved in # Ask which group the images should be saved in
self.fillGroupsComboBox(self.choosegroupform.groupComboBox, showTopLevelGroup=False) self.fillGroupsComboBox(self.choosegroupform.groupComboBox, showTopLevelGroup=False)
if self.choosegroupform.exec_(): if self.choosegroupform.exec_():
group_id = self.choosegroupform.groupComboBox.itemData( group_id = self.choosegroupform.groupComboBox.itemData(
self.choosegroupform.groupComboBox.currentIndex(), QtCore.Qt.UserRole) self.choosegroupform.groupComboBox.currentIndex(), QtCore.Qt.UserRole)
parent_group = self.manager.get_object_filtered(ImageGroups, ImageGroups.id == group_id)
else:
parent_group = target_group.data(0, QtCore.Qt.UserRole)
if isinstance(parent_group, ImageFilenames):
parent_group = target_group.parent().data(0, QtCore.Qt.UserRole)
# If no valid parent group is found, do nothing
if not isinstance(parent_group, ImageGroups):
return
# Save the new images in the database # Save the new images in the database
for filename in images: for filename in images:
if type(filename) is not str and type(filename) is not unicode: if type(filename) is not str and type(filename) is not unicode:
continue continue
log.debug(u'Adding new image: %s', filename) log.debug(u'Adding new image: %s', filename)
imageFile = ImageFilenames() imageFile = ImageFilenames()
imageFile.group_id = group_id imageFile.group_id = parent_group.id
imageFile.filename = unicode(filename) imageFile.filename = unicode(filename)
success = self.manager.save_object(imageFile) success = self.manager.save_object(imageFile)
self.loadFullList(self.manager.get_all_objects(ImageFilenames, order_by_ref=ImageFilenames.filename), self.loadFullList(self.manager.get_all_objects(ImageFilenames, order_by_ref=ImageFilenames.filename),

View File

@ -256,7 +256,7 @@ class MediaMediaItem(MediaManagerItem):
self.listView.takeTopLevelItem(row) self.listView.takeTopLevelItem(row)
Settings().setValue(self.settingsSection + u'/media files', self.getFileList()) Settings().setValue(self.settingsSection + u'/media files', self.getFileList())
def loadList(self, media): def loadList(self, media, target_group=None):
# Sort the media by its filename considering language specific # Sort the media by its filename considering language specific
# characters. # characters.
media.sort(cmp=locale_compare, key=lambda filename: os.path.split(unicode(filename))[1]) media.sort(cmp=locale_compare, key=lambda filename: os.path.split(unicode(filename))[1])

View File

@ -121,7 +121,7 @@ class PresentationMediaItem(MediaManagerItem):
""" """
self.listView.setIconSize(QtCore.QSize(88, 50)) self.listView.setIconSize(QtCore.QSize(88, 50))
files = Settings().value(self.settingsSection + u'/presentations files') files = Settings().value(self.settingsSection + u'/presentations files')
self.loadList(files, True) self.loadList(files, initialLoad=True)
self.populateDisplayTypes() self.populateDisplayTypes()
def populateDisplayTypes(self): def populateDisplayTypes(self):
@ -142,7 +142,7 @@ class PresentationMediaItem(MediaManagerItem):
else: else:
self.presentationWidget.hide() self.presentationWidget.hide()
def loadList(self, files, initialLoad=False): def loadList(self, files, target_group=None, initialLoad=False):
""" """
Add presentations into the media manager Add presentations into the media manager
This is called both on initial load of the plugin to populate with This is called both on initial load of the plugin to populate with