[accounts-dialog] Don't use SetIconData



commit e92220d37f14cfc46d7cdd163662aadc2d0e3008
Author: Matthias Clasen <mclasen redhat com>
Date:   Thu Mar 25 20:22:46 2010 -0400

    Don't use SetIconData
    
    Instead write a tempfile and use SetIconFile

 configure.ac    |    2 +-
 src/Makefile.am |    2 +
 src/um-user.c   |   59 ++++++++++++++++++++++++++++++------------------------
 3 files changed, 36 insertions(+), 27 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index f846cfa..34d2ee6 100644
--- a/configure.ac
+++ b/configure.ac
@@ -30,7 +30,7 @@ fi
 AC_SUBST(APG)
 
 PKG_CHECK_MODULES(GLIB, glib-2.0 gthread-2.0)
-PKG_CHECK_MODULES(GIO, gio-2.0)
+PKG_CHECK_MODULES(GIO, gio-2.0 gio-unix-2.0)
 PKG_CHECK_MODULES(GDK_PIXBUF, gdk-pixbuf-2.0)
 PKG_CHECK_MODULES(GTK, gtk+-2.0)
 PKG_CHECK_MODULES(GNOME_DESKTOP, gnome-desktop-2.0)
diff --git a/src/Makefile.am b/src/Makefile.am
index 18c1e58..ee97ec1 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -7,6 +7,7 @@ INCLUDES = \
 	-DGNOMELOCALEDIR=\""$(datadir)/locale"\"        \
 	-DUM_PIXMAP_DIR=\""$(pkgdatadir)/pixmaps"\"	\
 	$(GLIB_CFLAGS)					\
+	$(GIO_CFLAGS)					\
 	$(GTK_CFLAGS)					\
 	$(GNOME_DESKTOP_CFLAGS) 			\
 	$(UNIQUE_CFLAGS)				\
@@ -51,6 +52,7 @@ accounts_dialog_SOURCES = \
 
 accounts_dialog_LDADD = 		\
 	$(GLIB_LIBS)			\
+	$(GIO_LIBS)			\
 	$(GTK_LIBS)			\
 	$(GNOME_DESKTOP_LIBS)		\
 	$(UNIQUE_LIBS)			\
diff --git a/src/um-user.c b/src/um-user.c
index 15b2e8d..341aaae 100644
--- a/src/um-user.c
+++ b/src/um-user.c
@@ -31,9 +31,12 @@
 
 #include <glib.h>
 #include <glib/gi18n.h>
+#include <glib/gstdio.h>
 #include <gio/gio.h>
 #include <gtk/gtk.h>
 
+#include <gio/gunixoutputstream.h>
+
 #include <dbus/dbus-glib.h>
 
 #include "um-user.h"
@@ -860,36 +863,40 @@ void
 um_user_set_icon_data (UmUser    *user,
                        GdkPixbuf *pixbuf)
 {
-        GError *error = NULL;
-        GArray *data;
-        gint width, height, channels, rowstride;
-        guchar *pixels;
-
-        width = gdk_pixbuf_get_width (pixbuf);
-        height = gdk_pixbuf_get_height (pixbuf);
-        channels = gdk_pixbuf_get_n_channels (pixbuf);
-        rowstride = gdk_pixbuf_get_rowstride (pixbuf);
-        pixels = gdk_pixbuf_get_pixels (pixbuf);
-
-        data = g_array_sized_new (FALSE, FALSE, 1, rowstride * height);
-        g_array_insert_vals (data, 0, pixels, rowstride * height);
-        if (!dbus_g_proxy_call (user->proxy,
-                                "SetIconData",
-                                &error,
-                                G_TYPE_INT, width,
-                                G_TYPE_INT, height,
-                                G_TYPE_INT, channels,
-                                G_TYPE_INT, rowstride,
-                                DBUS_TYPE_G_UCHAR_ARRAY, data,
-                                G_TYPE_INVALID,
-                                G_TYPE_INVALID)) {
-                g_warning ("SetIconData call failed: %s", error->message);
+        gchar *path;
+        gint fd;
+        GOutputStream *stream;
+        GError *error;
+
+        path = g_build_filename (g_get_tmp_dir (), "usericonXXXXXX", NULL);
+        fd = g_mkstemp (path);
+
+        if (fd == -1) {
+                g_warning ("failed to create temporary file for image data");
+                g_free (path);
+                return;
+        }
+
+        stream = g_unix_output_stream_new (fd, TRUE);
+
+        error = NULL;
+        if (!gdk_pixbuf_save_to_stream (pixbuf, stream, "png", NULL, &error, NULL)) {
+                g_warning ("failed to save image: %s", error->message);
                 g_error_free (error);
-                g_array_unref (data);
+                g_object_unref (stream);
                 return;
         }
 
-        g_array_unref (data);
+        g_object_unref (stream);
+
+        um_user_set_icon_file (user, path);
+
+        /* if we ever make the dbus call async, the g_remove call needs
+         * to wait for its completion
+         */
+        g_remove (path);
+
+        g_free (path);
 }
 
 void



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]