aboutsummaryrefslogtreecommitdiffstats
path: root/libempathy-gtk/empathy-ui-utils.c
diff options
context:
space:
mode:
authorchantra <chantra@debuntu.org>2009-12-17 00:20:36 +0800
committerGuillaume Desmottes <guillaume.desmottes@collabora.co.uk>2009-12-17 00:22:01 +0800
commitfbaeb693027d63d94488702635630644971dfc2f (patch)
tree9b58024f0089129e197824550b68ee1f30fbea05 /libempathy-gtk/empathy-ui-utils.c
parentd6152461b68592397130f5df2dd285b5651eb460 (diff)
downloadgsoc2013-empathy-fbaeb693027d63d94488702635630644971dfc2f.tar
gsoc2013-empathy-fbaeb693027d63d94488702635630644971dfc2f.tar.gz
gsoc2013-empathy-fbaeb693027d63d94488702635630644971dfc2f.tar.bz2
gsoc2013-empathy-fbaeb693027d63d94488702635630644971dfc2f.tar.lz
gsoc2013-empathy-fbaeb693027d63d94488702635630644971dfc2f.tar.xz
gsoc2013-empathy-fbaeb693027d63d94488702635630644971dfc2f.tar.zst
gsoc2013-empathy-fbaeb693027d63d94488702635630644971dfc2f.zip
contact_list: displays an icon showing the protocol by the contact (#603877)
Diffstat (limited to 'libempathy-gtk/empathy-ui-utils.c')
-rw-r--r--libempathy-gtk/empathy-ui-utils.c112
1 files changed, 112 insertions, 0 deletions
diff --git a/libempathy-gtk/empathy-ui-utils.c b/libempathy-gtk/empathy-ui-utils.c
index 2d8f4091c..3fa39d53f 100644
--- a/libempathy-gtk/empathy-ui-utils.c
+++ b/libempathy-gtk/empathy-ui-utils.c
@@ -230,6 +230,21 @@ empathy_icon_name_for_contact (EmpathyContact *contact)
return empathy_icon_name_for_presence (presence);
}
+const gchar *
+empathy_protocol_name_for_contact (EmpathyContact *contact)
+{
+ TpAccount *account;
+
+ g_return_val_if_fail (EMPATHY_IS_CONTACT (contact), NULL);
+
+ account = empathy_contact_get_account (contact);
+ if (account == NULL) {
+ return NULL;
+ }
+
+ return tp_account_get_icon_name (account);
+}
+
GdkPixbuf *
empathy_pixbuf_from_data (gchar *data,
gsize data_size)
@@ -491,6 +506,103 @@ empathy_pixbuf_avatar_from_contact_scaled (EmpathyContact *contact,
}
GdkPixbuf *
+empathy_pixbuf_contact_status_icon (EmpathyContact *contact,
+ gboolean show_protocol)
+{
+ const gchar *icon_name;
+
+ g_return_val_if_fail (EMPATHY_IS_CONTACT (contact), NULL);
+
+ icon_name = empathy_icon_name_for_contact (contact);
+
+ if (icon_name == NULL) {
+ return NULL;
+ }
+ return empathy_pixbuf_contact_status_icon_with_icon_name (contact,
+ icon_name,
+ show_protocol);
+}
+
+GdkPixbuf *
+empathy_pixbuf_contact_status_icon_with_icon_name (EmpathyContact *contact,
+ const gchar *icon_name,
+ gboolean show_protocol)
+{
+ GdkPixbuf *pix_status;
+ GdkPixbuf *pix_protocol;
+ gchar *icon_filename;
+ gint height, width;
+ gint numerator, denominator;
+
+ g_return_val_if_fail (EMPATHY_IS_CONTACT (contact), NULL);
+
+ numerator = 3;
+ denominator = 4;
+
+ icon_filename = empathy_filename_from_icon_name (icon_name,
+ GTK_ICON_SIZE_MENU);
+ if (icon_filename == NULL) {
+ DEBUG ("icon name: %s could not be found\n", icon_name);
+ return NULL;
+ }
+
+ pix_status = gdk_pixbuf_new_from_file (icon_filename, NULL);
+
+ g_free (icon_filename);
+
+ if (pix_status == NULL) {
+ DEBUG ("Could not open icon %s\n", icon_filename);
+ return NULL;
+ }
+
+ if (!show_protocol)
+ return pix_status;
+
+ height = gdk_pixbuf_get_height (pix_status);
+ width = gdk_pixbuf_get_width (pix_status);
+
+ pix_protocol = empathy_pixbuf_protocol_from_contact_scaled (contact,
+ width * numerator / denominator,
+ height * numerator / denominator);
+
+ if (pix_protocol == NULL) {
+ return pix_status;
+ }
+ gdk_pixbuf_composite (pix_protocol, pix_status,
+ 0, height - height * numerator / denominator,
+ width * numerator / denominator, height * numerator / denominator,
+ 0, height - height * numerator / denominator,
+ 1, 1,
+ GDK_INTERP_BILINEAR, 255);
+
+ g_object_unref (pix_protocol);
+
+ return pix_status;
+}
+
+GdkPixbuf *
+empathy_pixbuf_protocol_from_contact_scaled (EmpathyContact *contact,
+ gint width,
+ gint height)
+{
+ TpAccount *account;
+ gchar *filename;
+ GdkPixbuf *pixbuf = NULL;
+
+ g_return_val_if_fail (EMPATHY_IS_CONTACT (contact), NULL);
+
+ account = empathy_contact_get_account (contact);
+ filename = empathy_filename_from_icon_name (tp_account_get_icon_name (account),
+ GTK_ICON_SIZE_MENU);
+ if (filename != NULL) {
+ pixbuf = gdk_pixbuf_new_from_file_at_size (filename, width, height, NULL);
+ g_free (filename);
+ }
+
+ return pixbuf;
+}
+
+GdkPixbuf *
empathy_pixbuf_scale_down_if_necessary (GdkPixbuf *pixbuf, gint max_size)
{
gint width, height;