Merge lp:~dbarth/indicator-me/avatar-support into lp:indicator-me

Proposed by David Barth
Status: Merged
Merge reported by: David Barth
Merged at revision: not available
Proposed branch: lp:~dbarth/indicator-me/avatar-support
Merge into: lp:indicator-me
Diff against target: 86 lines (+57/-2)
1 file modified
src/about-me-menu-item.c (+57/-2)
To merge this branch: bzr merge lp:~dbarth/indicator-me/avatar-support
Reviewer Review Type Date Requested Status
Ted Gould (community) Approve
Review via email: mp+20256@code.launchpad.net
To post a comment you must log in.
Revision history for this message
David Barth (dbarth) wrote :

This adds support for avatar icons, ie the one set by the user in the about-me preference dialog

Revision history for this message
Ted Gould (ted) wrote :

Some minor things:

     1. You need to free "file" as it's an allocated string.
     2. The buf structure should probably be a _g_stat_struct as that's
        what the g_stat function takes. In theory it should be the
        same... but :)
     3. The size variable is a double, but then it's passed into the
        pixbuf allocator which takes an int. This will cause
        truncation, is that what you want? If so, it'd probably good to
        have a comment saying as such.
     4. Need to check in your error handler if error != NULL as you're
        looking at the message property. It could be that error isn't
        set.

Clean up stuff, otherwise it looks good.

  review approve

review: Approve
81. By David Barth

fixes for error cases and type truncations

Revision history for this message
David Barth (dbarth) wrote :

Fixed in revision 81, except for the stat struct for which the doc and the API seem out of sync.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/about-me-menu-item.c'
2--- src/about-me-menu-item.c 2010-02-18 00:39:49 +0000
3+++ src/about-me-menu-item.c 2010-03-01 23:34:13 +0000
4@@ -25,6 +25,12 @@
5 * Cody Russell <crussell@canonical.com>
6 */
7
8+#include <sys/types.h>
9+#include <sys/stat.h>
10+#include <unistd.h>
11+
12+#include <glib/gstdio.h>
13+
14 #include <gtk/gtk.h>
15 #include "about-me-menu-item.h"
16
17@@ -197,6 +203,54 @@
18 return pixbuf;
19 }
20
21+
22+static gboolean
23+load_avatar (gpointer data)
24+{
25+ g_return_val_if_fail (ABOUT_IS_ME_MENU_ITEM (data), FALSE);
26+
27+ AboutMeMenuItemPrivate *priv = GET_PRIVATE (data);
28+
29+ /* check if the user defined an avatar */
30+ gchar *file = g_build_filename (g_get_home_dir (), ".face", NULL);
31+
32+ struct stat buf;
33+ if (! (g_stat (file, &buf) == 0 && buf.st_size > 0)) {
34+ goto avatar_fail;
35+ }
36+
37+ if (buf.st_size > 1024*1024) {
38+ g_warning ("avatar file too large (%lld)", (long long)buf.st_size);
39+ goto avatar_fail;
40+ }
41+
42+ GError *error = NULL;
43+ int size = get_pixels_per_em (priv->image) * 3;
44+
45+ GdkPixbuf *pixbuf = gdk_pixbuf_new_from_file_at_scale (file, -1, size, TRUE,
46+ &error);
47+ if (pixbuf == NULL) {
48+ if (error != NULL) {
49+ g_warning ("Couldn't read file %s: %s", file, error->message);
50+ g_error_free (error);
51+ }
52+ goto avatar_fail;
53+ }
54+
55+ gtk_image_set_from_pixbuf (GTK_IMAGE (priv->image), pixbuf);
56+
57+ g_object_unref (pixbuf);
58+ g_free (file);
59+
60+ return TRUE;
61+
62+avatar_fail:
63+ g_free (file);
64+
65+ return FALSE;
66+}
67+
68+
69 static void
70 image_size_allocate (GtkWidget *widget,
71 GtkAllocation *allocation,
72@@ -227,11 +281,12 @@
73 GdkPixbuf *pixbuf = load_icon ("stock_person", pixels_per_em * 3);
74 priv->image = gtk_image_new_from_pixbuf (pixbuf);
75 g_signal_connect (frame, "size-allocate", G_CALLBACK (image_size_allocate), NULL);
76- gint height, width;
77- gtk_widget_get_size_request (GTK_WIDGET (priv->image), &width, &height);
78 gtk_misc_set_padding (GTK_MISC (priv->image), 2, 2);
79 gtk_container_add (GTK_CONTAINER (frame), priv->image);
80
81+ /* try to load a personalized icon */
82+ g_idle_add (load_avatar, (gpointer)object);
83+
84 align = gtk_alignment_new (0, 0.3, 0, 0);
85 priv->label = gtk_label_new (priv->realname);
86 gtk_misc_set_padding (GTK_MISC (priv->label), 2, 2);

Subscribers

People subscribed via source and target branches