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.
This commit is contained in:
Milan Crha
2018-06-19 14:44:21 +02:00
parent 48670a187f
commit e5186dcba3
3 changed files with 68 additions and 3 deletions

View File

@ -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);

View File

@ -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);