From e5186dcba34847eb5ca915d142388fc98ca5d9ce Mon Sep 17 00:00:00 2001 From: Milan Crha Date: Tue, 19 Jun 2018 14:44:21 +0200 Subject: [PATCH] Make it possible to disable text-highlight module with a GSettings option Users can easily disable text-highlight module with command: $ gsettings set org.gnome.evolution.text-highlight enabled false to disable default processing through this module. It's still possible to manually format certain part with it using the 'Format as' context menu. --- ...me.evolution.text-highlight.gschema.xml.in | 4 ++ .../e-mail-display-popup-text-highlight.c | 25 ++++++++++- .../e-mail-formatter-text-highlight.c | 42 ++++++++++++++++++- 3 files changed, 68 insertions(+), 3 deletions(-) diff --git a/data/org.gnome.evolution.text-highlight.gschema.xml.in b/data/org.gnome.evolution.text-highlight.gschema.xml.in index a2938e6d11..c6be767c88 100644 --- a/data/org.gnome.evolution.text-highlight.gschema.xml.in +++ b/data/org.gnome.evolution.text-highlight.gschema.xml.in @@ -1,5 +1,9 @@ + + true + <_summary>Whether the text-highlight module is enabled + '' <_summary>Theme name to use, defaults to “bclear” diff --git a/src/modules/text-highlight/e-mail-display-popup-text-highlight.c b/src/modules/text-highlight/e-mail-display-popup-text-highlight.c index cbbab260a0..d1ab3211a0 100644 --- a/src/modules/text-highlight/e-mail-display-popup-text-highlight.c +++ b/src/modules/text-highlight/e-mail-display-popup-text-highlight.c @@ -149,6 +149,8 @@ reformat (GtkAction *old, query, g_strdup ("__formatas"), (gpointer) gtk_action_get_name (action)); g_hash_table_replace ( query, g_strdup ("mime_type"), (gpointer) "text/plain"); + g_hash_table_replace ( + query, g_strdup ("__force_highlight"), (gpointer) "true"); soup_uri_set_query_from_form (soup_uri, query); g_hash_table_destroy (query); @@ -276,6 +278,19 @@ create_group (EMailDisplayPopupExtension *extension) return group; } +static gboolean +emdp_text_highlight_is_enabled (void) +{ + GSettings *settings; + gboolean enabled; + + settings = e_util_ref_settings ("org.gnome.evolution.text-highlight"); + enabled = g_settings_get_boolean (settings, "enabled"); + g_object_unref (settings); + + return enabled; +} + static void update_actions (EMailDisplayPopupExtension *extension, const gchar *popup_document_uri) @@ -300,9 +315,15 @@ update_actions (EMailDisplayPopupExtension *extension, soup_uri = soup_uri_new (th_extension->document_uri); if (soup_uri && soup_uri->query) { GHashTable *query = soup_form_decode (soup_uri->query); - gchar *highlighter; + const gchar *highlighter; + + if (!emdp_text_highlight_is_enabled () && + g_strcmp0 (g_hash_table_lookup (query, "__force_highlight"), "true") != 0) { + highlighter = "txt"; + } else { + highlighter = g_hash_table_lookup (query, "__formatas"); + } - highlighter = g_hash_table_lookup (query, "__formatas"); if (highlighter && *highlighter) { GtkAction *action = gtk_action_group_get_action ( th_extension->action_group, highlighter); diff --git a/src/modules/text-highlight/e-mail-formatter-text-highlight.c b/src/modules/text-highlight/e-mail-formatter-text-highlight.c index 51d4dc2914..a89fd9f41d 100644 --- a/src/modules/text-highlight/e-mail-formatter-text-highlight.c +++ b/src/modules/text-highlight/e-mail-formatter-text-highlight.c @@ -54,6 +54,19 @@ G_DEFINE_DYNAMIC_TYPE ( e_mail_formatter_text_highlight, E_TYPE_MAIL_FORMATTER_EXTENSION) +static gboolean +emfe_text_highlight_formatter_is_enabled (void) +{ + GSettings *settings; + gboolean enabled; + + settings = e_util_ref_settings ("org.gnome.evolution.text-highlight"); + enabled = g_settings_get_boolean (settings, "enabled"); + g_object_unref (settings); + + return enabled; +} + static gchar * get_syntax (EMailPart *part, const gchar *uri) @@ -276,6 +289,33 @@ emfe_text_highlight_format (EMailFormatterExtension *extension, "--failsafe", NULL }; + if (!emfe_text_highlight_formatter_is_enabled ()) { + gboolean can_process = FALSE; + + if (context->uri) { + SoupURI *soup_uri; + + soup_uri = soup_uri_new (context->uri); + if (soup_uri) { + GHashTable *query; + + query = soup_form_decode (soup_uri->query); + can_process = query && g_strcmp0 (g_hash_table_lookup (query, "__force_highlight"), "true") == 0; + if (query) + g_hash_table_destroy (query); + soup_uri_free (soup_uri); + } + } + + if (!can_process) { + success = e_mail_formatter_format_as ( + formatter, context, part, stream, + "application/vnd.evolution.plaintext", + cancellable); + goto exit; + } + } + dw = camel_medium_get_content (CAMEL_MEDIUM (mime_part)); if (dw == NULL) goto exit; @@ -379,7 +419,7 @@ emfe_text_highlight_format (EMailFormatterExtension *extension, * for text/x-patch or application/php would show * an error, as there is no other handler registered * for these */ - e_mail_formatter_format_as ( + success = e_mail_formatter_format_as ( formatter, context, part, stream, "application/vnd.evolution.plaintext", cancellable);