Make last colors configurable using hidden prefs: tags bg/fg colors in
authorwwp <wwp@free.fr>
Fri, 9 Dec 2016 16:42:46 +0000 (17:42 +0100)
committerwwp <wwp@free.fr>
Fri, 9 Dec 2016 16:42:46 +0000 (17:42 +0100)
message view, default-to header field in compose view, and quicksearch
active + error.

src/compose.c
src/gtk/quicksearch.c
src/prefs_common.c
src/prefs_common.h
src/textview.c

index 21274bb..da8c9a0 100644 (file)
@@ -183,6 +183,20 @@ typedef enum {
 #define COMPOSE_DRAFT_TIMEOUT_UNSET -1
 #define COMPOSE_DRAFT_TIMEOUT_FORBIDDEN -2
 
+static GdkColor default_to_bgcolor = {
+       (gulong)0,
+       (gushort)0,
+       (gushort)0,
+       (gushort)0
+};
+
+static GdkColor default_to_color = {
+       (gulong)0,
+       (gushort)0,
+       (gushort)0,
+       (gushort)0
+};
+
 static GList *compose_list = NULL;
 static GSList *extra_headers = NULL;
 
@@ -2661,44 +2675,19 @@ void compose_entry_append(Compose *compose, const gchar *address,
 
 static void compose_entry_mark_default_to(Compose *compose, const gchar *mailto)
 {
-#if !GTK_CHECK_VERSION(3, 0, 0)
-       static GdkColor yellow;
-       static GdkColor black;
-       static gboolean yellow_initialised = FALSE;
-#else
-       static GdkColor yellow = { (guint32)0, (guint16)0xf5, (guint16)0xf6, (guint16)0xbe };
-       static GdkColor black = { (guint32)0, (guint16)0x0, (guint16)0x0, (guint16)0x0 };
-#endif
        GSList *h_list;
        GtkEntry *entry;
                
-#if !GTK_CHECK_VERSION(3, 0, 0)
-       if (!yellow_initialised) {
-               gdk_color_parse("#f5f6be", &yellow);
-               gdk_color_parse("#000000", &black);
-               yellow_initialised = gdk_colormap_alloc_color(
-                       gdk_colormap_get_system(), &yellow, FALSE, TRUE);
-               yellow_initialised &= gdk_colormap_alloc_color(
-                       gdk_colormap_get_system(), &black, FALSE, TRUE);
-       }
-#endif
-
        for (h_list = compose->header_list; h_list != NULL; h_list = h_list->next) {
                entry = GTK_ENTRY(((ComposeHeaderEntry *)h_list->data)->entry);
                if (gtk_entry_get_text(entry) && 
                    !g_utf8_collate(gtk_entry_get_text(entry), mailto)) {
-#if !GTK_CHECK_VERSION(3, 0, 0)
-                       if (yellow_initialised) {
-#endif
                                gtk_widget_modify_base(
                                        GTK_WIDGET(((ComposeHeaderEntry *)h_list->data)->entry),
-                                       GTK_STATE_NORMAL, &yellow);
+                                       GTK_STATE_NORMAL, &default_to_bgcolor);
                                gtk_widget_modify_text(
                                        GTK_WIDGET(((ComposeHeaderEntry *)h_list->data)->entry),
-                                       GTK_STATE_NORMAL, &black);
-#if !GTK_CHECK_VERSION(3, 0, 0)
-                       }
-#endif
+                                       GTK_STATE_NORMAL, &default_to_color);
                }
        }
 }
@@ -8103,6 +8092,11 @@ static Compose *compose_create(PrefsAccount *account,
                gtk_widget_show(window);
        }
        
+       gtkut_convert_int_to_gdk_color(prefs_common.default_to_bgcolor,
+                                          &default_to_bgcolor);
+       gtkut_convert_int_to_gdk_color(prefs_common.default_to_color,
+                                          &default_to_color);
+
        return compose;
 }
 
index 6f4dc00..4efbaf0 100644 (file)
@@ -91,6 +91,34 @@ struct _QuickSearch
        gboolean                         want_history;
 };
 
+static GdkColor qs_active_bgcolor = {
+       (gulong)0,
+       (gushort)0,
+       (gushort)0,
+       (gushort)0
+};
+
+static GdkColor qs_active_color = {
+       (gulong)0,
+       (gushort)0,
+       (gushort)0,
+       (gushort)0
+};
+
+static GdkColor qs_error_bgcolor = {
+       (gulong)0,
+       (gushort)0,
+       (gushort)0,
+       (gushort)0
+};
+
+static GdkColor qs_error_color = {
+       (gulong)0,
+       (gushort)0,
+       (gushort)0,
+       (gushort)0
+};
+
 void quicksearch_set_on_progress_cb(QuickSearch* search,
                gboolean (*cb)(gpointer data, guint at, guint matched, guint total), gpointer data)
 {
@@ -820,6 +848,15 @@ QuickSearch *quicksearch_new()
        
        update_extended_buttons(quicksearch);
 
+       gtkut_convert_int_to_gdk_color(prefs_common.qs_active_bgcolor,
+                                          &qs_active_bgcolor);
+       gtkut_convert_int_to_gdk_color(prefs_common.qs_active_color,
+                                          &qs_active_color);
+       gtkut_convert_int_to_gdk_color(prefs_common.qs_error_bgcolor,
+                                          &qs_error_bgcolor);
+       gtkut_convert_int_to_gdk_color(prefs_common.qs_error_color,
+                                          &qs_error_color);
+
        return quicksearch;
 }
 
@@ -917,35 +954,10 @@ gboolean quicksearch_has_sat_predicate(QuickSearch *quicksearch)
 
 static void quicksearch_set_active(QuickSearch *quicksearch, gboolean active)
 {
-#if !GTK_CHECK_VERSION(3, 0, 0)
-       static GdkColor yellow;
-       static GdkColor red;
-       static GdkColor black;
-       static gboolean colors_initialised = FALSE;
-#else
-       static GdkColor yellow = { (guint32)0, (guint16)0xf5, (guint16)0xf6, (guint16)0xbe };
-       static GdkColor red = { (guint32)0, (guint16)0xff, (guint16)0x70, (guint16)0x70 };
-       static GdkColor black = { (guint32)0, (guint16)0x0, (guint16)0x0, (guint16)0x0 };
-#endif
        gboolean error = FALSE;
 
-       
        quicksearch->active = active;
 
-#if !GTK_CHECK_VERSION(3, 0, 0)
-       if (!colors_initialised) {
-               gdk_color_parse("#f5f6be", &yellow);
-               gdk_color_parse("#000000", &black);
-               gdk_color_parse("#ff7070", &red);
-               colors_initialised = gdk_colormap_alloc_color(
-                       gdk_colormap_get_system(), &yellow, FALSE, TRUE);
-               colors_initialised &= gdk_colormap_alloc_color(
-                       gdk_colormap_get_system(), &black, FALSE, TRUE);
-               colors_initialised &= gdk_colormap_alloc_color(
-                       gdk_colormap_get_system(), &red, FALSE, TRUE);
-       }
-#endif
-
        if (active && 
                (prefs_common.summary_quicksearch_type == ADVANCED_SEARCH_EXTENDED
                 && !advsearch_has_proper_predicate(quicksearch->asearch)))
@@ -953,32 +965,20 @@ static void quicksearch_set_active(QuickSearch *quicksearch, gboolean active)
 
        if (active) {
                gtk_widget_set_sensitive(quicksearch->clear_search, TRUE);
-#if !GTK_CHECK_VERSION(3, 0, 0)
-               if (colors_initialised) {
-#endif
                        gtk_widget_modify_base(
                                gtk_bin_get_child(GTK_BIN((quicksearch->search_string_entry))),
-                               GTK_STATE_NORMAL, error ? &red : &yellow);
+                               GTK_STATE_NORMAL, error ? &qs_error_bgcolor : &qs_active_bgcolor);
                        gtk_widget_modify_text(
                                gtk_bin_get_child(GTK_BIN((quicksearch->search_string_entry))),
-                               GTK_STATE_NORMAL, &black);
-#if !GTK_CHECK_VERSION(3, 0, 0)
-               }
-#endif
+                               GTK_STATE_NORMAL, error ? &qs_error_color : &qs_active_color);
        } else {
                gtk_widget_set_sensitive(quicksearch->clear_search, FALSE);
-#if !GTK_CHECK_VERSION(3, 0, 0)
-               if (colors_initialised) {
-#endif
                        gtk_widget_modify_base(
                                gtk_bin_get_child(GTK_BIN((quicksearch->search_string_entry))),
                                GTK_STATE_NORMAL, NULL);
                        gtk_widget_modify_text(
                                gtk_bin_get_child(GTK_BIN((quicksearch->search_string_entry))),
                                GTK_STATE_NORMAL, NULL);
-#if !GTK_CHECK_VERSION(3, 0, 0)
-               }
-#endif
        }
 
        if (!active) {
index bf273a9..63e1816 100644 (file)
@@ -726,6 +726,23 @@ static PrefParam param[] = {
        {"recycle_quote_colors", "FALSE", &prefs_common.recycle_quote_colors,
         P_BOOL, NULL, NULL, NULL},
 
+       {"default_to_color", "#000000", &prefs_common.default_to_color, P_COLOR,
+        NULL, NULL, NULL},
+       {"default_to_bgcolor", "#f5f6be", &prefs_common.default_to_bgcolor, P_COLOR,
+        NULL, NULL, NULL},
+       {"tags_color", "#000000", &prefs_common.tags_color, P_COLOR,
+        NULL, NULL, NULL},
+       {"tags_bgcolor", "#f5f6be", &prefs_common.tags_bgcolor, P_COLOR,
+        NULL, NULL, NULL},
+       {"qs_active_color", "#000000", &prefs_common.qs_active_color, P_COLOR,
+        NULL, NULL, NULL},
+       {"qs_active_bgcolor", "#f5f6be", &prefs_common.qs_active_bgcolor, P_COLOR,
+        NULL, NULL, NULL},
+       {"qs_error_color", "#000000", &prefs_common.qs_error_color, P_COLOR,
+        NULL, NULL, NULL},
+       {"qs_error_bgcolor", "#ff7070", &prefs_common.qs_error_bgcolor, P_COLOR,
+        NULL, NULL, NULL},
+
        {"display_header_pane", "FALSE", &prefs_common.display_header_pane,
         P_BOOL, NULL, NULL, NULL},
        {"display_header", "TRUE", &prefs_common.display_header, P_BOOL,
index 533c0dd..58df319 100644 (file)
@@ -328,6 +328,14 @@ struct _PrefsCommon
        gulong signature_col;
        gulong emphasis_col;
        gboolean recycle_quote_colors;
+       gulong default_to_bgcolor;
+       gulong default_to_color;
+       gulong tags_bgcolor;
+       gulong tags_color;
+       gulong qs_active_bgcolor;
+       gulong qs_active_color;
+       gulong qs_error_bgcolor;
+       gulong qs_error_color;
        gboolean display_header_pane;
        gboolean display_header;
        gboolean display_xface;
index 916b8d2..b73071f 100644 (file)
@@ -123,6 +123,20 @@ static GdkColor diff_hunk_color = {
        (gushort)0
 };
 
+static GdkColor tags_bgcolor = {
+       (gulong)0,
+       (gushort)0,
+       (gushort)0,
+       (gushort)0
+};
+
+static GdkColor tags_color = {
+       (gulong)0,
+       (gushort)0,
+       (gushort)0,
+       (gushort)0
+};
+
 static GdkCursor *hand_cursor = NULL;
 static GdkCursor *text_cursor = NULL;
 static GdkCursor *watch_cursor= NULL;
@@ -401,26 +415,8 @@ static void textview_create_tags(GtkTextView *text, TextView *textview)
 {
        GtkTextBuffer *buffer;
        GtkTextTag *tag, *qtag;
-#if !GTK_CHECK_VERSION(3, 0, 0)
-       static GdkColor yellow, black;
-       static gboolean color_init = FALSE;
-#else
-       static GdkColor yellow = { (guint32)0, (guint16)0xf5, (guint16)0xf6, (guint16)0xbe };
-       static GdkColor black = { (guint32)0, (guint16)0x0, (guint16)0x0, (guint16)0x0 };
-#endif
        static PangoFontDescription *font_desc, *bold_font_desc;
        
-#if !GTK_CHECK_VERSION(3, 0, 0)
-       if (!color_init) {
-               gdk_color_parse("#f5f6be", &yellow);
-               gdk_color_parse("#000000", &black);
-               color_init = gdk_colormap_alloc_color(
-                       gdk_colormap_get_system(), &yellow, FALSE, TRUE);
-               color_init &= gdk_colormap_alloc_color(
-                       gdk_colormap_get_system(), &black, FALSE, TRUE);
-       }
-#endif
-
        if (!font_desc)
                font_desc = pango_font_description_from_string
                        (NORMAL_FONT);
@@ -488,8 +484,8 @@ static void textview_create_tags(GtkTextView *text, TextView *textview)
                                NULL);
        }
        gtk_text_buffer_create_tag(buffer, "tags",
-                       "foreground-gdk", &black,
-                       "paragraph-background-gdk", &yellow,
+                       "foreground-gdk", &tags_color,
+                       "paragraph-background-gdk", &tags_bgcolor,
                        NULL);
        gtk_text_buffer_create_tag(buffer, "emphasis",
                        "foreground-gdk", &emphasis_color,
@@ -565,6 +561,7 @@ static void textview_update_message_colors(TextView *textview)
        quote_colors[0] = quote_colors[1] = quote_colors[2] = black;
        uri_color = emphasis_color = signature_color = diff_added_color =
                diff_deleted_color = diff_hunk_color = black;
+       tags_bgcolor = tags_color = black;
 
        if (prefs_common.enable_color) {
                /* grab the quote colors, converting from an int to a GdkColor */
@@ -612,6 +609,11 @@ static void textview_update_message_colors(TextView *textview)
        CHANGE_TAG_COLOR("diff-add-file", &diff_added_color, NULL);
        CHANGE_TAG_COLOR("diff-del-file", &diff_deleted_color, NULL);
        CHANGE_TAG_COLOR("diff-hunk", &diff_hunk_color, NULL);
+
+       gtkut_convert_int_to_gdk_color(prefs_common.tags_bgcolor,
+                                          &tags_bgcolor);
+       gtkut_convert_int_to_gdk_color(prefs_common.tags_color,
+                                          &tags_color);
 }
 #undef CHANGE_TAG_COLOR