[Xfce4-commits] <midori:master> Copy g_icon_to_string_tokenized for GIO < 2.20 and include gio.h

Christian Dywan noreply at xfce.org
Mon Nov 16 18:00:02 CET 2009


Updating branch refs/heads/master
         to 8f8a7634e03bcf74a5b017a939251355c0fdc3a6 (commit)
       from 308b9dd07d91f49dfda955b6a79e052f02ec3fd6 (commit)

commit 8f8a7634e03bcf74a5b017a939251355c0fdc3a6
Author: Christian Dywan <christian at twotoasts.de>
Date:   Mon Nov 16 17:52:03 2009 +0100

    Copy g_icon_to_string_tokenized for GIO < 2.20 and include gio.h

 katze/katze-utils.c |  108 +++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 108 insertions(+), 0 deletions(-)

diff --git a/katze/katze-utils.c b/katze/katze-utils.c
index 50ed142..04c3449 100644
--- a/katze/katze-utils.c
+++ b/katze/katze-utils.c
@@ -13,6 +13,7 @@
 
 #include <glib/gstdio.h>
 #include <glib/gi18n.h>
+#include <gio/gio.h>
 
 #include <string.h>
 
@@ -324,6 +325,113 @@ katze_app_info_get_all_for_category (const gchar* category)
     return apps;
 }
 
+#if !GLIB_CHECK_VERSION (2, 20, 0)
+/* GIcon serialization
+   Copyright (C) 2006-2007 Red Hat, Inc.
+   Copyright (C) 2006-2007 Alexander Larsson <alexl at redhat.com>
+   Copied subtly changed from Glib 2.20 */
+static gboolean
+g_icon_to_string_tokenized (GIcon *icon, GString *s)
+{
+  char *ret;
+  GPtrArray *tokens;
+  gint version;
+  GIconIface *icon_iface;
+  guint i;
+
+  ret = NULL;
+
+  icon_iface = G_ICON_GET_IFACE (icon);
+  if (icon_iface->to_tokens == NULL)
+    return FALSE;
+
+  tokens = g_ptr_array_new ();
+  if (!icon_iface->to_tokens (icon, tokens, &version))
+    {
+      g_ptr_array_free (tokens, TRUE);
+      return FALSE;
+    }
+
+  /* format: TypeName[.Version] <token_0> .. <token_N-1>
+     version 0 is implicit and can be omitted
+     all the tokens are url escaped to ensure they have no spaces in them */
+
+  g_string_append (s, g_type_name_from_instance ((GTypeInstance *)icon));
+  if (version != 0)
+    g_string_append_printf (s, ".%d", version);
+
+  for (i = 0; i < tokens->len; i++)
+    {
+      char *token = g_ptr_array_index (tokens, i);
+      g_string_append_c (s, ' ');
+      /* We really only need to escape spaces here, so allow lots of otherwise reserved chars */
+      g_string_append_uri_escaped (s, token, "!$&'()*+,;=:@/", TRUE);
+      g_free (token);
+    }
+
+  g_ptr_array_free (tokens, TRUE);
+
+  return TRUE;
+}
+
+/* GIcon serialization
+   Copyright (C) 2006-2007 Red Hat, Inc.
+   Copyright (C) 2006-2007 Alexander Larsson <alexl at redhat.com>
+   Copied subtly changed from Glib 2.20 */
+gchar *
+g_icon_to_string (GIcon *icon)
+{
+  gchar *ret;
+
+  g_return_val_if_fail (icon != NULL, NULL);
+  g_return_val_if_fail (G_IS_ICON (icon), NULL);
+
+  ret = NULL;
+
+  if (G_IS_FILE_ICON (icon))
+    {
+      GFile *file;
+
+      file = g_file_icon_get_file (G_FILE_ICON (icon));
+      if (g_file_is_native (file))
+	{
+	  ret = g_file_get_path (file);
+	  if (!g_utf8_validate (ret, -1, NULL))
+	    {
+	      g_free (ret);
+	      ret = NULL;
+	    }
+	}
+      else
+        ret = g_file_get_uri (file);
+    }
+  else if (G_IS_THEMED_ICON (icon))
+    {
+      const char * const *names;
+
+      names = g_themed_icon_get_names (G_THEMED_ICON (icon));
+      if (names != NULL &&
+          names[0] != NULL &&
+          /* Allowing icons starting with dot would break G_ICON_SERIALIZATION_MAGIC0 */
+          names[0][0] != '.' &&
+          g_utf8_validate (names[0], -1, NULL) && /* Only return utf8 strings */
+          names[1] == NULL)
+        ret = g_strdup (names[0]);
+    }
+
+  if (ret == NULL)
+    {
+      GString *s = g_string_new (". ");
+      if (g_icon_to_string_tokenized (icon, s))
+        ret = g_string_free (s, FALSE);
+      else
+        g_string_free (s, TRUE);
+    }
+
+  return ret;
+}
+#endif
+
 /**
  * katze_property_proxy:
  * @object: a #GObject



More information about the Xfce4-commits mailing list