[evolution/wip/webkit2] Change API of e_content_editor_get_content()



commit cb9a32ea2d5932870dd441a967094d055bdd97d0
Author: Milan Crha <mcrha redhat com>
Date:   Wed Jun 22 09:45:39 2016 +0200

    Change API of e_content_editor_get_content()

 composer/e-msg-composer.c                 |   34 ++++++++++++-----------------
 e-util/e-content-editor.c                 |   11 ++++++---
 e-util/e-content-editor.h                 |   11 +++------
 e-util/e-html-editor.c                    |    4 +-
 e-util/e-mail-signature-editor.c          |    2 +-
 e-util/test-html-editor-units-utils.c     |   12 +++++-----
 mail/e-mail-notes.c                       |   29 +++++++++++-------------
 modules/webkit-editor/e-webkit-editor.c   |   25 ++++++++++++--------
 plugins/external-editor/external-editor.c |    2 +-
 9 files changed, 63 insertions(+), 67 deletions(-)
---
diff --git a/composer/e-msg-composer.c b/composer/e-msg-composer.c
index 853ece1..b2a4819 100644
--- a/composer/e-msg-composer.c
+++ b/composer/e-msg-composer.c
@@ -1270,7 +1270,7 @@ composer_build_message (EMsgComposer *composer,
                        cnt_editor,
                        E_CONTENT_EDITOR_GET_TEXT_PLAIN |
                        E_CONTENT_EDITOR_GET_PROCESSED,
-                       NULL);
+                       NULL, NULL);
 
                g_byte_array_append (data, (guint8 *) text, strlen (text));
                g_free (text);
@@ -1334,19 +1334,15 @@ composer_build_message (EMsgComposer *composer,
        if ((flags & COMPOSER_FLAG_HTML_CONTENT) != 0 &&
            !(flags & COMPOSER_FLAG_SAVE_DRAFT)) {
                gchar *text;
-               guint count;
                gsize length;
                gboolean pre_encode;
                EHTMLEditor *editor;
                EContentEditor *cnt_editor;
-               EContentEditorInlineImages *inline_images;
+               GSList *inline_images_parts = NULL, *link;
 
                editor = e_msg_composer_get_editor (composer);
                cnt_editor = e_html_editor_get_content_editor (editor);
 
-               inline_images = g_new0 (EContentEditorInlineImages, 1);
-               inline_images->from_domain = (gchar *) from_domain;
-
                data = g_byte_array_new ();
                if ((flags & COMPOSER_FLAG_SAVE_DRAFT) != 0) {
                        /* X-Evolution-Format */
@@ -1361,14 +1357,15 @@ composer_build_message (EMsgComposer *composer,
                                cnt_editor,
                                E_CONTENT_EDITOR_GET_TEXT_HTML |
                                E_CONTENT_EDITOR_GET_INLINE_IMAGES,
-                               &inline_images);
-               } else
+                               from_domain, &inline_images_parts);
+               } else {
                        text = e_content_editor_get_content (
                                cnt_editor,
                                E_CONTENT_EDITOR_GET_TEXT_HTML |
                                E_CONTENT_EDITOR_GET_PROCESSED |
                                E_CONTENT_EDITOR_GET_INLINE_IMAGES,
-                               &inline_images);
+                               from_domain, &inline_images_parts);
+               }
 
                length = strlen (text);
                g_byte_array_append (data, (guint8 *) text, (guint) length);
@@ -1424,9 +1421,7 @@ composer_build_message (EMsgComposer *composer,
 
                /* If there are inlined images, construct a multipart/related
                 * containing the multipart/alternative and the images. */
-               count = g_list_length (inline_images->images);
-               if (count > 0) {
-                       guint ii;
+               if (inline_images_parts) {
                        CamelMultipart *html_with_images;
 
                        html_with_images = camel_multipart_new ();
@@ -1445,10 +1440,10 @@ composer_build_message (EMsgComposer *composer,
 
                        g_object_unref (body);
 
-                       for (ii = 0; ii < count; ii++) {
-                               CamelMimePart *part = g_list_nth_data (inline_images->images, ii);
-                               camel_multipart_add_part (
-                                       html_with_images, part);
+                       for (link = inline_images_parts; link; link = g_slist_next (link)) {
+                               CamelMimePart *part = link->data;
+
+                               camel_multipart_add_part (html_with_images, part);
                        }
 
                        context->top_level_part =
@@ -1457,8 +1452,7 @@ composer_build_message (EMsgComposer *composer,
                        context->top_level_part =
                                CAMEL_DATA_WRAPPER (body);
                }
-               g_list_free_full (inline_images->images, g_object_unref);
-               g_free (inline_images);
+               g_slist_free_full (inline_images_parts, g_object_unref);
        }
 
        /* If there are attachments, wrap what we've built so far
@@ -5289,7 +5283,7 @@ e_msg_composer_get_raw_message_text_without_signature (EMsgComposer *composer)
                E_CONTENT_EDITOR_GET_BODY |
                E_CONTENT_EDITOR_GET_TEXT_PLAIN |
                E_CONTENT_EDITOR_GET_EXCLUDE_SIGNATURE,
-               NULL);
+               NULL, NULL);
 
        return g_byte_array_new_take ((guint8 *) content, strlen (content));
 }
@@ -5315,7 +5309,7 @@ e_msg_composer_get_raw_message_text (EMsgComposer *composer)
                cnt_editor,
                E_CONTENT_EDITOR_GET_BODY |
                E_CONTENT_EDITOR_GET_TEXT_PLAIN,
-               NULL);
+               NULL, NULL);
 
        return g_byte_array_new_take ((guint8 *) content, strlen (content));
 }
diff --git a/e-util/e-content-editor.c b/e-util/e-content-editor.c
index b6b2075..11db68f 100644
--- a/e-util/e-content-editor.c
+++ b/e-util/e-content-editor.c
@@ -1303,19 +1303,22 @@ e_content_editor_insert_content (EContentEditor *editor,
 gchar *
 e_content_editor_get_content (EContentEditor *editor,
                               EContentEditorGetContentFlags flags,
-                              EContentEditorInlineImages **inline_images)
+                             const gchar *inline_images_from_domain,
+                             GSList **inline_images_parts /* newly created CamelMimePart * */)
 {
        EContentEditorInterface *iface;
 
        g_return_val_if_fail (E_IS_CONTENT_EDITOR (editor), NULL);
-       if ((flags & E_CONTENT_EDITOR_GET_INLINE_IMAGES))
-               g_return_val_if_fail (inline_images != NULL, NULL);
+       if ((flags & E_CONTENT_EDITOR_GET_INLINE_IMAGES)) {
+               g_return_val_if_fail (inline_images_from_domain != NULL, NULL);
+               g_return_val_if_fail (inline_images_parts != NULL, NULL);
+       }
 
        iface = E_CONTENT_EDITOR_GET_IFACE (editor);
        g_return_val_if_fail (iface != NULL, NULL);
        g_return_val_if_fail (iface->get_content != NULL, NULL);
 
-       return iface->get_content (editor, flags, inline_images);
+       return iface->get_content (editor, flags, inline_images_from_domain, inline_images_parts);
 }
 
 void
diff --git a/e-util/e-content-editor.h b/e-util/e-content-editor.h
index 3714476..47dc742 100644
--- a/e-util/e-content-editor.h
+++ b/e-util/e-content-editor.h
@@ -39,11 +39,6 @@ struct _EHTMLEditor;
 #define E_TYPE_CONTENT_EDITOR e_content_editor_get_type ()
 G_DECLARE_INTERFACE (EContentEditor, e_content_editor, E, CONTENT_EDITOR, GtkWidget)
 
-typedef struct {
-       const gchar *from_domain;
-       GList *images;
-} EContentEditorInlineImages;
-
 struct _EContentEditorInterface {
        GTypeInterface parent_interface;
 
@@ -56,7 +51,8 @@ struct _EContentEditorInterface {
 
        gchar *         (*get_content)                  (EContentEditor *editor,
                                                         EContentEditorGetContentFlags flags,
-                                                        EContentEditorInlineImages **inline_images);
+                                                        const gchar *inline_images_from_domain,
+                                                        GSList **inline_images_parts /* newly created 
CamelMimePart * */);
 
        void            (*insert_image)                 (EContentEditor *editor,
                                                         const gchar *uri);
@@ -524,7 +520,8 @@ void                e_content_editor_insert_content (EContentEditor *editor,
 
 gchar *                e_content_editor_get_content    (EContentEditor *editor,
                                                 EContentEditorGetContentFlags flags,
-                                                EContentEditorInlineImages **inline_images);
+                                                const gchar *inline_images_from_domain,
+                                                GSList **inline_images_parts /* newly created CamelMimePart 
* */);
 
 void            e_content_editor_insert_image_from_mime_part
                                                (EContentEditor *editor,
diff --git a/e-util/e-html-editor.c b/e-util/e-html-editor.c
index c2f495a..3af14ba 100644
--- a/e-util/e-html-editor.c
+++ b/e-util/e-html-editor.c
@@ -1242,13 +1242,13 @@ e_html_editor_save (EHTMLEditor *editor,
                        cnt_editor,
                        E_CONTENT_EDITOR_GET_TEXT_HTML |
                        E_CONTENT_EDITOR_GET_PROCESSED,
-                       NULL);
+                       NULL, NULL);
        else
                content = e_content_editor_get_content (
                        cnt_editor,
                        E_CONTENT_EDITOR_GET_TEXT_PLAIN |
                        E_CONTENT_EDITOR_GET_PROCESSED,
-                       NULL);
+                       NULL, NULL);
 
        if (!content || !*content) {
                g_set_error (
diff --git a/e-util/e-mail-signature-editor.c b/e-util/e-mail-signature-editor.c
index e24a418..1b0d489 100644
--- a/e-util/e-mail-signature-editor.c
+++ b/e-util/e-mail-signature-editor.c
@@ -853,7 +853,7 @@ e_mail_signature_editor_commit (EMailSignatureEditor *window,
                cnt_editor,
                E_CONTENT_EDITOR_GET_TEXT_HTML |
                E_CONTENT_EDITOR_GET_BODY,
-               NULL);
+               NULL, NULL);
 
        extension_name = E_SOURCE_EXTENSION_MAIL_SIGNATURE;
        extension = e_source_get_extension (source, extension_name);
diff --git a/e-util/test-html-editor-units-utils.c b/e-util/test-html-editor-units-utils.c
index 608aff7..aa9a247 100644
--- a/e-util/test-html-editor-units-utils.c
+++ b/e-util/test-html-editor-units-utils.c
@@ -42,8 +42,8 @@ undo_content_new (TestFixture *fixture)
        cnt_editor = e_html_editor_get_content_editor (fixture->editor);
 
        uc = g_new0 (UndoContent, 1);
-       uc->html = e_content_editor_get_content (cnt_editor, E_CONTENT_EDITOR_GET_PROCESSED | 
E_CONTENT_EDITOR_GET_TEXT_HTML, NULL);
-       uc->plain = e_content_editor_get_content (cnt_editor, E_CONTENT_EDITOR_GET_PROCESSED | 
E_CONTENT_EDITOR_GET_TEXT_PLAIN, NULL);
+       uc->html = e_content_editor_get_content (cnt_editor, E_CONTENT_EDITOR_GET_PROCESSED | 
E_CONTENT_EDITOR_GET_TEXT_HTML, NULL, NULL);
+       uc->plain = e_content_editor_get_content (cnt_editor, E_CONTENT_EDITOR_GET_PROCESSED | 
E_CONTENT_EDITOR_GET_TEXT_PLAIN, NULL, NULL);
 
        g_warn_if_fail (uc->html != NULL);
        g_warn_if_fail (uc->plain != NULL);
@@ -76,7 +76,7 @@ undo_content_test (TestFixture *fixture,
 
        cnt_editor = e_html_editor_get_content_editor (fixture->editor);
 
-       text = e_content_editor_get_content (cnt_editor, E_CONTENT_EDITOR_GET_PROCESSED | 
E_CONTENT_EDITOR_GET_TEXT_HTML, NULL);
+       text = e_content_editor_get_content (cnt_editor, E_CONTENT_EDITOR_GET_PROCESSED | 
E_CONTENT_EDITOR_GET_TEXT_HTML, NULL, NULL);
        g_return_val_if_fail (text != NULL, FALSE);
 
        if (!test_utils_html_equal (fixture, text, uc->html)) {
@@ -87,7 +87,7 @@ undo_content_test (TestFixture *fixture,
 
        g_free (text);
 
-       text = e_content_editor_get_content (cnt_editor, E_CONTENT_EDITOR_GET_PROCESSED | 
E_CONTENT_EDITOR_GET_TEXT_PLAIN, NULL);
+       text = e_content_editor_get_content (cnt_editor, E_CONTENT_EDITOR_GET_PROCESSED | 
E_CONTENT_EDITOR_GET_TEXT_PLAIN, NULL, NULL);
        g_return_val_if_fail (text != NULL, FALSE);
 
        if (!test_utils_html_equal (fixture, text, uc->plain)) {
@@ -738,7 +738,7 @@ test_utils_run_simple_test (TestFixture *fixture,
                return FALSE;
 
        if (expected_html) {
-               text = e_content_editor_get_content (cnt_editor, E_CONTENT_EDITOR_GET_PROCESSED | 
E_CONTENT_EDITOR_GET_TEXT_HTML, NULL);
+               text = e_content_editor_get_content (cnt_editor, E_CONTENT_EDITOR_GET_PROCESSED | 
E_CONTENT_EDITOR_GET_TEXT_HTML, NULL, NULL);
                g_return_val_if_fail (text != NULL, FALSE);
 
                if (!test_utils_html_equal (fixture, text, expected_html)) {
@@ -751,7 +751,7 @@ test_utils_run_simple_test (TestFixture *fixture,
        }
 
        if (expected_plain) {
-               text = e_content_editor_get_content (cnt_editor, E_CONTENT_EDITOR_GET_PROCESSED | 
E_CONTENT_EDITOR_GET_TEXT_PLAIN, NULL);
+               text = e_content_editor_get_content (cnt_editor, E_CONTENT_EDITOR_GET_PROCESSED | 
E_CONTENT_EDITOR_GET_TEXT_PLAIN, NULL, NULL);
                g_return_val_if_fail (text != NULL, FALSE);
 
                if (!test_utils_html_equal (fixture, text, expected_plain)) {
diff --git a/mail/e-mail-notes.c b/mail/e-mail-notes.c
index ac5ee43..0119edf 100644
--- a/mail/e-mail-notes.c
+++ b/mail/e-mail-notes.c
@@ -331,7 +331,7 @@ e_mail_notes_editor_encode_text_to_message (EMailNotesEditor *notes_editor)
                CamelMultipart *multipart_alternative;
                CamelMultipart *multipart_body;
                CamelMimePart *part;
-               EContentEditorInlineImages *inline_images = NULL;
+               GSList *inline_images_parts = NULL;
                gchar *text;
 
                multipart_alternative = camel_multipart_new ();
@@ -342,7 +342,7 @@ e_mail_notes_editor_encode_text_to_message (EMailNotesEditor *notes_editor)
                        cnt_editor,
                        E_CONTENT_EDITOR_GET_TEXT_PLAIN |
                        E_CONTENT_EDITOR_GET_PROCESSED,
-                       NULL);
+                       NULL, NULL);
 
                if (text && *text) {
                        part = camel_mime_part_new ();
@@ -356,14 +356,13 @@ e_mail_notes_editor_encode_text_to_message (EMailNotesEditor *notes_editor)
 
                g_free (text);
 
-               inline_images = g_new0 (EContentEditorInlineImages, 1);
-               inline_images->from_domain = (gchar *) g_get_host_name ();
-
                text = e_content_editor_get_content (
                        cnt_editor,
+                       E_CONTENT_EDITOR_GET_PROCESSED |
                        E_CONTENT_EDITOR_GET_TEXT_HTML |
-                       E_CONTENT_EDITOR_GET_PROCESSED,
-                       &inline_images);
+                       E_CONTENT_EDITOR_GET_INLINE_IMAGES,
+                       g_get_host_name (),
+                       &inline_images_parts);
 
                if (has_attachments && !has_text && (!text || !*text)) {
                        /* Text is required, thus if there are attachments,
@@ -381,15 +380,14 @@ e_mail_notes_editor_encode_text_to_message (EMailNotesEditor *notes_editor)
 
                        has_text = TRUE;
                } else {
-                       g_list_free_full (inline_images->images, g_object_unref);
-                       g_free (inline_images);
-                       inline_images = NULL;
+                       g_slist_free_full (inline_images_parts, g_object_unref);
+                       inline_images_parts = NULL;
                }
 
                g_free (text);
 
-               if (inline_images) {
-                       GList *link = inline_images->images;
+               if (inline_images_parts) {
+                       GSList *link;
 
                        multipart_body = camel_multipart_new ();
                        camel_data_wrapper_set_mime_type (CAMEL_DATA_WRAPPER (multipart_body), 
"multipart/related");
@@ -400,7 +398,7 @@ e_mail_notes_editor_encode_text_to_message (EMailNotesEditor *notes_editor)
                        camel_multipart_add_part (multipart_body, part);
                        g_object_unref (part);
 
-                       for (; link; link = g_list_next (link)) {
+                       for (link = inline_images_parts; link; link = g_slist_next (link)) {
                                CamelMimePart *part = link->data;
 
                                if (!part)
@@ -433,8 +431,7 @@ e_mail_notes_editor_encode_text_to_message (EMailNotesEditor *notes_editor)
 
                camel_medium_set_content (CAMEL_MEDIUM (message), CAMEL_DATA_WRAPPER (multipart_body));
 
-               g_list_free_full (inline_images->images, g_object_unref);
-               g_free (inline_images);
+               g_slist_free_full (inline_images_parts, g_object_unref);
                g_clear_object (&multipart_alternative);
                g_clear_object (&multipart_body);
        } else {
@@ -444,7 +441,7 @@ e_mail_notes_editor_encode_text_to_message (EMailNotesEditor *notes_editor)
                        cnt_editor,
                        E_CONTENT_EDITOR_GET_TEXT_PLAIN |
                        E_CONTENT_EDITOR_GET_PROCESSED,
-                       NULL);
+                       NULL, NULL);
 
                if (has_attachments && !has_text && (!text || !*text)) {
                        /* Text is required, thus if there are attachments,
diff --git a/modules/webkit-editor/e-webkit-editor.c b/modules/webkit-editor/e-webkit-editor.c
index c1eb292..e640054 100644
--- a/modules/webkit-editor/e-webkit-editor.c
+++ b/modules/webkit-editor/e-webkit-editor.c
@@ -1420,12 +1420,12 @@ out:
        return part;
 }
 
-static GList *
+static GSList *
 webkit_editor_get_parts_for_inline_images (GVariant *images)
 {
        const gchar *element_src, *name, *id;
        GVariantIter *iter;
-       GList *parts = NULL;
+       GSList *parts = NULL;
 
        g_variant_get (images, "asss", &iter);
        while (g_variant_iter_loop (iter, "&s&s&s", &element_src, &name, &id)) {
@@ -1433,17 +1433,18 @@ webkit_editor_get_parts_for_inline_images (GVariant *images)
 
                part = create_part_for_inline_image_from_element_data (
                        element_src, name, id);
-               parts = g_list_append (parts, part);
+               parts = g_slist_prepend (parts, part);
        }
        g_variant_iter_free (iter);
 
-       return parts;
+       return g_slist_reverse (parts);
 }
 
 static gchar *
 webkit_editor_get_content (EContentEditor *editor,
                            EContentEditorGetContentFlags flags,
-                           EContentEditorInlineImages **inline_images)
+                           const gchar *inline_images_from_domain,
+                          GSList **inline_images_parts)
 {
        EWebKitEditor *wk_editor;
        GVariant *result;
@@ -1474,7 +1475,7 @@ webkit_editor_get_content (EContentEditor *editor,
                g_variant_new (
                        "(tsi)",
                        current_page_id (wk_editor),
-                       inline_images ?  (*inline_images)->from_domain : "",
+                       inline_images_from_domain ? inline_images_from_domain : "",
                        (gint32) flags),
                G_DBUS_CALL_FLAGS_NONE,
                -1,
@@ -1488,12 +1489,16 @@ webkit_editor_get_content (EContentEditor *editor,
                        wk_editor, "DOMRemoveEmbeddedStyleSheet");
 
        if (result) {
-               GVariant *images;
-               gchar *value;
+               GVariant *images = NULL;
+               gchar *value = NULL;
 
                g_variant_get (result, "(sv)", &value, &images);
-               if (inline_images)
-                       (*inline_images)->images = webkit_editor_get_parts_for_inline_images (images);
+               if (inline_images_parts)
+                       *inline_images_parts = webkit_editor_get_parts_for_inline_images (images);
+
+               if (images)
+                       g_variant_unref (images);
+
                g_variant_unref (result);
 
                return value;
diff --git a/plugins/external-editor/external-editor.c b/plugins/external-editor/external-editor.c
index 6515fe2..f349b5f 100644
--- a/plugins/external-editor/external-editor.c
+++ b/plugins/external-editor/external-editor.c
@@ -283,7 +283,7 @@ external_editor_thread (gpointer user_data)
                        cnt_editor,
                        E_CONTENT_EDITOR_GET_TEXT_PLAIN |
                        E_CONTENT_EDITOR_GET_PROCESSED,
-                       NULL);
+                       NULL, NULL);
                if (content && *content)
                        g_file_set_contents (filename, content, strlen (content), NULL);
        } else {


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]