comparison pidgin/gtknotify.c @ 20217:d4e250c3cd44

applied changes from 4bb1d6cbfe69a2e7782336a7e6e93e438a8bdbfc through 3fcc47961d378fa0cd4eeb00dc6923b16a3a4151
author Richard Laager <rlaager@wiktel.com>
date Fri, 28 Sep 2007 15:45:06 +0000
parents 44b4e8bd759b
children 6b8bc3309ab7
comparison
equal deleted inserted replaced
20216:a252ac635978 20217:d4e250c3cd44
410 410
411 /* count == 0 means this is a detailed mail notification. 411 /* count == 0 means this is a detailed mail notification.
412 * count > 0 mean non-detailed. 412 * count > 0 mean non-detailed.
413 */ 413 */
414 static void * 414 static void *
415 pidgin_notify_add_mail(GtkTreeStore *treemodel, PurpleAccount *account, char *notification, const char *url, int count) 415 pidgin_notify_add_mail(GtkTreeStore *treemodel, PurpleAccount *account, char *notification, const char *url, int count, gboolean clear)
416 { 416 {
417 PidginNotifyMailData *data = NULL; 417 PidginNotifyMailData *data = NULL;
418 GtkTreeIter iter; 418 GtkTreeIter iter;
419 GdkPixbuf *icon; 419 GdkPixbuf *icon;
420 gboolean new_n = TRUE; 420 gboolean new_n = TRUE;
421 421
422 icon = pidgin_create_prpl_icon(account, PIDGIN_PRPL_ICON_MEDIUM); 422 icon = pidgin_create_prpl_icon(account, PIDGIN_PRPL_ICON_MEDIUM);
423 423
424 if (count > 0) { 424 if (count > 0 || clear) {
425 /* Allow only one non-detailed email notification for each account */ 425 /* Allow only one non-detailed email notification for each account */
426 if (gtk_tree_model_get_iter_first(GTK_TREE_MODEL(treemodel), &iter)) { 426 if (gtk_tree_model_get_iter_first(GTK_TREE_MODEL(treemodel), &iter)) {
427 gboolean advanced;
427 do { 428 do {
429 advanced = FALSE;
428 gtk_tree_model_get(GTK_TREE_MODEL(treemodel), &iter, 430 gtk_tree_model_get(GTK_TREE_MODEL(treemodel), &iter,
429 PIDGIN_MAIL_DATA, &data, -1); 431 PIDGIN_MAIL_DATA, &data, -1);
430 if (data->account == account && data->count > 0) { 432 if (data->account == account) {
431 new_n = FALSE; 433 if (clear) {
432 g_free(data->url); 434 advanced = gtk_tree_store_remove(treemodel, &iter);
433 data->url = NULL; 435 purple_notify_close(PURPLE_NOTIFY_EMAILS, data);
434 mail_dialog->total_count -= data->count; 436 /* We're completely done if we've processed all entries */
435 break; 437 if (!advanced)
438 return NULL;
439 } else if (data->count > 0) {
440 new_n = FALSE;
441 g_free(data->url);
442 data->url = NULL;
443 mail_dialog->total_count -= data->count;
444 break;
445 }
436 } 446 }
437 } while (gtk_tree_model_iter_next(GTK_TREE_MODEL(treemodel), &iter)); 447 } while (advanced || gtk_tree_model_iter_next(GTK_TREE_MODEL(treemodel), &iter));
438 } 448 }
439 } 449 }
440 450
441 if (new_n) { 451 if (new_n) {
442 data = g_new0(PidginNotifyMailData, 1); 452 data = g_new0(PidginNotifyMailData, 1);
469 GtkWidget *dialog = NULL; 479 GtkWidget *dialog = NULL;
470 char *notification; 480 char *notification;
471 PurpleAccount *account; 481 PurpleAccount *account;
472 PidginNotifyMailData *data = NULL; 482 PidginNotifyMailData *data = NULL;
473 483
484 /* Don't bother updating if there aren't new emails and we don't have any displayed currently */
485 if (count == 0 && mail_dialog == NULL)
486 return NULL;
487
474 account = purple_connection_get_account(gc); 488 account = purple_connection_get_account(gc);
475 dialog = pidgin_get_mail_dialog(); /* This creates mail_dialog if necessary */ 489 dialog = pidgin_get_mail_dialog(); /* This creates mail_dialog if necessary */
476 490
477 mail_dialog->total_count += count; 491 mail_dialog->total_count += count;
478 if (detailed) { 492 if (detailed) {
479 while (count--) { 493 while (count--) {
480 char *to_text = NULL; 494 char *to_text = NULL;
481 char *from_text = NULL; 495 char *from_text = NULL;
509 #undef SAFE 523 #undef SAFE
510 g_free(to_text); 524 g_free(to_text);
511 g_free(from_text); 525 g_free(from_text);
512 g_free(subject_text); 526 g_free(subject_text);
513 527
514 data = pidgin_notify_add_mail(mail_dialog->treemodel, account, notification, urls ? *urls : NULL, 0); 528 data = pidgin_notify_add_mail(mail_dialog->treemodel, account, notification, urls ? *urls : NULL, 0, FALSE);
515 g_free(notification); 529 g_free(notification);
516 530
517 if (urls != NULL) 531 if (urls != NULL)
518 urls++; 532 urls++;
519 } 533 }
520 } else { 534 } else {
521 notification = g_strdup_printf(ngettext("%s has %d new message.", 535 if (count > 0) {
522 "%s has %d new messages.", 536 notification = g_strdup_printf(ngettext("%s has %d new message.",
523 (int)count), 537 "%s has %d new messages.",
524 *tos, (int)count); 538 (int)count),
525 data = pidgin_notify_add_mail(mail_dialog->treemodel, account, notification, urls ? *urls : NULL, count); 539 *tos, (int)count);
526 g_free(notification); 540 data = pidgin_notify_add_mail(mail_dialog->treemodel, account, notification, urls ? *urls : NULL, count, FALSE);
541 g_free(notification);
542 } else {
543 GtkTreeIter iter;
544
545 /* Clear out all mails for the account */
546 pidgin_notify_add_mail(mail_dialog->treemodel, account, NULL, NULL, 0, TRUE);
547
548 if (!gtk_tree_model_get_iter_first(GTK_TREE_MODEL(mail_dialog->treemodel), &iter)) {
549 /* There is no API to clear the headline specifically */
550 /* This will trigger reset_mail_dialog() */
551 pidgin_blist_set_headline(NULL, NULL, NULL, NULL, NULL);
552 }
553
554 return NULL;
555 }
527 } 556 }
528 557
529 if (!GTK_WIDGET_VISIBLE(dialog)) { 558 if (!GTK_WIDGET_VISIBLE(dialog)) {
530 GdkPixbuf *pixbuf = gtk_widget_render_icon(dialog, PIDGIN_STOCK_DIALOG_MAIL, 559 GdkPixbuf *pixbuf = gtk_widget_render_icon(dialog, PIDGIN_STOCK_DIALOG_MAIL,
531 gtk_icon_size_from_name(PIDGIN_ICON_SIZE_TANGO_EXTRA_SMALL), NULL); 560 gtk_icon_size_from_name(PIDGIN_ICON_SIZE_TANGO_EXTRA_SMALL), NULL);
533 "<b>You have %d new e-mails.</b>", 562 "<b>You have %d new e-mails.</b>",
534 mail_dialog->total_count), mail_dialog->total_count); 563 mail_dialog->total_count), mail_dialog->total_count);
535 mail_dialog->in_use = TRUE; /* So that _set_headline doesn't accidentally 564 mail_dialog->in_use = TRUE; /* So that _set_headline doesn't accidentally
536 remove the notifications when replacing an 565 remove the notifications when replacing an
537 old notification. */ 566 old notification. */
538 pidgin_blist_set_headline(label_text, 567 pidgin_blist_set_headline(label_text,
539 pixbuf, G_CALLBACK(gtk_widget_show_all), dialog, 568 pixbuf, G_CALLBACK(gtk_widget_show_all), dialog,
540 (GDestroyNotify)reset_mail_dialog); 569 (GDestroyNotify)reset_mail_dialog);
541 mail_dialog->in_use = FALSE; 570 mail_dialog->in_use = FALSE;
542 g_free(label_text); 571 g_free(label_text);
543 if (pixbuf) 572 if (pixbuf)