Bug 555740 - gicon serialization Based on patch from David Zeuthen

2008-10-21  Alexander Larsson  <alexl@redhat.com>

	Bug 555740 - gicon serialization
	Based on patch from David Zeuthen
	
        * gicon.[ch]:
        * gio.symbols:
	Add g_icon_to_string() and g_icon_new_for_string().
	
        * gemblem.c:
        * gemblemedicon.c:
        * gfileicon.c:
        * gthemedicon.c:
	Implement icon serialization for built-in icon types
	
        * tests/Makefile.am:
        * tests/g-icon.c:
	Added GIcon serialization test



svn path=/trunk/; revision=7618
This commit is contained in:
Alexander Larsson
2008-10-21 11:51:48 +00:00
committed by Alexander Larsson
parent cef6abff8e
commit 4f0b18d203
12 changed files with 947 additions and 11 deletions

View File

@@ -26,6 +26,7 @@
#include "gthemedicon.h"
#include "gicon.h"
#include "gioerror.h"
#include "glibintl.h"
#include "gioalias.h"
@@ -458,11 +459,67 @@ g_themed_icon_equal (GIcon *icon1,
return themed1->names[i] == NULL && themed2->names[i] == NULL;
}
static gboolean
g_themed_icon_to_tokens (GIcon *icon,
GPtrArray *tokens,
gint *out_version)
{
GThemedIcon *themed_icon = G_THEMED_ICON (icon);
int n;
g_return_val_if_fail (out_version != NULL, FALSE);
*out_version = 0;
for (n = 0; themed_icon->names[n] != NULL; n++)
g_ptr_array_add (tokens,
g_strdup (themed_icon->names[n]));
return TRUE;
}
static GIcon *
g_themed_icon_from_tokens (gchar **tokens,
gint num_tokens,
gint version,
GError **error)
{
GIcon *icon;
gchar **names;
int n;
icon = NULL;
if (version != 0)
{
g_set_error (error,
G_IO_ERROR,
G_IO_ERROR_INVALID_ARGUMENT,
_("Can't handle version %d of GThemedIcon encoding"),
version);
goto out;
}
names = g_new0 (gchar *, num_tokens + 1);
for (n = 0; n < num_tokens; n++)
names[n] = tokens[n];
names[n] = NULL;
icon = g_themed_icon_new_from_names (names, num_tokens);
g_free (names);
out:
return icon;
}
static void
g_themed_icon_icon_iface_init (GIconIface *iface)
{
iface->hash = g_themed_icon_hash;
iface->equal = g_themed_icon_equal;
iface->to_tokens = g_themed_icon_to_tokens;
iface->from_tokens = g_themed_icon_from_tokens;
}
#define __G_THEMED_ICON_C__