# HG changeset patch # User Daniel Atallah # Date 1190336021 0 # Node ID 04590d9db8b798467c8f409bb3dd4321387ea607 # Parent a37166aa49cabac76dc628d4672424df09417cfb Clear out the mail notifications for an account when we receive a notification of 0 emails. diff -r a37166aa49ca -r 04590d9db8b7 libpurple/notify.c --- a/libpurple/notify.c Fri Sep 21 00:32:33 2007 +0000 +++ b/libpurple/notify.c Fri Sep 21 00:53:41 2007 +0000 @@ -150,8 +150,6 @@ { PurpleNotifyUiOps *ops; - g_return_val_if_fail(count != 0, NULL); - if (count == 1) { return purple_notify_email(handle, (subjects == NULL ? NULL : *subjects), @@ -506,7 +504,7 @@ g_return_if_fail(user_info_entry != NULL); g_free(user_info_entry->label); - g_free(user_info_entry->value); + g_free(user_info_entry->value); PURPLE_DBUS_UNREGISTER_POINTER(user_info_entry); g_free(user_info_entry); } @@ -568,7 +566,7 @@ if (user_info_entry->label && user_info_entry->value) g_string_append(text, ": "); if (user_info_entry->value) - g_string_append(text, user_info_entry->value); + g_string_append(text, user_info_entry->value); /* Display a section break as a horizontal line */ if (user_info_entry->type == PURPLE_NOTIFY_USER_INFO_ENTRY_SECTION_BREAK) diff -r a37166aa49ca -r 04590d9db8b7 pidgin/gtkblist.c --- a/pidgin/gtkblist.c Fri Sep 21 00:32:33 2007 +0000 +++ b/pidgin/gtkblist.c Fri Sep 21 00:53:41 2007 +0000 @@ -3105,7 +3105,7 @@ { N_("/_Help"), NULL, NULL, 0, "", NULL }, { N_("/Help/Online _Help"), "F1", gtk_blist_show_onlinehelp_cb, 0, "", GTK_STOCK_HELP }, { N_("/Help/_Debug Window"), NULL, toggle_debug, 0, "", NULL }, -#if GTK_CHECK_VERSION(2,6,0) +#if GTK_CHECK_VERSION(2,6,0) { N_("/Help/_About"), NULL, pidgin_dialogs_about, 0, "", GTK_STOCK_ABOUT }, #else { N_("/Help/_About"), NULL, pidgin_dialogs_about, 0, "", NULL }, @@ -4820,7 +4820,7 @@ "visible", EMBLEM_VISIBLE_COLUMN, NULL); rend = gtk_cell_renderer_pixbuf_new(); - gtk_tree_view_column_pack_start(column, rend, FALSE); + gtk_tree_view_column_pack_start(column, rend, FALSE); gtk_tree_view_column_set_attributes(column, rend, "pixbuf", PROTOCOL_ICON_COLUMN, "visible", PROTOCOL_ICON_VISIBLE_COLUMN, @@ -5265,7 +5265,7 @@ group = (PurpleGroup*)gnode; textcolor = gtkblist->treeview->style->fg[GTK_STATE_ACTIVE]; - + if (gtk_tree_selection_get_selected(gtk_tree_view_get_selection(GTK_TREE_VIEW(gtkblist->treeview)), NULL, &iter)) { gtk_tree_model_get(GTK_TREE_MODEL(gtkblist->treemodel), &iter, NODE_COLUMN, &selected_node, -1); @@ -6319,9 +6319,13 @@ gtkblist->headline_callback = callback; gtkblist->headline_data = user_data; gtkblist->headline_destroy = destroy; - if (!GTK_WIDGET_HAS_FOCUS(gtkblist->window)) - pidgin_set_urgent(GTK_WINDOW(gtkblist->window), TRUE); - gtk_widget_show_all(gtkblist->headline_hbox); + if (text != NULL || pixbuf != NULL) { + if (!GTK_WIDGET_HAS_FOCUS(gtkblist->window)) + pidgin_set_urgent(GTK_WINDOW(gtkblist->window), TRUE); + gtk_widget_show_all(gtkblist->headline_hbox); + } else { + gtk_widget_hide(gtkblist->headline_hbox); + } } static PurpleBlistUiOps blist_ui_ops = diff -r a37166aa49ca -r 04590d9db8b7 pidgin/gtknotify.c --- a/pidgin/gtknotify.c Fri Sep 21 00:32:33 2007 +0000 +++ b/pidgin/gtknotify.c Fri Sep 21 00:53:41 2007 +0000 @@ -413,7 +413,7 @@ * count > 0 mean non-detailed. */ static void * -pidgin_notify_add_mail(GtkTreeStore *treemodel, PurpleAccount *account, char *notification, const char *url, int count) +pidgin_notify_add_mail(GtkTreeStore *treemodel, PurpleAccount *account, char *notification, const char *url, int count, gboolean clear) { PidginNotifyMailData *data = NULL; GtkTreeIter iter; @@ -422,20 +422,30 @@ icon = pidgin_create_prpl_icon(account, PIDGIN_PRPL_ICON_MEDIUM); - if (count > 0) { + if (count > 0 || clear) { /* Allow only one non-detailed email notification for each account */ if (gtk_tree_model_get_iter_first(GTK_TREE_MODEL(treemodel), &iter)) { + gboolean advanced; do { + advanced = FALSE; gtk_tree_model_get(GTK_TREE_MODEL(treemodel), &iter, PIDGIN_MAIL_DATA, &data, -1); - if (data->account == account && data->count > 0) { - new_n = FALSE; - g_free(data->url); - data->url = NULL; - mail_dialog->total_count -= data->count; - break; + if (data->account == account) { + if (clear) { + advanced = gtk_tree_store_remove(treemodel, &iter); + purple_notify_close(PURPLE_NOTIFY_EMAILS, data); + /* We're completely done if we've processed all entries */ + if (!advanced) + return NULL; + } else if (data->count > 0) { + new_n = FALSE; + g_free(data->url); + data->url = NULL; + mail_dialog->total_count -= data->count; + break; + } } - } while (gtk_tree_model_iter_next(GTK_TREE_MODEL(treemodel), &iter)); + } while (advanced || gtk_tree_model_iter_next(GTK_TREE_MODEL(treemodel), &iter)); } } @@ -472,9 +482,13 @@ PurpleAccount *account; PidginNotifyMailData *data = NULL; + /* Don't bother updating if there aren't new emails and we don't have any displayed currently */ + if (count == 0 && mail_dialog == NULL) + return NULL; + account = purple_connection_get_account(gc); dialog = pidgin_get_mail_dialog(); /* This creates mail_dialog if necessary */ - + mail_dialog->total_count += count; if (detailed) { while (count--) { @@ -512,19 +526,34 @@ g_free(from_text); g_free(subject_text); - data = pidgin_notify_add_mail(mail_dialog->treemodel, account, notification, urls ? *urls : NULL, 0); + data = pidgin_notify_add_mail(mail_dialog->treemodel, account, notification, urls ? *urls : NULL, 0, FALSE); g_free(notification); if (urls != NULL) urls++; } } else { - notification = g_strdup_printf(ngettext("%s has %d new message.", - "%s has %d new messages.", - (int)count), - *tos, (int)count); - data = pidgin_notify_add_mail(mail_dialog->treemodel, account, notification, urls ? *urls : NULL, count); - g_free(notification); + if (count > 0) { + notification = g_strdup_printf(ngettext("%s has %d new message.", + "%s has %d new messages.", + (int)count), + *tos, (int)count); + data = pidgin_notify_add_mail(mail_dialog->treemodel, account, notification, urls ? *urls : NULL, count, FALSE); + g_free(notification); + } else { + GtkTreeIter iter; + + /* Clear out all mails for the account */ + pidgin_notify_add_mail(mail_dialog->treemodel, account, NULL, NULL, 0, TRUE); + + if (!gtk_tree_model_get_iter_first(GTK_TREE_MODEL(mail_dialog->treemodel), &iter)) { + /* There is no API to clear the headline specifically */ + /* This will trigger reset_mail_dialog() */ + pidgin_blist_set_headline(NULL, NULL, NULL, NULL, NULL); + } + + return NULL; + } } if (!GTK_WIDGET_VISIBLE(dialog)) { @@ -536,7 +565,7 @@ mail_dialog->in_use = TRUE; /* So that _set_headline doesn't accidentally remove the notifications when replacing an old notification. */ - pidgin_blist_set_headline(label_text, + pidgin_blist_set_headline(label_text, pixbuf, G_CALLBACK(gtk_widget_show_all), dialog, (GDestroyNotify)reset_mail_dialog); mail_dialog->in_use = FALSE;