diff options
author | Matthew Barnes <mbarnes@redhat.com> | 2013-06-15 20:19:27 +0800 |
---|---|---|
committer | Matthew Barnes <mbarnes@redhat.com> | 2013-06-15 20:19:27 +0800 |
commit | f642e03d4967c80aaad45475475752264c95de5c (patch) | |
tree | 23b2f4e862f73b86e13f92c433b8315d783b1d2e /mail | |
parent | 2f43685f591581bc7ad051ac6464799f8e5df5bf (diff) | |
download | gsoc2013-evolution-f642e03d4967c80aaad45475475752264c95de5c.tar.gz gsoc2013-evolution-f642e03d4967c80aaad45475475752264c95de5c.tar.zst gsoc2013-evolution-f642e03d4967c80aaad45475475752264c95de5c.zip |
message_list_get_selected: Give the returned array a free func.
The returned UID array now has a built-in "free" function for its
elements and should be released by callers with g_ptr_array_unref()
rather than em_utils_uids_free() or some equivalent.
Diffstat (limited to 'mail')
-rw-r--r-- | mail/e-mail-folder-pane.c | 4 | ||||
-rw-r--r-- | mail/e-mail-reader-utils.c | 27 | ||||
-rw-r--r-- | mail/e-mail-reader.c | 43 | ||||
-rw-r--r-- | mail/em-utils.c | 7 | ||||
-rw-r--r-- | mail/message-list.c | 36 |
5 files changed, 43 insertions, 74 deletions
diff --git a/mail/e-mail-folder-pane.c b/mail/e-mail-folder-pane.c index 5da74e4e7b..5c1ef76806 100644 --- a/mail/e-mail-folder-pane.c +++ b/mail/e-mail-folder-pane.c @@ -88,10 +88,6 @@ mail_paned_view_open_selected_mail (EMailPanedView *view) shell = e_shell_backend_get_shell (E_SHELL_BACKEND (backend)); registry = e_shell_get_registry (shell); - /* XXX Either e_mail_reader_get_selected_uids() - * or MessageList should do this itself. */ - g_ptr_array_set_free_func (uids, (GDestroyNotify) g_free); - if (!em_utils_ask_open_many (window, uids->len)) goto exit; diff --git a/mail/e-mail-reader-utils.c b/mail/e-mail-reader-utils.c index 2cd9f96351..b50a06b42e 100644 --- a/mail/e-mail-reader-utils.c +++ b/mail/e-mail-reader-utils.c @@ -764,7 +764,7 @@ e_mail_reader_mark_selected (EMailReader *reader, camel_folder_set_message_flags ( folder, uids->pdata[ii], mask, set); - em_utils_uids_free (uids); + g_ptr_array_unref (uids); camel_folder_thaw (folder); @@ -829,12 +829,11 @@ e_mail_reader_open_selected (EMailReader *reader) em_utils_folder_is_outbox (registry, folder) || em_utils_folder_is_templates (registry, folder)) { - /* FIXME This is leaking the UID array. Give - * the array a "free func" and unref it. */ e_mail_reader_edit_messages (reader, folder, uids, TRUE, TRUE); - g_clear_object (&folder); - return uids->len; + ii = uids->len; + + goto exit; } views = g_ptr_array_new (); @@ -906,7 +905,7 @@ e_mail_reader_open_selected (EMailReader *reader) exit: g_clear_object (&folder); - em_utils_uids_free (uids); + g_ptr_array_unref (uids); return ii; } @@ -1121,10 +1120,6 @@ e_mail_reader_remove_attachments (EMailReader *reader) uids = e_mail_reader_get_selected_uids (reader); g_return_if_fail (uids != NULL); - /* XXX Either e_mail_reader_get_selected_uids() - * or MessageList should do this itself. */ - g_ptr_array_set_free_func (uids, (GDestroyNotify) g_free); - /* Remove attachments asynchronously. */ activity = e_mail_reader_new_activity (reader); @@ -1264,10 +1259,6 @@ e_mail_reader_remove_duplicates (EMailReader *reader) uids = e_mail_reader_get_selected_uids (reader); g_return_if_fail (uids != NULL); - /* XXX Either e_mail_reader_get_selected_uids() - * or MessageList should do this itself. */ - g_ptr_array_set_free_func (uids, (GDestroyNotify) g_free); - /* Find duplicate messages asynchronously. */ activity = e_mail_reader_new_activity (reader); @@ -2042,10 +2033,6 @@ e_mail_reader_save_messages (EMailReader *reader) message_uid = g_ptr_array_index (uids, 0); - /* XXX Either e_mail_reader_get_selected_uids() - * or MessageList should do this itself. */ - g_ptr_array_set_free_func (uids, (GDestroyNotify) g_free); - title = ngettext ("Save Message", "Save Messages", uids->len); /* Suggest as a filename the subject of the first message. */ @@ -2246,7 +2233,7 @@ e_mail_reader_create_filter_from_selected (EMailReader *reader, g_object_unref (activity); - em_utils_uids_free (uids); + g_ptr_array_unref (uids); g_object_unref (folder); } @@ -2363,7 +2350,7 @@ e_mail_reader_create_vfolder_from_selected (EMailReader *reader, g_object_unref (activity); - em_utils_uids_free (uids); + g_ptr_array_unref (uids); } static void diff --git a/mail/e-mail-reader.c b/mail/e-mail-reader.c index 598be3a5f2..449879a173 100644 --- a/mail/e-mail-reader.c +++ b/mail/e-mail-reader.c @@ -203,7 +203,7 @@ action_mail_add_sender_cb (GtkAction *action, exit: if (info != NULL) camel_folder_free_message_info (folder, info); - em_utils_uids_free (uids); + g_ptr_array_unref (uids); g_clear_object (&folder); } @@ -435,6 +435,7 @@ action_mail_check_for_junk_cb (GtkAction *action, E_FILTER_SOURCE_JUNKTEST, FALSE); g_clear_object (&folder); + g_ptr_array_unref (uids); } static void @@ -487,20 +488,16 @@ action_mail_copy_cb (GtkAction *action, g_free (default_xfer_messages_uri); default_xfer_messages_uri = g_strdup (uri); - if (uri != NULL) { + if (uri != NULL) mail_transfer_messages ( session, folder, uids, FALSE, uri, 0, NULL, NULL); - uids = NULL; - } exit: - if (uids != NULL) - em_utils_uids_free (uids); - gtk_widget_destroy (dialog); g_clear_object (&folder); + g_ptr_array_unref (uids); } static void @@ -568,6 +565,7 @@ action_mail_filters_apply_cb (GtkAction *action, E_FILTER_SOURCE_DEMAND, FALSE); g_clear_object (&folder); + g_ptr_array_unref (uids); } static void @@ -610,6 +608,7 @@ action_mail_flag_clear_cb (GtkAction *action, e_mail_display_reload (display); g_clear_object (&folder); + g_ptr_array_unref (uids); } static void @@ -631,6 +630,7 @@ action_mail_flag_completed_cb (GtkAction *action, e_mail_display_reload (display); g_clear_object (&folder); + g_ptr_array_unref (uids); } static void @@ -646,6 +646,7 @@ action_mail_flag_for_followup_cb (GtkAction *action, em_utils_flag_for_followup (reader, folder, uids); g_clear_object (&folder); + g_ptr_array_unref (uids); } static void @@ -659,10 +660,6 @@ action_mail_forward_cb (GtkAction *action, uids = e_mail_reader_get_selected_uids (reader); g_return_if_fail (uids != NULL); - /* XXX Either e_mail_reader_get_selected_uids() - * or MessageList should do this itself. */ - g_ptr_array_set_free_func (uids, (GDestroyNotify) g_free); - if (em_utils_ask_open_many (window, uids->len)) { CamelFolder *folder; @@ -689,10 +686,6 @@ action_mail_forward_attached_cb (GtkAction *action, uids = e_mail_reader_get_selected_uids (reader); g_return_if_fail (uids != NULL); - /* XXX Either e_mail_reader_get_selected_uids() - * or MessageList should do this itself. */ - g_ptr_array_set_free_func (uids, (GDestroyNotify) g_free); - if (em_utils_ask_open_many (window, uids->len)) { CamelFolder *folder; @@ -719,10 +712,6 @@ action_mail_forward_inline_cb (GtkAction *action, uids = e_mail_reader_get_selected_uids (reader); g_return_if_fail (uids != NULL); - /* XXX Either e_mail_reader_get_selected_uids() - * or MessageList should do this itself. */ - g_ptr_array_set_free_func (uids, (GDestroyNotify) g_free); - if (em_utils_ask_open_many (window, uids->len)) { CamelFolder *folder; @@ -749,10 +738,6 @@ action_mail_forward_quoted_cb (GtkAction *action, uids = e_mail_reader_get_selected_uids (reader); g_return_if_fail (uids != NULL); - /* XXX Either e_mail_reader_get_selected_uids() - * or MessageList should do this itself. */ - g_ptr_array_set_free_func (uids, (GDestroyNotify) g_free); - if (em_utils_ask_open_many (window, uids->len)) { CamelFolder *folder; @@ -915,10 +900,6 @@ action_mail_message_edit_cb (GtkAction *action, shell = e_shell_backend_get_shell (E_SHELL_BACKEND (backend)); registry = e_shell_get_registry (shell); - /* XXX Either e_mail_reader_get_selected_uids() - * or MessageList should do this itself. */ - g_ptr_array_set_free_func (uids, (GDestroyNotify) g_free); - folder = e_mail_reader_ref_folder (reader); replace = em_utils_folder_is_drafts (registry, folder); e_mail_reader_edit_messages (reader, folder, uids, replace, replace); @@ -1016,7 +997,7 @@ action_mail_move_cb (GtkAction *action, exit: if (uids != NULL) - em_utils_uids_free (uids); + g_ptr_array_unref (uids); gtk_widget_destroy (dialog); @@ -1829,7 +1810,7 @@ action_mail_show_source_cb (GtkAction *action, g_object_unref (activity); - em_utils_uids_free (uids); + g_ptr_array_unref (uids); g_clear_object (&folder); } @@ -1864,7 +1845,7 @@ action_mail_toggle_important_cb (GtkAction *action, camel_folder_thaw (folder); g_clear_object (&folder); - em_utils_uids_free (uids); + g_ptr_array_unref (uids); } static void @@ -4263,7 +4244,7 @@ e_mail_reader_check_state (EMailReader *reader) state |= E_MAIL_READER_FOLDER_IS_JUNK; g_clear_object (&folder); - em_utils_uids_free (uids); + g_ptr_array_unref (uids); return state; } diff --git a/mail/em-utils.c b/mail/em-utils.c index 103ed62b1a..16a0d677ae 100644 --- a/mail/em-utils.c +++ b/mail/em-utils.c @@ -431,9 +431,6 @@ em_utils_flag_for_followup (EMailReader *reader, e_mail_display_reload (display); exit: - /* XXX We shouldn't be freeing this. */ - em_utils_uids_free (uids); - gtk_widget_destroy (GTK_WIDGET (editor)); } @@ -470,8 +467,6 @@ em_utils_flag_for_followup_clear (GtkWindow *parent, } camel_folder_thaw (folder); - - em_utils_uids_free (uids); } /** @@ -514,8 +509,6 @@ em_utils_flag_for_followup_completed (GtkWindow *parent, camel_folder_thaw (folder); g_free (now); - - em_utils_uids_free (uids); } /* This kind of sucks, because for various reasons most callers need to run diff --git a/mail/message-list.c b/mail/message-list.c index 7657cc13b2..b0fd942679 100644 --- a/mail/message-list.c +++ b/mail/message-list.c @@ -550,14 +550,12 @@ static void clear_selection (MessageList *message_list, struct _MLSelection *selection) { - if (selection->uids) { - em_utils_uids_free (selection->uids); + if (selection->uids != NULL) { + g_ptr_array_unref (selection->uids); selection->uids = NULL; } - if (selection->folder) { - g_object_unref (selection->folder); - selection->folder = NULL; - } + + g_clear_object (&selection->folder); } static ETreePath @@ -1052,18 +1050,20 @@ message_list_copy (MessageList *message_list, g_object_unref (folder); } - p->clipboard.uids = uids; + p->clipboard.uids = g_ptr_array_ref (uids); p->clipboard.folder = message_list_ref_folder (message_list); + gtk_selection_owner_set ( p->invisible, GDK_SELECTION_CLIPBOARD, gtk_get_current_event_time ()); } else { - em_utils_uids_free (uids); gtk_selection_owner_set ( NULL, GDK_SELECTION_CLIPBOARD, gtk_get_current_event_time ()); } + + g_ptr_array_unref (uids); } void @@ -2328,7 +2328,7 @@ ml_tree_drag_data_get (ETree *tree, } g_clear_object (&folder); - em_utils_uids_free (uids); + g_ptr_array_unref (uids); } /* TODO: merge this with the folder tree stuff via empopup targets */ @@ -3533,7 +3533,9 @@ build_tree (MessageList *message_list, saveuid = find_next_selectable (message_list); selected = message_list_get_selected (message_list); + e_tree_memory_freeze (E_TREE_MEMORY (etm)); + clear_tree (message_list, FALSE); build_subtree ( @@ -3552,7 +3554,8 @@ build_tree (MessageList *message_list, e_tree_memory_freeze (E_TREE_MEMORY (etm)); message_list_set_selected (message_list, selected); - em_utils_uids_free (selected); + + g_ptr_array_unref (selected); /* Show the cursor unless we're responding to a * "folder-changed" signal from our CamelFolder. */ @@ -3841,16 +3844,22 @@ build_flat (MessageList *message_list, saveuid = find_next_selectable (message_list); selected = message_list_get_selected (message_list); + e_tree_memory_freeze (E_TREE_MEMORY (etm)); + clear_tree (message_list, FALSE); + for (i = 0; i < summary->len; i++) { CamelMessageInfo *info = summary->pdata[i]; ml_uid_nodemap_insert (message_list, info, NULL, -1); } + e_tree_memory_thaw (E_TREE_MEMORY (etm)); + message_list_set_selected (message_list, selected); - em_utils_uids_free (selected); + + g_ptr_array_unref (selected); if (saveuid) { ETreePath node; @@ -4343,6 +4352,7 @@ on_selection_changed_cmd (ETree *tree, /* 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 (message_list); + if (uids->len == 1) newuid = g_ptr_array_index (uids, 0); else if ((cursor = e_tree_get_cursor (tree))) @@ -4368,7 +4378,7 @@ on_selection_changed_cmd (ETree *tree, message_list->last_sel_single = uids->len == 1; - em_utils_uids_free (uids); + g_ptr_array_unref (uids); } static gint @@ -4496,6 +4506,8 @@ message_list_get_selected (MessageList *message_list) g_ptr_array_new () }; + g_ptr_array_set_free_func (data.uids, (GDestroyNotify) g_free); + e_tree_selected_path_foreach ( E_TREE (message_list), ml_getselected_cb, &data); |