comparison pidgin/gtkblist.c @ 15442:2dc742344eb7

PRPL Icons in tooltips
author Sean Egan <seanegan@gmail.com>
date Sun, 28 Jan 2007 08:51:21 +0000
parents 42961709cb30
children 8721df7d419f
comparison
equal deleted inserted replaced
15438:ea9ec8c3a3b8 15442:2dc742344eb7
2179 g_object_unref(G_OBJECT(buf)); 2179 g_object_unref(G_OBJECT(buf));
2180 } 2180 }
2181 2181
2182 return ret; 2182 return ret;
2183 } 2183 }
2184 2184 /* # - Status Icon
2185 * P - Protocol Icon
2186 * A - Buddy Icon
2187 * [ - SMALL_SPACE
2188 * = - LARGE_SPACE
2189 * +--- STATUS_SIZE +--- td->avatar_width
2190 * | +-- td->name_width |
2191 * +----+ +-------+ +---------+
2192 * | | | | | |
2193 * +-------------------------------------------+
2194 * | [ = [ |--- TOOLTIP_BORDER
2195 *name_height --+-| ######[BuddyName = PP [ AAAAAAAAAAA |--+
2196 * | | ######[ = PP [ AAAAAAAAAAA | |
2197 * STATUS SIZE -| | ######[[[[[[[[[[[[[[[[[[[[[ AAAAAAAAAAA | |
2198 * +--+-| ######[Account: So-and-so [ AAAAAAAAAAA | |-- td->avatar_height
2199 * | | [Idle: 4h 15m [ AAAAAAAAAAA | |
2200 * height --+ | [Foo: Bar, Baz [ AAAAAAAAAAA | |
2201 * | | [Status: Awesome [ AAAAAAAAAAA |--+
2202 * +----| [Stop: Hammer Time [ |
2203 * | [ [ |--- TOOLTIP_BORDER
2204 * +-------------------------------------------+
2205 * | | | |
2206 * | +----------------+ |
2207 * | | |
2208 * | +-- td->width |
2209 * | |
2210 * +---- TOOLTIP_BORDER +---- TOOLTIP_BORDER
2211 *
2212 *
2213 */
2214 #define STATUS_SIZE 32
2215 #define TOOLTIP_BORDER 12
2216 #define SMALL_SPACE 6
2217 #define LARGE_SPACE 12
2218 #define PRPL_SIZE 22
2185 struct tooltip_data { 2219 struct tooltip_data {
2186 PangoLayout *layout; 2220 PangoLayout *layout;
2221 PangoLayout *name_layout;
2222 GdkPixbuf *prpl_icon;
2187 GdkPixbuf *status_icon; 2223 GdkPixbuf *status_icon;
2188 GdkPixbuf *avatar; 2224 GdkPixbuf *avatar;
2189 const char *protocol; 2225 gboolean avatar_is_prpl_icon;
2190 int avatar_width; 2226 int avatar_width;
2191 int avatar_height; 2227 int avatar_height;
2228 int name_height;
2229 int name_width;
2192 int width; 2230 int width;
2193 int height; 2231 int height;
2194 }; 2232 };
2195 2233
2196 static struct tooltip_data * create_tip_for_node(GaimBlistNode *node, gboolean full) 2234 static struct tooltip_data * create_tip_for_node(GaimBlistNode *node, gboolean full)
2197 { 2235 {
2198 char *tooltip_text = NULL; 2236 char *tooltip_text = NULL;
2199 struct tooltip_data *td = g_new0(struct tooltip_data, 1); 2237 struct tooltip_data *td = g_new0(struct tooltip_data, 1);
2200 GaimAccount *account = NULL; 2238 GaimAccount *account = NULL;
2201 GaimPlugin *prpl = NULL; 2239 char *tmp, *node_name;
2202 GaimPluginProtocolInfo *prpl_info;
2203 2240
2204 if(GAIM_BLIST_NODE_IS_BUDDY(node)) { 2241 if(GAIM_BLIST_NODE_IS_BUDDY(node)) {
2205 account = ((GaimBuddy*)(node))->account; 2242 account = ((GaimBuddy*)(node))->account;
2206 } else if(GAIM_BLIST_NODE_IS_CHAT(node)) { 2243 } else if(GAIM_BLIST_NODE_IS_CHAT(node)) {
2207 account = ((GaimChat*)(node))->account; 2244 account = ((GaimChat*)(node))->account;
2208 } 2245 }
2209 2246
2210 if(account != NULL) {
2211 prpl = gaim_find_prpl(gaim_account_get_protocol_id(account));
2212 }
2213
2214 td->protocol = NULL;
2215 if (prpl) {
2216 prpl_info = GAIM_PLUGIN_PROTOCOL_INFO(prpl);
2217 if(prpl_info && prpl_info->list_icon) {
2218 td->protocol = prpl_info->list_icon(account, (GaimBuddy*)node);
2219 }
2220 }
2221 td->status_icon = gaim_gtk_blist_get_status_icon(node, GAIM_STATUS_ICON_LARGE); 2247 td->status_icon = gaim_gtk_blist_get_status_icon(node, GAIM_STATUS_ICON_LARGE);
2222 td->avatar = gaim_gtk_blist_get_buddy_icon(node, !full, FALSE, TRUE); 2248 td->avatar = gaim_gtk_blist_get_buddy_icon(node, !full, FALSE, TRUE);
2249 td->prpl_icon = gaim_gtk_create_prpl_icon(account, PIDGIN_PRPL_ICON_MEDIUM);
2223 tooltip_text = gaim_get_tooltip_text(node, full); 2250 tooltip_text = gaim_get_tooltip_text(node, full);
2224 td->layout = gtk_widget_create_pango_layout(gtkblist->tipwindow, NULL); 2251 td->layout = gtk_widget_create_pango_layout(gtkblist->tipwindow, NULL);
2252 td->name_layout = gtk_widget_create_pango_layout(gtkblist->tipwindow, NULL);
2253
2254 if (GAIM_BLIST_NODE_IS_BUDDY(node))
2255 tmp = g_markup_escape_text(gaim_buddy_get_name((GaimBuddy*)node), -1);
2256 else
2257 tmp = g_markup_escape_text(gaim_chat_get_name((GaimChat*)node), -1);
2258 node_name = g_strdup_printf("<span size='x-large' weight='bold'>%s</span>", tmp);
2259
2225 pango_layout_set_markup(td->layout, tooltip_text, -1); 2260 pango_layout_set_markup(td->layout, tooltip_text, -1);
2226 pango_layout_set_wrap(td->layout, PANGO_WRAP_WORD); 2261 pango_layout_set_wrap(td->layout, PANGO_WRAP_WORD);
2227 pango_layout_set_width(td->layout, 300000); 2262 pango_layout_set_width(td->layout, 300000);
2228 2263
2229 pango_layout_get_size (td->layout, &td->width, &td->height); 2264 pango_layout_get_size (td->layout, &td->width, &td->height);
2230 td->width = PANGO_PIXELS(td->width) + 12 + 32 + 6 + 12; 2265 td->width = PANGO_PIXELS(td->width);
2231 td->height = MAX(PANGO_PIXELS(td->height + 4) + 24, 56); 2266 td->height = PANGO_PIXELS(td->height);
2232 2267
2233 if(td->avatar) { 2268 pango_layout_set_markup(td->name_layout, node_name, -1);
2234 int height_with_protocol = 0; 2269 pango_layout_set_wrap(td->name_layout, PANGO_WRAP_WORD);
2235 td->avatar_width = gdk_pixbuf_get_width(td->avatar); 2270 pango_layout_set_width(td->name_layout, 300000);
2236 td->avatar_height = gdk_pixbuf_get_height(td->avatar); 2271
2237 height_with_protocol = td->avatar_height; 2272 pango_layout_get_size (td->name_layout, &td->name_width, &td->name_height);
2238 if (td->avatar_height < 50 && td->protocol != NULL) 2273 td->name_width = PANGO_PIXELS(td->name_width) + SMALL_SPACE + PRPL_SIZE;
2239 height_with_protocol += 24; 2274 td->name_height = MAX(PANGO_PIXELS(td->name_height), PRPL_SIZE + SMALL_SPACE);
2240 td->width += td->avatar_width + 8; 2275
2241 td->height = MAX(td->height, height_with_protocol + 24); 2276 if(!td->avatar) {
2242 } 2277 td->avatar = gaim_gtk_create_prpl_icon(account, PIDGIN_PRPL_ICON_LARGE);
2243 2278 td->avatar_is_prpl_icon = TRUE;
2279 }
2280 td->avatar_width = gdk_pixbuf_get_width(td->avatar);
2281 td->avatar_height = gdk_pixbuf_get_height(td->avatar);
2282
2244 g_free(tooltip_text); 2283 g_free(tooltip_text);
2245 return td; 2284 return td;
2246 } 2285 }
2247 2286
2248 static void gaim_gtk_blist_paint_tip(GtkWidget *widget, GdkEventExpose *event, GaimBlistNode *node) 2287 static void gaim_gtk_blist_paint_tip(GtkWidget *widget, GdkEventExpose *event, GaimBlistNode *node)
2260 2299
2261 max_width = 0; 2300 max_width = 0;
2262 for(l = gtkblist->tooltipdata; l; l = l->next) 2301 for(l = gtkblist->tooltipdata; l; l = l->next)
2263 { 2302 {
2264 struct tooltip_data *td = l->data; 2303 struct tooltip_data *td = l->data;
2265 max_width = MAX(max_width, td->width); 2304 max_width = MAX(max_width,
2305 TOOLTIP_BORDER + STATUS_SIZE + SMALL_SPACE +
2306 MAX(td->width, td->name_width) + SMALL_SPACE + td->avatar_width + TOOLTIP_BORDER);
2266 } 2307 }
2267 2308
2268 current_height = 12; 2309 current_height = 12;
2269 for(l = gtkblist->tooltipdata; l; l = l->next) 2310 for(l = gtkblist->tooltipdata; l; l = l->next)
2270 { 2311 {
2271 struct tooltip_data *td = l->data; 2312 struct tooltip_data *td = l->data;
2313
2272 if (td->avatar && gaim_gdk_pixbuf_is_opaque(td->avatar)) 2314 if (td->avatar && gaim_gdk_pixbuf_is_opaque(td->avatar))
2273 gtk_paint_flat_box(style, gtkblist->tipwindow->window, GTK_STATE_NORMAL, GTK_SHADOW_OUT, 2315 gtk_paint_flat_box(style, gtkblist->tipwindow->window, GTK_STATE_NORMAL, GTK_SHADOW_OUT,
2274 NULL, gtkblist->tipwindow, "tooltip", max_width - (td->avatar_width+12)-1, current_height-1,td->avatar_width+2, td->avatar_height+2); 2316 NULL, gtkblist->tipwindow, "tooltip",
2317 max_width - (td->avatar_width+ TOOLTIP_BORDER)-1,
2318 current_height-1,td->avatar_width+2, td->avatar_height+2);
2275 2319
2276 2320
2277 #if GTK_CHECK_VERSION(2,2,0) 2321 #if GTK_CHECK_VERSION(2,2,0)
2278 gdk_draw_pixbuf(GDK_DRAWABLE(gtkblist->tipwindow->window), NULL, td->status_icon, 2322 gdk_draw_pixbuf(GDK_DRAWABLE(gtkblist->tipwindow->window), NULL, td->status_icon,
2279 0, 0, 12, current_height, -1 , -1, GDK_RGB_DITHER_NONE, 0, 0); 2323 0, 0, TOOLTIP_BORDER, current_height, -1 , -1, GDK_RGB_DITHER_NONE, 0, 0);
2280 if(td->avatar) 2324 if(td->avatar)
2281 gdk_draw_pixbuf(GDK_DRAWABLE(gtkblist->tipwindow->window), NULL, 2325 gdk_draw_pixbuf(GDK_DRAWABLE(gtkblist->tipwindow->window), NULL,
2282 td->avatar, 0, 0, max_width - (td->avatar_width + 12), current_height, -1 , -1, GDK_RGB_DITHER_NONE, 0, 0); 2326 td->avatar, 0, 0, max_width - (td->avatar_width + TOOLTIP_BORDER),
2283 2327 current_height, -1 , -1, GDK_RGB_DITHER_NONE, 0, 0);
2328 if (!td->avatar_is_prpl_icon)
2329 gdk_draw_pixbuf(GDK_DRAWABLE(gtkblist->tipwindow->window), NULL, td->prpl_icon,
2330 0, 0,
2331 TOOLTIP_BORDER + STATUS_SIZE + SMALL_SPACE + td->name_width - PRPL_SIZE,
2332 current_height + ((td->name_height / 2) - (PRPL_SIZE / 2)),
2333 -1 , -1, GDK_RGB_DITHER_NONE, 0, 0);
2334
2284 #else 2335 #else
2285 gdk_pixbuf_render_to_drawable(td->status_icon, GDK_DRAWABLE(gtkblist->tipwindow->window), NULL, 0, 0, 12, current_height, -1, -1, GDK_RGB_DITHER_NONE, 0, 0); 2336 gdk_pixbuf_render_to_drawable(td->status_icon, GDK_DRAWABLE(gtkblist->tipwindow->window), NULL, 0, 0, 12, current_height, -1, -1, GDK_RGB_DITHER_NONE, 0, 0);
2286 if(td->avatar) 2337 if(td->avatar)
2287 gdk_pixbuf_render_to_drawable(td->avatar, 2338 gdk_pixbuf_render_to_drawable(td->avatar,
2288 GDK_DRAWABLE(gtkblist->tipwindow->window), NULL, 0, 0, 2339 GDK_DRAWABLE(gtkblist->tipwindow->window), NULL, 0, 0,
2289 max_width - (td->avatar_width + 12), 2340 max_width - (td->avatar_width + 12),
2290 current_height, -1, -1, GDK_RGB_DITHER_NONE, 0, 0); 2341 current_height, -1, -1, GDK_RGB_DITHER_NONE, 0, 0);
2291 #endif 2342 #endif
2292 2343
2293 gtk_paint_layout (style, gtkblist->tipwindow->window, GTK_STATE_NORMAL, FALSE, 2344 gtk_paint_layout (style, gtkblist->tipwindow->window, GTK_STATE_NORMAL, FALSE,
2294 NULL, gtkblist->tipwindow, "tooltip", 44 + 6, current_height, td->layout); 2345 NULL, gtkblist->tipwindow, "tooltip",
2295 2346 TOOLTIP_BORDER + STATUS_SIZE + SMALL_SPACE, current_height, td->name_layout);
2296 current_height += td->height; 2347 current_height += td->name_height;
2297 2348
2298 if(l->next) 2349 gtk_paint_layout (style, gtkblist->tipwindow->window, GTK_STATE_NORMAL, FALSE,
2299 gtk_paint_hline(style, gtkblist->tipwindow->window, GTK_STATE_NORMAL, NULL, NULL, NULL, 12, max_width - 12, current_height-6); 2350 NULL, gtkblist->tipwindow, "tooltip",
2351 TOOLTIP_BORDER + STATUS_SIZE + SMALL_SPACE, current_height, td->layout);
2352
2353 current_height += td->height + TOOLTIP_BORDER;
2300 2354
2301 } 2355 }
2302 } 2356 }
2303 2357
2304 2358
2309 2363
2310 if(td->avatar) 2364 if(td->avatar)
2311 g_object_unref(td->avatar); 2365 g_object_unref(td->avatar);
2312 if(td->status_icon) 2366 if(td->status_icon)
2313 g_object_unref(td->status_icon); 2367 g_object_unref(td->status_icon);
2368 if(td->prpl_icon)
2369 g_object_unref(td->prpl_icon);
2314 g_object_unref(td->layout); 2370 g_object_unref(td->layout);
2371 g_object_unref(td->name_layout);
2315 g_free(td); 2372 g_free(td);
2316 gtkblist->tooltipdata = g_list_delete_link(gtkblist->tooltipdata, gtkblist->tooltipdata); 2373 gtkblist->tooltipdata = g_list_delete_link(gtkblist->tooltipdata, gtkblist->tooltipdata);
2317 } 2374 }
2318 2375
2319 if (gtkblist->tipwindow == NULL) 2376 if (gtkblist->tipwindow == NULL)
2414 gtkblist->tipwindow = gtk_window_new(GTK_WINDOW_POPUP); 2471 gtkblist->tipwindow = gtk_window_new(GTK_WINDOW_POPUP);
2415 2472
2416 if(GAIM_BLIST_NODE_IS_CHAT(node) || GAIM_BLIST_NODE_IS_BUDDY(node)) { 2473 if(GAIM_BLIST_NODE_IS_CHAT(node) || GAIM_BLIST_NODE_IS_BUDDY(node)) {
2417 struct tooltip_data *td = create_tip_for_node(node, TRUE); 2474 struct tooltip_data *td = create_tip_for_node(node, TRUE);
2418 gtkblist->tooltipdata = g_list_append(gtkblist->tooltipdata, td); 2475 gtkblist->tooltipdata = g_list_append(gtkblist->tooltipdata, td);
2419 w = td->width; 2476 w = TOOLTIP_BORDER + STATUS_SIZE + SMALL_SPACE +
2420 h = td->height; 2477 MAX(td->width, td->name_width) + SMALL_SPACE + td->avatar_width + TOOLTIP_BORDER;
2478 h = TOOLTIP_BORDER + MAX(td->height + td->name_height, MAX(STATUS_SIZE, td->avatar_height))
2479 + TOOLTIP_BORDER;
2421 } else if(GAIM_BLIST_NODE_IS_CONTACT(node)) { 2480 } else if(GAIM_BLIST_NODE_IS_CONTACT(node)) {
2422 GaimBlistNode *child; 2481 GaimBlistNode *child;
2423 GaimBuddy *b = gaim_contact_get_priority_buddy((GaimContact *)node); 2482 GaimBuddy *b = gaim_contact_get_priority_buddy((GaimContact *)node);
2424 w = h = 0; 2483 w = h = 0;
2425 for(child = node->child; child; child = child->next) 2484 for(child = node->child; child; child = child->next)
2429 if (b == (GaimBuddy *)child) { 2488 if (b == (GaimBuddy *)child) {
2430 gtkblist->tooltipdata = g_list_prepend(gtkblist->tooltipdata, td); 2489 gtkblist->tooltipdata = g_list_prepend(gtkblist->tooltipdata, td);
2431 } else { 2490 } else {
2432 gtkblist->tooltipdata = g_list_append(gtkblist->tooltipdata, td); 2491 gtkblist->tooltipdata = g_list_append(gtkblist->tooltipdata, td);
2433 } 2492 }
2434 w = MAX(w, td->width); 2493 w = MAX(w, TOOLTIP_BORDER + STATUS_SIZE + SMALL_SPACE +
2435 h += td->height; 2494 MAX(td->width, td->name_width) + SMALL_SPACE +
2495 td->avatar_width + TOOLTIP_BORDER);
2496 h += MAX(TOOLTIP_BORDER + MAX(STATUS_SIZE,td->avatar_height) + TOOLTIP_BORDER,
2497 TOOLTIP_BORDER + td->height + td->name_height + TOOLTIP_BORDER);
2436 } 2498 }
2437 } 2499 }
2438 } else { 2500 } else {
2439 gtk_widget_destroy(gtkblist->tipwindow); 2501 gtk_widget_destroy(gtkblist->tipwindow);
2440 gtkblist->tipwindow = NULL; 2502 gtkblist->tipwindow = NULL;
2681 2743
2682 chat = (GaimChat *)node; 2744 chat = (GaimChat *)node;
2683 prpl = gaim_find_prpl(gaim_account_get_protocol_id(chat->account)); 2745 prpl = gaim_find_prpl(gaim_account_get_protocol_id(chat->account));
2684 prpl_info = GAIM_PLUGIN_PROTOCOL_INFO(prpl); 2746 prpl_info = GAIM_PLUGIN_PROTOCOL_INFO(prpl);
2685 2747
2686 tmp = g_markup_escape_text(gaim_chat_get_name(chat), -1);
2687 g_string_append_printf(str, "<span size='larger' weight='bold'>%s</span>", tmp);
2688 g_free(tmp);
2689
2690 if (g_list_length(gaim_connections_get_all()) > 1) 2748 if (g_list_length(gaim_connections_get_all()) > 1)
2691 { 2749 {
2692 tmp = g_markup_escape_text(chat->account->username, -1); 2750 tmp = g_markup_escape_text(chat->account->username, -1);
2693 g_string_append_printf(str, _("\n<b>Account:</b> %s"), tmp); 2751 g_string_append_printf(str, _("\n<b>Account:</b> %s"), tmp);
2694 g_free(tmp); 2752 g_free(tmp);
2747 2805
2748 prpl = gaim_find_prpl(gaim_account_get_protocol_id(b->account)); 2806 prpl = gaim_find_prpl(gaim_account_get_protocol_id(b->account));
2749 prpl_info = GAIM_PLUGIN_PROTOCOL_INFO(prpl); 2807 prpl_info = GAIM_PLUGIN_PROTOCOL_INFO(prpl);
2750 2808
2751 presence = gaim_buddy_get_presence(b); 2809 presence = gaim_buddy_get_presence(b);
2752
2753 /* Buddy Name */
2754 tmp = g_markup_escape_text(gaim_buddy_get_name(b), -1);
2755 g_string_append_printf(str, "<span size='larger' weight='bold'>%s</span>\n", tmp);
2756 g_free(tmp);
2757
2758 user_info = gaim_notify_user_info_new(); 2810 user_info = gaim_notify_user_info_new();
2759 2811
2760 /* Account */ 2812 /* Account */
2761 if (full && g_list_length(gaim_connections_get_all()) > 1) 2813 if (full && g_list_length(gaim_connections_get_all()) > 1)
2762 { 2814 {