mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2025-08-01 15:03:39 +02:00
GIcon: add g_icon_[de]serialize()
Add support for serialising a GIcon to a GVariant and deserialising the result back to a GIcon. This solves a number of problems suffered by the existing to_string() API, primarily these: - not forcing the icon to be a utf8 string means that we can efficiently encode a PNG (ie: just give the array of bytes) - there is no need to ensure that proper types are loaded before using the deserialisation interface. 'Foreign' icon types will probably emit a serialised format the deserialises to a GBytesIcon. We additionally clearly document what is required for being a consumer or implementation of #GIcon. Further patches will be required to GdkPixbuf and GVfsIcon to bring their implementations in line with the new rules (essentially: introduce implementations of the new serialize() API). https://bugzilla.gnome.org/show_bug.cgi?id=688820
This commit is contained in:
@@ -256,6 +256,14 @@ g_file_icon_from_tokens (gchar **tokens,
|
||||
return icon;
|
||||
}
|
||||
|
||||
static GVariant *
|
||||
g_file_icon_serialize (GIcon *icon)
|
||||
{
|
||||
GFileIcon *file_icon = G_FILE_ICON (icon);
|
||||
|
||||
return g_variant_new ("(sv)", "file", g_variant_new_take_string (g_file_get_uri (file_icon->file)));
|
||||
}
|
||||
|
||||
static void
|
||||
g_file_icon_icon_iface_init (GIconIface *iface)
|
||||
{
|
||||
@@ -263,6 +271,7 @@ g_file_icon_icon_iface_init (GIconIface *iface)
|
||||
iface->equal = g_file_icon_equal;
|
||||
iface->to_tokens = g_file_icon_to_tokens;
|
||||
iface->from_tokens = g_file_icon_from_tokens;
|
||||
iface->serialize = g_file_icon_serialize;
|
||||
}
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user