aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthew Barnes <mbarnes@redhat.com>2011-05-13 02:34:31 +0800
committerRodrigo Moya <rodrigo@gnome-db.org>2011-06-30 00:42:13 +0800
commit33abe3198aaabe7bdb271894e0492dd1ce71b785 (patch)
treec063cfaa0cef8d3396bb9caee5233d2926d71004
parenta28477a27c0a558ec6a736405c383e45e69a6e16 (diff)
downloadgsoc2013-evolution-33abe3198aaabe7bdb271894e0492dd1ce71b785.tar.gz
gsoc2013-evolution-33abe3198aaabe7bdb271894e0492dd1ce71b785.tar.zst
gsoc2013-evolution-33abe3198aaabe7bdb271894e0492dd1ce71b785.zip
Reimplement e_mail_reader_create_filter_from_selected().
Now uses camel_folder_get_message().
-rw-r--r--mail/e-mail-reader-utils.c105
1 files changed, 72 insertions, 33 deletions
diff --git a/mail/e-mail-reader-utils.c b/mail/e-mail-reader-utils.c
index 0311b3d429..7bb4fefab5 100644
--- a/mail/e-mail-reader-utils.c
+++ b/mail/e-mail-reader-utils.c
@@ -49,6 +49,8 @@ typedef struct _AsyncContext AsyncContext;
struct _AsyncContext {
EActivity *activity;
EMailReader *reader;
+ const gchar *filter_source;
+ gint filter_type;
};
static void
@@ -651,25 +653,54 @@ e_mail_reader_select_next_message (EMailReader *reader,
/* Helper for e_mail_reader_create_filter_from_selected() */
static void
mail_reader_create_filter_cb (CamelFolder *folder,
- const gchar *uid,
- CamelMimeMessage *message,
- gpointer user_data)
+ GAsyncResult *result,
+ AsyncContext *context)
{
- struct {
- EMailSession *session;
- const gchar *source;
- gint type;
- } *filter_data = user_data;
+ EMailBackend *backend;
+ EMailSession *session;
+ EAlertSink *alert_sink;
+ CamelMimeMessage *message;
+ GError *error = NULL;
- if (message != NULL)
- filter_gui_add_from_message (
- filter_data->session,
- message,
- filter_data->source,
- filter_data->type);
-
- g_object_unref (filter_data->session);
- g_free (filter_data);
+ alert_sink = e_activity_get_alert_sink (context->activity);
+
+ message = camel_folder_get_message_finish (folder, result, &error);
+
+ if (e_activity_handle_cancellation (context->activity, error)) {
+ g_warn_if_fail (message == NULL);
+ async_context_free (context);
+ g_error_free (error);
+ return;
+
+ } else if (error != NULL) {
+ g_warn_if_fail (message == NULL);
+ e_alert_submit (
+ alert_sink, "no-retrieve-message",
+ error->message, NULL);
+ async_context_free (context);
+ g_error_free (error);
+ return;
+ }
+
+ g_return_if_fail (CAMEL_IS_MIME_MESSAGE (message));
+
+ /* Finalize the activity here so we don't leave a message
+ * in the task bar while displaying the filter editor. */
+ e_activity_set_state (context->activity, E_ACTIVITY_COMPLETED);
+ g_object_unref (context->activity);
+ context->activity = NULL;
+
+ backend = e_mail_reader_get_backend (context->reader);
+ session = e_mail_backend_get_session (backend);
+
+ filter_gui_add_from_message (
+ session, message,
+ context->filter_source,
+ context->filter_type);
+
+ g_object_unref (message);
+
+ async_context_free (context);
}
void
@@ -677,22 +708,14 @@ e_mail_reader_create_filter_from_selected (EMailReader *reader,
gint filter_type)
{
EMailBackend *backend;
- EMailSession *session;
CamelFolder *folder;
const gchar *filter_source;
GPtrArray *uids;
- struct {
- EMailSession *session;
- const gchar *source;
- gint type;
- } *filter_data;
-
g_return_if_fail (E_IS_MAIL_READER (reader));
folder = e_mail_reader_get_folder (reader);
backend = e_mail_reader_get_backend (reader);
- session = e_mail_backend_get_session (backend);
if (em_utils_folder_is_sent (folder))
filter_source = E_FILTER_SOURCE_OUTGOING;
@@ -704,15 +727,31 @@ e_mail_reader_create_filter_from_selected (EMailReader *reader,
uids = e_mail_reader_get_selected_uids (reader);
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;
+ AsyncContext *context;
+ EAlertSink *alert_sink;
+ GCancellable *cancellable;
- mail_get_message (
- folder, uids->pdata[0],
- mail_reader_create_filter_cb,
- filter_data, mail_msg_unordered_push);
+ context = g_slice_new0 (AsyncContext);
+ context->activity = e_activity_new ();
+ context->reader = g_object_ref (reader);
+ context->filter_source = filter_source;
+ context->filter_type = filter_type;
+
+ alert_sink = e_mail_reader_get_alert_sink (reader);
+ e_activity_set_alert_sink (context->activity, alert_sink);
+
+ cancellable = camel_operation_new ();
+ e_activity_set_cancellable (context->activity, cancellable);
+
+ e_shell_backend_add_activity (
+ E_SHELL_BACKEND (backend), context->activity);
+
+ camel_folder_get_message (
+ folder, uids->pdata[0], G_PRIORITY_DEFAULT,
+ cancellable, (GAsyncReadyCallback)
+ mail_reader_create_filter_cb, context);
+
+ g_object_unref (cancellable);
}
em_utils_uids_free (uids);