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

@@ -29,6 +29,7 @@
#include "gloadableicon.h"
#include "ginputstream.h"
#include "gsimpleasyncresult.h"
#include "gioerror.h"
#include "gioalias.h"
@@ -202,12 +203,66 @@ g_file_icon_equal (GIcon *icon1,
return g_file_equal (file1->file, file2->file);
}
static gboolean
g_file_icon_to_tokens (GIcon *icon,
GPtrArray *tokens,
gint *out_version)
{
GFileIcon *file_icon = G_FILE_ICON (icon);
g_return_val_if_fail (out_version != NULL, FALSE);
*out_version = 0;
g_ptr_array_add (tokens, g_file_get_uri (file_icon->file));
return TRUE;
}
static GIcon *
g_file_icon_from_tokens (gchar **tokens,
gint num_tokens,
gint version,
GError **error)
{
GIcon *icon;
GFile *file;
icon = NULL;
if (version != 0)
{
g_set_error (error,
G_IO_ERROR,
G_IO_ERROR_INVALID_ARGUMENT,
_("Can't handle version %d of GFileIcon encoding"),
version);
goto out;
}
if (num_tokens != 1)
{
g_set_error_literal (error,
G_IO_ERROR,
G_IO_ERROR_INVALID_ARGUMENT,
_("Malformed input data for GFileIcon"));
goto out;
}
file = g_file_new_for_uri (tokens[0]);
icon = g_file_icon_new (file);
g_object_unref (file);
out:
return icon;
}
static void
g_file_icon_icon_iface_init (GIconIface *iface)
{
iface->hash = g_file_icon_hash;
iface->equal = g_file_icon_equal;
iface->to_tokens = g_file_icon_to_tokens;
iface->from_tokens = g_file_icon_from_tokens;
}