[evolution] Make it possible to change theme for text-highlight module



commit 74e097a98a184f39825732ecd5f96a08dc36242b
Author: Milan Crha <mcrha redhat com>
Date:   Thu Jun 29 12:49:45 2017 +0200

    Make it possible to change theme for text-highlight module
    
    Since now, users can change theme being used by the text-highlight module,
    not being forced to use a hard-coded theme in the code. First of all,
    figure out which themes are installed. It's done with command:
    
       $ highlight --list-scripts=themes
    
    Pick one, say "editor-vim-dark" (supposing it's installed), and execute:
    
       $ gsettings set org.gnome.evolution.text-highlight theme edit-vim-dark
    
    And the next time the text-highlight will be called, like when changing the used
    format with right-click in the body->Format As->..., the changed theme will
    be used. In case the value being set in the GSettings is no longer valid,
    like when the theme is not available or had been uninstalled, there will be
    no formatting in the message content at all and evolution's console may
    contain an error message from highlight, like this one:
    
       highlight: cannot open themes/unknown.theme: No such file or directory

 data/CMakeLists.txt                                |    1 +
 ...g.gnome.evolution.text-highlight.gschema.xml.in |    9 +++++++++
 po/POTFILES.in                                     |    1 +
 .../e-mail-formatter-text-highlight.c              |   16 ++++++++++++++--
 4 files changed, 25 insertions(+), 2 deletions(-)
---
diff --git a/data/CMakeLists.txt b/data/CMakeLists.txt
index 7a49596..e41dddc 100644
--- a/data/CMakeLists.txt
+++ b/data/CMakeLists.txt
@@ -43,6 +43,7 @@ set(SCHEMAS
        org.gnome.evolution.shell.gschema.xml
        org.gnome.evolution.bogofilter.gschema.xml
        org.gnome.evolution.spamassassin.gschema.xml
+       org.gnome.evolution.text-highlight.gschema.xml
        org.gnome.evolution.plugin.attachment-reminder.gschema.xml
        org.gnome.evolution.plugin.autocontacts.gschema.xml
        org.gnome.evolution.plugin.email-custom-header.gschema.xml
diff --git a/data/org.gnome.evolution.text-highlight.gschema.xml.in 
b/data/org.gnome.evolution.text-highlight.gschema.xml.in
new file mode 100644
index 0000000..d37c83d
--- /dev/null
+++ b/data/org.gnome.evolution.text-highlight.gschema.xml.in
@@ -0,0 +1,9 @@
+<schemalist>
+  <schema gettext-domain="evolution" id="org.gnome.evolution.text-highlight" 
path="/org/gnome/evolution/text-highlight/">
+    <key name="theme" type="s">
+      <default>''</default>
+      <_summary>Theme name to use, defaults to 'bclear'</_summary>
+      <_description>Use 'highlight --list-scripts=themes' to get the list of installed themes and then the 
value to one of them. The change requires only re-format of the message part to take into effect, like using 
right-click->Format As->....</_description>
+    </key>
+  </schema>
+</schemalist>
diff --git a/po/POTFILES.in b/po/POTFILES.in
index acc3b3b..23058f7 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -21,6 +21,7 @@ data/org.gnome.evolution.plugin.publish-calendar.gschema.xml.in
 data/org.gnome.evolution.plugin.templates.gschema.xml.in
 data/org.gnome.evolution.shell.gschema.xml.in
 data/org.gnome.evolution.spamassassin.gschema.xml.in
+data/org.gnome.evolution.text-highlight.gschema.xml.in
 data/views/addressbook/galview.xml
 data/views/calendar/galview.xml
 data/views/mail/galview.xml
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 6edc291..a46a246 100644
--- a/src/modules/text-highlight/e-mail-formatter-text-highlight.c
+++ b/src/modules/text-highlight/e-mail-formatter-text-highlight.c
@@ -253,7 +253,7 @@ emfe_text_highlight_format (EMailFormatterExtension *extension,
                gint pipe_stdin, pipe_stdout;
                GPid pid;
                CamelDataWrapper *dw;
-               gchar *font_family, *font_size, *syntax;
+               gchar *font_family, *font_size, *syntax, *theme;
                PangoFontDescription *fd;
                GSettings *settings;
                gchar *font = NULL;
@@ -263,10 +263,10 @@ emfe_text_highlight_format (EMailFormatterExtension *extension,
                        NULL,   /* --font= */
                        NULL,   /* --font-size= */
                        NULL,   /* --syntax= */
+                       NULL,   /* --style= */
                        "--out-format=html",
                        "--include-style",
                        "--inline-css",
-                       "--style=bclear",
                        "--encoding=none",
                        "--failsafe",
                        NULL };
@@ -310,10 +310,21 @@ emfe_text_highlight_format (EMailFormatterExtension *extension,
                        "--font-size=%d",
                        pango_font_description_get_size (fd) / PANGO_SCALE);
 
+               settings = e_util_ref_settings ("org.gnome.evolution.text-highlight");
+               theme = g_settings_get_string (settings, "theme");
+               g_object_unref (settings);
+
+               if (!theme || !*theme) {
+                       g_free (theme);
+                       theme = g_strdup ("bclear");
+               }
+
                argv[1] = font_family;
                argv[2] = font_size;
                argv[3] = g_strdup_printf ("--syntax=%s", syntax);
+               argv[4] = g_strdup_printf ("--style=%s", theme);
                g_free (syntax);
+               g_free (theme);
 
                success = g_spawn_async_with_pipes (
                        NULL, (gchar **) argv, NULL, 0, NULL, NULL,
@@ -373,6 +384,7 @@ emfe_text_highlight_format (EMailFormatterExtension *extension,
                g_free (font_family);
                g_free (font_size);
                g_free ((gchar *) argv[3]);
+               g_free ((gchar *) argv[4]);
                pango_font_description_free (fd);
 
        } else {


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