aboutsummaryrefslogtreecommitdiffstats
path: root/libempathy-gtk/empathy-ui-utils.c
diff options
context:
space:
mode:
authorXavier Claessens <xclaesse@gmail.com>2007-10-09 00:44:44 +0800
committerXavier Claessens <xclaesse@src.gnome.org>2007-10-09 00:44:44 +0800
commit0d4e81432f5ace47ac86991aa239e4a55686de00 (patch)
tree22cc64055c78370d4a973af8e85a36740f60f930 /libempathy-gtk/empathy-ui-utils.c
parent311dbc21826654538e098a8d838153d5b075f6c7 (diff)
downloadgsoc2013-empathy-0d4e81432f5ace47ac86991aa239e4a55686de00.tar
gsoc2013-empathy-0d4e81432f5ace47ac86991aa239e4a55686de00.tar.gz
gsoc2013-empathy-0d4e81432f5ace47ac86991aa239e4a55686de00.tar.bz2
gsoc2013-empathy-0d4e81432f5ace47ac86991aa239e4a55686de00.tar.lz
gsoc2013-empathy-0d4e81432f5ace47ac86991aa239e4a55686de00.tar.xz
gsoc2013-empathy-0d4e81432f5ace47ac86991aa239e4a55686de00.tar.zst
gsoc2013-empathy-0d4e81432f5ace47ac86991aa239e4a55686de00.zip
Implement EmpathyAvatarChooser and EmpathyAvatarImage and make use of them
2007-10-08 Xavier Claessens <xclaesse@gmail.com> * libempathy-gtk/empathy-ui-utils.c: * libempathy-gtk/empathy-ui-utils.h: * libempathy-gtk/empathy-contact-widget.c: * libempathy-gtk/empathy-contact-widget.h: * libempathy-gtk/empathy-avatar-chooser.c: * libempathy-gtk/empathy-avatar-chooser.h: * libempathy-gtk/empathy-avatar-image.c: * libempathy-gtk/empathy-avatar-image.h: * libempathy-gtk/Makefile.am: * src/empathy.c: Implement EmpathyAvatarChooser and EmpathyAvatarImage and make use of them in contact information windows. That means we can now enlarge avatars when clicking on it and we can set our own avatar if we edit our own contact. svn path=/trunk/; revision=363
Diffstat (limited to 'libempathy-gtk/empathy-ui-utils.c')
-rw-r--r--libempathy-gtk/empathy-ui-utils.c119
1 files changed, 90 insertions, 29 deletions
diff --git a/libempathy-gtk/empathy-ui-utils.c b/libempathy-gtk/empathy-ui-utils.c
index 1c2d79c7b..fe032c9ee 100644
--- a/libempathy-gtk/empathy-ui-utils.c
+++ b/libempathy-gtk/empathy-ui-utils.c
@@ -201,35 +201,6 @@ empathy_glade_setup_size_group (GladeXML *gui,
va_end (args);
}
-GdkPixbuf *
-empathy_pixbuf_from_icon_name (const gchar *icon_name,
- GtkIconSize icon_size)
-{
- GtkIconTheme *theme;
- GdkPixbuf *pixbuf = NULL;
- GError *error = NULL;
- gint w, h;
- gint size = 48;
-
- theme = gtk_icon_theme_get_default ();
-
- if (gtk_icon_size_lookup (icon_size, &w, &h)) {
- size = (w + h) / 2;
- }
-
- pixbuf = gtk_icon_theme_load_icon (theme,
- icon_name,
- size,
- 0,
- &error);
- if (error) {
- empathy_debug (DEBUG_DOMAIN, "Error loading icon: %s", error->message);
- g_clear_error (&error);
- }
-
- return pixbuf;
-}
-
const gchar *
empathy_icon_name_from_account (McAccount *account)
{
@@ -293,6 +264,44 @@ empathy_icon_name_for_contact (EmpathyContact *contact)
return EMPATHY_IMAGE_UNKNOWN;
}
+GdkPixbuf *
+empathy_pixbuf_from_data (gchar *data,
+ gsize data_size)
+{
+ GdkPixbufLoader *loader;
+ GdkPixbuf *pixbuf = NULL;
+ GError *error = NULL;
+
+ if (!data) {
+ return NULL;
+ }
+
+ loader = gdk_pixbuf_loader_new ();
+ if (!gdk_pixbuf_loader_write (loader, data, data_size, &error)) {
+ empathy_debug (DEBUG_DOMAIN, "Failed to write to pixbuf loader: %s",
+ error ? error->message : "No error given");
+ g_clear_error (&error);
+ g_object_unref (loader);
+ return NULL;
+ }
+ if (!gdk_pixbuf_loader_close (loader, &error)) {
+ empathy_debug (DEBUG_DOMAIN, "Failed to close pixbuf loader: %s",
+ error ? error->message : "No error given");
+ g_clear_error (&error);
+ g_object_unref (loader);
+ return NULL;
+ }
+
+ pixbuf = gdk_pixbuf_loader_get_pixbuf (loader);
+ if (pixbuf) {
+ g_object_ref (pixbuf);
+ }
+
+ g_object_unref (loader);
+
+ return pixbuf;
+}
+
static void
pixbuf_from_avatar_size_prepared_cb (GdkPixbufLoader *loader,
int width,
@@ -488,6 +497,58 @@ empathy_pixbuf_avatar_from_contact_scaled (EmpathyContact *contact,
return empathy_pixbuf_from_avatar_scaled (avatar, width, height);
}
+GdkPixbuf *
+empathy_pixbuf_scale_down_if_necessary (GdkPixbuf *pixbuf, gint max_size)
+{
+ gint width, height;
+ gdouble factor;
+
+ width = gdk_pixbuf_get_width (pixbuf);
+ height = gdk_pixbuf_get_height (pixbuf);
+
+ if (width > max_size || height > max_size) {
+ factor = (gdouble) max_size / MAX (width, height);
+
+ width = width * factor;
+ height = height * factor;
+
+ return gdk_pixbuf_scale_simple (pixbuf,
+ width, height,
+ GDK_INTERP_HYPER);
+ }
+
+ return g_object_ref (pixbuf);
+}
+
+GdkPixbuf *
+empathy_pixbuf_from_icon_name (const gchar *icon_name,
+ GtkIconSize icon_size)
+{
+ GtkIconTheme *theme;
+ GdkPixbuf *pixbuf = NULL;
+ GError *error = NULL;
+ gint w, h;
+ gint size = 48;
+
+ theme = gtk_icon_theme_get_default ();
+
+ if (gtk_icon_size_lookup (icon_size, &w, &h)) {
+ size = (w + h) / 2;
+ }
+
+ pixbuf = gtk_icon_theme_load_icon (theme,
+ icon_name,
+ size,
+ 0,
+ &error);
+ if (error) {
+ empathy_debug (DEBUG_DOMAIN, "Error loading icon: %s", error->message);
+ g_clear_error (&error);
+ }
+
+ return pixbuf;
+}
+
/* Stolen from GtkSourceView, hence the weird intendation. Please keep it like
* that to make it easier to apply changes from the original code.
*/