diff options
author | Milan Crha <mcrha@redhat.com> | 2013-04-26 21:35:47 +0800 |
---|---|---|
committer | Milan Crha <mcrha@redhat.com> | 2013-04-26 21:35:47 +0800 |
commit | bf761cd2bf4d426b3340cee5f39823e51c49fe7c (patch) | |
tree | 742fb993ca527ed833c9d8bb206948f0246a636b | |
parent | e90c8380f91ecbff3f0125c89b5a90ca1d26acde (diff) | |
download | gsoc2013-evolution-bf761cd2bf4d426b3340cee5f39823e51c49fe7c.tar.gz gsoc2013-evolution-bf761cd2bf4d426b3340cee5f39823e51c49fe7c.tar.zst gsoc2013-evolution-bf761cd2bf4d426b3340cee5f39823e51c49fe7c.zip |
Bug #626215 - Prefer mail saving in order by UI
-rw-r--r-- | mail/e-mail-reader-utils.c | 10 | ||||
-rw-r--r-- | mail/message-list.c | 60 | ||||
-rw-r--r-- | mail/message-list.h | 3 |
3 files changed, 73 insertions, 0 deletions
diff --git a/mail/e-mail-reader-utils.c b/mail/e-mail-reader-utils.c index dcb3383093..7414ba12c7 100644 --- a/mail/e-mail-reader-utils.c +++ b/mail/e-mail-reader-utils.c @@ -1605,6 +1605,16 @@ e_mail_reader_save_messages (EMailReader *reader) uids = e_mail_reader_get_selected_uids (reader); g_return_if_fail (uids != NULL && uids->len > 0); + + if (uids->len > 1) { + GtkWidget *message_list = e_mail_reader_get_message_list (reader); + + g_warn_if_fail (message_list != NULL); + + if (message_list) + message_list_sort_uids (MESSAGE_LIST (message_list), uids); + } + message_uid = g_ptr_array_index (uids, 0); /* XXX Either e_mail_reader_get_selected_uids() diff --git a/mail/message-list.c b/mail/message-list.c index cc23f99621..aa7d67e377 100644 --- a/mail/message-list.c +++ b/mail/message-list.c @@ -4252,6 +4252,66 @@ message_list_set_selected (MessageList *ml, g_ptr_array_free (paths, TRUE); } +struct ml_sort_uids_data { + gchar *uid; + gint row; +}; + +static gint +ml_sort_uids_cb (gconstpointer a, + gconstpointer b) +{ + struct ml_sort_uids_data * const *pdataA = a; + struct ml_sort_uids_data * const *pdataB = b; + + return (* pdataA)->row - (* pdataB)->row; +} + +void +message_list_sort_uids (MessageList *message_list, + GPtrArray *uids) +{ + struct ml_sort_uids_data *data; + GPtrArray *array; + ETreePath path; + ETreeTableAdapter *adapter; + gint ii; + + g_return_if_fail (message_list != NULL); + g_return_if_fail (IS_MESSAGE_LIST (message_list)); + g_return_if_fail (uids != NULL); + + if (uids->len <= 1) + return; + + adapter = e_tree_get_table_adapter (E_TREE (message_list)); + + array = g_ptr_array_new_full (uids->len, g_free); + + for (ii = 0; ii < uids->len; ii++) { + data = g_new0 (struct ml_sort_uids_data, 1); + data->uid = g_ptr_array_index (uids, ii); + + path = g_hash_table_lookup (message_list->uid_nodemap, data->uid); + if (path) + data->row = e_tree_table_adapter_row_of_node (adapter, path); + else + data->row = ii; + + g_ptr_array_add (array, data); + } + + g_ptr_array_sort (array, ml_sort_uids_cb); + + for (ii = 0; ii < uids->len; ii++) { + data = g_ptr_array_index (array, ii); + + uids->pdata[ii] = data->uid; + } + + g_ptr_array_free (array, TRUE); +} + struct ml_count_data { MessageList *ml; guint count; diff --git a/mail/message-list.h b/mail/message-list.h index daa27f2c1a..4396291199 100644 --- a/mail/message-list.h +++ b/mail/message-list.h @@ -229,6 +229,9 @@ void message_list_ensure_message (MessageList *message_list, const gchar *uid); void message_list_save_state (MessageList *message_list); +void message_list_sort_uids (MessageList *message_list, + GPtrArray *uids); + #define MESSAGE_LIST_LOCK(m, l) g_mutex_lock(((MessageList *)m)->l) #define MESSAGE_LIST_UNLOCK(m, l) g_mutex_unlock(((MessageList *)m)->l) |