gnome-terminal r2620 - trunk/src



Author: chpe
Date: Thu May 29 19:39:19 2008
New Revision: 2620
URL: http://svn.gnome.org/viewvc/gnome-terminal?rev=2620&view=rev

Log:
Replace dragged URIs with shell-quoted FUSE paths, if they have one.


Modified:
   trunk/src/terminal-screen.c
   trunk/src/terminal-screen.h
   trunk/src/terminal-util.c
   trunk/src/terminal-util.h

Modified: trunk/src/terminal-screen.c
==============================================================================
--- trunk/src/terminal-screen.c	(original)
+++ trunk/src/terminal-screen.c	Thu May 29 19:39:19 2008
@@ -1,5 +1,3 @@
-/* object representing one terminal window/tab with settings */
-
 /*
  * Copyright  2001 Havoc Pennington
  * Copyright  2007, 2008 Christian Persch
@@ -1870,7 +1868,7 @@
 {
   TerminalScreen *screen = TERMINAL_SCREEN (data);
 
-#if 1
+#if 0
   {
     GList *tmp;
 
@@ -1893,27 +1891,12 @@
     {
       char **uris;
       char *text;
-      guint i;
 
       uris = gtk_selection_data_get_uris (selection_data);
       if (!uris)
         return;
 
-      /* Replace file:/// URIS with shell-quoted filename strings */
-      for (i = 0; uris[i] != NULL; ++i)
-        {
-          char *uri = uris[i];
-          char *filename;
-
-          filename = g_filename_from_uri (uri, NULL, NULL);
-          if (!filename)
-            continue;
-              
-          uris[i] = g_shell_quote (filename);
-
-          g_free (uri);
-          g_free (filename);
-        }
+      terminal_util_transform_uris_to_quoted_fuse_paths (uris);
 
       text = g_strjoinv (" ", uris);
       vte_terminal_feed_child (VTE_TERMINAL (screen), text, strlen (text));
@@ -1971,7 +1954,8 @@
 
     case TARGET_MOZ_URL:
       {
-        char *utf8_data, *newline, *filename;
+        char *utf8_data, *newline;
+        char *uris[2];
         
         /* MOZ_URL is in UCS-2 but in format 8. BROKEN!
          *
@@ -1981,12 +1965,7 @@
         if (selection_data->format != 8 ||
             selection_data->length == 0 ||
             (selection_data->length % 2) != 0)
-          {
-            g_printerr (_("Mozilla url dropped on terminal had wrong format (%d) or length (%d)\n"),
-                        selection_data->format,
-                        selection_data->length);
-            return;
-          }
+          return;
 
         utf8_data = g_utf16_to_utf8 ((const gunichar2*) selection_data->data,
                                      selection_data->length / 2,
@@ -1998,26 +1977,19 @@
         if (newline)
           *newline = '\0';
 
-        /* If it's a file:/// URI, paste as quoted filename */
-        filename = g_filename_from_uri (utf8_data, NULL, NULL);
-        if (filename)
-          {
-            char *text;
+        uris[0] = utf8_data;
+        uris[1] = NULL;
+        terminal_util_transform_uris_to_quoted_fuse_paths (uris); /* This may replace uris[0] */
 
-            text = g_shell_quote (filename);
-            vte_terminal_feed_child (VTE_TERMINAL (screen), text, strlen (text));
-            g_free (filename);
-          }
-        else
-          vte_terminal_feed_child (VTE_TERMINAL (screen), utf8_data, strlen (utf8_data));
-          
-        g_free (utf8_data);
+        vte_terminal_feed_child (VTE_TERMINAL (screen), uris[0], strlen (uris[0]));
+        g_free (uris[0]);
       }
       break;
 
     case TARGET_NETSCAPE_URL:
       {
-        char *utf8_data, *newline, *filename;
+        char *utf8_data, *newline;
+        char *uris[2];
         
         /* The data contains the URL, a \n, then the
          * title of the web page.
@@ -2030,20 +2002,12 @@
         if (newline)
           *newline = '\0';
 
-        /* If it's a file:/// URI, paste as quoted filename */
-        filename = g_filename_from_uri (utf8_data, NULL, NULL);
-        if (filename)
-          {
-            char *text;
+        uris[0] = utf8_data;
+        uris[1] = NULL;
+        terminal_util_transform_uris_to_quoted_fuse_paths (uris); /* This may replace uris[0] */
 
-            text = g_shell_quote (filename);
-            vte_terminal_feed_child (VTE_TERMINAL (screen), text, strlen (text));
-            g_free (filename);
-          }
-        else
-          vte_terminal_feed_child (VTE_TERMINAL (screen), utf8_data, strlen (utf8_data));
-          
-        g_free (utf8_data);
+        vte_terminal_feed_child (VTE_TERMINAL (screen), uris[0], strlen (uris[0]));
+        g_free (uris[0]);
       }
       break;
        
@@ -2059,6 +2023,8 @@
         uris = g_uri_list_extract_uris (utf8_data);
         g_free (utf8_data);
 
+        /* FIXME: use terminal_util_transform_uris_to_quoted_fuse_paths? */
+
         if (uris && uris[0])
           {
             TerminalProfile *profile;

Modified: trunk/src/terminal-screen.h
==============================================================================
--- trunk/src/terminal-screen.h	(original)
+++ trunk/src/terminal-screen.h	Thu May 29 19:39:19 2008
@@ -1,5 +1,3 @@
-/* object representing one Zvt widget and its properties */
-
 /*
  * Copyright  2001 Havoc Pennington
  *

Modified: trunk/src/terminal-util.c
==============================================================================
--- trunk/src/terminal-util.c	(original)
+++ trunk/src/terminal-util.c	Thu May 29 19:39:19 2008
@@ -1,4 +1,3 @@
-/* terminal program */
 /*
  * Copyright  2001, 2002 Havoc Pennington
  * Copyright  2002 Red Hat, Inc.
@@ -246,3 +245,40 @@
 
   g_free (url);
 }
+
+/**
+ * terminal_util_transform_uris_to_quoted_fuse_paths:
+ * @uris:
+ *
+ * Transforms those URIs in @uris to shell-quoted paths that point to
+ * GIO fuse paths.
+ */
+void
+terminal_util_transform_uris_to_quoted_fuse_paths (char **uris)
+{
+  guint i;
+
+  if (!uris)
+    return;
+
+  for (i = 0; uris[i]; ++i)
+    {
+      GFile *file;
+      char *path;
+
+      file = g_file_new_for_uri (uris[i]);
+
+      if ((path = g_file_get_path (file)))
+        {
+          char *quoted;
+
+          quoted = g_shell_quote (path);
+          g_free (uris[i]);
+          g_free (path);
+
+          uris[i] = quoted;
+        }
+
+      g_object_unref (file);
+    }
+}

Modified: trunk/src/terminal-util.h
==============================================================================
--- trunk/src/terminal-util.h	(original)
+++ trunk/src/terminal-util.h	Thu May 29 19:39:19 2008
@@ -1,5 +1,3 @@
-/* application-wide commands */
-
 /*
  * Copyright  2001 Havoc Pennington
  *
@@ -50,4 +48,6 @@
                              TerminalURLFlavour flavor);
 
 
+void terminal_util_transform_uris_to_quoted_fuse_paths (char **uris);
+
 #endif /* TERMINAL_UTIL_H */



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