summaryrefslogtreecommitdiff
path: root/common
diff options
context:
space:
mode:
authorRyan Lortie <desrt@desrt.ca>2013-04-20 19:35:34 -0400
committerRyan Lortie <desrt@desrt.ca>2013-04-21 16:36:33 -0400
commitc9bbd01b70fea6488f48d2360893196295e13429 (patch)
treeae1f71d9488e67841ca420c0c3e061edff824997 /common
parent89c89f5a3a0ce4dedb969f4cc2e996c581141c97 (diff)
GVfsIcon: support icon serialisation
Add support for the new icon serialisation interface to GVfsIcon as well as implementing the new interface on GVfsClass for deserialising. https://bugzilla.gnome.org/show_bug.cgi?id=688820
Diffstat (limited to 'common')
-rw-r--r--common/gvfsicon.c34
-rw-r--r--common/gvfsicon.h3
2 files changed, 37 insertions, 0 deletions
diff --git a/common/gvfsicon.c b/common/gvfsicon.c
index 318440c7..3bacf8c5 100644
--- a/common/gvfsicon.c
+++ b/common/gvfsicon.c
@@ -272,6 +272,39 @@ g_vfs_icon_from_tokens (gchar **tokens,
return icon;
}
+static GVariant *
+g_vfs_icon_serialize (GIcon *icon)
+{
+ GVfsIcon *vfs_icon = G_VFS_ICON (icon);
+
+ return g_variant_new ("(@ss)",
+ g_variant_new_take_string (g_mount_spec_to_string (vfs_icon->mount_spec)),
+ vfs_icon->icon_id);
+}
+
+GIcon *
+g_vfs_icon_deserialize (GVariant *value)
+{
+ const gchar *mount_spec_str;
+ const gchar *id_str;
+ GMountSpec *mount_spec;
+ GIcon *icon;
+
+ if (!g_variant_is_of_type (value, G_VARIANT_TYPE ("(ss)")))
+ return NULL;
+
+ g_variant_get (value, "(&s&s)", &mount_spec_str, &id_str);
+
+ mount_spec = g_mount_spec_new_from_string (mount_spec_str, NULL);
+ if (mount_spec == NULL)
+ return NULL;
+
+ icon = g_vfs_icon_new (mount_spec, id_str);
+ g_mount_spec_unref (mount_spec);
+
+ return icon;
+}
+
static void
g_vfs_icon_icon_iface_init (GIconIface *iface)
{
@@ -279,4 +312,5 @@ g_vfs_icon_icon_iface_init (GIconIface *iface)
iface->equal = g_vfs_icon_equal;
iface->to_tokens = g_vfs_icon_to_tokens;
iface->from_tokens = g_vfs_icon_from_tokens;
+ iface->serialize = g_vfs_icon_serialize;
}
diff --git a/common/gvfsicon.h b/common/gvfsicon.h
index 7ed0935e..1bba7e7c 100644
--- a/common/gvfsicon.h
+++ b/common/gvfsicon.h
@@ -61,9 +61,12 @@ GType g_vfs_icon_get_type (void) G_GNUC_CONST;
GIcon *g_vfs_icon_new (GMountSpec *mount_spec,
const gchar *icon_id);
+GIcon *g_vfs_icon_deserialize (GVariant *value);
+
GMountSpec *g_vfs_icon_get_mount_spec (GVfsIcon *vfs_icon);
const gchar *g_vfs_icon_get_icon_id (GVfsIcon *vfs_icon);
+
G_END_DECLS
#endif /* __G_VFS_ICON_H__ */