From 94cc603cca2152ad8aedcbec3cd0e28110e9a21c Mon Sep 17 00:00:00 2001 From: Milan Crha Date: Thu, 1 Apr 2010 14:02:43 +0200 Subject: Bug #374533 - Read window stays open after last email is deleted --- mail/e-mail-browser.c | 23 +++++++++++++++++++++++ mail/message-list.c | 27 +++++++++++++++++++++++++++ mail/message-list.h | 2 +- 3 files changed, 51 insertions(+), 1 deletion(-) diff --git a/mail/e-mail-browser.c b/mail/e-mail-browser.c index 96f168fec9..26d3a876f1 100644 --- a/mail/e-mail-browser.c +++ b/mail/e-mail-browser.c @@ -266,6 +266,25 @@ mail_browser_message_selected_cb (EMailBrowser *browser, camel_folder_free_message_info (folder, info); } +static gboolean +close_on_idle_cb (gpointer browser) +{ + e_mail_browser_close (browser); + return FALSE; +} + +static void +mail_browser_message_list_built_cb (EMailBrowser *browser, MessageList *message_list) +{ + g_return_if_fail (browser != NULL); + g_return_if_fail (E_IS_MAIL_BROWSER (browser)); + g_return_if_fail (message_list != NULL); + g_return_if_fail (IS_MESSAGE_LIST (message_list)); + + if (!message_list_count (message_list)) + g_idle_add (close_on_idle_cb, browser); +} + static gboolean mail_browser_popup_event_cb (EMailBrowser *browser, GdkEventButton *event, @@ -486,6 +505,10 @@ mail_browser_constructed (GObject *object) priv->message_list, "message-selected", G_CALLBACK (mail_browser_message_selected_cb), object); + g_signal_connect_swapped ( + priv->message_list, "message-list-built", + G_CALLBACK (mail_browser_message_list_built_cb), object); + g_signal_connect_swapped ( web_view, "popup-event", G_CALLBACK (mail_browser_popup_event_cb), object); diff --git a/mail/message-list.c b/mail/message-list.c index 88a711085b..453e261574 100644 --- a/mail/message-list.c +++ b/mail/message-list.c @@ -3851,6 +3851,33 @@ message_list_set_selected(MessageList *ml, GPtrArray *uids) g_ptr_array_free(paths, TRUE); } +struct ml_count_data { + MessageList *ml; + guint count; +}; + +static void +ml_getcount_cb (ETreePath path, gpointer user_data) +{ + struct ml_count_data *data = user_data; + + if (!e_tree_model_node_is_root (data->ml->model, path)) + data->count++; +} + +guint +message_list_count (MessageList *message_list) +{ + struct ml_count_data data = { message_list, 0 }; + + g_return_val_if_fail (message_list != NULL, 0); + g_return_val_if_fail (IS_MESSAGE_LIST (message_list), 0); + + e_tree_path_foreach (E_TREE (message_list), ml_getcount_cb, &data); + + return data.count; +} + void message_list_freeze(MessageList *ml) { diff --git a/mail/message-list.h b/mail/message-list.h index 4431f8658c..a817047cc6 100644 --- a/mail/message-list.h +++ b/mail/message-list.h @@ -202,7 +202,7 @@ void message_list_invert_selection (MessageList *message_list); void message_list_copy (MessageList *message_list, gboolean cut); void message_list_paste (MessageList *message_list); -guint message_list_length (MessageList *message_list); +guint message_list_count (MessageList *message_list); void message_list_set_threaded (MessageList *message_list, gboolean threaded); void message_list_set_threaded_expand_all -- cgit v1.2.3