summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Atallah <datallah@pidgin.im>2007-09-21 00:53:41 +0000
committerDaniel Atallah <datallah@pidgin.im>2007-09-21 00:53:41 +0000
commitf46b6da31156b1b915b004fbd7108b10fe700b74 (patch)
tree8d551aa60e2b7cbb3f38fab171bea135926f8e61
parent3650f2a01283e059e3ced138c01219b2858e9c8c (diff)
downloadpidgin-f46b6da31156b1b915b004fbd7108b10fe700b74.tar.gz
Clear out the mail notifications for an account when we receive a notification of 0 emails.
-rw-r--r--libpurple/notify.c6
-rw-r--r--pidgin/gtkblist.c16
-rw-r--r--pidgin/gtknotify.c65
3 files changed, 59 insertions, 28 deletions
diff --git a/libpurple/notify.c b/libpurple/notify.c
index 7acc5856af..1bf9d72632 100644
--- a/libpurple/notify.c
+++ b/libpurple/notify.c
@@ -150,8 +150,6 @@ purple_notify_emails(void *handle, size_t count, gboolean detailed,
{
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 @@ purple_notify_user_info_entry_destroy(PurpleNotifyUserInfoEntry *user_info_entry
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 @@ purple_notify_user_info_get_text_with_newline(PurpleNotifyUserInfo *user_info, c
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 --git a/pidgin/gtkblist.c b/pidgin/gtkblist.c
index ccf1173928..64dbdee9fc 100644
--- a/pidgin/gtkblist.c
+++ b/pidgin/gtkblist.c
@@ -3105,7 +3105,7 @@ static GtkItemFactoryEntry blist_menu[] =
{ 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 },
@@ -4820,7 +4820,7 @@ static void pidgin_blist_show(PurpleBuddyList *list)
"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 @@ static char *pidgin_get_group_title(PurpleBlistNode *gnode, gboolean expanded)
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 @@ pidgin_blist_set_headline(const char *text, GdkPixbuf *pixbuf, GCallback callbac
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 --git a/pidgin/gtknotify.c b/pidgin/gtknotify.c
index cf0f3cb4ca..cfbb83f6b6 100644
--- a/pidgin/gtknotify.c
+++ b/pidgin/gtknotify.c
@@ -413,7 +413,7 @@ pidgin_get_mail_dialog()
* 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 @@ pidgin_notify_add_mail(GtkTreeStore *treemodel, PurpleAccount *account, char *no
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 @@ pidgin_notify_emails(PurpleConnection *gc, size_t count, gboolean detailed,
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 @@ pidgin_notify_emails(PurpleConnection *gc, size_t count, gboolean detailed,
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 @@ pidgin_notify_emails(PurpleConnection *gc, size_t count, gboolean detailed,
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;