comparison src/gtkconv.c @ 12468:6faefbebcd24

[gaim-migrate @ 14778] SF Patch #1372898 from charkins "This patch updates the unseen conversation api in gtkconv to ensure consistancy and avoid code duplication. The ...first_unseen() function is renamed and expanded to return a list of conversations that match the specified criteria. A max_count parameter is used to allow this to short circuit early (using 1 gives old behavior). An additional flag was added to allow this function to only consider hidden conversations (used by the buddy list). The blist is currently inconsistant in which conversations it loops over for showing the menu tray icon, creating the tooltip and the unseen menu. This patch fixes that. The ...find_unseen_list() now handles contact-aware conversations correctly as well (based on sadrul's patches in #1362579 which are obsoleted by this patch). I also included the fix from #1362579 which increments unseen_count only when state>=UNSEEN_TEXT." committer: Tailor Script <tailor@pidgin.im>
author Richard Laager <rlaager@wiktel.com>
date Mon, 12 Dec 2005 18:59:29 +0000
parents b1717befbb26
children f4efe0c0de88
comparison
equal deleted inserted replaced
12467:1b57012eec7b 12468:6faefbebcd24
2414 gaim_gtk_conv_window_switch_gtkconv(gtkconv->win, gtkconv); 2414 gaim_gtk_conv_window_switch_gtkconv(gtkconv->win, gtkconv);
2415 gaim_gtk_conv_window_raise(gtkconv->win); 2415 gaim_gtk_conv_window_raise(gtkconv->win);
2416 gtk_window_present(GTK_WINDOW(gtkconv->win->window)); 2416 gtk_window_present(GTK_WINDOW(gtkconv->win->window));
2417 } 2417 }
2418 2418
2419 GaimConversation * 2419 GList *
2420 gaim_gtk_conversations_get_first_unseen(GaimConversationType type, 2420 gaim_gtk_conversations_find_unseen_list(GaimConversationType type,
2421 GaimUnseenState min_state) 2421 GaimUnseenState min_state,
2422 gboolean hidden_only,
2423 guint max_count)
2422 { 2424 {
2423 GList *l; 2425 GList *l;
2424 2426 GList *r = NULL;
2425 if(type==GAIM_CONV_TYPE_IM) { 2427 guint c = 0;
2428
2429 if (type==GAIM_CONV_TYPE_IM) {
2426 l = gaim_get_ims(); 2430 l = gaim_get_ims();
2427 } else if(type==GAIM_CONV_TYPE_CHAT) { 2431 } else if (type==GAIM_CONV_TYPE_CHAT) {
2428 l = gaim_get_chats(); 2432 l = gaim_get_chats();
2429 } else { 2433 } else {
2430 l = gaim_get_conversations(); 2434 l = gaim_get_conversations();
2431 } 2435 }
2432 2436
2433 for(; l!=NULL; l=l->next) { 2437 for (; l!=NULL && (max_count==0 || c < max_count); l = l->next) {
2434 GaimConversation *conv = (GaimConversation*)l->data; 2438 GaimConversation *conv = (GaimConversation*)l->data;
2435 if (GAIM_GTK_CONVERSATION(conv)->unseen_state >= min_state) 2439 GaimGtkConversation *gtkconv = GAIM_GTK_CONVERSATION(conv);
2436 return conv; 2440
2437 } 2441 if(gtkconv->active_conv != conv)
2438 2442 continue;
2439 return NULL; 2443
2444 if (gtkconv->unseen_state >= min_state && (!hidden_only ||
2445 (hidden_only && gtkconv->win==hidden_convwin))) {
2446
2447 r = g_list_prepend(r, conv);
2448 c++;
2449 }
2450 }
2451
2452 return r;
2440 } 2453 }
2441 2454
2442 static void 2455 static void
2443 unseen_conv_menu_cb(GtkMenuItem *item, GaimConversation *conv) 2456 unseen_conv_menu_cb(GtkMenuItem *item, GaimConversation *conv)
2444 { 2457 {
2445 g_return_if_fail(conv != NULL); 2458 g_return_if_fail(conv != NULL);
2446 gaim_gtkconv_present_conversation(conv); 2459 gaim_gtkconv_present_conversation(conv);
2447 } 2460 }
2448 2461
2449 guint 2462 guint
2450 gaim_gtk_conversations_fill_unseen_menu(GtkWidget *menu, 2463 gaim_gtk_conversations_fill_menu(GtkWidget *menu, GList *convs)
2451 GaimConversationType type,
2452 GaimUnseenState min_state)
2453 { 2464 {
2454 GList *l; 2465 GList *l;
2455 guint ret = 0; 2466 guint ret=0;
2456 2467
2457 g_return_val_if_fail(menu != NULL, 0); 2468 g_return_val_if_fail(menu != NULL, 0);
2458 2469 g_return_val_if_fail(convs != NULL, 0);
2459 if (type == GAIM_CONV_TYPE_IM) { 2470
2460 l = gaim_get_ims(); 2471 for (l = convs; l != NULL ; l = l->next) {
2461 } else if (type == GAIM_CONV_TYPE_CHAT) {
2462 l = gaim_get_chats();
2463 } else {
2464 l = gaim_get_conversations();
2465 }
2466
2467 for (; l != NULL ; l = l->next) {
2468 GaimConversation *conv = (GaimConversation*)l->data; 2472 GaimConversation *conv = (GaimConversation*)l->data;
2469 GaimGtkConversation *gtkconv = GAIM_GTK_CONVERSATION(conv); 2473 GaimGtkConversation *gtkconv = GAIM_GTK_CONVERSATION(conv);
2470 2474
2471 if (gtkconv->unseen_state >= min_state && gtkconv->win == hidden_convwin) { 2475 GtkWidget *icon = gtk_image_new();
2472 GtkWidget *icon = gtk_image_new(); 2476 GdkPixbuf *pbuf = gaim_gtkconv_get_tab_icon(conv, TRUE);
2473 GdkPixbuf *pbuf = gaim_gtkconv_get_tab_icon(conv, TRUE); 2477 GtkWidget *item;
2474 GtkWidget *item; 2478 gchar *text = g_strdup_printf("%s (%d)",
2475 gchar *text = g_strdup_printf("%s (%d)", 2479 gtk_label_get_text(GTK_LABEL(gtkconv->tab_label)),
2476 gtk_label_get_text(GTK_LABEL(gtkconv->tab_label)), 2480 gtkconv->unseen_count);
2477 gtkconv->unseen_count); 2481
2478 2482 gtk_image_set_from_pixbuf(GTK_IMAGE(icon), pbuf);
2479 gtk_image_set_from_pixbuf(GTK_IMAGE(icon), pbuf); 2483 g_object_unref(pbuf);
2480 g_object_unref(pbuf); 2484
2481 2485 item = gtk_image_menu_item_new_with_label(text);
2482 item = gtk_image_menu_item_new_with_label(text); 2486 gtk_image_menu_item_set_image(GTK_IMAGE_MENU_ITEM(item), icon);
2483 gtk_image_menu_item_set_image(GTK_IMAGE_MENU_ITEM(item), icon); 2487 g_signal_connect(G_OBJECT(item), "activate", G_CALLBACK(unseen_conv_menu_cb), conv);
2484 g_signal_connect(G_OBJECT(item), "activate", G_CALLBACK(unseen_conv_menu_cb), conv); 2488 gtk_menu_shell_append(GTK_MENU_SHELL(menu), item);
2485 gtk_menu_shell_append(GTK_MENU_SHELL(menu), item); 2489 g_free(text);
2486 g_free(text); 2490 ret++;
2487 ret++;
2488 }
2489 } 2491 }
2490 2492
2491 return ret; 2493 return ret;
2492 } 2494 }
2493 2495
6194 gtkconv->unseen_count = 0; 6196 gtkconv->unseen_count = 0;
6195 gtkconv->unseen_state = GAIM_UNSEEN_NONE; 6197 gtkconv->unseen_state = GAIM_UNSEEN_NONE;
6196 } 6198 }
6197 else 6199 else
6198 { 6200 {
6199 gtkconv->unseen_count++; 6201 if (state >= GAIM_UNSEEN_TEXT)
6202 gtkconv->unseen_count++;
6200 6203
6201 if (state > gtkconv->unseen_state) 6204 if (state > gtkconv->unseen_state)
6202 gtkconv->unseen_state = state; 6205 gtkconv->unseen_state = state;
6203 } 6206 }
6204 6207