From 2d2d30c05b8f54de94a89be3db54df024a11fc7e Mon Sep 17 00:00:00 2001 From: Matthew Barnes Date: Sun, 2 Jun 2013 09:23:58 -0400 Subject: Simplify em_utils_forward_message() arguments. Replace the EShell and CamelSession arguments with a single EMailBackend argument, from which both the EShell and CamelSession can be obtained. (cherry picked from commit 540acdbfa95d29a66ad94bad68222b5ae9c98720) Conflicts: mail/em-composer-utils.h modules/mail/e-mail-attachment-handler.c --- mail/em-composer-utils.c | 44 +++++++++++++++---------------- mail/em-composer-utils.h | 5 ++-- modules/mail/e-mail-attachment-handler.c | 45 +++++++++++++++----------------- 3 files changed, 44 insertions(+), 50 deletions(-) diff --git a/mail/em-composer-utils.c b/mail/em-composer-utils.c index a8a878e053..686b493333 100644 --- a/mail/em-composer-utils.c +++ b/mail/em-composer-utils.c @@ -1711,14 +1711,17 @@ setup_forward_attached_callbacks (EMsgComposer *composer, } static EMsgComposer * -forward_attached (EShell *shell, +forward_attached (EMailBackend *backend, CamelFolder *folder, GPtrArray *uids, CamelMimePart *part, gchar *subject) { + EShell *shell; EMsgComposer *composer; + shell = e_shell_backend_get_shell (E_SHELL_BACKEND (backend)); + composer = create_new_composer (shell, subject, folder); e_msg_composer_attach (composer, part); @@ -1739,7 +1742,6 @@ forward_attached_cb (GObject *source_object, gpointer user_data) { CamelFolder *folder; - EShell *shell; EMailBackend *backend; EActivity *activity; EAlertSink *alert_sink; @@ -1778,10 +1780,9 @@ forward_attached_cb (GObject *source_object, } backend = e_mail_reader_get_backend (async_context->reader); - shell = e_shell_backend_get_shell (E_SHELL_BACKEND (backend)); forward_attached ( - shell, folder, async_context->ptr_array, part, subject); + backend, folder, async_context->ptr_array, part, subject); e_activity_set_state (activity, E_ACTIVITY_COMPLETED); @@ -1793,14 +1794,15 @@ exit: } static EMsgComposer * -forward_non_attached (EShell *shell, - CamelSession *session, +forward_non_attached (EMailBackend *backend, CamelFolder *folder, const gchar *uid, CamelMimeMessage *message, EMailForwardStyle style) { EMsgComposer *composer = NULL; + EMailSession *session; + EShell *shell; gchar *text, *forward; guint32 validity_found = 0; guint32 flags; @@ -1810,9 +1812,13 @@ forward_non_attached (EShell *shell, if (style == E_MAIL_FORWARD_STYLE_QUOTED) flags |= E_MAIL_FORMATTER_QUOTE_FLAG_CITE; + session = e_mail_backend_get_session (backend); + shell = e_shell_backend_get_shell (E_SHELL_BACKEND (backend)); + forward = quoting_text (QUOTING_FORWARD); text = em_utils_message_to_html ( - session, message, forward, flags, NULL, NULL, &validity_found); + CAMEL_SESSION (session), message, + forward, flags, NULL, NULL, &validity_found); if (text != NULL) { CamelDataWrapper *content; @@ -1859,8 +1865,7 @@ forward_non_attached (EShell *shell, /** * em_utils_forward_message: - * @shell: an #EShell - * @session: a #CamelSession + * @backend: an #EMailBackend * @message: a #CamelMimeMessage to forward * @style: the forward style to use * @folder: a #CamelFolder, or %NULL @@ -1870,8 +1875,7 @@ forward_non_attached (EShell *shell, * for more details about forwarding styles. **/ EMsgComposer * -em_utils_forward_message (EShell *shell, - CamelSession *session, +em_utils_forward_message (EMailBackend *backend, CamelMimeMessage *message, EMailForwardStyle style, CamelFolder *folder, @@ -1881,8 +1885,7 @@ em_utils_forward_message (EShell *shell, gchar *subject; EMsgComposer *composer = NULL; - g_return_val_if_fail (E_IS_SHELL (shell), NULL); - g_return_val_if_fail (CAMEL_IS_SESSION (session), NULL); + g_return_val_if_fail (E_IS_MAIL_BACKEND (backend), NULL); g_return_val_if_fail (CAMEL_IS_MIME_MESSAGE (message), NULL); switch (style) { @@ -1892,7 +1895,7 @@ em_utils_forward_message (EShell *shell, subject = mail_tool_generate_forward_subject (message); composer = forward_attached ( - shell, NULL, NULL, part, subject); + backend, NULL, NULL, part, subject); g_object_unref (part); g_free (subject); @@ -1901,7 +1904,7 @@ em_utils_forward_message (EShell *shell, case E_MAIL_FORWARD_STYLE_INLINE: case E_MAIL_FORWARD_STYLE_QUOTED: composer = forward_non_attached ( - shell, session, folder, uid, message, style); + backend, folder, uid, message, style); break; } @@ -1914,9 +1917,7 @@ forward_got_messages_cb (GObject *source_object, gpointer user_data) { CamelFolder *folder; - EShell *shell; EMailBackend *backend; - EMailSession *session; EActivity *activity; EAlertSink *alert_sink; GHashTable *hash_table; @@ -1931,6 +1932,8 @@ forward_got_messages_cb (GObject *source_object, activity = async_context->activity; alert_sink = e_activity_get_alert_sink (activity); + backend = e_mail_reader_get_backend (async_context->reader); + hash_table = e_mail_folder_get_multiple_messages_finish ( folder, result, &local_error); @@ -1954,10 +1957,6 @@ forward_got_messages_cb (GObject *source_object, goto exit; } - backend = e_mail_reader_get_backend (async_context->reader); - session = e_mail_backend_get_session (backend); - shell = e_shell_backend_get_shell (E_SHELL_BACKEND (backend)); - /* Create a new composer window for each message. */ g_hash_table_iter_init (&iter, hash_table); @@ -1970,8 +1969,7 @@ forward_got_messages_cb (GObject *source_object, message = CAMEL_MIME_MESSAGE (value); em_utils_forward_message ( - shell, CAMEL_SESSION (session), - message, async_context->style, + backend, message, async_context->style, folder, message_uid); } diff --git a/mail/em-composer-utils.h b/mail/em-composer-utils.h index cda63d1458..fff33624e2 100644 --- a/mail/em-composer-utils.h +++ b/mail/em-composer-utils.h @@ -46,9 +46,8 @@ void em_utils_edit_messages (EMailReader *reader, CamelFolder *folder, GPtrArray *uids, gboolean replace); -EMsgComposer * em_utils_forward_message (EShell *shell, - CamelSession *session, - CamelMimeMessage *msg, +EMsgComposer * em_utils_forward_message (EMailBackend *backend, + CamelMimeMessage *message, EMailForwardStyle style, CamelFolder *folder, const gchar *uid); diff --git a/modules/mail/e-mail-attachment-handler.c b/modules/mail/e-mail-attachment-handler.c index e47d11678b..db94ce7f03 100644 --- a/modules/mail/e-mail-attachment-handler.c +++ b/modules/mail/e-mail-attachment-handler.c @@ -35,8 +35,7 @@ ((obj), E_TYPE_MAIL_ATTACHMENT_HANDLER, EMailAttachmentHandlerPrivate)) struct _EMailAttachmentHandlerPrivate { - EShell *shell; - EMailSession *session; + EMailBackend *backend; }; static gpointer parent_class; @@ -143,6 +142,8 @@ mail_attachment_handler_forward (GtkAction *action, EShellSettings *shell_settings; EMailForwardStyle style; CamelMimeMessage *message; + EShellBackend *shell_backend; + EShell *shell; const gchar *property_name; priv = E_MAIL_ATTACHMENT_HANDLER_GET_PRIVATE (handler); @@ -150,13 +151,14 @@ mail_attachment_handler_forward (GtkAction *action, message = mail_attachment_handler_get_selected_message (handler); g_return_if_fail (message != NULL); + shell_backend = E_SHELL_BACKEND (priv->backend); + shell = e_shell_backend_get_shell (shell_backend); + property_name = "mail-forward-style"; - shell_settings = e_shell_get_shell_settings (priv->shell); + shell_settings = e_shell_get_shell_settings (shell); style = e_shell_settings_get_int (shell_settings, property_name); - em_utils_forward_message ( - priv->shell, CAMEL_SESSION (priv->session), - message, style, NULL, NULL); + em_utils_forward_message (priv->backend, message, style, NULL, NULL); g_object_unref (message); } @@ -169,6 +171,8 @@ mail_attachment_handler_reply (EAttachmentHandler *handler, EShellSettings *shell_settings; EMailReplyStyle style; CamelMimeMessage *message; + EShellBackend *shell_backend; + EShell *shell; const gchar *property_name; priv = E_MAIL_ATTACHMENT_HANDLER_GET_PRIVATE (handler); @@ -176,13 +180,15 @@ mail_attachment_handler_reply (EAttachmentHandler *handler, message = mail_attachment_handler_get_selected_message (handler); g_return_if_fail (message != NULL); + shell_backend = E_SHELL_BACKEND (priv->backend); + shell = e_shell_backend_get_shell (shell_backend); + property_name = "mail-reply-style"; - shell_settings = e_shell_get_shell_settings (priv->shell); + shell_settings = e_shell_get_shell_settings (shell); style = e_shell_settings_get_int (shell_settings, property_name); em_utils_reply_to_message ( - priv->shell, message, - NULL, NULL, reply_type, style, NULL, NULL); + shell, message, NULL, NULL, reply_type, style, NULL, NULL); g_object_unref (message); } @@ -308,6 +314,7 @@ mail_attachment_handler_x_uid_list (EAttachmentView *view, CamelFolder *folder = NULL; EAttachment *attachment; EAttachmentStore *store; + EMailSession *session; GPtrArray *uids; const gchar *data; const gchar *cp, *end; @@ -356,10 +363,12 @@ mail_attachment_handler_x_uid_list (EAttachmentView *view, if (uids->len == 0) goto exit; + session = e_mail_backend_get_session (priv->backend); + /* The first string is the folder URI. */ /* FIXME Not passing a GCancellable here. */ folder = e_mail_session_uri_to_folder_sync ( - priv->session, data, 0, NULL, &local_error); + session, data, 0, NULL, &local_error); if (folder == NULL) goto exit; @@ -509,15 +518,7 @@ mail_attachment_handler_dispose (GObject *object) priv = E_MAIL_ATTACHMENT_HANDLER_GET_PRIVATE (object); - if (priv->shell != NULL) { - g_object_unref (priv->shell); - priv->shell = NULL; - } - - if (priv->session != NULL) { - g_object_unref (priv->session); - priv->session = NULL; - } + g_clear_object (&priv->backend); /* Chain up to parent's dispose() method. */ G_OBJECT_CLASS (parent_class)->dispose (object); @@ -531,7 +532,6 @@ mail_attachment_handler_constructed (GObject *object) EShellBackend *shell_backend; EAttachmentHandler *handler; EAttachmentView *view; - EMailSession *session; GtkActionGroup *action_group; GtkUIManager *ui_manager; GError *error = NULL; @@ -544,10 +544,7 @@ mail_attachment_handler_constructed (GObject *object) shell = e_shell_get_default (); shell_backend = e_shell_get_backend_by_name (shell, "mail"); - session = e_mail_backend_get_session (E_MAIL_BACKEND (shell_backend)); - - priv->shell = g_object_ref (shell); - priv->session = g_object_ref (session); + priv->backend = g_object_ref (shell_backend); view = e_attachment_handler_get_view (handler); -- cgit v1.2.3