gvfs r2069 - in trunk: . common monitor/proxy



Author: alexl
Date: Tue Oct 21 12:04:50 2008
New Revision: 2069
URL: http://svn.gnome.org/viewvc/gvfs?rev=2069&view=rev

Log:
2008-10-21  Alexander Larsson  <alexl redhat com>

        * configure.ac:
	Require glib 2.19.1 for GIcon serialization support
	
        * common/gvfsdaemonprotocol.c:
	Use g_icon_to_string & co instead of home-brewed serialization
	
        * monitor/proxy/gproxydrive.c:
        * monitor/proxy/gproxymount.c:
        * monitor/proxy/gproxyvolume.c:
        * monitor/proxy/gproxyvolumemonitor.c:
        * monitor/proxy/gproxyvolumemonitor.h:
        * monitor/proxy/gvfsproxyvolumemonitordaemon.c:
	Use g_icon_to_string & co instead of home-brewed serialization



Modified:
   trunk/ChangeLog
   trunk/common/gvfsdaemonprotocol.c
   trunk/configure.ac
   trunk/monitor/proxy/gproxydrive.c
   trunk/monitor/proxy/gproxymount.c
   trunk/monitor/proxy/gproxyvolume.c
   trunk/monitor/proxy/gproxyvolumemonitor.c
   trunk/monitor/proxy/gproxyvolumemonitor.h
   trunk/monitor/proxy/gvfsproxyvolumemonitordaemon.c

Modified: trunk/common/gvfsdaemonprotocol.c
==============================================================================
--- trunk/common/gvfsdaemonprotocol.c	(original)
+++ trunk/common/gvfsdaemonprotocol.c	Tue Oct 21 12:04:50 2008
@@ -32,62 +32,21 @@
 static const char *
 get_object_signature (GObject *obj)
 {
-  if (G_IS_THEMED_ICON (obj))
+  if (G_IS_ICON (obj))
     {
       return
 	DBUS_STRUCT_BEGIN_CHAR_AS_STRING
-	  DBUS_TYPE_UINT32_AS_STRING
-	  DBUS_TYPE_ARRAY_AS_STRING DBUS_TYPE_STRING_AS_STRING
+	 DBUS_TYPE_UINT32_AS_STRING
+	 DBUS_TYPE_STRING_AS_STRING
 	DBUS_STRUCT_END_CHAR_AS_STRING;
-	}
-  else if (G_IS_FILE_ICON (obj))
-    {
-      GFile *file;
-      char *path;
-      
-      file = g_file_icon_get_file (G_FILE_ICON (obj));
-      
-      path = g_file_get_path (file);
-      if (path)
-	{
-	  g_free (path);
-	  return
-	    DBUS_STRUCT_BEGIN_CHAR_AS_STRING
-	      DBUS_TYPE_UINT32_AS_STRING
-	      DBUS_TYPE_ARRAY_AS_STRING DBUS_TYPE_BYTE_AS_STRING
-	    DBUS_STRUCT_END_CHAR_AS_STRING;
-	}
     }
   return
     DBUS_STRUCT_BEGIN_CHAR_AS_STRING
-      DBUS_TYPE_UINT32_AS_STRING
+     DBUS_TYPE_UINT32_AS_STRING
     DBUS_STRUCT_END_CHAR_AS_STRING;
 }
 
 static void
-append_string_array (DBusMessageIter *iter, char **strs)
-{
-  DBusMessageIter array;
-  int i;
-
-  if (!dbus_message_iter_open_container (iter,
-					 DBUS_TYPE_ARRAY,
-					 DBUS_TYPE_STRING_AS_STRING,
-					 &array))
-    _g_dbus_oom ();
-  
-              
-  for (i = 0; strs[i] != NULL; i++)
-    {
-      if (!dbus_message_iter_append_basic (&array, DBUS_TYPE_STRING, &strs[i]))
-	_g_dbus_oom ();
-    }
-  
-  if (!dbus_message_iter_close_container (iter, &array))
-    _g_dbus_oom ();
-}
-
-static void
 append_object (DBusMessageIter *iter, GObject *obj)
 {
   DBusMessageIter obj_struct_iter;
@@ -99,51 +58,22 @@
 					 &obj_struct_iter))
     _g_dbus_oom ();
 
-  if (G_IS_THEMED_ICON (obj))
+  /* version 1 and 2 are deprecated old themed-icon and file-icon values */
+  if (G_IS_ICON (obj))
     {
-      const char * const *icons;
-      
-      icons = g_themed_icon_get_names (G_THEMED_ICON (obj));
-      
-      v_uint32 = 1;
+      char *data;
+
+      data = g_icon_to_string (G_ICON (obj));
+      v_uint32 = 3;
       if (!dbus_message_iter_append_basic (&obj_struct_iter,
 					   DBUS_TYPE_UINT32, &v_uint32))
 	_g_dbus_oom ();
-      
-      append_string_array (&obj_struct_iter, (char **)icons);
-    }
-  else if (G_IS_FILE_ICON (obj))
-    {
-      GFile *file;
-      char *path;
-      
-      file = g_file_icon_get_file (G_FILE_ICON (obj));
-      
-      path = g_file_get_path (file);
-      if (path)
-	{
-	  v_uint32 = 2;
-	  if (!dbus_message_iter_append_basic (&obj_struct_iter,
-					       DBUS_TYPE_UINT32, &v_uint32))
-	    _g_dbus_oom ();
-	  
-	  path = g_file_get_path (file);
-	  _g_dbus_message_iter_append_cstring (&obj_struct_iter, path);
-	  g_free (path);
-	}
-      else
-	{
-	  /* Seems unlikely that daemon backend will generate GFileIcons with
-	     files on the vfs, so its probably not a problem not to support this.
-	     (Its tricky to support, since we don't link the daemon to the client/
-	     library directly.) */
-	  g_warning ("Unknown file type for icon in attribute, ignoring");
-	  
-	  v_uint32 = 0;
-	  if (!dbus_message_iter_append_basic (&obj_struct_iter,
-					       DBUS_TYPE_UINT32, &v_uint32))
-	    _g_dbus_oom ();
-	}
+
+      if (!dbus_message_iter_append_basic (&obj_struct_iter,
+					   DBUS_TYPE_STRING, &data))
+	_g_dbus_oom ();
+
+      g_free (data);
     }
   else
     {
@@ -429,7 +359,7 @@
 
       if (obj_type == 1)
 	{
-	  /* G_THEMED_ICON */
+	  /* Old deprecated G_THEMED_ICON */
 	  if (_g_dbus_message_iter_get_args (&obj_iter,
 					     NULL,
 					     DBUS_TYPE_ARRAY, DBUS_TYPE_STRING,
@@ -441,7 +371,7 @@
 	}
       else if (obj_type == 2)
 	{
-	  /* G_FILE_ICON, w/ local file */
+	  /* Old deprecated G_FILE_ICON, w/ local file */
 	  if (_g_dbus_message_iter_get_args (&obj_iter,
 					     NULL,
 					     G_DBUS_TYPE_CSTRING, &str,
@@ -452,6 +382,15 @@
 	      g_free (str);
 	    }
 	}
+      else if (obj_type == 3)
+	{
+	  /* serialized G_ICON */
+	  if (_g_dbus_message_iter_get_args (&obj_iter,
+					     NULL,
+					     DBUS_TYPE_STRING, &str,
+					     0))
+	    obj = (GObject *)g_icon_new_for_string (str, NULL);
+	}
       else
 	{
 	  /* NULL (or unsupported) */

Modified: trunk/configure.ac
==============================================================================
--- trunk/configure.ac	(original)
+++ trunk/configure.ac	Tue Oct 21 12:04:50 2008
@@ -45,7 +45,7 @@
 DISTCHECK_CONFIGURE_FLAGS="--enable-gtk-doc"
 AC_SUBST(DISTCHECK_CONFIGURE_FLAGS)
 
-PKG_CHECK_MODULES(GLIB, glib-2.0 >= 2.17.6 gthread-2.0 gobject-2.0 gmodule-no-export-2.0 gio-unix-2.0 gio-2.0)
+PKG_CHECK_MODULES(GLIB, glib-2.0 >= 2.19.1 gthread-2.0 gobject-2.0 gmodule-no-export-2.0 gio-unix-2.0 gio-2.0)
 AC_SUBST(GLIB_CFLAGS)
 AC_SUBST(GLIB_LIBS)
 

Modified: trunk/monitor/proxy/gproxydrive.c
==============================================================================
--- trunk/monitor/proxy/gproxydrive.c	(original)
+++ trunk/monitor/proxy/gproxydrive.c	Tue Oct 21 12:04:50 2008
@@ -198,7 +198,11 @@
   /* in with the new */
   drive->id = g_strdup (id);
   drive->name = g_strdup (name);
-  drive->icon = _g_icon_new_from_serialized_data (gicon_data);
+  if (*gicon_data == 0)
+    drive->icon = NULL;
+  else
+    drive->icon = g_icon_new_for_string (gicon_data, NULL);
+
   drive->can_eject = can_eject;
   drive->can_poll_for_media = can_poll_for_media;
   drive->has_media = has_media;

Modified: trunk/monitor/proxy/gproxymount.c
==============================================================================
--- trunk/monitor/proxy/gproxymount.c	(original)
+++ trunk/monitor/proxy/gproxymount.c	Tue Oct 21 12:04:50 2008
@@ -212,7 +212,10 @@
   /* in with the new */
   mount->id = g_strdup (id);
   mount->name = g_strdup (name);
-  mount->icon = _g_icon_new_from_serialized_data (gicon_data);
+  if (*gicon_data == 0)
+    mount->icon = NULL;
+  else
+    mount->icon = g_icon_new_for_string (gicon_data, NULL);
   mount->uuid = g_strdup (uuid);
   mount->root = g_file_new_for_uri (root_uri);
   mount->can_unmount = can_unmount;

Modified: trunk/monitor/proxy/gproxyvolume.c
==============================================================================
--- trunk/monitor/proxy/gproxyvolume.c	(original)
+++ trunk/monitor/proxy/gproxyvolume.c	Tue Oct 21 12:04:50 2008
@@ -254,7 +254,10 @@
   volume->name = g_strdup (name);
   volume->uuid = g_strdup (uuid);
   volume->activation_uri = g_strdup (activation_uri);
-  volume->icon = _g_icon_new_from_serialized_data (gicon_data);
+  if (*gicon_data == 0)
+    volume->icon = NULL;
+  else
+    volume->icon = g_icon_new_for_string (gicon_data, NULL);
   volume->drive_id = g_strdup (drive_id);
   volume->mount_id = g_strdup (mount_id);
   volume->can_mount = can_mount;

Modified: trunk/monitor/proxy/gproxyvolumemonitor.c
==============================================================================
--- trunk/monitor/proxy/gproxyvolumemonitor.c	(original)
+++ trunk/monitor/proxy/gproxyvolumemonitor.c	Tue Oct 21 12:04:50 2008
@@ -982,119 +982,6 @@
   return hash_table;
 }
 
-static GIcon *
-_g_icon_new_from_tokens (char **tokens, int num_tokens)
-{
-  GIcon *icon;
-  
-  icon = NULL;
-  if (strcmp (tokens[0], "GFileIcon") == 0)
-    {
-      GFile *file;
-      char *unescaped_uri;
-
-      if (num_tokens != 2)
-        goto out;
-
-      unescaped_uri = g_uri_unescape_string (tokens[1], NULL);
-      file = g_file_new_for_uri (unescaped_uri);
-      icon = g_file_icon_new (file);
-      g_object_unref (file);
-      g_free (unescaped_uri);
-    }
-  else if (strcmp (tokens[0], "GThemedIcon") == 0)
-    {
-      int n;
-
-      for (n = 1; n < num_tokens; n++)
-        {
-          char *unescaped_name;
-
-          unescaped_name = g_uri_unescape_string (tokens[n], NULL);
-          if (icon == NULL)
-            icon = g_themed_icon_new (unescaped_name);
-          else
-            g_themed_icon_append_name (G_THEMED_ICON (icon), unescaped_name);
-          g_free (unescaped_name);
-        }
-    }
-  else if (strcmp (tokens[0], "GEmblemedIcon") == 0)
-    {
-       int n, m, i;
-       GIcon *base, *e_icon;
-       GEmblem *emblem;
-       GList *emblems, *e;
-       GEmblemOrigin origin;
-       char **t = tokens;
-
-       t++;
-       n = atoi (*t);
-       t++;
-       if (t - tokens >= num_tokens) 
-         goto out;
-       base = _g_icon_new_from_tokens (t, n);
-       if (base == NULL)
-         goto out;
-
-       t = t + n;
-       m = atoi (*t);
-       t++;
-       emblems = NULL;
-       for (i = 0; i < m; i++)
-         {
-           origin = atoi (*t);
-           t++;
-           n = atoi (*t);
-           t++;
-           if (t - tokens >= num_tokens) 
-             goto cleanup;
-           e_icon = _g_icon_new_from_tokens (t, n);
-           t += n;
-           if (e_icon == NULL)
-             goto cleanup;
-           emblem = g_emblem_new_with_origin (e_icon, origin);
-           emblems = g_list_append (emblems, emblem);
-         }
-       icon = g_emblemed_icon_new (base, (GEmblem*)emblems->data);
-       for (e = emblems->next; e; e = e->next)
-         g_emblemed_icon_add_emblem (G_EMBLEMED_ICON (icon), (GEmblem*)e->data);
-
- cleanup:
-       g_object_unref (base);
-       g_list_foreach (emblems, (GFunc)g_object_unref, NULL);
-       g_list_free (emblems);
-    }
-
- out:
-   return icon;
-}
-
-GIcon *
-_g_icon_new_from_serialized_data (const char *gicon_data)
-{
-  char **tokens;
-  GIcon *icon;
-  gint num_tokens;
-
-  g_return_val_if_fail (gicon_data != NULL, NULL);
-
-  icon = NULL;
-
-  tokens = g_strsplit (gicon_data, " ", 0);
-
-  if (g_strv_length (tokens) >= 3)
-    {
-      num_tokens = atoi (tokens[0]);
-      icon = _g_icon_new_from_tokens (tokens + 1, num_tokens);
-    }
-
-  if (icon == NULL)
-    g_warning ("malformed GIcon data \"%s\"", gicon_data);
-
-  g_strfreev (tokens);
-  return icon;
-}
-
 DBusConnection *
 g_proxy_volume_monitor_get_dbus_connection (GProxyVolumeMonitor *volume_monitor)
 {

Modified: trunk/monitor/proxy/gproxyvolumemonitor.h
==============================================================================
--- trunk/monitor/proxy/gproxyvolumemonitor.h	(original)
+++ trunk/monitor/proxy/gproxyvolumemonitor.h	Tue Oct 21 12:04:50 2008
@@ -70,8 +70,6 @@
 
 GHashTable *_get_identifiers (DBusMessageIter *iter);
 
-GIcon *_g_icon_new_from_serialized_data (const char *gicon_data);
-
 G_END_DECLS
 
 #endif /* __G_PROXY_VOLUME_MONITOR_H__ */

Modified: trunk/monitor/proxy/gvfsproxyvolumemonitordaemon.c
==============================================================================
--- trunk/monitor/proxy/gvfsproxyvolumemonitordaemon.c	(original)
+++ trunk/monitor/proxy/gvfsproxyvolumemonitordaemon.c	Tue Oct 21 12:04:50 2008
@@ -39,103 +39,6 @@
 
 static void monitor_try_create (void);
 
-static char *
-_g_icon_serialize (GIcon *icon)
-{
-  char *ret;
-
-  g_return_val_if_fail (icon != NULL, NULL);
-  g_return_val_if_fail (G_IS_ICON (icon), NULL);
-
-  /* We encode icons as a series of whitespace-separated tokens.
-   * The first token is the type of the icon. To help decoding, 
-   * the number of tokens is prepended as the first token (not 
-   * included in the count).
-   */
-  if (G_IS_FILE_ICON (icon))
-    {
-      GFileIcon *file_icon = G_FILE_ICON (icon);
-      GFile *file;
-      char *uri;
-      char *escaped_uri;
-
-      file = g_file_icon_get_file (file_icon);
-      uri = g_file_get_uri (file);
-      escaped_uri = g_uri_escape_string (uri, NULL, TRUE);
-
-      ret = g_strdup_printf ("2 GFileIcon %s", escaped_uri);
-
-      g_free (uri);
-      g_free (escaped_uri);
-    }
-  else if (G_IS_THEMED_ICON (icon))
-    {
-      GThemedIcon *themed_icon = G_THEMED_ICON (icon);
-      char *escaped_name;
-      char **names;
-      GString *s;
-
-      g_object_get (themed_icon,
-                    "names", &names,
-                    NULL);
-
-      s = g_string_new (0); 
-      g_string_append_printf (s, "%d GThemedIcon", g_strv_length (names) + 1);
-
-      if (names != NULL)
-        {
-          int n;
-          for (n = 0; names[n] != NULL; n++)
-            {
-              escaped_name = g_uri_escape_string (names[n], NULL, TRUE);
-              g_string_append_c (s, ' ');
-              g_string_append (s, escaped_name);
-              g_free (escaped_name);
-            }
-        }
-
-      ret = g_string_free (s, FALSE);
-
-      g_strfreev (names);
-    }
-  else if (G_IS_EMBLEMED_ICON (icon))
-    {
-      char *base, *s;
-      GList *emblems, *e;
-      int n;
-      GString *str;
-
-      /* GEmblemedIcons are encoded as 
-       * 
-       *   <num_tokens> GEmblemedIcon <num_emblems> [<origin> <encoded_icon> ]*
-       */
-      str = g_string_new ("");
-      base = _g_icon_serialize (g_emblemed_icon_get_icon (G_EMBLEMED_ICON (icon)));
-      emblems = g_emblemed_icon_get_emblems (G_EMBLEMED_ICON (icon));
-      g_string_append_printf (str, "GEmblemedIcon %s %d", base, g_list_length (emblems));
-      n = atoi (base) + 2;
-      g_free (base);
-      for (e = emblems; e; e = e->next)
-        {
-          s = _g_icon_serialize (g_emblem_get_icon (G_EMBLEM (e->data)));
-          g_string_append_printf (str, " %d %s", g_emblem_get_origin (G_EMBLEM (e->data)), s);
-          n += atoi (s) + 2;
-          g_free (s);
-        }
-       
-      s = g_string_free (str, FALSE);
-      ret = g_strdup_printf ("%d %s", n + 1, s);
-      g_free (s);
-    }
-  else
-    {
-      ret = NULL;
-      g_warning ("unknown icon type; please add support");
-    }
-
-  return ret;
-}
-
 /* string               id
  * string               name
  * string               gicon_data
@@ -171,7 +74,10 @@
   id = g_strdup_printf ("%p", drive);
   name = g_drive_get_name (drive);
   icon = g_drive_get_icon (drive);
-  icon_data = _g_icon_serialize (icon);
+  if (icon)
+    icon_data = g_icon_to_string (icon);
+  else
+    icon_data = g_strdup ("");
   can_eject = g_drive_can_eject (drive);
   can_poll_for_media = g_drive_can_poll_for_media (drive);
   has_media = g_drive_has_media (drive);
@@ -268,7 +174,10 @@
   id = g_strdup_printf ("%p", volume);
   name = g_volume_get_name (volume);
   icon = g_volume_get_icon (volume);
-  icon_data = _g_icon_serialize (icon);
+  if (icon)
+    icon_data = g_icon_to_string (icon);
+  else
+    icon_data = g_strdup ("");
   uuid = g_volume_get_uuid (volume);
   activation_root = g_volume_get_activation_root (volume);
   if (activation_root == NULL)
@@ -374,7 +283,10 @@
   id = g_strdup_printf ("%p", mount);
   name = g_mount_get_name (mount);
   icon = g_mount_get_icon (mount);
-  icon_data = _g_icon_serialize (icon);
+  if (icon)
+    icon_data = g_icon_to_string (icon);
+  else
+    icon_data = g_strdup ("");
   uuid = g_mount_get_uuid (mount);
   root = g_mount_get_root (mount);
   root_uri = g_file_get_uri (root);



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