comparison gtk/gtkblist.c @ 14852:cf25420b074d

[gaim-migrate @ 17621] Allow custom buddy icons for people in the buddylist. It's done completely in the UI side. The custom icon does not overwrite the original icon, which is displayed in the tooltip. You can set the icon by dragging an image on the conv window, or on the buddy in the buddylist. You can also set/remove custom icon from the conversation window by right clicking on the icon in the conv window. committer: Tailor Script <tailor@pidgin.im>
author Sadrul Habib Chowdhury <imadil@gmail.com>
date Sun, 29 Oct 2006 23:35:57 +0000
parents 77c68f898389
children 41ced1c9ba29
comparison
equal deleted inserted replaced
14851:036927fddcba 14852:cf25420b074d
1990 } 1990 }
1991 } 1991 }
1992 } 1992 }
1993 1993
1994 static GdkPixbuf *gaim_gtk_blist_get_buddy_icon(GaimBlistNode *node, 1994 static GdkPixbuf *gaim_gtk_blist_get_buddy_icon(GaimBlistNode *node,
1995 gboolean scaled, gboolean greyed) 1995 gboolean scaled, gboolean greyed, gboolean custom)
1996 { 1996 {
1997 GdkPixbuf *buf, *ret = NULL; 1997 GdkPixbuf *buf, *ret = NULL;
1998 GdkPixbufLoader *loader; 1998 GdkPixbufLoader *loader;
1999 GaimBuddyIcon *icon; 1999 GaimBuddyIcon *icon;
2000 const guchar *data; 2000 const guchar *data = NULL;
2001 gsize len; 2001 gsize len;
2002 GaimBuddy *buddy = (GaimBuddy *)node; 2002 GaimBuddy *buddy = (GaimBuddy *)node;
2003 2003
2004 if(GAIM_BLIST_NODE_IS_CONTACT(node)) { 2004 if(GAIM_BLIST_NODE_IS_CONTACT(node)) {
2005 buddy = gaim_contact_get_priority_buddy((GaimContact*)node); 2005 buddy = gaim_contact_get_priority_buddy((GaimContact*)node);
2012 #if 0 2012 #if 0
2013 if (!gaim_prefs_get_bool("/gaim/gtk/blist/show_buddy_icons")) 2013 if (!gaim_prefs_get_bool("/gaim/gtk/blist/show_buddy_icons"))
2014 return NULL; 2014 return NULL;
2015 #endif 2015 #endif
2016 2016
2017 if (!(icon = gaim_buddy_get_icon(buddy))) 2017 if (custom) {
2018 if (!(icon = gaim_buddy_icons_find(buddy->account, buddy->name))) /* Not sure I like this...*/ 2018 const char *file = gaim_blist_node_get_string((GaimBlistNode*)gaim_buddy_get_contact(buddy),
2019 return NULL; 2019 "custom_buddy_icon");
2020 if (file && *file) {
2021 char *contents;
2022 GError *err = NULL;
2023 if (!g_file_get_contents(file, &contents, &len, &err)) {
2024 gaim_debug_info("custom -icon", "Could not open custom-icon %s for %s\n",
2025 file, gaim_buddy_get_name(buddy), err->message);
2026 g_error_free(err);
2027 } else
2028 data = (const guchar*)contents;
2029 }
2030 }
2031
2032 if (data == NULL) {
2033 if (!(icon = gaim_buddy_get_icon(buddy)))
2034 if (!(icon = gaim_buddy_icons_find(buddy->account, buddy->name))) /* Not sure I like this...*/
2035 return NULL;
2036 data = gaim_buddy_icon_get_data(icon, &len);
2037 custom = FALSE; /* We are not using the custom icon */
2038 }
2020 2039
2021 loader = gdk_pixbuf_loader_new(); 2040 loader = gdk_pixbuf_loader_new();
2022 data = gaim_buddy_icon_get_data(icon, &len);
2023 gdk_pixbuf_loader_write(loader, data, len, NULL); 2041 gdk_pixbuf_loader_write(loader, data, len, NULL);
2024 gdk_pixbuf_loader_close(loader, NULL); 2042 gdk_pixbuf_loader_close(loader, NULL);
2025 buf = gdk_pixbuf_loader_get_pixbuf(loader); 2043 buf = gdk_pixbuf_loader_get_pixbuf(loader);
2026 if (buf) 2044 if (buf)
2027 g_object_ref(G_OBJECT(buf)); 2045 g_object_ref(G_OBJECT(buf));
2028 g_object_unref(G_OBJECT(loader)); 2046 g_object_unref(G_OBJECT(loader));
2029 2047
2048 if (custom)
2049 g_free((void*)data);
2030 if (buf) { 2050 if (buf) {
2031 GaimAccount *account = gaim_buddy_get_account(buddy); 2051 GaimAccount *account = gaim_buddy_get_account(buddy);
2032 GaimPluginProtocolInfo *prpl_info = NULL; 2052 GaimPluginProtocolInfo *prpl_info = NULL;
2033 int orig_width, orig_height; 2053 int orig_width, orig_height;
2034 int scale_width, scale_height; 2054 int scale_width, scale_height;
2086 { 2106 {
2087 char *tooltip_text = NULL; 2107 char *tooltip_text = NULL;
2088 struct tooltip_data *td = g_new0(struct tooltip_data, 1); 2108 struct tooltip_data *td = g_new0(struct tooltip_data, 1);
2089 2109
2090 td->status_icon = gaim_gtk_blist_get_status_icon(node, GAIM_STATUS_ICON_LARGE); 2110 td->status_icon = gaim_gtk_blist_get_status_icon(node, GAIM_STATUS_ICON_LARGE);
2091 td->avatar = gaim_gtk_blist_get_buddy_icon(node, !full, FALSE); 2111 td->avatar = gaim_gtk_blist_get_buddy_icon(node, !full, FALSE, FALSE);
2092 tooltip_text = gaim_get_tooltip_text(node, full); 2112 tooltip_text = gaim_get_tooltip_text(node, full);
2093 td->layout = gtk_widget_create_pango_layout(gtkblist->tipwindow, NULL); 2113 td->layout = gtk_widget_create_pango_layout(gtkblist->tipwindow, NULL);
2094 pango_layout_set_markup(td->layout, tooltip_text, -1); 2114 pango_layout_set_markup(td->layout, tooltip_text, -1);
2095 pango_layout_set_wrap(td->layout, PANGO_WRAP_WORD); 2115 pango_layout_set_wrap(td->layout, PANGO_WRAP_WORD);
2096 pango_layout_set_width(td->layout, 300000); 2116 pango_layout_set_width(td->layout, 300000);
4468 presence = gaim_buddy_get_presence(buddy); 4488 presence = gaim_buddy_get_presence(buddy);
4469 4489
4470 status = gaim_gtk_blist_get_status_icon((GaimBlistNode*)buddy, 4490 status = gaim_gtk_blist_get_status_icon((GaimBlistNode*)buddy,
4471 biglist ? GAIM_STATUS_ICON_LARGE : GAIM_STATUS_ICON_SMALL); 4491 biglist ? GAIM_STATUS_ICON_LARGE : GAIM_STATUS_ICON_SMALL);
4472 4492
4473 avatar = gaim_gtk_blist_get_buddy_icon((GaimBlistNode *)buddy, TRUE, TRUE); 4493 avatar = gaim_gtk_blist_get_buddy_icon((GaimBlistNode *)buddy, TRUE, TRUE, TRUE);
4474 mark = gaim_gtk_blist_get_name_markup(buddy, selected); 4494 mark = gaim_gtk_blist_get_name_markup(buddy, selected);
4475 4495
4476 if (gaim_prefs_get_bool("/gaim/gtk/blist/show_idle_time") && 4496 if (gaim_prefs_get_bool("/gaim/gtk/blist/show_idle_time") &&
4477 gaim_presence_is_idle(presence) && 4497 gaim_presence_is_idle(presence) &&
4478 !gaim_prefs_get_bool("/gaim/gtk/blist/show_buddy_icons")) 4498 !gaim_prefs_get_bool("/gaim/gtk/blist/show_buddy_icons"))