summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlexander Larsson <alexl@redhat.com>2008-10-21 12:04:50 +0000
committerAlexander Larsson <alexl@src.gnome.org>2008-10-21 12:04:50 +0000
commit1078f20f47debb00d0a0f6966b6680ad0473e32f (patch)
tree79de62213d9d346c8d6e778d587454fa340a6bde
parenta1bee70a1fcd53a6540b9d8198979306d6a4125b (diff)
downloadgvfs-1078f20f47debb00d0a0f6966b6680ad0473e32f.tar.gz
Require glib 2.19.1 for GIcon serialization support
2008-10-21 Alexander Larsson <alexl@redhat.com> * configure.ac: Require glib 2.19.1 for GIcon serialization support * common/gvfsdaemonprotocol.c: Use g_icon_to_string & co instead of home-brewed serialization * monitor/proxy/gproxydrive.c: * monitor/proxy/gproxymount.c: * monitor/proxy/gproxyvolume.c: * monitor/proxy/gproxyvolumemonitor.c: * monitor/proxy/gproxyvolumemonitor.h: * monitor/proxy/gvfsproxyvolumemonitordaemon.c: Use g_icon_to_string & co instead of home-brewed serialization svn path=/trunk/; revision=2069
-rw-r--r--ChangeLog16
-rw-r--r--common/gvfsdaemonprotocol.c115
-rw-r--r--configure.ac2
-rw-r--r--monitor/proxy/gproxydrive.c6
-rw-r--r--monitor/proxy/gproxymount.c5
-rw-r--r--monitor/proxy/gproxyvolume.c5
-rw-r--r--monitor/proxy/gproxyvolumemonitor.c113
-rw-r--r--monitor/proxy/gproxyvolumemonitor.h2
-rw-r--r--monitor/proxy/gvfsproxyvolumemonitordaemon.c112
9 files changed, 69 insertions, 307 deletions
diff --git a/ChangeLog b/ChangeLog
index 95b2e4aa..edb7997c 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,19 @@
+2008-10-21 Alexander Larsson <alexl@redhat.com>
+
+ * configure.ac:
+ Require glib 2.19.1 for GIcon serialization support
+
+ * common/gvfsdaemonprotocol.c:
+ Use g_icon_to_string & co instead of home-brewed serialization
+
+ * monitor/proxy/gproxydrive.c:
+ * monitor/proxy/gproxymount.c:
+ * monitor/proxy/gproxyvolume.c:
+ * monitor/proxy/gproxyvolumemonitor.c:
+ * monitor/proxy/gproxyvolumemonitor.h:
+ * monitor/proxy/gvfsproxyvolumemonitordaemon.c:
+ Use g_icon_to_string & co instead of home-brewed serialization
+
2008-10-20 Richard Hughes <richard@hughsie.com>
reviewed by: Christian Kellner <ck@xatom.net>
diff --git a/common/gvfsdaemonprotocol.c b/common/gvfsdaemonprotocol.c
index 0dc600a0..c90a7ba2 100644
--- a/common/gvfsdaemonprotocol.c
+++ b/common/gvfsdaemonprotocol.c
@@ -32,62 +32,21 @@
static const char *
get_object_signature (GObject *obj)
{
- if (G_IS_THEMED_ICON (obj))
+ if (G_IS_ICON (obj))
{
return
DBUS_STRUCT_BEGIN_CHAR_AS_STRING
- DBUS_TYPE_UINT32_AS_STRING
- DBUS_TYPE_ARRAY_AS_STRING DBUS_TYPE_STRING_AS_STRING
+ DBUS_TYPE_UINT32_AS_STRING
+ DBUS_TYPE_STRING_AS_STRING
DBUS_STRUCT_END_CHAR_AS_STRING;
- }
- else if (G_IS_FILE_ICON (obj))
- {
- GFile *file;
- char *path;
-
- file = g_file_icon_get_file (G_FILE_ICON (obj));
-
- path = g_file_get_path (file);
- if (path)
- {
- g_free (path);
- return
- DBUS_STRUCT_BEGIN_CHAR_AS_STRING
- DBUS_TYPE_UINT32_AS_STRING
- DBUS_TYPE_ARRAY_AS_STRING DBUS_TYPE_BYTE_AS_STRING
- DBUS_STRUCT_END_CHAR_AS_STRING;
- }
}
return
DBUS_STRUCT_BEGIN_CHAR_AS_STRING
- DBUS_TYPE_UINT32_AS_STRING
+ DBUS_TYPE_UINT32_AS_STRING
DBUS_STRUCT_END_CHAR_AS_STRING;
}
static void
-append_string_array (DBusMessageIter *iter, char **strs)
-{
- DBusMessageIter array;
- int i;
-
- if (!dbus_message_iter_open_container (iter,
- DBUS_TYPE_ARRAY,
- DBUS_TYPE_STRING_AS_STRING,
- &array))
- _g_dbus_oom ();
-
-
- for (i = 0; strs[i] != NULL; i++)
- {
- if (!dbus_message_iter_append_basic (&array, DBUS_TYPE_STRING, &strs[i]))
- _g_dbus_oom ();
- }
-
- if (!dbus_message_iter_close_container (iter, &array))
- _g_dbus_oom ();
-}
-
-static void
append_object (DBusMessageIter *iter, GObject *obj)
{
DBusMessageIter obj_struct_iter;
@@ -99,51 +58,22 @@ append_object (DBusMessageIter *iter, GObject *obj)
&obj_struct_iter))
_g_dbus_oom ();
- if (G_IS_THEMED_ICON (obj))
+ /* version 1 and 2 are deprecated old themed-icon and file-icon values */
+ if (G_IS_ICON (obj))
{
- const char * const *icons;
-
- icons = g_themed_icon_get_names (G_THEMED_ICON (obj));
-
- v_uint32 = 1;
+ char *data;
+
+ data = g_icon_to_string (G_ICON (obj));
+ v_uint32 = 3;
if (!dbus_message_iter_append_basic (&obj_struct_iter,
DBUS_TYPE_UINT32, &v_uint32))
_g_dbus_oom ();
-
- append_string_array (&obj_struct_iter, (char **)icons);
- }
- else if (G_IS_FILE_ICON (obj))
- {
- GFile *file;
- char *path;
-
- file = g_file_icon_get_file (G_FILE_ICON (obj));
-
- path = g_file_get_path (file);
- if (path)
- {
- v_uint32 = 2;
- if (!dbus_message_iter_append_basic (&obj_struct_iter,
- DBUS_TYPE_UINT32, &v_uint32))
- _g_dbus_oom ();
-
- path = g_file_get_path (file);
- _g_dbus_message_iter_append_cstring (&obj_struct_iter, path);
- g_free (path);
- }
- else
- {
- /* Seems unlikely that daemon backend will generate GFileIcons with
- files on the vfs, so its probably not a problem not to support this.
- (Its tricky to support, since we don't link the daemon to the client/
- library directly.) */
- g_warning ("Unknown file type for icon in attribute, ignoring");
-
- v_uint32 = 0;
- if (!dbus_message_iter_append_basic (&obj_struct_iter,
- DBUS_TYPE_UINT32, &v_uint32))
- _g_dbus_oom ();
- }
+
+ if (!dbus_message_iter_append_basic (&obj_struct_iter,
+ DBUS_TYPE_STRING, &data))
+ _g_dbus_oom ();
+
+ g_free (data);
}
else
{
@@ -429,7 +359,7 @@ _g_dbus_get_file_attribute (DBusMessageIter *iter,
if (obj_type == 1)
{
- /* G_THEMED_ICON */
+ /* Old deprecated G_THEMED_ICON */
if (_g_dbus_message_iter_get_args (&obj_iter,
NULL,
DBUS_TYPE_ARRAY, DBUS_TYPE_STRING,
@@ -441,7 +371,7 @@ _g_dbus_get_file_attribute (DBusMessageIter *iter,
}
else if (obj_type == 2)
{
- /* G_FILE_ICON, w/ local file */
+ /* Old deprecated G_FILE_ICON, w/ local file */
if (_g_dbus_message_iter_get_args (&obj_iter,
NULL,
G_DBUS_TYPE_CSTRING, &str,
@@ -452,6 +382,15 @@ _g_dbus_get_file_attribute (DBusMessageIter *iter,
g_free (str);
}
}
+ else if (obj_type == 3)
+ {
+ /* serialized G_ICON */
+ if (_g_dbus_message_iter_get_args (&obj_iter,
+ NULL,
+ DBUS_TYPE_STRING, &str,
+ 0))
+ obj = (GObject *)g_icon_new_for_string (str, NULL);
+ }
else
{
/* NULL (or unsupported) */
diff --git a/configure.ac b/configure.ac
index 843fa122..294c093f 100644
--- a/configure.ac
+++ b/configure.ac
@@ -45,7 +45,7 @@ GTK_DOC_CHECK
DISTCHECK_CONFIGURE_FLAGS="--enable-gtk-doc"
AC_SUBST(DISTCHECK_CONFIGURE_FLAGS)
-PKG_CHECK_MODULES(GLIB, glib-2.0 >= 2.17.6 gthread-2.0 gobject-2.0 gmodule-no-export-2.0 gio-unix-2.0 gio-2.0)
+PKG_CHECK_MODULES(GLIB, glib-2.0 >= 2.19.1 gthread-2.0 gobject-2.0 gmodule-no-export-2.0 gio-unix-2.0 gio-2.0)
AC_SUBST(GLIB_CFLAGS)
AC_SUBST(GLIB_LIBS)
diff --git a/monitor/proxy/gproxydrive.c b/monitor/proxy/gproxydrive.c
index b1e9533b..5c150f7a 100644
--- a/monitor/proxy/gproxydrive.c
+++ b/monitor/proxy/gproxydrive.c
@@ -198,7 +198,11 @@ g_proxy_drive_update (GProxyDrive *drive,
/* in with the new */
drive->id = g_strdup (id);
drive->name = g_strdup (name);
- drive->icon = _g_icon_new_from_serialized_data (gicon_data);
+ if (*gicon_data == 0)
+ drive->icon = NULL;
+ else
+ drive->icon = g_icon_new_for_string (gicon_data, NULL);
+
drive->can_eject = can_eject;
drive->can_poll_for_media = can_poll_for_media;
drive->has_media = has_media;
diff --git a/monitor/proxy/gproxymount.c b/monitor/proxy/gproxymount.c
index 123f5c43..4f9a4a8c 100644
--- a/monitor/proxy/gproxymount.c
+++ b/monitor/proxy/gproxymount.c
@@ -212,7 +212,10 @@ g_proxy_mount_update (GProxyMount *mount,
/* in with the new */
mount->id = g_strdup (id);
mount->name = g_strdup (name);
- mount->icon = _g_icon_new_from_serialized_data (gicon_data);
+ if (*gicon_data == 0)
+ mount->icon = NULL;
+ else
+ mount->icon = g_icon_new_for_string (gicon_data, NULL);
mount->uuid = g_strdup (uuid);
mount->root = g_file_new_for_uri (root_uri);
mount->can_unmount = can_unmount;
diff --git a/monitor/proxy/gproxyvolume.c b/monitor/proxy/gproxyvolume.c
index da6696ad..6eb8be67 100644
--- a/monitor/proxy/gproxyvolume.c
+++ b/monitor/proxy/gproxyvolume.c
@@ -254,7 +254,10 @@ void g_proxy_volume_update (GProxyVolume *volume,
volume->name = g_strdup (name);
volume->uuid = g_strdup (uuid);
volume->activation_uri = g_strdup (activation_uri);
- volume->icon = _g_icon_new_from_serialized_data (gicon_data);
+ if (*gicon_data == 0)
+ volume->icon = NULL;
+ else
+ volume->icon = g_icon_new_for_string (gicon_data, NULL);
volume->drive_id = g_strdup (drive_id);
volume->mount_id = g_strdup (mount_id);
volume->can_mount = can_mount;
diff --git a/monitor/proxy/gproxyvolumemonitor.c b/monitor/proxy/gproxyvolumemonitor.c
index e71fcde0..d9b4654c 100644
--- a/monitor/proxy/gproxyvolumemonitor.c
+++ b/monitor/proxy/gproxyvolumemonitor.c
@@ -982,119 +982,6 @@ _get_identifiers (DBusMessageIter *iter)
return hash_table;
}
-static GIcon *
-_g_icon_new_from_tokens (char **tokens, int num_tokens)
-{
- GIcon *icon;
-
- icon = NULL;
- if (strcmp (tokens[0], "GFileIcon") == 0)
- {
- GFile *file;
- char *unescaped_uri;
-
- if (num_tokens != 2)
- goto out;
-
- unescaped_uri = g_uri_unescape_string (tokens[1], NULL);
- file = g_file_new_for_uri (unescaped_uri);
- icon = g_file_icon_new (file);
- g_object_unref (file);
- g_free (unescaped_uri);
- }
- else if (strcmp (tokens[0], "GThemedIcon") == 0)
- {
- int n;
-
- for (n = 1; n < num_tokens; n++)
- {
- char *unescaped_name;
-
- unescaped_name = g_uri_unescape_string (tokens[n], NULL);
- if (icon == NULL)
- icon = g_themed_icon_new (unescaped_name);
- else
- g_themed_icon_append_name (G_THEMED_ICON (icon), unescaped_name);
- g_free (unescaped_name);
- }
- }
- else if (strcmp (tokens[0], "GEmblemedIcon") == 0)
- {
- int n, m, i;
- GIcon *base, *e_icon;
- GEmblem *emblem;
- GList *emblems, *e;
- GEmblemOrigin origin;
- char **t = tokens;
-
- t++;
- n = atoi (*t);
- t++;
- if (t - tokens >= num_tokens)
- goto out;
- base = _g_icon_new_from_tokens (t, n);
- if (base == NULL)
- goto out;
-
- t = t + n;
- m = atoi (*t);
- t++;
- emblems = NULL;
- for (i = 0; i < m; i++)
- {
- origin = atoi (*t);
- t++;
- n = atoi (*t);
- t++;
- if (t - tokens >= num_tokens)
- goto cleanup;
- e_icon = _g_icon_new_from_tokens (t, n);
- t += n;
- if (e_icon == NULL)
- goto cleanup;
- emblem = g_emblem_new_with_origin (e_icon, origin);
- emblems = g_list_append (emblems, emblem);
- }
- icon = g_emblemed_icon_new (base, (GEmblem*)emblems->data);
- for (e = emblems->next; e; e = e->next)
- g_emblemed_icon_add_emblem (G_EMBLEMED_ICON (icon), (GEmblem*)e->data);
-
- cleanup:
- g_object_unref (base);
- g_list_foreach (emblems, (GFunc)g_object_unref, NULL);
- g_list_free (emblems);
- }
-
- out:
- return icon;
-}
-
-GIcon *
-_g_icon_new_from_serialized_data (const char *gicon_data)
-{
- char **tokens;
- GIcon *icon;
- gint num_tokens;
-
- g_return_val_if_fail (gicon_data != NULL, NULL);
-
- icon = NULL;
-
- tokens = g_strsplit (gicon_data, " ", 0);
-
- if (g_strv_length (tokens) >= 3)
- {
- num_tokens = atoi (tokens[0]);
- icon = _g_icon_new_from_tokens (tokens + 1, num_tokens);
- }
-
- if (icon == NULL)
- g_warning ("malformed GIcon data \"%s\"", gicon_data);
-
- g_strfreev (tokens);
- return icon;
-}
-
DBusConnection *
g_proxy_volume_monitor_get_dbus_connection (GProxyVolumeMonitor *volume_monitor)
{
diff --git a/monitor/proxy/gproxyvolumemonitor.h b/monitor/proxy/gproxyvolumemonitor.h
index 4768ba8f..7d87c809 100644
--- a/monitor/proxy/gproxyvolumemonitor.h
+++ b/monitor/proxy/gproxyvolumemonitor.h
@@ -70,8 +70,6 @@ void g_proxy_volume_monitor_teardown_session_bus_connection (void);
GHashTable *_get_identifiers (DBusMessageIter *iter);
-GIcon *_g_icon_new_from_serialized_data (const char *gicon_data);
-
G_END_DECLS
#endif /* __G_PROXY_VOLUME_MONITOR_H__ */
diff --git a/monitor/proxy/gvfsproxyvolumemonitordaemon.c b/monitor/proxy/gvfsproxyvolumemonitordaemon.c
index 3ee5bbf8..26bb0eb7 100644
--- a/monitor/proxy/gvfsproxyvolumemonitordaemon.c
+++ b/monitor/proxy/gvfsproxyvolumemonitordaemon.c
@@ -39,103 +39,6 @@ static const char *the_dbus_name = NULL;
static void monitor_try_create (void);
-static char *
-_g_icon_serialize (GIcon *icon)
-{
- char *ret;
-
- g_return_val_if_fail (icon != NULL, NULL);
- g_return_val_if_fail (G_IS_ICON (icon), NULL);
-
- /* We encode icons as a series of whitespace-separated tokens.
- * The first token is the type of the icon. To help decoding,
- * the number of tokens is prepended as the first token (not
- * included in the count).
- */
- if (G_IS_FILE_ICON (icon))
- {
- GFileIcon *file_icon = G_FILE_ICON (icon);
- GFile *file;
- char *uri;
- char *escaped_uri;
-
- file = g_file_icon_get_file (file_icon);
- uri = g_file_get_uri (file);
- escaped_uri = g_uri_escape_string (uri, NULL, TRUE);
-
- ret = g_strdup_printf ("2 GFileIcon %s", escaped_uri);
-
- g_free (uri);
- g_free (escaped_uri);
- }
- else if (G_IS_THEMED_ICON (icon))
- {
- GThemedIcon *themed_icon = G_THEMED_ICON (icon);
- char *escaped_name;
- char **names;
- GString *s;
-
- g_object_get (themed_icon,
- "names", &names,
- NULL);
-
- s = g_string_new (0);
- g_string_append_printf (s, "%d GThemedIcon", g_strv_length (names) + 1);
-
- if (names != NULL)
- {
- int n;
- for (n = 0; names[n] != NULL; n++)
- {
- escaped_name = g_uri_escape_string (names[n], NULL, TRUE);
- g_string_append_c (s, ' ');
- g_string_append (s, escaped_name);
- g_free (escaped_name);
- }
- }
-
- ret = g_string_free (s, FALSE);
-
- g_strfreev (names);
- }
- else if (G_IS_EMBLEMED_ICON (icon))
- {
- char *base, *s;
- GList *emblems, *e;
- int n;
- GString *str;
-
- /* GEmblemedIcons are encoded as
- *
- * <num_tokens> GEmblemedIcon <num_emblems> [<origin> <encoded_icon> ]*
- */
- str = g_string_new ("");
- base = _g_icon_serialize (g_emblemed_icon_get_icon (G_EMBLEMED_ICON (icon)));
- emblems = g_emblemed_icon_get_emblems (G_EMBLEMED_ICON (icon));
- g_string_append_printf (str, "GEmblemedIcon %s %d", base, g_list_length (emblems));
- n = atoi (base) + 2;
- g_free (base);
- for (e = emblems; e; e = e->next)
- {
- s = _g_icon_serialize (g_emblem_get_icon (G_EMBLEM (e->data)));
- g_string_append_printf (str, " %d %s", g_emblem_get_origin (G_EMBLEM (e->data)), s);
- n += atoi (s) + 2;
- g_free (s);
- }
-
- s = g_string_free (str, FALSE);
- ret = g_strdup_printf ("%d %s", n + 1, s);
- g_free (s);
- }
- else
- {
- ret = NULL;
- g_warning ("unknown icon type; please add support");
- }
-
- return ret;
-}
-
/* string id
* string name
* string gicon_data
@@ -171,7 +74,10 @@ append_drive (GDrive *drive, DBusMessageIter *iter_array)
id = g_strdup_printf ("%p", drive);
name = g_drive_get_name (drive);
icon = g_drive_get_icon (drive);
- icon_data = _g_icon_serialize (icon);
+ if (icon)
+ icon_data = g_icon_to_string (icon);
+ else
+ icon_data = g_strdup ("");
can_eject = g_drive_can_eject (drive);
can_poll_for_media = g_drive_can_poll_for_media (drive);
has_media = g_drive_has_media (drive);
@@ -268,7 +174,10 @@ append_volume (GVolume *volume, DBusMessageIter *iter_array)
id = g_strdup_printf ("%p", volume);
name = g_volume_get_name (volume);
icon = g_volume_get_icon (volume);
- icon_data = _g_icon_serialize (icon);
+ if (icon)
+ icon_data = g_icon_to_string (icon);
+ else
+ icon_data = g_strdup ("");
uuid = g_volume_get_uuid (volume);
activation_root = g_volume_get_activation_root (volume);
if (activation_root == NULL)
@@ -374,7 +283,10 @@ append_mount (GMount *mount, DBusMessageIter *iter_array)
id = g_strdup_printf ("%p", mount);
name = g_mount_get_name (mount);
icon = g_mount_get_icon (mount);
- icon_data = _g_icon_serialize (icon);
+ if (icon)
+ icon_data = g_icon_to_string (icon);
+ else
+ icon_data = g_strdup ("");
uuid = g_mount_get_uuid (mount);
root = g_mount_get_root (mount);
root_uri = g_file_get_uri (root);