[evolution] Miscellaneous cleanups.



commit b663d51f1bd01979030b8dff57a2631cd672775e
Author: Matthew Barnes <mbarnes redhat com>
Date:   Thu May 12 19:00:09 2011 -0400

    Miscellaneous cleanups.

 mail/e-mail-reader-utils.c                         |  115 ++++++++++----------
 mail/e-mail-reader.c                               |   25 +++--
 mail/em-utils.c                                    |    9 ++-
 mail/message-list.c                                |    4 +-
 modules/mail/e-mail-attachment-handler.c           |    6 +-
 modules/mail/e-mail-shell-view-private.c           |   42 ++++----
 .../mailing-list-actions/mailing-list-actions.c    |    9 +-
 plugins/templates/templates.c                      |   35 ++++---
 8 files changed, 137 insertions(+), 108 deletions(-)
---
diff --git a/mail/e-mail-reader-utils.c b/mail/e-mail-reader-utils.c
index 1947584..12a5991 100644
--- a/mail/e-mail-reader-utils.c
+++ b/mail/e-mail-reader-utils.c
@@ -387,39 +387,36 @@ void
 e_mail_reader_print (EMailReader *reader,
                      GtkPrintOperationAction action)
 {
+	EActivity *activity;
+	AsyncContext *context;
+	GCancellable *cancellable;
 	CamelFolder *folder;
 	GPtrArray *uids;
+	const gchar *message_uid;
 
 	g_return_if_fail (E_IS_MAIL_READER (reader));
 
 	folder = e_mail_reader_get_folder (reader);
-	g_return_if_fail (folder != NULL);
+	g_return_if_fail (CAMEL_IS_FOLDER (folder));
 
 	/* XXX Learn to handle len > 1. */
 	uids = e_mail_reader_get_selected_uids (reader);
-	g_return_if_fail (uids != NULL);
+	g_return_if_fail (uids != NULL && uids->len == 1);
+	message_uid = g_ptr_array_index (uids, 0);
 
-	if (uids->len == 1) {
-		EActivity *activity;
-		AsyncContext *context;
-		GCancellable *cancellable;
-		const gchar *message_uid;
-
-		activity = e_mail_reader_new_activity (reader);
-		cancellable = e_activity_get_cancellable (activity);
-		message_uid = uids->pdata[0];
-
-		context = g_slice_new0 (AsyncContext);
-		context->activity = activity;
-		context->reader = g_object_ref (reader);
-		context->message_uid = g_strdup (message_uid);
-		context->print_action = action;
-
-		camel_folder_get_message (
-			folder, message_uid, G_PRIORITY_DEFAULT,
-			cancellable, (GAsyncReadyCallback)
-			mail_reader_print_cb, context);
-	}
+	activity = e_mail_reader_new_activity (reader);
+	cancellable = e_activity_get_cancellable (activity);
+
+	context = g_slice_new0 (AsyncContext);
+	context->activity = activity;
+	context->reader = g_object_ref (reader);
+	context->message_uid = g_strdup (message_uid);
+	context->print_action = action;
+
+	camel_folder_get_message (
+		folder, message_uid, G_PRIORITY_DEFAULT,
+		cancellable, (GAsyncReadyCallback)
+		mail_reader_print_cb, context);
 
 	em_utils_uids_free (uids);
 }
@@ -773,13 +770,18 @@ void
 e_mail_reader_create_filter_from_selected (EMailReader *reader,
                                            gint filter_type)
 {
+	EActivity *activity;
+	AsyncContext *context;
+	GCancellable *cancellable;
 	CamelFolder *folder;
-	const gchar *filter_source;
 	GPtrArray *uids;
+	const gchar *filter_source;
+	const gchar *message_uid;
 
 	g_return_if_fail (E_IS_MAIL_READER (reader));
 
 	folder = e_mail_reader_get_folder (reader);
+	g_return_if_fail (CAMEL_IS_FOLDER (folder));
 
 	if (em_utils_folder_is_sent (folder))
 		filter_source = E_FILTER_SOURCE_OUTGOING;
@@ -789,26 +791,22 @@ e_mail_reader_create_filter_from_selected (EMailReader *reader,
 		filter_source = E_FILTER_SOURCE_INCOMING;
 
 	uids = e_mail_reader_get_selected_uids (reader);
+	g_return_if_fail (uids != NULL && uids->len == 1);
+	message_uid = g_ptr_array_index (uids, 0);
 
-	if (uids->len == 1) {
-		EActivity *activity;
-		AsyncContext *context;
-		GCancellable *cancellable;
-
-		activity = e_mail_reader_new_activity (reader);
-		cancellable = e_activity_get_cancellable (activity);
+	activity = e_mail_reader_new_activity (reader);
+	cancellable = e_activity_get_cancellable (activity);
 
-		context = g_slice_new0 (AsyncContext);
-		context->activity = activity;
-		context->reader = g_object_ref (reader);
-		context->filter_source = filter_source;
-		context->filter_type = filter_type;
+	context = g_slice_new0 (AsyncContext);
+	context->activity = activity;
+	context->reader = g_object_ref (reader);
+	context->filter_source = filter_source;
+	context->filter_type = filter_type;
 
-		camel_folder_get_message (
-			folder, uids->pdata[0], G_PRIORITY_DEFAULT,
-			cancellable, (GAsyncReadyCallback)
-			mail_reader_create_filter_cb, context);
-	}
+	camel_folder_get_message (
+		folder, message_uid, G_PRIORITY_DEFAULT,
+		cancellable, (GAsyncReadyCallback)
+		mail_reader_create_filter_cb, context);
 
 	em_utils_uids_free (uids);
 }
@@ -870,34 +868,35 @@ void
 e_mail_reader_create_vfolder_from_selected (EMailReader *reader,
                                             gint vfolder_type)
 {
+	EActivity *activity;
+	AsyncContext *context;
+	GCancellable *cancellable;
 	CamelFolder *folder;
 	GPtrArray *uids;
+	const gchar *message_uid;
 
 	g_return_if_fail (E_IS_MAIL_READER (reader));
 
 	folder = e_mail_reader_get_folder (reader);
+	g_return_if_fail (CAMEL_IS_FOLDER (folder));
 
 	uids = e_mail_reader_get_selected_uids (reader);
+	g_return_if_fail (uids != NULL && uids->len == 1);
+	message_uid = g_ptr_array_index (uids, 0);
 
-	if (uids->len == 1) {
-		EActivity *activity;
-		AsyncContext *context;
-		GCancellable *cancellable;
-
-		activity = e_mail_reader_new_activity (reader);
-		cancellable = e_activity_get_cancellable (activity);
+	activity = e_mail_reader_new_activity (reader);
+	cancellable = e_activity_get_cancellable (activity);
 
-		context = g_slice_new0 (AsyncContext);
-		context->activity = activity;
-		context->folder = g_object_ref (folder);
-		context->reader = g_object_ref (reader);
-		context->filter_type = vfolder_type;
+	context = g_slice_new0 (AsyncContext);
+	context->activity = activity;
+	context->folder = g_object_ref (folder);
+	context->reader = g_object_ref (reader);
+	context->filter_type = vfolder_type;
 
-		camel_folder_get_message (
-			folder, uids->pdata[0], G_PRIORITY_DEFAULT,
-			cancellable, (GAsyncReadyCallback)
-			mail_reader_create_vfolder_cb, context);
-	}
+	camel_folder_get_message (
+		folder, message_uid, G_PRIORITY_DEFAULT,
+		cancellable, (GAsyncReadyCallback)
+		mail_reader_create_vfolder_cb, context);
 
 	em_utils_uids_free (uids);
 }
diff --git a/mail/e-mail-reader.c b/mail/e-mail-reader.c
index 673a5b2..a281634 100644
--- a/mail/e-mail-reader.c
+++ b/mail/e-mail-reader.c
@@ -153,15 +153,16 @@ action_mail_add_sender_cb (GtkAction *action,
 	CamelFolder *folder;
 	GPtrArray *uids;
 	const gchar *address;
+	const gchar *message_uid;
 
 	folder = e_mail_reader_get_folder (reader);
 	backend = e_mail_reader_get_backend (reader);
-	uids = e_mail_reader_get_selected_uids (reader);
 
-	if (uids->len != 1)
-		goto exit;
+	uids = e_mail_reader_get_selected_uids (reader);
+	g_return_if_fail (uids != NULL && uids->len == 1);
+	message_uid = g_ptr_array_index (uids, 0);
 
-	info = camel_folder_get_message_info (folder, uids->pdata[0]);
+	info = camel_folder_get_message_info (folder, message_uid);
 	if (info == NULL)
 		goto exit;
 
@@ -1455,20 +1456,22 @@ action_mail_save_as_cb (GtkAction *action,
 	CamelFolder *folder;
 	GPtrArray *uids;
 	GFile *file;
+	const gchar *message_uid;
 	const gchar *title;
 	gchar *suggestion = NULL;
 	gchar *uri;
 
 	folder = e_mail_reader_get_folder (reader);
 	backend = e_mail_reader_get_backend (reader);
-	uids = e_mail_reader_get_selected_uids (reader);
 
-	g_return_if_fail (uids->len > 0);
+	uids = e_mail_reader_get_selected_uids (reader);
+	g_return_if_fail (uids != NULL && uids->len == 1);
+	message_uid = g_ptr_array_index (uids, 0);
 
 	title = ngettext ("Save Message", "Save Messages", uids->len);
 
 	/* Suggest as a filename the subject of the first message. */
-	info = camel_folder_get_message_info (folder, uids->pdata[0]);
+	info = camel_folder_get_message_info (folder, message_uid);
 	if (info != NULL) {
 		const gchar *subject = camel_message_info_subject (info);
 
@@ -1569,12 +1572,14 @@ action_mail_show_source_cb (GtkAction *action,
 	CamelFolder *folder;
 	GtkWidget *browser;
 	GPtrArray *uids;
+	const gchar *message_uid;
 
 	backend = e_mail_reader_get_backend (reader);
 	folder = e_mail_reader_get_folder (reader);
-	uids = e_mail_reader_get_selected_uids (reader);
 
-	g_return_if_fail (uids->len > 0);
+	uids = e_mail_reader_get_selected_uids (reader);
+	g_return_if_fail (uids != NULL && uids->len == 1);
+	message_uid = g_ptr_array_index (uids, 0);
 
 	browser = e_mail_browser_new (backend);
 	reader = E_MAIL_READER (browser);
@@ -1585,7 +1590,7 @@ action_mail_show_source_cb (GtkAction *action,
 			EM_FORMAT (formatter), EM_FORMAT_MODE_SOURCE);
 
 	e_mail_reader_set_folder (reader, folder);
-	e_mail_reader_set_message (reader, uids->pdata[0]);
+	e_mail_reader_set_message (reader, message_uid);
 	gtk_widget_show (browser);
 
 	em_utils_uids_free (uids);
diff --git a/mail/em-utils.c b/mail/em-utils.c
index 67ee603..a9027e0 100644
--- a/mail/em-utils.c
+++ b/mail/em-utils.c
@@ -444,8 +444,10 @@ em_utils_flag_for_followup (EMailReader *reader,
 	/* special-case... */
 	if (uids->len == 1) {
 		CamelMessageInfo *info;
+		const gchar *message_uid;
 
-		info = camel_folder_get_message_info (folder, uids->pdata[0]);
+		message_uid = g_ptr_array_index (uids, 0);
+		info = camel_folder_get_message_info (folder, message_uid);
 		if (info) {
 			tags = (CamelTag *) camel_message_info_user_tags (info);
 
@@ -899,7 +901,10 @@ em_utils_selection_set_urilist (GtkSelectionData *data,
 
 	/* Try to get the drop filename from the message or folder */
 	if (uids->len == 1) {
-		info = camel_folder_get_message_info (folder, uids->pdata[0]);
+		const gchar *message_uid;
+
+		message_uid = g_ptr_array_index (uids, 0);
+		info = camel_folder_get_message_info (folder, message_uid);
 		if (info) {
 			file = g_strdup (camel_message_info_subject (info));
 			camel_folder_free_message_info (folder, info);
diff --git a/mail/message-list.c b/mail/message-list.c
index 592e8e1..9adf2b4 100644
--- a/mail/message-list.c
+++ b/mail/message-list.c
@@ -3937,14 +3937,14 @@ static void
 on_selection_changed_cmd (ETree *tree, MessageList *ml)
 {
 	GPtrArray *uids;
-	gchar *newuid;
+	const gchar *newuid;
 	ETreePath cursor;
 
 	/* not sure if we could just ignore this for the cursor, i think sometimes you
 	   only get a selection changed when you should also get a cursor activated? */
 	uids = message_list_get_selected (ml);
 	if (uids->len == 1)
-		newuid = uids->pdata[0];
+		newuid = g_ptr_array_index (uids, 0);
 	else if ((cursor = e_tree_get_cursor (tree)))
 		newuid = (gchar *) camel_message_info_uid (e_tree_memory_node_get_data ((ETreeMemory *) tree, cursor));
 	else
diff --git a/modules/mail/e-mail-attachment-handler.c b/modules/mail/e-mail-attachment-handler.c
index befac08..6b2efaf 100644
--- a/modules/mail/e-mail-attachment-handler.c
+++ b/modules/mail/e-mail-attachment-handler.c
@@ -323,9 +323,13 @@ mail_attachment_handler_x_uid_list (EAttachmentView *view,
 
 	/* Handle one message. */
 	if (uids->len == 1) {
+		const gchar *message_uid;
+
+		message_uid = g_ptr_array_index (uids, 0);
+
 		/* FIXME Not passing a GCancellable here. */
 		message = camel_folder_get_message_sync (
-			folder, uids->pdata[0], NULL, &local_error);
+			folder, message_uid, NULL, &local_error);
 		if (message == NULL)
 			goto exit;
 
diff --git a/modules/mail/e-mail-shell-view-private.c b/modules/mail/e-mail-shell-view-private.c
index b3cfb7e..5eb7aca 100644
--- a/modules/mail/e-mail-shell-view-private.c
+++ b/modules/mail/e-mail-shell-view-private.c
@@ -948,6 +948,7 @@ e_mail_shell_view_create_filter_from_selected (EMailShellView *mail_shell_view,
 	EMailView *mail_view;
 	CamelFolder *folder;
 	const gchar *filter_source;
+	const gchar *message_uid;
 	GPtrArray *uids;
 
 	struct {
@@ -969,7 +970,10 @@ e_mail_shell_view_create_filter_from_selected (EMailShellView *mail_shell_view,
 
 	reader = E_MAIL_READER (mail_view);
 	folder = e_mail_reader_get_folder (reader);
+
 	uids = e_mail_reader_get_selected_uids (reader);
+	g_return_if_fail (uids != NULL && uids->len == 1);
+	message_uid = g_ptr_array_index (uids, 0);
 
 	if (em_utils_folder_is_sent (folder))
 		filter_source = E_FILTER_SOURCE_OUTGOING;
@@ -978,17 +982,15 @@ e_mail_shell_view_create_filter_from_selected (EMailShellView *mail_shell_view,
 	else
 		filter_source = E_FILTER_SOURCE_INCOMING;
 
-	if (uids->len == 1) {
-		filter_data = g_malloc (sizeof (*filter_data));
-		filter_data->session = g_object_ref (session);
-		filter_data->source = filter_source;
-		filter_data->type = filter_type;
+	filter_data = g_malloc (sizeof (*filter_data));
+	filter_data->session = g_object_ref (session);
+	filter_data->source = filter_source;
+	filter_data->type = filter_type;
 
-		mail_get_message (
-			folder, uids->pdata[0],
-			mail_shell_view_create_filter_cb,
-			filter_data, mail_msg_unordered_push);
-	}
+	mail_get_message (
+		folder, message_uid,
+		mail_shell_view_create_filter_cb,
+		filter_data, mail_msg_unordered_push);
 
 	em_utils_uids_free (uids);
 }
@@ -1027,6 +1029,7 @@ e_mail_shell_view_create_vfolder_from_selected (EMailShellView *mail_shell_view,
 	EMailView *mail_view;
 	CamelFolder *folder;
 	GPtrArray *uids;
+	const gchar *message_uid;
 
 	struct {
 		EMailSession *session;
@@ -1046,18 +1049,19 @@ e_mail_shell_view_create_vfolder_from_selected (EMailShellView *mail_shell_view,
 
 	reader = E_MAIL_READER (mail_view);
 	folder = e_mail_reader_get_folder (reader);
+
 	uids = e_mail_reader_get_selected_uids (reader);
+	g_return_if_fail (uids != NULL && uids->len == 1);
+	message_uid = g_ptr_array_index (uids, 0);
 
-	if (uids->len == 1) {
-		vfolder_data = g_malloc (sizeof (*vfolder_data));
-		vfolder_data->session = g_object_ref (session);
-		vfolder_data->type = vfolder_type;
+	vfolder_data = g_malloc (sizeof (*vfolder_data));
+	vfolder_data->session = g_object_ref (session);
+	vfolder_data->type = vfolder_type;
 
-		mail_get_message (
-			folder, uids->pdata[0],
-			mail_shell_view_create_vfolder_cb,
-			vfolder_data, mail_msg_unordered_push);
-	}
+	mail_get_message (
+		folder, message_uid,
+		mail_shell_view_create_vfolder_cb,
+		vfolder_data, mail_msg_unordered_push);
 
 	em_utils_uids_free (uids);
 }
diff --git a/plugins/mailing-list-actions/mailing-list-actions.c b/plugins/mailing-list-actions/mailing-list-actions.c
index 310c9af..f974632 100644
--- a/plugins/mailing-list-actions/mailing-list-actions.c
+++ b/plugins/mailing-list-actions/mailing-list-actions.c
@@ -228,18 +228,21 @@ emla_list_action (EMailReader *reader,
 	CamelFolder *folder;
 	GPtrArray *uids;
 	emla_action_data *data;
+	const gchar *message_uid;
 
 	folder = e_mail_reader_get_folder (reader);
-	uids = e_mail_reader_get_selected_uids (reader);
+	g_return_if_fail (CAMEL_IS_FOLDER (folder));
 
-	g_return_if_fail (uids->len == 1);
+	uids = e_mail_reader_get_selected_uids (reader);
+	g_return_if_fail (uids != NULL && uids->len == 1);
+	message_uid = g_ptr_array_index (uids, 0);
 
 	data = g_malloc (sizeof (emla_action_data));
 	data->reader = g_object_ref (reader);
 	data->action = action;
 
 	mail_get_message (
-		folder, uids->pdata[0],
+		folder, message_uid,
 		emla_list_action_do, data,
 		mail_msg_unordered_push);
 
diff --git a/plugins/templates/templates.c b/plugins/templates/templates.c
index 48a3b9e..5fa6017 100644
--- a/plugins/templates/templates.c
+++ b/plugins/templates/templates.c
@@ -812,45 +812,54 @@ create_new_message (CamelFolder *folder, const gchar *uid, CamelMimeMessage *mes
 
 static void
 action_reply_with_template_cb (GtkAction *action,
-				EShellView *shell_view)
+                               EShellView *shell_view)
 {
 	CamelFolder *folder, *template_folder;
 	EShellContent *shell_content;
+	CamelMimeMessage *template;
 	EMailReader *reader;
 	GPtrArray *uids;
-	const gchar *uid;
-	CamelMimeMessage *template;
+	const gchar *message_uid;
+	const gchar *template_uid;
 
 	shell_content = e_shell_view_get_shell_content (shell_view);
 	reader = E_MAIL_READER (shell_content);
+
 	folder = e_mail_reader_get_folder (reader);
+	g_return_if_fail (CAMEL_IS_FOLDER (folder));
+
 	uids = e_mail_reader_get_selected_uids (reader);
+	g_return_if_fail (uids != NULL && uids->len == 1);
+	message_uid = g_ptr_array_index (uids, 0);
 
-	if (!uids->len || !folder)
-		return;
+	g_object_ref (action);
 
-	g_object_ref (G_OBJECT (action));
+	template_folder = g_object_get_data (
+		G_OBJECT (action), "template-folder");
+	template_uid = g_object_get_data (
+		G_OBJECT (action), "template-uid");
 
-	template_folder = g_object_get_data (G_OBJECT (action), "template-folder");
-	uid = g_object_get_data (G_OBJECT (action), "template-uid");
-	template = camel_folder_get_message_sync (template_folder, uid, NULL, NULL);
+	/* FIXME This blocks. */
+	template = camel_folder_get_message_sync (
+		template_folder, template_uid, NULL, NULL);
 
-	mail_get_message (folder, uids->pdata[0], create_new_message,
+	mail_get_message (
+		folder, message_uid, create_new_message,
 		(gpointer) template, mail_msg_unordered_push);
 
-	g_object_unref (G_OBJECT (action));
+	g_object_unref (action);
 
 	em_utils_uids_free (uids);
 }
 
 static void
 build_template_menus_recurse (GtkUIManager *ui_manager,
-			       GtkActionGroup *action_group,
+                              GtkActionGroup *action_group,
                               const gchar *menu_path,
                               guint *action_count,
                               guint merge_id,
                               CamelFolderInfo *folder_info,
-			       EShellView *shell_view)
+                              EShellView *shell_view)
 {
 	CamelStore *store;
 	EShellWindow *shell_window = e_shell_view_get_shell_window (shell_view);



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