diff options
author | Ted Gould <ted@gould.cx> | 2010-03-11 14:22:51 -0600 |
---|---|---|
committer | Ted Gould <ted@gould.cx> | 2010-03-11 14:22:51 -0600 |
commit | 8caf60a3944a876075f173b520c53272003ebbe4 (patch) | |
tree | 383699d46a012fe984beac14ea23c0db29d082e2 /libindicator/indicator-image-helper.c | |
parent | 5ca699baae839672ca9a418ab2f9c063dfdf9ae0 (diff) | |
parent | bb8b7032dfd93cd0cdad55967b973dd4de7ca044 (diff) | |
download | libayatana-indicator-8caf60a3944a876075f173b520c53272003ebbe4.tar.gz libayatana-indicator-8caf60a3944a876075f173b520c53272003ebbe4.tar.bz2 libayatana-indicator-8caf60a3944a876075f173b520c53272003ebbe4.zip |
Upstream release 0.3.5
Diffstat (limited to 'libindicator/indicator-image-helper.c')
-rw-r--r-- | libindicator/indicator-image-helper.c | 49 |
1 files changed, 34 insertions, 15 deletions
diff --git a/libindicator/indicator-image-helper.c b/libindicator/indicator-image-helper.c index cbbad3d..86d6c25 100644 --- a/libindicator/indicator-image-helper.c +++ b/libindicator/indicator-image-helper.c @@ -109,24 +109,41 @@ image_destroyed_cb (GtkImage * image, gpointer user_data) return; } +/* Catch the style changing on the image to make sure + we've got the latest. */ +static void +image_style_change_cb (GtkImage * image, GtkStyle * previous_style, gpointer user_data) +{ + refresh_image(image); + return; +} + +/* Builds an image with the name and fallbacks and all kinds of fun + stuff . */ GtkImage * indicator_image_helper (const gchar * name) { - g_return_val_if_fail(name != NULL, NULL); - g_return_val_if_fail(name[0] != '\0', NULL); + /* Build us an image */ + GtkImage * image = GTK_IMAGE(gtk_image_new()); + + indicator_image_helper_update(image, name); + + return image; +} + +/* Updates and image with all the fun stuff */ +void +indicator_image_helper_update (GtkImage * image, const gchar * name) +{ + g_return_if_fail(name != NULL); + g_return_if_fail(name[0] != '\0'); + g_return_if_fail(image != NULL); /* Build us a GIcon */ GIcon * icon_names = g_themed_icon_new_with_default_fallbacks(name); - g_return_val_if_fail(icon_names != NULL, NULL); - - /* Build us an image */ - GtkImage * image = GTK_IMAGE(gtk_image_new()); + g_return_if_fail(icon_names != NULL); - if (image == NULL) { - g_error("Unable to create image from pixbuf on icon name '%s'", name); - g_object_unref(icon_names); - return NULL; - } + gboolean seen_previously = (g_object_get_data(G_OBJECT(image), INDICATOR_NAMES_DATA) != NULL); /* Attach our names to the image */ g_object_set_data_full(G_OBJECT(image), INDICATOR_NAMES_DATA, icon_names, g_object_unref); @@ -135,9 +152,11 @@ indicator_image_helper (const gchar * name) refresh_image(image); /* Connect to all changes */ - g_signal_connect(G_OBJECT(gtk_icon_theme_get_default()), "changed", G_CALLBACK(theme_changed_cb), image); - g_signal_connect(G_OBJECT(image), "destroy", G_CALLBACK(image_destroyed_cb), NULL); + if (!seen_previously) { + g_signal_connect(G_OBJECT(gtk_icon_theme_get_default()), "changed", G_CALLBACK(theme_changed_cb), image); + g_signal_connect(G_OBJECT(image), "destroy", G_CALLBACK(image_destroyed_cb), NULL); + g_signal_connect(G_OBJECT(image), "style-set", G_CALLBACK(image_style_change_cb), NULL); + } - /* Return our built image */ - return image; + return; } |