[evolution/wip/webkit2] Plain text signature is opened as an HTML one



commit 9f525223b1013aa5fac5dcfe5bfc10e11a359174
Author: Tomas Popela <tpopela redhat com>
Date:   Tue May 31 09:46:01 2016 +0200

    Plain text signature is opened as an HTML one
    
    After the commit cca2aa2 signatures are always saved in HTML. Remember the
    editor mode to be able to switch to the right one after editing the signature
    again.
    
    Also force the font in the preview to be monospaced for the signatures that were
    saved in the plain text mode.

 e-util/e-mail-signature-editor.c                   |   12 ++++++-
 e-util/e-mail-signature-preview.c                  |   29 -----------------
 .../e-html-editor-view-dom-functions.c             |   16 +++++++++
 web-extensions/e-web-extension.c                   |   33 +++++++++++--------
 4 files changed, 45 insertions(+), 45 deletions(-)
---
diff --git a/e-util/e-mail-signature-editor.c b/e-util/e-mail-signature-editor.c
index b75b07d..e24a418 100644
--- a/e-util/e-mail-signature-editor.c
+++ b/e-util/e-mail-signature-editor.c
@@ -147,13 +147,21 @@ mail_signature_editor_loaded_cb (GObject *object,
        cnt_editor = e_html_editor_get_content_editor (editor);
        e_content_editor_set_html_mode (cnt_editor, is_html);
 
-       if (is_html)
+       if (is_html) {
+               if (strstr (contents, "data-evo-signature-plain-text-mode")) {
+                       EContentEditorContentFlags flags;
+
+                       flags = e_content_editor_get_current_content_flags (cnt_editor);
+                       flags |= E_CONTENT_EDITOR_MESSAGE_DRAFT;
+
+                       e_content_editor_set_html_mode (cnt_editor, TRUE);
+               }
                e_content_editor_insert_content (
                        cnt_editor,
                        contents,
                        E_CONTENT_EDITOR_INSERT_TEXT_HTML |
                        E_CONTENT_EDITOR_INSERT_REPLACE_ALL);
-       else
+       } else
                e_content_editor_insert_content (
                        cnt_editor,
                        contents,
diff --git a/e-util/e-mail-signature-preview.c b/e-util/e-mail-signature-preview.c
index d511ab8..d8e4553 100644
--- a/e-util/e-mail-signature-preview.c
+++ b/e-util/e-mail-signature-preview.c
@@ -56,31 +56,6 @@ G_DEFINE_TYPE (
        E_TYPE_WEB_VIEW)
 
 static void
-signature_preview_load_changed_cb (WebKitWebView *web_view,
-                                   WebKitLoadEvent load_event)
-{
-       GDBusProxy *web_extension;
-
-       if (load_event != WEBKIT_LOAD_FINISHED)
-               return;
-
-       web_extension = e_web_view_get_web_extension_proxy (E_WEB_VIEW (web_view));
-       if (web_extension) {
-               g_dbus_proxy_call (
-                       web_extension,
-                       "ReplaceLocalImageLinks",
-                       g_variant_new (
-                               "(t)",
-                               webkit_web_view_get_page_id (web_view)),
-                       G_DBUS_CALL_FLAGS_NONE,
-                       -1,
-                       NULL,
-                       NULL,
-                       NULL);
-       }
-}
-
-static void
 mail_signature_preview_load_cb (ESource *source,
                                 GAsyncResult *result,
                                 EMailSignaturePreview *preview)
@@ -329,10 +304,6 @@ static void
 e_mail_signature_preview_init (EMailSignaturePreview *preview)
 {
        preview->priv = E_MAIL_SIGNATURE_PREVIEW_GET_PRIVATE (preview);
-
-       g_signal_connect (
-               preview, "load-changed",
-               G_CALLBACK (signature_preview_load_changed_cb), NULL);
 }
 
 GtkWidget *
diff --git a/modules/webkit-content-editor/web-extension/e-html-editor-view-dom-functions.c 
b/modules/webkit-content-editor/web-extension/e-html-editor-view-dom-functions.c
index d0e1600..1359942 100644
--- a/modules/webkit-content-editor/web-extension/e-html-editor-view-dom-functions.c
+++ b/modules/webkit-content-editor/web-extension/e-html-editor-view-dom-functions.c
@@ -7349,10 +7349,26 @@ dom_process_content_for_draft (WebKitDOMDocument *document,
 
        if (only_inner_body) {
                WebKitDOMElement *body;
+               WebKitDOMNode *first_child;
 
                body = webkit_dom_element_query_selector (
                        WEBKIT_DOM_ELEMENT (document_element_clone), "body", NULL);
+
+               first_child = webkit_dom_node_get_first_child (WEBKIT_DOM_NODE (body));
+
+               if (!e_html_editor_web_extension_get_html_mode (extension))
+                       webkit_dom_element_set_attribute (
+                               WEBKIT_DOM_ELEMENT (first_child),
+                               "data-evo-signature-plain-text-mode",
+                               "",
+                               NULL);
+
                content = webkit_dom_element_get_inner_html (body);
+
+               if (!e_html_editor_web_extension_get_html_mode (extension))
+                       webkit_dom_element_remove_attribute (
+                               WEBKIT_DOM_ELEMENT (first_child),
+                               "data-evo-signature-plain-text-mode");
        } else
                content = webkit_dom_element_get_outer_html (
                        WEBKIT_DOM_ELEMENT (document_element_clone));
diff --git a/web-extensions/e-web-extension.c b/web-extensions/e-web-extension.c
index 62758fe..b0ebdb9 100644
--- a/web-extensions/e-web-extension.c
+++ b/web-extensions/e-web-extension.c
@@ -72,9 +72,6 @@ static const char introspection_xml[] =
 "    <signal name='HeadersCollapsed'>"
 "      <arg type='b' name='expanded' direction='out'/>"
 "    </signal>"
-"    <method name='ReplaceLocalImageLinks'>"
-"      <arg type='t' name='page_id' direction='in'/>"
-"    </method>"
 "    <method name='DocumentHasSelection'>"
 "      <arg type='t' name='page_id' direction='in'/>"
 "      <arg type='b' name='has_selection' direction='out'/>"
@@ -337,17 +334,6 @@ handle_method_call (GDBusConnection *connection,
                }
 
                g_dbus_method_invocation_return_value (invocation, NULL);
-       } else if (g_strcmp0 (method_name, "ReplaceLocalImageLinks") == 0) {
-               g_variant_get (parameters, "(t)", &page_id);
-               web_page = get_webkit_web_page_or_return_dbus_error (
-                       invocation, web_extension, page_id);
-               if (!web_page)
-                       return;
-
-               document = webkit_web_page_get_dom_document (web_page);
-               e_dom_utils_replace_local_image_links (document);
-
-               g_dbus_method_invocation_return_value (invocation, NULL);
        } else if (g_strcmp0 (method_name, "DocumentHasSelection") == 0) {
                gboolean has_selection;
 
@@ -764,6 +750,25 @@ static void
 web_page_document_loaded_cb (WebKitWebPage *web_page,
                              gpointer user_data)
 {
+       WebKitDOMDocument *document;
+
+       document = webkit_web_page_get_dom_document (web_page);
+
+       e_dom_utils_replace_local_image_links (document);
+
+       if ((webkit_dom_document_query_selector (
+               document, "[data-evo-signature-plain-text-mode]", NULL))) {
+
+               WebKitDOMHTMLElement *body;
+
+               body = webkit_dom_document_get_body (document);
+
+               webkit_dom_element_set_attribute (
+                       WEBKIT_DOM_ELEMENT (body),
+                       "style",
+                       "font-family: Monospace;",
+                       NULL);
+       }
 }
 
 static void


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