[evolution/wip/webkit2] Add an option to choose which content editor implementation is preferred



commit 9704f017203809941fca100400636766266c6086
Author: Milan Crha <mcrha redhat com>
Date:   Wed Jun 8 23:57:48 2016 +0200

    Add an option to choose which content editor implementation is preferred

 data/org.gnome.evolution.mail.gschema.xml.in       |    5 ++
 e-util/e-content-editor.h                          |    2 +
 e-util/e-html-editor-private.h                     |    3 +-
 e-util/e-html-editor.c                             |   64 +++++++++++++++++---
 e-util/e-html-editor.h                             |    1 +
 .../e-webkit-editor-extension.c                    |    4 +-
 6 files changed, 68 insertions(+), 11 deletions(-)
---
diff --git a/data/org.gnome.evolution.mail.gschema.xml.in b/data/org.gnome.evolution.mail.gschema.xml.in
index 7b90aa0..66bb9cb 100644
--- a/data/org.gnome.evolution.mail.gschema.xml.in
+++ b/data/org.gnome.evolution.mail.gschema.xml.in
@@ -40,6 +40,11 @@
       <_summary>Default charset in which to compose messages</_summary>
       <_description>Default charset in which to compose messages. Uses UTF-8, if not set.</_description>
     </key>
+    <key name="composer-editor" type="s">
+      <default>''</default>
+      <_summary>Name of the editor to prefer in the message composer</_summary>
+      <_description>If the name doesn't correspond to any known editor, then the built-in WebKit editor is 
used.</_description>
+    </key>
     <key name="composer-gallery-path" type="s">
       <default>''</default>
       <_summary>Path where picture gallery should search for its content</_summary>
diff --git a/e-util/e-content-editor.h b/e-util/e-content-editor.h
index 94a5ddd..fbd4dd5 100644
--- a/e-util/e-content-editor.h
+++ b/e-util/e-content-editor.h
@@ -30,6 +30,8 @@
 #include <e-util/e-emoticon.h>
 #include <e-util/e-spell-checker.h>
 
+#define DEFAULT_CONTENT_EDITOR_NAME "WebKit"
+
 G_BEGIN_DECLS
 
 #define E_TYPE_CONTENT_EDITOR e_content_editor_get_type ()
diff --git a/e-util/e-html-editor-private.h b/e-util/e-html-editor-private.h
index 46a1e14..d201214 100644
--- a/e-util/e-html-editor-private.h
+++ b/e-util/e-html-editor-private.h
@@ -83,7 +83,8 @@ struct _EHTMLEditorPrivate {
        GtkWidget *style_combo_box;
        GtkWidget *scrolled_window;
 
-       GList *content_editors;
+       GHashTable *content_editors;
+       EContentEditor *use_content_editor;
 
        EContentEditorNodeFlags node_flags;
 
diff --git a/e-util/e-html-editor.c b/e-util/e-html-editor.c
index 8474c31..48b24b8 100644
--- a/e-util/e-html-editor.c
+++ b/e-util/e-html-editor.c
@@ -33,6 +33,7 @@
 #include "e-alert-sink.h"
 #include "e-html-editor-private.h"
 #include "e-content-editor.h"
+#include "e-misc-utils.h"
 
 #define E_HTML_EDITOR_GET_PRIVATE(obj) \
        (G_TYPE_INSTANCE_GET_PRIVATE \
@@ -742,6 +743,17 @@ html_editor_dispose (GObject *object)
 }
 
 static void
+html_editor_finalize (GObject *object)
+{
+       EHTMLEditor *editor = E_HTML_EDITOR (object);
+
+       g_hash_table_destroy (editor->priv->content_editors);
+
+       /* Chain up to parent's method. */
+       G_OBJECT_CLASS (e_html_editor_parent_class)->finalize (object);
+}
+
+static void
 html_editor_submit_alert (EAlertSink *alert_sink,
                           EAlert *alert)
 {
@@ -787,6 +799,7 @@ e_html_editor_class_init (EHTMLEditorClass *class)
        object_class->get_property = html_editor_get_property;
        object_class->constructed = html_editor_constructed;
        object_class->dispose = html_editor_dispose;
+       object_class->finalize = html_editor_finalize;
 
        widget_class = GTK_WIDGET_CLASS (class);
        widget_class->parent_set = html_editor_parent_changed;
@@ -851,7 +864,7 @@ e_html_editor_init (EHTMLEditor *editor)
        priv->language_actions = gtk_action_group_new ("language");
        priv->spell_check_actions = gtk_action_group_new ("spell-check");
        priv->suggestion_actions = gtk_action_group_new ("suggestion");
-       priv->content_editors = NULL;
+       priv->content_editors = g_hash_table_new_full (camel_strcase_hash, camel_strcase_equal, g_free, NULL);
 
        filename = html_editor_find_ui_file ("e-html-editor-manager.ui");
        if (!gtk_ui_manager_add_ui_from_file (priv->manager, filename, &error)) {
@@ -885,23 +898,58 @@ e_html_editor_get_content_editor (EHTMLEditor *editor)
 {
        g_return_val_if_fail (E_IS_HTML_EDITOR (editor), NULL);
 
-       if (!editor->priv->content_editors)
-               return NULL;
+       if (!editor->priv->use_content_editor) {
+               GSettings *settings;
+               gchar *name;
+
+               if (!g_hash_table_size (editor->priv->content_editors))
+                       return NULL;
+
+               settings = e_util_ref_settings ("org.gnome.evolution.mail");
+               name = g_settings_get_string (settings, "composer-editor");
+               g_clear_object (&settings);
+
+               if (name)
+                       editor->priv->use_content_editor = g_hash_table_lookup 
(editor->priv->content_editors, name);
 
-       return editor->priv->content_editors->data;
+               g_free (name);
+
+               if (!editor->priv->use_content_editor)
+                       editor->priv->use_content_editor = g_hash_table_lookup 
(editor->priv->content_editors, DEFAULT_CONTENT_EDITOR_NAME);
+
+               if (!editor->priv->use_content_editor) {
+                       GHashTableIter iter;
+                       gpointer key, value;
+
+                       g_hash_table_iter_init (&iter, editor->priv->content_editors);
+                       if (g_hash_table_iter_next (&iter, &key, &value)) {
+                               editor->priv->use_content_editor = value;
+                       }
+               }
+       }
+
+       return editor->priv->use_content_editor;
 }
 
 void
 e_html_editor_register_content_editor (EHTMLEditor *editor,
+                                      const gchar *name,
                                        EContentEditor *cnt_editor)
 {
+       EContentEditor *already_taken;
+
        g_return_if_fail (E_IS_HTML_EDITOR (editor));
+       g_return_if_fail (name != NULL);
        g_return_if_fail (E_IS_CONTENT_EDITOR (cnt_editor));
 
-       /* FIXME XXX */
-       /* Insert the content editors base on some preferences, so the first
-        * one is the most preferable */
-       editor->priv->content_editors = g_list_append (editor->priv->content_editors, cnt_editor);
+       already_taken = g_hash_table_lookup (editor->priv->content_editors, name);
+
+       if (already_taken) {
+               g_warning ("%s: Cannot register %s with name '%s', because it's already taken by %s",
+                       G_STRFUNC, G_OBJECT_TYPE_NAME (cnt_editor), name, G_OBJECT_TYPE_NAME (already_taken));
+       } else {
+               g_hash_table_insert (editor->priv->content_editors, g_strdup (name), cnt_editor);
+       }
 }
 
 /**
diff --git a/e-util/e-html-editor.h b/e-util/e-html-editor.h
index 884d552..1546dd9 100644
--- a/e-util/e-html-editor.h
+++ b/e-util/e-html-editor.h
@@ -76,6 +76,7 @@ EContentEditor *
                                                (EHTMLEditor *editor);
 void           e_html_editor_register_content_editor
                                                (EHTMLEditor *editor,
+                                                const gchar *name,
                                                 EContentEditor *cnt_editor);
 GtkBuilder *   e_html_editor_get_builder       (EHTMLEditor *editor);
 GtkUIManager * e_html_editor_get_ui_manager    (EHTMLEditor *editor);
diff --git a/modules/webkit-content-editor/e-webkit-editor-extension.c 
b/modules/webkit-content-editor/e-webkit-editor-extension.c
index 6ef7059..9d5876c 100644
--- a/modules/webkit-content-editor/e-webkit-editor-extension.c
+++ b/modules/webkit-content-editor/e-webkit-editor-extension.c
@@ -56,8 +56,8 @@ webkit_editor_extension_constructed (GObject *object)
        priv = E_WEBKIT_EDITOR_EXTENSION_GET_PRIVATE (object);
        extensible = e_extension_get_extensible (E_EXTENSION (object));
 
-       e_html_editor_register_content_editor (
-               E_HTML_EDITOR (extensible), E_CONTENT_EDITOR (priv->wk_editor));
+       e_html_editor_register_content_editor (E_HTML_EDITOR (extensible),
+               DEFAULT_CONTENT_EDITOR_NAME, E_CONTENT_EDITOR (priv->wk_editor));
 }
 
 static void


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