Beispiel #1
0
GdkPixbuf *
empathy_pixbuf_avatar_from_contact_scaled (EmpathyContact *contact,
    gint width,
    gint height)
{
  EmpathyAvatar *avatar;

  g_return_val_if_fail (EMPATHY_IS_CONTACT (contact), NULL);

  avatar = empathy_contact_get_avatar (contact);

  return empathy_pixbuf_from_avatar_scaled (avatar, width, height);
}
Beispiel #2
0
static void
megaphone_applet_update_icon (MegaphoneApplet *applet)
{
	MegaphoneAppletPriv *priv = GET_PRIV (applet);
	EmpathyAvatar       *avatar = NULL;
	GdkPixbuf           *avatar_pixbuf;

	if (priv->contact) {
		avatar = empathy_contact_get_avatar (priv->contact);
	} else {
		gtk_image_set_from_icon_name (GTK_IMAGE (priv->image),
					      GTK_STOCK_PREFERENCES,
					      GTK_ICON_SIZE_MENU);
		return;
	}

	if (!avatar) {
		gchar *avatar_token;

		/* Try to take avatar from cache */
		avatar_token = panel_applet_gconf_get_string (PANEL_APPLET (applet),
							      "avatar_token",
							      NULL);
		if (!EMP_STR_EMPTY (avatar_token)) {
			empathy_contact_load_avatar_cache (priv->contact, avatar_token);
			avatar = empathy_contact_get_avatar (priv->contact);
		}
		g_free (avatar_token);
	}

	if (avatar) {
		avatar_pixbuf = empathy_pixbuf_from_avatar_scaled (avatar,
								   priv->image_size - 2,
								   priv->image_size - 2);
	} else {
		GtkIconTheme *icon_theme;

		/* Load the default icon when no avatar is found */
		icon_theme = gtk_icon_theme_get_default ();
		avatar_pixbuf = gtk_icon_theme_load_icon (icon_theme,
							  "stock_contact",
							  priv->image_size - 2,
							  0, NULL);
	}

	/* Now some desaturation if the contact is offline */
	if (!empathy_contact_is_online (priv->contact)) {
		GdkPixbuf *offline_avatar;

		offline_avatar = gdk_pixbuf_new (GDK_COLORSPACE_RGB, TRUE,
						 8,
						 gdk_pixbuf_get_height (avatar_pixbuf),
						 gdk_pixbuf_get_width (avatar_pixbuf));
		gdk_pixbuf_saturate_and_pixelate (avatar_pixbuf,
						  offline_avatar,
						  0.0,
						  TRUE);
		g_object_unref (avatar_pixbuf);
		avatar_pixbuf = offline_avatar;
	}

	gtk_image_set_from_pixbuf (GTK_IMAGE (priv->image), avatar_pixbuf);
	g_object_unref (avatar_pixbuf);
}