From 9b30450f333bd6aa60bf98c6847002f8dccf0349 Mon Sep 17 00:00:00 2001 From: Benny Malengier Date: Mon, 1 Mar 2010 08:51:17 +0000 Subject: [PATCH] Fix bug: allow drop from Nautilius/Dolphin svn: r14539 --- src/gui/editors/displaytabs/gallerytab.py | 3 +- src/plugins/view/mediaview.py | 53 +++++++++++++---------- 2 files changed, 31 insertions(+), 25 deletions(-) diff --git a/src/gui/editors/displaytabs/gallerytab.py b/src/gui/editors/displaytabs/gallerytab.py index 5f610b1ec..779f6e086 100644 --- a/src/gui/editors/displaytabs/gallerytab.py +++ b/src/gui/editors/displaytabs/gallerytab.py @@ -456,14 +456,13 @@ class GalleryTab(ButtonTab, DbGUIElement): elif self._DND_EXTRA and mytype == self._DND_EXTRA.drag_type: self.handle_extra_type(mytype, obj) except pickle.UnpicklingError: - #We assume this is for URI_LIST for Linux. For Windows split sel_data.data + #modern file managers provide URI_LIST. For Windows split sel_data.data if constfunc.win(): files = sel_data.data.split('\n') else: files = sel_data.get_uris() for file in files: d = Utils.fix_encoding(file.replace('\0',' ').strip()) - print repr(d) protocol, site, mfile, j, k, l = urlparse.urlparse(d) if protocol == "file": name = Utils.fix_encoding(mfile) diff --git a/src/plugins/view/mediaview.py b/src/plugins/view/mediaview.py index 5d4081ac8..184500292 100644 --- a/src/plugins/view/mediaview.py +++ b/src/plugins/view/mediaview.py @@ -147,8 +147,9 @@ class MediaView(ListView): dnd_types = [ self._DND_TYPE.target() ] - self.list.drag_dest_set(gtk.DEST_DEFAULT_ALL, dnd_types, - gtk.gdk.ACTION_PRIVATE) + self.list.drag_dest_set(gtk.DEST_DEFAULT_MOTION|gtk.DEST_DEFAULT_DROP, + dnd_types, + gtk.gdk.ACTION_MOVE|gtk.gdk.ACTION_COPY) self.list.drag_source_set(gtk.gdk.BUTTON1_MASK, [self._DND_TYPE.target()], gtk.gdk.ACTION_COPY) @@ -198,27 +199,33 @@ class MediaView(ListView): The only data we accept on mediaview is dropping a file, so URI_LIST. We assume this is what we obtain """ - if sel_data and sel_data.data: - cleaned_string = sel_data.data.replace('\0', ' ') - cleaned_string = cleaned_string.replace("\r", " ").strip() - data_list = Utils.fix_encoding(cleaned_string).split('\n') - for d in [item.strip() for item in data_list]: - protocol, site, mfile, j, k, l = urlparse.urlparse(d) - if protocol == "file": - name = unicode(urllib.url2pathname(mfile.encode(sys.getfilesystemencoding()))) - mime = gen.mime.get_type(name) - if not gen.mime.is_valid_type(mime): - return - photo = gen.lib.MediaObject() - photo.set_path(name) - photo.set_mime_type(mime) - basename = os.path.basename(name) - (root, ext) = os.path.splitext(basename) - photo.set_description(root) - trans = self.dbstate.db.transaction_begin() - self.dbstate.db.add_object(photo, trans) - self.dbstate.db.transaction_commit(trans, - _("Drag Media Object")) + if not sel_data: + return + #modern file managers provide URI_LIST. For Windows split sel_data.data + if constfunc.win(): + files = sel_data.data.split('\n') + else: + files = sel_data.get_uris() + for file in files: + clean_string = Utils.fix_encoding( + file.replace('\0',' ').replace("\r", " ").strip()) + protocol, site, mfile, j, k, l = urlparse.urlparse(clean_string) + if protocol == "file": + name = unicode(urllib.url2pathname( + mfile.encode(sys.getfilesystemencoding()))) + mime = gen.mime.get_type(name) + if not gen.mime.is_valid_type(mime): + return + photo = gen.lib.MediaObject() + photo.set_path(name) + photo.set_mime_type(mime) + basename = os.path.basename(name) + (root, ext) = os.path.splitext(basename) + photo.set_description(root) + trans = self.dbstate.db.transaction_begin() + self.dbstate.db.add_object(photo, trans) + self.dbstate.db.transaction_commit(trans, + _("Drag Media Object")) widget.emit_stop_by_name('drag_data_received') def get_bookmarks(self):