[evolution/gnome-3-2] Bug #660224 - Assertion failure when forwarding message



commit 6007aba94d8464aa7235c5e7915ed8c44f5bc3ca
Author: Milan Crha <mcrha redhat com>
Date:   Tue Sep 27 11:16:13 2011 +0200

    Bug #660224 - Assertion failure when forwarding message

 mail/e-mail-reader.c     |   45 +++++++++++++++++++++++++++------------------
 mail/em-composer-utils.c |   11 ++++++++++-
 mail/em-composer-utils.h |    3 ++-
 3 files changed, 39 insertions(+), 20 deletions(-)
---
diff --git a/mail/e-mail-reader.c b/mail/e-mail-reader.c
index 430f71d..9209942 100644
--- a/mail/e-mail-reader.c
+++ b/mail/e-mail-reader.c
@@ -479,8 +479,8 @@ action_mail_flag_for_followup_cb (GtkAction *action,
 	em_utils_flag_for_followup (reader, folder, uids);
 }
 
-static void
-check_close_browser_reader (EMailReader *reader)
+static gboolean
+get_close_browser_reader (EMailReader *reader)
 {
 	GConfClient *client;
 	const gchar *key;
@@ -489,7 +489,7 @@ check_close_browser_reader (EMailReader *reader)
 
 	/* only allow closing of a mail browser and nothing else */
 	if (!E_IS_MAIL_BROWSER (reader))
-		return;
+		return FALSE;
 
 	client = gconf_client_get_default ();
 
@@ -529,11 +529,16 @@ check_close_browser_reader (EMailReader *reader)
 	}
 
 	g_free (value);
+	g_object_unref (client);
 
-	if (close_it)
-		gtk_widget_destroy (GTK_WIDGET (reader));
+	return close_it;
+}
 
-	g_object_unref (client);
+static void
+check_close_browser_reader (EMailReader *reader)
+{
+	if (get_close_browser_reader (reader))
+		gtk_widget_destroy (GTK_WIDGET (reader));
 }
 
 static void
@@ -543,11 +548,13 @@ action_mail_forward_cb (GtkAction *action,
 	CamelFolder *folder;
 	GtkWindow *window;
 	GPtrArray *uids;
+	gboolean close_reader;
 
 	folder = e_mail_reader_get_folder (reader);
 	window = e_mail_reader_get_window (reader);
 	uids = e_mail_reader_get_selected_uids (reader);
 	g_return_if_fail (uids != NULL);
+	close_reader = get_close_browser_reader (reader);
 
 	/* XXX Either e_mail_reader_get_selected_uids()
 	 *     or MessageList should do this itself. */
@@ -556,11 +563,10 @@ action_mail_forward_cb (GtkAction *action,
 	if (em_utils_ask_open_many (window, uids->len))
 		em_utils_forward_messages (
 			reader, folder, uids,
-			e_mail_reader_get_forward_style (reader));
+			e_mail_reader_get_forward_style (reader),
+			close_reader ? GTK_WIDGET (reader) : NULL);
 
 	g_ptr_array_unref (uids);
-
-	check_close_browser_reader (reader);
 }
 
 static void
@@ -570,11 +576,13 @@ action_mail_forward_attached_cb (GtkAction *action,
 	CamelFolder *folder;
 	GtkWindow *window;
 	GPtrArray *uids;
+	gboolean close_reader;
 
 	folder = e_mail_reader_get_folder (reader);
 	window = e_mail_reader_get_window (reader);
 	uids = e_mail_reader_get_selected_uids (reader);
 	g_return_if_fail (uids != NULL);
+	close_reader = get_close_browser_reader (reader);
 
 	/* XXX Either e_mail_reader_get_selected_uids()
 	 *     or MessageList should do this itself. */
@@ -583,11 +591,10 @@ action_mail_forward_attached_cb (GtkAction *action,
 	if (em_utils_ask_open_many (window, uids->len))
 		em_utils_forward_messages (
 			reader, folder, uids,
-			E_MAIL_FORWARD_STYLE_ATTACHED);
+			E_MAIL_FORWARD_STYLE_ATTACHED,
+			close_reader ? GTK_WIDGET (reader) : NULL);
 
 	g_ptr_array_unref (uids);
-
-	check_close_browser_reader (reader);
 }
 
 static void
@@ -597,11 +604,13 @@ action_mail_forward_inline_cb (GtkAction *action,
 	CamelFolder *folder;
 	GtkWindow *window;
 	GPtrArray *uids;
+	gboolean close_reader;
 
 	folder = e_mail_reader_get_folder (reader);
 	window = e_mail_reader_get_window (reader);
 	uids = e_mail_reader_get_selected_uids (reader);
 	g_return_if_fail (uids != NULL);
+	close_reader = get_close_browser_reader (reader);
 
 	/* XXX Either e_mail_reader_get_selected_uids()
 	 *     or MessageList should do this itself. */
@@ -610,11 +619,10 @@ action_mail_forward_inline_cb (GtkAction *action,
 	if (em_utils_ask_open_many (window, uids->len))
 		em_utils_forward_messages (
 			reader, folder, uids,
-			E_MAIL_FORWARD_STYLE_INLINE);
+			E_MAIL_FORWARD_STYLE_INLINE,
+			close_reader ? GTK_WIDGET (reader) : NULL);
 
 	g_ptr_array_unref (uids);
-
-	check_close_browser_reader (reader);
 }
 
 static void
@@ -624,11 +632,13 @@ action_mail_forward_quoted_cb (GtkAction *action,
 	CamelFolder *folder;
 	GtkWindow *window;
 	GPtrArray *uids;
+	gboolean close_reader;
 
 	folder = e_mail_reader_get_folder (reader);
 	window = e_mail_reader_get_window (reader);
 	uids = e_mail_reader_get_selected_uids (reader);
 	g_return_if_fail (uids != NULL);
+	close_reader = get_close_browser_reader (reader);
 
 	/* XXX Either e_mail_reader_get_selected_uids()
 	 *     or MessageList should do this itself. */
@@ -637,11 +647,10 @@ action_mail_forward_quoted_cb (GtkAction *action,
 	if (em_utils_ask_open_many (window, uids->len))
 		em_utils_forward_messages (
 			reader, folder, uids,
-			E_MAIL_FORWARD_STYLE_QUOTED);
+			E_MAIL_FORWARD_STYLE_QUOTED,
+			close_reader ? GTK_WIDGET (reader) : NULL);
 
 	g_ptr_array_unref (uids);
-
-	check_close_browser_reader (reader);
 }
 
 static void
diff --git a/mail/em-composer-utils.c b/mail/em-composer-utils.c
index 8c98040..1dfa3c4 100644
--- a/mail/em-composer-utils.c
+++ b/mail/em-composer-utils.c
@@ -85,6 +85,7 @@ struct _AsyncContext {
 	gchar *folder_uri;
 	gchar *message_uid;
 	gboolean replace;
+	GtkWidget *destroy_when_done;
 };
 
 struct _ForwardData {
@@ -112,6 +113,9 @@ async_context_free (AsyncContext *context)
 	if (context->ptr_array != NULL)
 		g_ptr_array_unref (context->ptr_array);
 
+	if (context->destroy_when_done != NULL)
+		gtk_widget_destroy (context->destroy_when_done);
+
 	g_free (context->folder_uri);
 	g_free (context->message_uid);
 
@@ -1680,6 +1684,7 @@ forward_got_messages_cb (CamelFolder *folder,
 
 	if (e_activity_handle_cancellation (context->activity, error)) {
 		g_warn_if_fail (hash_table == NULL);
+		context->destroy_when_done = NULL;
 		async_context_free (context);
 		g_error_free (error);
 		return;
@@ -1690,6 +1695,7 @@ forward_got_messages_cb (CamelFolder *folder,
 			alert_sink,
 			"mail:get-multiple-messages",
 			error->message, NULL);
+		context->destroy_when_done = NULL;
 		async_context_free (context);
 		g_error_free (error);
 		return;
@@ -1721,6 +1727,7 @@ forward_got_messages_cb (CamelFolder *folder,
  * @folder: folder containing messages to forward
  * @uids: uids of messages to forward
  * @style: the forward style to use
+ * @destroy_when_done: a #GtkWidget to destroy with gtk_widget_destroy() when done; can be NULL
  *
  * Forwards a group of messages in the given style.
  *
@@ -1742,7 +1749,8 @@ void
 em_utils_forward_messages (EMailReader *reader,
                            CamelFolder *folder,
                            GPtrArray *uids,
-                           EMailForwardStyle style)
+                           EMailForwardStyle style,
+			   GtkWidget *destroy_when_done)
 {
 	EActivity *activity;
 	AsyncContext *context;
@@ -1760,6 +1768,7 @@ em_utils_forward_messages (EMailReader *reader,
 	context->reader = g_object_ref (reader);
 	context->ptr_array = g_ptr_array_ref (uids);
 	context->style = style;
+	context->destroy_when_done = destroy_when_done;
 
 	switch (style) {
 		case E_MAIL_FORWARD_STYLE_ATTACHED:
diff --git a/mail/em-composer-utils.h b/mail/em-composer-utils.h
index e651186..3dba3e9 100644
--- a/mail/em-composer-utils.h
+++ b/mail/em-composer-utils.h
@@ -54,7 +54,8 @@ EMsgComposer *	em_utils_forward_message	(EShell *shell,
 void		em_utils_forward_messages	(EMailReader *reader,
 						 CamelFolder *folder,
 						 GPtrArray *uids,
-						 EMailForwardStyle style);
+						 EMailForwardStyle style,
+						 GtkWidget *destroy_when_done);
 void		em_utils_redirect_message	(EShell *shell,
 						 CamelMimeMessage *message);
 void		em_utils_handle_receipt		(EMailSession *session,



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]