[nautilus/colin/nautilus-dnd-native-uris] Prefer local (file://) URIs than native ones (smb:// for example).



commit 03b540dbe9b59016e4392b710023aa675ffbc382
Author: Colin Leroy <colin colino net>
Date:   Fri Sep 8 10:14:11 2017 +0200

    Prefer local (file://) URIs than native ones (smb:// for example).
    
    This allows drag and dropping files from network shares in Thunar
    to other applications that don't handle native URIs (Claws Mail,
    Chromium, Firefox...)

 src/nautilus-dnd.c            |    8 +++++++-
 src/nautilus-file-utilities.c |   21 +++++++++++++++++++++
 src/nautilus-file-utilities.h |    2 ++
 3 files changed, 30 insertions(+), 1 deletions(-)
---
diff --git a/src/nautilus-dnd.c b/src/nautilus-dnd.c
index 4b1d016..575d12f 100644
--- a/src/nautilus-dnd.c
+++ b/src/nautilus-dnd.c
@@ -709,7 +709,13 @@ cache_one_item (const char *uri,
     NautilusDragSelectionItem *item;
 
     item = nautilus_drag_selection_item_new ();
-    item->uri = g_strdup (uri);
+    item->uri = nautilus_uri_to_native_uri (uri);
+
+    if (item->uri == NULL)
+    {
+        item->uri = g_strdup (uri);
+    }
+
     item->file = nautilus_file_get_by_uri (uri);
     item->icon_x = x;
     item->icon_y = y;
diff --git a/src/nautilus-file-utilities.c b/src/nautilus-file-utilities.c
index 59add50..78d693e 100644
--- a/src/nautilus-file-utilities.c
+++ b/src/nautilus-file-utilities.c
@@ -1396,3 +1396,24 @@ nautilus_file_can_rename_files (GList *files)
 
     return TRUE;
 }
+
+/* Try to get a native file:// URI instead of any other GVFS
+ * scheme, for interoperability with apps only handling file:// URIs.
+ */
+gchar *
+nautilus_uri_to_native_uri (const gchar *uri)
+{
+    g_autoptr (GFile) file = NULL;
+    g_autofree gchar *path = NULL;
+
+    file = g_file_new_for_uri (uri);
+    path = g_file_get_path (file);
+
+    if (path != NULL)
+    {
+        return g_filename_to_uri (path, NULL, NULL);
+    }
+
+    return NULL;
+}
+
diff --git a/src/nautilus-file-utilities.h b/src/nautilus-file-utilities.h
index da165cd..e9b9a22 100644
--- a/src/nautilus-file-utilities.h
+++ b/src/nautilus-file-utilities.h
@@ -123,4 +123,6 @@ gboolean nautilus_file_can_rename_files (GList *files);
 
 GList * nautilus_file_list_from_uri_list (GList *uris);
 
+gchar * nautilus_uri_to_native_uri (const gchar *uri);
+
 #endif /* NAUTILUS_FILE_UTILITIES_H */


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]