changeset 20217:d4e250c3cd44

applied changes from 4bb1d6cbfe69a2e7782336a7e6e93e438a8bdbfc through 3fcc47961d378fa0cd4eeb00dc6923b16a3a4151
author Richard Laager <rlaager@wiktel.com>
date Fri, 28 Sep 2007 15:45:06 +0000
parents a252ac635978
children 99ceb1329a5b
files libpurple/notify.c pidgin/gtkblist.c pidgin/gtknotify.c
diffstat 3 files changed, 59 insertions(+), 28 deletions(-) [+]
line wrap: on
line diff
--- a/libpurple/notify.c	Fri Sep 28 15:44:45 2007 +0000
+++ b/libpurple/notify.c	Fri Sep 28 15:45:06 2007 +0000
@@ -149,8 +149,6 @@
 {
 	PurpleNotifyUiOps *ops;
 
-	g_return_val_if_fail(count != 0, NULL);
-
 	if (count == 1) {
 		return purple_notify_email(handle,
 								 (subjects == NULL ? NULL : *subjects),
@@ -505,7 +503,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);
 }
@@ -567,7 +565,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)
--- a/pidgin/gtkblist.c	Fri Sep 28 15:44:45 2007 +0000
+++ b/pidgin/gtkblist.c	Fri Sep 28 15:45:06 2007 +0000
@@ -2906,7 +2906,7 @@
 	{ N_("/_Help"), NULL, NULL, 0, "<Branch>", NULL },
 	{ N_("/Help/Online _Help"), "F1", gtk_blist_show_onlinehelp_cb, 0, "<StockItem>", GTK_STOCK_HELP },
 	{ N_("/Help/_Debug Window"), NULL, toggle_debug, 0, "<Item>", NULL },
-#if GTK_CHECK_VERSION(2,6,0)	
+#if GTK_CHECK_VERSION(2,6,0)
 	{ N_("/Help/_About"), NULL, pidgin_dialogs_about, 0,  "<StockItem>", GTK_STOCK_ABOUT },
 #else
 	{ N_("/Help/_About"), NULL, pidgin_dialogs_about, 0,  "<Item>", NULL },
@@ -4537,7 +4537,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,
@@ -4978,7 +4978,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);
@@ -6018,9 +6018,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 =
--- a/pidgin/gtknotify.c	Fri Sep 28 15:44:45 2007 +0000
+++ b/pidgin/gtknotify.c	Fri Sep 28 15:45:06 2007 +0000
@@ -412,7 +412,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;
@@ -421,20 +421,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));
 		}
 	}
 
@@ -471,9 +481,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--) {
@@ -511,19 +525,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)) {
@@ -535,7 +564,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;