diff options
author | Matthew Barnes <mbarnes@redhat.com> | 2013-03-16 03:02:46 +0800 |
---|---|---|
committer | Matthew Barnes <mbarnes@redhat.com> | 2013-03-17 20:49:12 +0800 |
commit | c9f01692ea5affd0a4c7ff1b5e3ce82329ca5e2e (patch) | |
tree | dbe01fae6c08ed940acfbd7ab9806694e27327fc | |
parent | 7ec9a50ee085ea083e0424dbd7e117573cf4847a (diff) | |
download | gsoc2013-evolution-c9f01692ea5affd0a4c7ff1b5e3ce82329ca5e2e.tar.gz gsoc2013-evolution-c9f01692ea5affd0a4c7ff1b5e3ce82329ca5e2e.tar.zst gsoc2013-evolution-c9f01692ea5affd0a4c7ff1b5e3ce82329ca5e2e.zip |
Add e_msg_composer_ref_session().
Replaces e_msg_composer_get_session().
-rw-r--r-- | composer/e-composer-actions.c | 4 | ||||
-rw-r--r-- | composer/e-msg-composer.c | 50 | ||||
-rw-r--r-- | composer/e-msg-composer.h | 2 | ||||
-rw-r--r-- | mail/em-composer-utils.c | 9 |
4 files changed, 34 insertions, 31 deletions
diff --git a/composer/e-composer-actions.c b/composer/e-composer-actions.c index 1317775364..d085a3a751 100644 --- a/composer/e-composer-actions.c +++ b/composer/e-composer-actions.c @@ -245,7 +245,7 @@ action_send_cb (GtkAction *action, { CamelSession *session; - session = e_msg_composer_get_session (composer); + session = e_msg_composer_ref_session (composer); /* If we're online, send the message now. * Otherwise write the message to Outbox. */ @@ -258,6 +258,8 @@ action_send_cb (GtkAction *action, "mail-composer:saving-to-outbox", NULL); e_msg_composer_save_to_outbox (composer); } + + g_object_unref (session); } static void diff --git a/composer/e-msg-composer.c b/composer/e-msg-composer.c index 7ce38e85ff..eb6ed8a8e8 100644 --- a/composer/e-msg-composer.c +++ b/composer/e-msg-composer.c @@ -176,11 +176,12 @@ async_context_free (AsyncContext *context) * Return Value: The part in displayable html format. **/ static gchar * -emcu_part_to_html (CamelSession *session, +emcu_part_to_html (EMsgComposer *composer, CamelMimePart *part, gssize *len, GCancellable *cancellable) { + CamelSession *session; CamelStreamMem *mem; GByteArray *buf; gchar *text; @@ -195,6 +196,8 @@ emcu_part_to_html (CamelSession *session, shell = e_shell_get_default (); window = e_shell_get_active_window (shell); + session = e_msg_composer_ref_session (composer); + buf = g_byte_array_new (); mem = (CamelStreamMem *) camel_stream_mem_new (); camel_stream_mem_set_byte_array (mem, buf); @@ -234,6 +237,8 @@ emcu_part_to_html (CamelSession *session, *len = buf->len - 1; g_byte_array_free (buf, FALSE); + g_object_unref (session); + return text; } @@ -1078,7 +1083,6 @@ composer_build_message (EMsgComposer *composer, const gchar *organization; CamelMultipart *body = NULL; CamelContentType *type; - CamelSession *session; CamelStream *stream; CamelStream *mem_stream; CamelMimePart *part; @@ -1092,7 +1096,6 @@ composer_build_message (EMsgComposer *composer, table = e_msg_composer_get_header_table (composer); view = e_msg_composer_get_attachment_view (composer); store = e_attachment_view_get_store (view); - session = e_msg_composer_get_session (composer); registry = e_composer_header_table_get_registry (table); identity_uid = e_composer_header_table_get_identity_uid (table); @@ -1104,7 +1107,7 @@ composer_build_message (EMsgComposer *composer, context = g_slice_new0 (AsyncContext); context->source = source; /* takes the reference */ - context->session = g_object_ref (session); + context->session = e_msg_composer_ref_session (composer); context->from = e_msg_composer_get_from (composer); if (flags & COMPOSER_FLAG_PGP_SIGN) @@ -2660,12 +2663,9 @@ handle_multipart_signed (EMsgComposer *composer, CamelContentType *content_type; CamelDataWrapper *content; CamelMimePart *mime_part; - CamelSession *session; GtkToggleAction *action = NULL; const gchar *protocol; - session = e_msg_composer_get_session (composer); - content = CAMEL_DATA_WRAPPER (multipart); content_type = camel_data_wrapper_get_mime_type_field (content); protocol = camel_content_type_param (content_type, "protocol"); @@ -2726,8 +2726,9 @@ handle_multipart_signed (EMsgComposer *composer, gssize length; html = emcu_part_to_html ( - session, mime_part, &length, cancellable); + composer, mime_part, &length, cancellable); e_msg_composer_set_pending_body (composer, html, length); + } else { e_msg_composer_attach (composer, mime_part); } @@ -2761,12 +2762,13 @@ handle_multipart_encrypted (EMsgComposer *composer, if (action) gtk_toggle_action_set_active (action, TRUE); - session = e_msg_composer_get_session (composer); + session = e_msg_composer_ref_session (composer); cipher = camel_gpg_context_new (session); mime_part = camel_mime_part_new (); valid = camel_cipher_context_decrypt_sync ( cipher, multipart, mime_part, cancellable, NULL); g_object_unref (cipher); + g_object_unref (session); if (valid == NULL) return; @@ -2814,8 +2816,9 @@ handle_multipart_encrypted (EMsgComposer *composer, gssize length; html = emcu_part_to_html ( - session, mime_part, &length, cancellable); + composer, mime_part, &length, cancellable); e_msg_composer_set_pending_body (composer, html, length); + } else { e_msg_composer_attach (composer, mime_part); } @@ -2831,11 +2834,8 @@ handle_multipart_alternative (EMsgComposer *composer, { /* Find the text/html part and set the composer body to it's contents */ CamelMimePart *text_part = NULL; - CamelSession *session; gint i, nparts; - session = e_msg_composer_get_session (composer); - nparts = camel_multipart_get_number (multipart); for (i = 0; i < nparts; i++) { @@ -2895,7 +2895,7 @@ handle_multipart_alternative (EMsgComposer *composer, gssize length; html = emcu_part_to_html ( - session, text_part, &length, cancellable); + composer, text_part, &length, cancellable); e_msg_composer_set_pending_body (composer, html, length); } } @@ -2906,11 +2906,8 @@ handle_multipart (EMsgComposer *composer, GCancellable *cancellable, gint depth) { - CamelSession *session; gint i, nparts; - session = e_msg_composer_get_session (composer); - nparts = camel_multipart_get_number (multipart); for (i = 0; i < nparts; i++) { @@ -2963,13 +2960,15 @@ handle_multipart (EMsgComposer *composer, /* Since the first part is not multipart/alternative, * this must be the body. */ html = emcu_part_to_html ( - session, mime_part, &length, cancellable); + composer, mime_part, &length, cancellable); e_msg_composer_set_pending_body (composer, html, length); + } else if (camel_mime_part_get_content_id (mime_part) || camel_mime_part_get_content_location (mime_part)) { /* special in-line attachment */ e_msg_composer_add_inline_image_from_mime_part ( composer, mime_part); + } else { /* normal attachment */ e_msg_composer_attach (composer, mime_part); @@ -3074,7 +3073,6 @@ e_msg_composer_new_with_message (EShell *shell, CamelContentType *content_type; struct _camel_header_raw *headers; CamelDataWrapper *content; - CamelSession *session; EMsgComposer *composer; EMsgComposerPrivate *priv; EComposerHeaderTable *table; @@ -3101,7 +3099,6 @@ e_msg_composer_new_with_message (EShell *shell, composer = e_msg_composer_new (shell); priv = E_MSG_COMPOSER_GET_PRIVATE (composer); - session = e_msg_composer_get_session (composer); table = e_msg_composer_get_header_table (composer); registry = e_composer_header_table_get_registry (table); @@ -3345,7 +3342,7 @@ e_msg_composer_new_with_message (EShell *shell, } html = emcu_part_to_html ( - session, CAMEL_MIME_PART (message), + composer, CAMEL_MIME_PART (message), &length, cancellable); e_msg_composer_set_pending_body (composer, html, length); } @@ -3404,16 +3401,19 @@ e_msg_composer_new_redirect (EShell *shell, } /** - * e_msg_composer_get_session: + * e_msg_composer_ref_session: * @composer: an #EMsgComposer * * Returns the mail module's global #CamelSession instance. Calling * this function will load the mail module if it isn't already loaded. * + * The returned #CamelSession is referenced for thread-safety and must + * be unreferenced with g_object_unref() when finished with it. + * * Returns: the mail module's #CamelSession **/ CamelSession * -e_msg_composer_get_session (EMsgComposer *composer) +e_msg_composer_ref_session (EMsgComposer *composer) { EShell *shell; EShellBackend *shell_backend; @@ -3427,10 +3427,6 @@ e_msg_composer_get_session (EMsgComposer *composer) g_object_get (shell_backend, "session", &session, NULL); g_return_val_if_fail (CAMEL_IS_SESSION (session), NULL); - /* FIXME Drop the new reference for backward-compatibility. - * Rename this function to e_msg_composer_ref_session(). */ - g_object_unref (session); - return session; } diff --git a/composer/e-msg-composer.h b/composer/e-msg-composer.h index 941845af70..28c189a377 100644 --- a/composer/e-msg-composer.h +++ b/composer/e-msg-composer.h @@ -95,7 +95,7 @@ EMsgComposer * e_msg_composer_new_redirect (EShell *shell, GCancellable *cancellable); EFocusTracker * e_msg_composer_get_focus_tracker (EMsgComposer *composer); -CamelSession * e_msg_composer_get_session (EMsgComposer *composer); +CamelSession * e_msg_composer_ref_session (EMsgComposer *composer); EShell * e_msg_composer_get_shell (EMsgComposer *composer); EWebViewGtkHTML * e_msg_composer_get_web_view (EMsgComposer *composer); diff --git a/mail/em-composer-utils.c b/mail/em-composer-utils.c index 515f27885c..c9bdaabe79 100644 --- a/mail/em-composer-utils.c +++ b/mail/em-composer-utils.c @@ -694,7 +694,6 @@ composer_save_to_drafts_cleanup (CamelFolder *drafts_folder, GCancellable *cancellable; GError *error = NULL; - session = e_msg_composer_get_session (context->composer); alert_sink = e_activity_get_alert_sink (context->activity); cancellable = e_activity_get_cancellable (context->activity); @@ -720,12 +719,16 @@ composer_save_to_drafts_cleanup (CamelFolder *drafts_folder, return; } + session = e_msg_composer_ref_session (context->composer); + /* Mark the previously saved draft message for deletion. * Note: This is just a nice-to-have; ignore failures. */ e_mail_session_handle_draft_headers ( E_MAIL_SESSION (session), context->message, G_PRIORITY_DEFAULT, cancellable, (GAsyncReadyCallback) composer_save_to_drafts_complete, context); + + g_object_unref (session); } static void @@ -2875,7 +2878,7 @@ composer_set_body (EMsgComposer *composer, gboolean start_bottom, has_body_text = FALSE; guint32 validity_found = 0; - session = e_msg_composer_get_session (composer); + session = e_msg_composer_ref_session (composer); settings = g_settings_new ("org.gnome.evolution.mail"); @@ -2943,6 +2946,8 @@ composer_set_body (EMsgComposer *composer, } g_object_unref (settings); + + g_object_unref (session); } gchar * |