gvfs r1858 - in trunk: . monitor/proxy



Author: matthiasc
Date: Mon Aug  4 15:55:39 2008
New Revision: 1858
URL: http://svn.gnome.org/viewvc/gvfs?rev=1858&view=rev

Log:
Update the GIcon serialization code to work with GEmblem


Modified:
   trunk/ChangeLog
   trunk/monitor/proxy/gproxyvolumemonitor.c
   trunk/monitor/proxy/gvfsproxyvolumemonitordaemon.c

Modified: trunk/monitor/proxy/gproxyvolumemonitor.c
==============================================================================
--- trunk/monitor/proxy/gproxyvolumemonitor.c	(original)
+++ trunk/monitor/proxy/gproxyvolumemonitor.c	Mon Aug  4 15:55:39 2008
@@ -919,29 +919,49 @@
     }
   else if (strcmp (tokens[0], "GEmblemedIcon") == 0)
     {
-       int n, m;
-       GIcon *base;
-       GIcon *emblem;
-     
-       n = atoi (tokens[1]);
-       if (num_tokens < n + 2)
+       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;
-       m = atoi (tokens[n+2]);
-       if (num_tokens < n + m + 3)
-         goto out;
-       
-       base = _g_icon_new_from_tokens (tokens + 2, n);
+       base = _g_icon_new_from_tokens (t, n);
        if (base == NULL)
          goto out;
-       emblem = _g_icon_new_from_tokens (tokens + n + 3, m);
-       if (emblem == NULL)
+
+       t = t + n;
+       m = atoi (*t);
+       t++;
+       emblems = NULL;
+       for (i = 0; i < m; i++)
          {
-           g_object_unref (base);
-           goto out;
+           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, 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_object_unref (emblem);
+       g_list_foreach (emblems, (GFunc)g_object_unref, NULL);
+       g_list_free (emblems);
     }
 
  out:

Modified: trunk/monitor/proxy/gvfsproxyvolumemonitordaemon.c
==============================================================================
--- trunk/monitor/proxy/gvfsproxyvolumemonitordaemon.c	(original)
+++ trunk/monitor/proxy/gvfsproxyvolumemonitordaemon.c	Mon Aug  4 15:55:39 2008
@@ -46,6 +46,11 @@
   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);
@@ -94,17 +99,32 @@
     }
   else if (G_IS_EMBLEMED_ICON (icon))
     {
-      char *base;
-      char *emblem;
+      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)));
-      emblem = _g_icon_serialize (g_emblemed_icon_get_emblem (G_EMBLEMED_ICON (icon)));
-
-      n = atoi (base) + atoi (emblem) + 3;
-      ret = g_strdup_printf ("%d GEmblemedIcon %s %s", n, base, emblem);
+      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);
-      g_free (emblem);
+      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
     {



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