diff options
author | Matthew Barnes <mbarnes@redhat.com> | 2011-05-13 03:32:33 +0800 |
---|---|---|
committer | Matthew Barnes <mbarnes@redhat.com> | 2011-05-13 06:24:41 +0800 |
commit | 366dacefa0a59c66320f65f19796eb30ad23f255 (patch) | |
tree | b5e559fc920513222c45002a836ece4fa9c87632 /mail | |
parent | c082e5843416aae0002251640e2f72327fd014d0 (diff) | |
download | gsoc2013-evolution-366dacefa0a59c66320f65f19796eb30ad23f255.tar.gz gsoc2013-evolution-366dacefa0a59c66320f65f19796eb30ad23f255.tar.zst gsoc2013-evolution-366dacefa0a59c66320f65f19796eb30ad23f255.zip |
Add e_mail_reader_new_activity().
Configuring and submitting an EActivity for every mail operation is
getting tedious. This function helps reduce boilerplate code by:
* Creating a new EActivity instance.
* Installing an EAlertSink using e_mail_reader_get_alert_sink().
* Installing a GCancellable (which is really a CamelOperation).
* Submitting the activity via e_shell_backend_add_activity().
I'm considering adding a similar function (or class method) for
EShellView. Not sure yet...
Diffstat (limited to 'mail')
-rw-r--r-- | mail/e-mail-reader-utils.c | 56 | ||||
-rw-r--r-- | mail/e-mail-reader.c | 41 | ||||
-rw-r--r-- | mail/e-mail-reader.h | 1 | ||||
-rw-r--r-- | mail/em-composer-utils.c | 32 |
4 files changed, 54 insertions, 76 deletions
diff --git a/mail/e-mail-reader-utils.c b/mail/e-mail-reader-utils.c index 6544f1f9da..1da1a65084 100644 --- a/mail/e-mail-reader-utils.c +++ b/mail/e-mail-reader-utils.c @@ -453,9 +453,9 @@ mail_reader_remove_duplicates_cb (CamelFolder *folder, void e_mail_reader_remove_duplicates (EMailReader *reader) { + EActivity *activity; AsyncContext *context; GCancellable *cancellable; - EMailBackend *backend; CamelFolder *folder; GPtrArray *uids; @@ -471,25 +471,19 @@ e_mail_reader_remove_duplicates (EMailReader *reader) /* Find duplicate messages asynchronously. */ + activity = e_mail_reader_new_activity (reader); + cancellable = e_activity_get_cancellable (activity); + context = g_slice_new0 (AsyncContext); - context->activity = e_activity_new (); + context->activity = activity; context->reader = g_object_ref (reader); - cancellable = camel_operation_new (); - e_activity_set_cancellable (context->activity, cancellable); - - backend = e_mail_reader_get_backend (reader); - e_shell_backend_add_activity ( - E_SHELL_BACKEND (backend), context->activity); - e_mail_folder_find_duplicate_messages ( folder, uids, G_PRIORITY_DEFAULT, cancellable, (GAsyncReadyCallback) mail_reader_remove_duplicates_cb, context); - g_object_unref (cancellable); - g_ptr_array_unref (uids); } @@ -711,7 +705,6 @@ void e_mail_reader_create_filter_from_selected (EMailReader *reader, gint filter_type) { - EMailBackend *backend; CamelFolder *folder; const gchar *filter_source; GPtrArray *uids; @@ -719,7 +712,6 @@ e_mail_reader_create_filter_from_selected (EMailReader *reader, g_return_if_fail (E_IS_MAIL_READER (reader)); folder = e_mail_reader_get_folder (reader); - backend = e_mail_reader_get_backend (reader); if (em_utils_folder_is_sent (folder)) filter_source = E_FILTER_SOURCE_OUTGOING; @@ -731,31 +723,23 @@ e_mail_reader_create_filter_from_selected (EMailReader *reader, uids = e_mail_reader_get_selected_uids (reader); if (uids->len == 1) { + EActivity *activity; AsyncContext *context; - EAlertSink *alert_sink; GCancellable *cancellable; + activity = e_mail_reader_new_activity (reader); + cancellable = e_activity_get_cancellable (activity); + context = g_slice_new0 (AsyncContext); - context->activity = e_activity_new (); + context->activity = activity; 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); @@ -818,43 +802,33 @@ void e_mail_reader_create_vfolder_from_selected (EMailReader *reader, gint vfolder_type) { - EMailBackend *backend; CamelFolder *folder; GPtrArray *uids; g_return_if_fail (E_IS_MAIL_READER (reader)); 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) { + EActivity *activity; AsyncContext *context; - EAlertSink *alert_sink; GCancellable *cancellable; + activity = e_mail_reader_new_activity (reader); + cancellable = e_activity_get_cancellable (activity); + context = g_slice_new0 (AsyncContext); - context->activity = e_activity_new (); + context->activity = activity; context->folder = g_object_ref (folder); context->reader = g_object_ref (reader); context->filter_type = vfolder_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_vfolder_cb, context); - - g_object_unref (cancellable); } em_utils_uids_free (uids); diff --git a/mail/e-mail-reader.c b/mail/e-mail-reader.c index 8cca498aec..85d623ddde 100644 --- a/mail/e-mail-reader.c +++ b/mail/e-mail-reader.c @@ -2556,7 +2556,6 @@ mail_reader_message_selected_timeout_cb (EMailReader *reader) GtkWidget *message_list; EWebView *web_view; CamelFolder *folder; - EMailBackend *backend; const gchar *cursor_uid; const gchar *format_uid; @@ -2564,7 +2563,6 @@ mail_reader_message_selected_timeout_cb (EMailReader *reader) folder = e_mail_reader_get_folder (reader); - backend = e_mail_reader_get_backend (reader); formatter = e_mail_reader_get_formatter (reader); message_list = e_mail_reader_get_message_list (reader); @@ -2601,14 +2599,12 @@ mail_reader_message_selected_timeout_cb (EMailReader *reader) #endif g_free (string); - activity = e_activity_new (); - - cancellable = camel_operation_new (); - e_activity_set_cancellable (activity, cancellable); + activity = e_mail_reader_new_activity (reader); + cancellable = e_activity_get_cancellable (activity); closure = g_slice_new0 (EMailReaderClosure); + closure->activity = activity; closure->reader = g_object_ref (reader); - closure->activity = g_object_ref (activity); closure->message_uid = g_strdup (cursor_uid); camel_folder_get_message ( @@ -2616,14 +2612,9 @@ mail_reader_message_selected_timeout_cb (EMailReader *reader) cancellable, (GAsyncReadyCallback) mail_reader_message_loaded_cb, closure); - e_shell_backend_add_activity ( - E_SHELL_BACKEND (backend), activity); - if (priv->retrieving_message != NULL) g_object_unref (priv->retrieving_message); - priv->retrieving_message = cancellable; - - g_object_unref (activity); + priv->retrieving_message = g_object_ref (cancellable); } } else { /* FIXME Need to pass a GCancellable. */ @@ -3742,7 +3733,31 @@ e_mail_reader_check_state (EMailReader *reader) em_utils_uids_free (uids); return state; +} + +EActivity * +e_mail_reader_new_activity (EMailReader *reader) +{ + EActivity *activity; + EMailBackend *backend; + EAlertSink *alert_sink; + GCancellable *cancellable; + + g_return_val_if_fail (E_IS_MAIL_READER (reader), NULL); + + activity = e_activity_new (); + + alert_sink = e_mail_reader_get_alert_sink (reader); + e_activity_set_alert_sink (activity, alert_sink); + + cancellable = camel_operation_new (); + e_activity_set_cancellable (activity, cancellable); + g_object_unref (cancellable); + + backend = e_mail_reader_get_backend (reader); + e_shell_backend_add_activity (E_SHELL_BACKEND (backend), activity); + return activity; } void diff --git a/mail/e-mail-reader.h b/mail/e-mail-reader.h index 9c5da8fcd8..0e874603c4 100644 --- a/mail/e-mail-reader.h +++ b/mail/e-mail-reader.h @@ -115,6 +115,7 @@ void e_mail_reader_init (EMailReader *reader, gboolean connect_signals); void e_mail_reader_changed (EMailReader *reader); guint32 e_mail_reader_check_state (EMailReader *reader); +EActivity * e_mail_reader_new_activity (EMailReader *reader); void e_mail_reader_update_actions (EMailReader *reader, guint32 state); GtkAction * e_mail_reader_get_action (EMailReader *reader, diff --git a/mail/em-composer-utils.c b/mail/em-composer-utils.c index c91870ff5b..98e24ac8a2 100644 --- a/mail/em-composer-utils.c +++ b/mail/em-composer-utils.c @@ -1314,33 +1314,27 @@ em_utils_edit_messages (EMailReader *reader, GPtrArray *uids, gboolean replace) { + EActivity *activity; AsyncContext *context; GCancellable *cancellable; - EMailBackend *backend; g_return_if_fail (E_IS_MAIL_READER (reader)); g_return_if_fail (CAMEL_IS_FOLDER (folder)); g_return_if_fail (uids != NULL); + activity = e_mail_reader_new_activity (reader); + cancellable = e_activity_get_cancellable (activity); + context = g_slice_new0 (AsyncContext); - context->activity = e_activity_new (); + context->activity = activity; context->reader = g_object_ref (reader); context->ptr_array = g_ptr_array_ref (uids); context->replace = replace; - cancellable = camel_operation_new (); - e_activity_set_cancellable (context->activity, cancellable); - - backend = e_mail_reader_get_backend (reader); - e_shell_backend_add_activity ( - E_SHELL_BACKEND (backend), context->activity); - e_mail_folder_get_multiple_messages ( folder, uids, G_PRIORITY_DEFAULT, cancellable, (GAsyncReadyCallback) edit_messages_cb, context); - - g_object_unref (cancellable); } static void @@ -1681,27 +1675,23 @@ em_utils_forward_messages (EMailReader *reader, GPtrArray *uids, EMailForwardStyle style) { + EActivity *activity; AsyncContext *context; GCancellable *cancellable; - EMailBackend *backend; g_return_if_fail (E_IS_MAIL_READER (reader)); g_return_if_fail (CAMEL_IS_FOLDER (folder)); g_return_if_fail (uids != NULL); + activity = e_mail_reader_new_activity (reader); + cancellable = e_activity_get_cancellable (activity); + context = g_slice_new0 (AsyncContext); - context->activity = e_activity_new (); + context->activity = activity; context->reader = g_object_ref (reader); context->ptr_array = g_ptr_array_ref (uids); context->style = style; - cancellable = camel_operation_new (); - e_activity_set_cancellable (context->activity, cancellable); - - backend = e_mail_reader_get_backend (reader); - e_shell_backend_add_activity ( - E_SHELL_BACKEND (backend), context->activity); - switch (style) { case E_MAIL_FORWARD_STYLE_ATTACHED: e_mail_folder_build_attachment ( @@ -1721,8 +1711,6 @@ em_utils_forward_messages (EMailReader *reader, default: g_warn_if_reached (); } - - g_object_unref (cancellable); } /* Redirecting messages... */ |