Fix bug: allow drop from Nautilius/Dolphin

svn: r14540
This commit is contained in:
Benny Malengier 2010-03-01 08:51:48 +00:00
parent 2f8d6d0ce0
commit 699d0d9eb8
2 changed files with 31 additions and 25 deletions

View File

@ -456,14 +456,13 @@ class GalleryTab(ButtonTab, DbGUIElement):
elif self._DND_EXTRA and mytype == self._DND_EXTRA.drag_type: elif self._DND_EXTRA and mytype == self._DND_EXTRA.drag_type:
self.handle_extra_type(mytype, obj) self.handle_extra_type(mytype, obj)
except pickle.UnpicklingError: 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(): if constfunc.win():
files = sel_data.data.split('\n') files = sel_data.data.split('\n')
else: else:
files = sel_data.get_uris() files = sel_data.get_uris()
for file in files: for file in files:
d = Utils.fix_encoding(file.replace('\0',' ').strip()) d = Utils.fix_encoding(file.replace('\0',' ').strip())
print repr(d)
protocol, site, mfile, j, k, l = urlparse.urlparse(d) protocol, site, mfile, j, k, l = urlparse.urlparse(d)
if protocol == "file": if protocol == "file":
name = Utils.fix_encoding(mfile) name = Utils.fix_encoding(mfile)

View File

@ -147,8 +147,9 @@ class MediaView(ListView):
dnd_types = [ self._DND_TYPE.target() ] dnd_types = [ self._DND_TYPE.target() ]
self.list.drag_dest_set(gtk.DEST_DEFAULT_ALL, dnd_types, self.list.drag_dest_set(gtk.DEST_DEFAULT_MOTION|gtk.DEST_DEFAULT_DROP,
gtk.gdk.ACTION_PRIVATE) dnd_types,
gtk.gdk.ACTION_MOVE|gtk.gdk.ACTION_COPY)
self.list.drag_source_set(gtk.gdk.BUTTON1_MASK, self.list.drag_source_set(gtk.gdk.BUTTON1_MASK,
[self._DND_TYPE.target()], [self._DND_TYPE.target()],
gtk.gdk.ACTION_COPY) 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. The only data we accept on mediaview is dropping a file, so URI_LIST.
We assume this is what we obtain We assume this is what we obtain
""" """
if sel_data and sel_data.data: if not sel_data:
cleaned_string = sel_data.data.replace('\0', ' ') return
cleaned_string = cleaned_string.replace("\r", " ").strip() #modern file managers provide URI_LIST. For Windows split sel_data.data
data_list = Utils.fix_encoding(cleaned_string).split('\n') if constfunc.win():
for d in [item.strip() for item in data_list]: files = sel_data.data.split('\n')
protocol, site, mfile, j, k, l = urlparse.urlparse(d) else:
if protocol == "file": files = sel_data.get_uris()
name = unicode(urllib.url2pathname(mfile.encode(sys.getfilesystemencoding()))) for file in files:
mime = gen.mime.get_type(name) clean_string = Utils.fix_encoding(
if not gen.mime.is_valid_type(mime): file.replace('\0',' ').replace("\r", " ").strip())
return protocol, site, mfile, j, k, l = urlparse.urlparse(clean_string)
photo = gen.lib.MediaObject() if protocol == "file":
photo.set_path(name) name = unicode(urllib.url2pathname(
photo.set_mime_type(mime) mfile.encode(sys.getfilesystemencoding())))
basename = os.path.basename(name) mime = gen.mime.get_type(name)
(root, ext) = os.path.splitext(basename) if not gen.mime.is_valid_type(mime):
photo.set_description(root) return
trans = self.dbstate.db.transaction_begin() photo = gen.lib.MediaObject()
self.dbstate.db.add_object(photo, trans) photo.set_path(name)
self.dbstate.db.transaction_commit(trans, photo.set_mime_type(mime)
_("Drag Media Object")) 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') widget.emit_stop_by_name('drag_data_received')
def get_bookmarks(self): def get_bookmarks(self):