comparison src/gtkblist.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 31e4eb57cc86
children d180bb2953e7
comparison
equal deleted inserted replaced
12467:1b57012eec7b 12468:6faefbebcd24
3165 3165
3166 static void 3166 static void
3167 unseen_conv_menu() 3167 unseen_conv_menu()
3168 { 3168 {
3169 static GtkWidget *menu = NULL; 3169 static GtkWidget *menu = NULL;
3170 GList *convs = NULL;
3170 3171
3171 if (menu) 3172 if (menu)
3172 gtk_widget_destroy(menu); 3173 gtk_widget_destroy(menu);
3173 3174
3174 menu = gtk_menu_new(); 3175 menu = gtk_menu_new();
3175 if (!gaim_gtk_conversations_fill_unseen_menu(menu, GAIM_CONV_TYPE_IM, GAIM_UNSEEN_TEXT)) { 3176
3177 convs = gaim_gtk_conversations_find_unseen_list(GAIM_CONV_TYPE_IM, GAIM_UNSEEN_TEXT, TRUE, 0);
3178 if (!convs) {
3176 /* no conversations added, don't show the menu */ 3179 /* no conversations added, don't show the menu */
3177 gtk_widget_destroy(menu); 3180 gtk_widget_destroy(menu);
3178 return; 3181 return;
3179 } 3182 }
3183 gaim_gtk_conversations_fill_menu(menu, convs);
3184 g_list_free(convs);
3180 gtk_widget_show_all(menu); 3185 gtk_widget_show_all(menu);
3181 gtk_menu_popup(GTK_MENU(menu), NULL, NULL, NULL, NULL, 3, 3186 gtk_menu_popup(GTK_MENU(menu), NULL, NULL, NULL, NULL, 3,
3182 gtk_get_current_event_time()); 3187 gtk_get_current_event_time());
3183 } 3188 }
3184 3189
3185 static gboolean 3190 static gboolean
3186 menutray_press_cb(GtkWidget *widget, GdkEventButton *event) 3191 menutray_press_cb(GtkWidget *widget, GdkEventButton *event)
3187 { 3192 {
3188 GaimConversation *conv; 3193 GList *convs;
3189 3194
3190 switch (event->button) { 3195 switch (event->button) {
3191 case 1: 3196 case 1:
3192 conv = gaim_gtk_conversations_get_first_unseen(GAIM_CONV_TYPE_IM, GAIM_UNSEEN_TEXT); 3197 convs = gaim_gtk_conversations_find_unseen_list(GAIM_CONV_TYPE_IM,
3193 if (conv != NULL) 3198 GAIM_UNSEEN_TEXT, TRUE, 1);
3194 gaim_gtkconv_present_conversation(conv); 3199 if (convs) {
3200 gaim_gtkconv_present_conversation((GaimConversation*)convs->data);
3201 g_list_free(convs);
3202 }
3195 break; 3203 break;
3196 case 3: 3204 case 3:
3197 unseen_conv_menu(); 3205 unseen_conv_menu();
3198 break; 3206 break;
3199 } 3207 }
3202 3210
3203 static void 3211 static void
3204 conversation_updated_cb(GaimConversation *conv, GaimConvUpdateType type, 3212 conversation_updated_cb(GaimConversation *conv, GaimConvUpdateType type,
3205 GaimGtkBuddyList *gtkblist) 3213 GaimGtkBuddyList *gtkblist)
3206 { 3214 {
3207 GtkWidget *img = NULL; 3215 GList *convs = NULL;
3208 GString *tooltip_text = NULL; 3216 GList *l = NULL;
3209 3217
3210 if (type != GAIM_CONV_UPDATE_UNSEEN) 3218 if (type != GAIM_CONV_UPDATE_UNSEEN)
3211 return; 3219 return;
3212 3220
3213 if (gtkblist->menutrayicon) { 3221 if (gtkblist->menutrayicon) {
3214 gtk_widget_destroy(gtkblist->menutrayicon); 3222 gtk_widget_destroy(gtkblist->menutrayicon);
3215 gtkblist->menutrayicon = NULL; 3223 gtkblist->menutrayicon = NULL;
3216 } 3224 }
3217 3225
3218 if (gaim_gtk_conversations_get_first_unseen(GAIM_CONV_TYPE_IM, GAIM_UNSEEN_TEXT)) { 3226 convs = gaim_gtk_conversations_find_unseen_list(GAIM_CONV_TYPE_IM, GAIM_UNSEEN_TEXT, TRUE, 0);
3219 GList *convs = gaim_get_ims(); 3227 if (convs) {
3228 GtkWidget *img = NULL;
3229 GString *tooltip_text = NULL;
3230
3220 tooltip_text = g_string_new(""); 3231 tooltip_text = g_string_new("");
3221 while (convs) { 3232 l = convs;
3222 if(GAIM_IS_GTK_CONVERSATION(convs->data)) { 3233 while (l != NULL) {
3223 GaimGtkConversation *gtkconv = GAIM_GTK_CONVERSATION((GaimConversation *)convs->data); 3234 if (GAIM_IS_GTK_CONVERSATION(l->data)) {
3224 3235 GaimGtkConversation *gtkconv = GAIM_GTK_CONVERSATION((GaimConversation *)l->data);
3225 if (gtkconv->unseen_state >= GAIM_UNSEEN_TEXT && gaim_gtkconv_is_hidden(gtkconv)) { 3236
3226 g_string_append_printf(tooltip_text, 3237 g_string_append_printf(tooltip_text,
3227 ngettext("%d unread message from %s\n", "%d unread messages from %s\n", gtkconv->unseen_count), 3238 ngettext("%d unread message from %s\n", "%d unread messages from %s\n", gtkconv->unseen_count),
3228 gtkconv->unseen_count, 3239 gtkconv->unseen_count,
3229 gtk_label_get_text(GTK_LABEL(gtkconv->tab_label))); 3240 gtk_label_get_text(GTK_LABEL(gtkconv->tab_label)));
3230 }
3231 } 3241 }
3232 convs = convs->next; 3242 l = l->next;
3233 } 3243 }
3234 if(tooltip_text->len > 0) { 3244 if(tooltip_text->len > 0) {
3235 /* get rid of the last newline */ 3245 /* get rid of the last newline */
3236 tooltip_text = g_string_truncate(tooltip_text, tooltip_text->len -1); 3246 tooltip_text = g_string_truncate(tooltip_text, tooltip_text->len -1);
3237 img = gtk_image_new_from_stock(GAIM_STOCK_PENDING, GTK_ICON_SIZE_MENU); 3247 img = gtk_image_new_from_stock(GAIM_STOCK_PENDING, GTK_ICON_SIZE_MENU);
3243 g_signal_connect(G_OBJECT(gtkblist->menutrayicon), "button-press-event", G_CALLBACK(menutray_press_cb), NULL); 3253 g_signal_connect(G_OBJECT(gtkblist->menutrayicon), "button-press-event", G_CALLBACK(menutray_press_cb), NULL);
3244 3254
3245 gaim_gtk_menu_tray_append(GAIM_GTK_MENU_TRAY(gtkblist->menutray), gtkblist->menutrayicon, tooltip_text->str); 3255 gaim_gtk_menu_tray_append(GAIM_GTK_MENU_TRAY(gtkblist->menutray), gtkblist->menutrayicon, tooltip_text->str);
3246 } 3256 }
3247 g_string_free(tooltip_text, TRUE); 3257 g_string_free(tooltip_text, TRUE);
3258 g_list_free(convs);
3248 } 3259 }
3249 } 3260 }
3250 3261
3251 static void 3262 static void
3252 conversation_deleting_cb(GaimConversation *conv, GaimGtkBuddyList *gtkblist) 3263 conversation_deleting_cb(GaimConversation *conv, GaimGtkBuddyList *gtkblist)