Blame SOURCES/0256-gui-replace-gtk_widget_override-functions.patch

28bab8
From 4c0f1e7f4cd136ef515529df9330989f398ed6a1 Mon Sep 17 00:00:00 2001
28bab8
From: Martin Kutlak <mkutlak@redhat.com>
28bab8
Date: Thu, 8 Jun 2017 12:06:40 +0200
28bab8
Subject: [PATCH] gui: replace gtk_widget_override functions
28bab8
28bab8
gtk_widget_override_{font, color} functions were deprecated in version 3.16.
28bab8
28bab8
Elements should be styled with CSS.
28bab8
28bab8
https://developer.gnome.org/gtk3/stable/GtkWidget.html#gtk-widget-override-color
28bab8
28bab8
Signed-off-by: Martin Kutlak <mkutlak@redhat.com>
28bab8
---
28bab8
 src/gtk-helpers/event_config_dialog.c | 17 +++++----
28bab8
 src/gui-wizard-gtk/wizard.c           | 55 +++++++++++++++------------
28bab8
 2 files changed, 41 insertions(+), 31 deletions(-)
28bab8
28bab8
diff --git a/src/gtk-helpers/event_config_dialog.c b/src/gtk-helpers/event_config_dialog.c
28bab8
index 421a156..029e459 100644
28bab8
--- a/src/gtk-helpers/event_config_dialog.c
28bab8
+++ b/src/gtk-helpers/event_config_dialog.c
28bab8
@@ -292,13 +292,16 @@ config_dialog_t *create_event_config_dialog_content(event_config_t *event, GtkWi
28bab8
         GtkWidget *keyring_warn_lbl =
28bab8
         gtk_label_new(
28bab8
           _("Secret Service is not available, your settings won't be saved!"));
28bab8
-        static const GdkRGBA red = {
28bab8
-            .red   = 1.0,
28bab8
-            .green = 0.0,
28bab8
-            .blue  = 0.0,
28bab8
-            .alpha = 1.0,
28bab8
-        };
28bab8
-        gtk_widget_override_color(keyring_warn_lbl, GTK_STATE_FLAG_NORMAL, &red;;
28bab8
+        gtk_widget_set_name(keyring_warn_lbl, "keyring_warn_lbl");
28bab8
+
28bab8
+        GtkCssProvider *g_provider = gtk_css_provider_new();
28bab8
+        gtk_style_context_add_provider_for_screen(gdk_screen_get_default(),
28bab8
+                                                  GTK_STYLE_PROVIDER(g_provider),
28bab8
+                                                  GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
28bab8
+        const gchar *data = "#keyring_warn_lbl {color: rgba(100%, 0%, 0%, 1);}";
28bab8
+        gtk_css_provider_load_from_data(g_provider, data, -1, NULL);
28bab8
+        g_object_unref (g_provider);
28bab8
+
28bab8
         gtk_box_pack_start(GTK_BOX(content), keyring_warn_lbl, false, false, 0);
28bab8
     }
28bab8
 
28bab8
diff --git a/src/gui-wizard-gtk/wizard.c b/src/gui-wizard-gtk/wizard.c
28bab8
index 634a508..e19f790 100644
28bab8
--- a/src/gui-wizard-gtk/wizard.c
28bab8
+++ b/src/gui-wizard-gtk/wizard.c
28bab8
@@ -61,6 +61,8 @@ static guint g_event_source_id = 0;
28bab8
 
28bab8
 static bool g_expert_mode;
28bab8
 
28bab8
+static GtkCssProvider *g_provider = NULL;
28bab8
+
28bab8
 static GtkNotebook *g_assistant;
28bab8
 static GtkWindow *g_wnd_assistant;
28bab8
 static GtkBox *g_box_assistant;
28bab8
@@ -172,7 +174,6 @@ enum
28bab8
 };
28bab8
 
28bab8
 static GtkBuilder *g_builder;
28bab8
-static PangoFontDescription *g_monospace_font;
28bab8
 
28bab8
 /* THE PAGE FLOW
28bab8
  * page_0: introduction/summary
28bab8
@@ -294,6 +295,20 @@ static GtkBuilder *make_builder()
28bab8
     return builder;
28bab8
 }
28bab8
 
28bab8
+static void load_css_style()
28bab8
+{
28bab8
+    g_provider = gtk_css_provider_new();
28bab8
+    gtk_style_context_add_provider_for_screen(gdk_screen_get_default(),
28bab8
+                                              GTK_STYLE_PROVIDER(g_provider),
28bab8
+                                              GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
28bab8
+    const gchar *data = "#green_color {color: rgba(0%, 50%, 0%, 1);}\
28bab8
+                         #red_color {color: rgba(100%, 0%, 0%, 1);}\
28bab8
+                         #tev, #g_tv_event_log {font-family: monospace;}\
28bab8
+                         #g_eb_comment {color: #CC3333;}";
28bab8
+    gtk_css_provider_load_from_data(g_provider, data, -1, NULL);
28bab8
+    g_object_unref (g_provider);
28bab8
+}
28bab8
+
28bab8
 static void label_wrapper(GtkWidget *widget, gpointer data_unused)
28bab8
 {
28bab8
     if (GTK_IS_CONTAINER(widget))
28bab8
@@ -1061,6 +1076,9 @@ static event_gui_data_t *add_event_buttons(GtkBox *box,
28bab8
                 char *event_name,
28bab8
                 GCallback func)
28bab8
 {
28bab8
+    if (g_provider == NULL)
28bab8
+        load_css_style();
28bab8
+
28bab8
     //log_info("removing all buttons from box %p", box);
28bab8
     gtk_container_foreach(GTK_CONTAINER(box), &remove_child_widget, NULL);
28bab8
     g_list_foreach(*p_event_list, (GFunc)free_event_gui_data_t, NULL);
28bab8
@@ -1155,21 +1173,8 @@ static event_gui_data_t *add_event_buttons(GtkBox *box,
28bab8
             GtkWidget *child = gtk_bin_get_child(GTK_BIN(button));
28bab8
             if (child)
28bab8
             {
28bab8
-                static const GdkRGBA red = {
28bab8
-                    .red   = 1.0,
28bab8
-                    .green = 0.0,
28bab8
-                    .blue  = 0.0,
28bab8
-                    .alpha = 1.0,
28bab8
-                };
28bab8
-                static const GdkRGBA green = {
28bab8
-                    .red   = 0.0,
28bab8
-                    .green = 0.5,
28bab8
-                    .blue  = 0.0,
28bab8
-                    .alpha = 1.0,
28bab8
-                };
28bab8
-                const GdkRGBA *color = (green_choice ? &green : &red;;
28bab8
-                //gtk_widget_modify_text(button, GTK_STATE_NORMAL, color);
28bab8
-                gtk_widget_override_color(child, GTK_STATE_FLAG_NORMAL, color);
28bab8
+                const char *child_name = (green_choice ? "green_color" : "red_color");
28bab8
+                gtk_widget_set_name(child, child_name);
28bab8
             }
28bab8
         }
28bab8
 
28bab8
@@ -1321,6 +1326,9 @@ static void remove_tabs_from_notebook(GtkNotebook *notebook)
28bab8
 
28bab8
 static void append_item_to_ls_details(gpointer name, gpointer value, gpointer data)
28bab8
 {
28bab8
+    if (g_provider == NULL)
28bab8
+        load_css_style();
28bab8
+
28bab8
     problem_item *item = (problem_item*)value;
28bab8
     struct cd_stats *stats = data;
28bab8
     GtkTreeIter iter;
28bab8
@@ -1335,11 +1343,11 @@ static void append_item_to_ls_details(gpointer name, gpointer value, gpointer da
28bab8
         {
28bab8
             GtkWidget *tab_lbl = gtk_label_new((char *)name);
28bab8
             GtkWidget *tev = gtk_text_view_new();
28bab8
+            gtk_widget_set_name(GTK_WIDGET(tev), "tev");
28bab8
 
28bab8
             if (strcmp(name, FILENAME_COMMENT) == 0 || strcmp(name, FILENAME_REASON) == 0)
28bab8
                 gtk_text_view_set_wrap_mode(GTK_TEXT_VIEW(tev), GTK_WRAP_WORD);
28bab8
 
28bab8
-            gtk_widget_override_font(GTK_WIDGET(tev), g_monospace_font);
28bab8
             load_text_to_text_view(GTK_TEXT_VIEW(tev), (char *)name);
28bab8
             /* init searching */
28bab8
             GtkTextBuffer *buf = gtk_text_view_get_buffer(GTK_TEXT_VIEW(tev));
28bab8
@@ -3503,6 +3511,9 @@ static void add_pages(void)
28bab8
 {
28bab8
     g_builder = make_builder();
28bab8
 
28bab8
+    if (g_provider == NULL)
28bab8
+        load_css_style();
28bab8
+
28bab8
     int i;
28bab8
     int page_no = 0;
28bab8
     for (i = 0; page_names[i] != NULL; i++)
28bab8
@@ -3549,7 +3560,9 @@ static void add_pages(void)
28bab8
 
28bab8
     gtk_widget_set_no_show_all(GTK_WIDGET(g_spinner_event_log), true);
28bab8
 
28bab8
-    gtk_widget_override_font(GTK_WIDGET(g_tv_event_log), g_monospace_font);
28bab8
+    gtk_widget_set_name(GTK_WIDGET(g_tv_event_log), "g_tv_event_log");
28bab8
+    gtk_widget_set_name(GTK_WIDGET(g_eb_comment), "g_eb_comment");
28bab8
+
28bab8
     fix_all_wrapped_labels(GTK_WIDGET(g_assistant));
28bab8
 
28bab8
     g_signal_connect(g_cb_no_comment, "toggled", G_CALLBACK(on_no_comment_toggled), NULL);
28bab8
@@ -3557,10 +3570,6 @@ static void add_pages(void)
28bab8
     g_signal_connect(g_rb_forbidden_words, "toggled", G_CALLBACK(on_forbidden_words_toggled), NULL);
28bab8
     g_signal_connect(g_rb_custom_search, "toggled", G_CALLBACK(on_custom_search_toggled), NULL);
28bab8
 
28bab8
-    /* Set color of the comment evenbox */
28bab8
-    GdkRGBA color;
28bab8
-    gdk_rgba_parse(&color, "#CC3333");
28bab8
-    gtk_widget_override_color(GTK_WIDGET(g_eb_comment), GTK_STATE_FLAG_NORMAL, &color;;
28bab8
 
28bab8
     g_signal_connect(g_tv_details, "key-press-event", G_CALLBACK(on_key_press_event_in_item_list), NULL);
28bab8
     g_tv_sensitive_sel_hndlr = g_signal_connect(g_tv_sensitive_sel, "changed", G_CALLBACK(on_sensitive_word_selection_changed), NULL);
28bab8
@@ -3730,8 +3739,6 @@ void create_assistant(GtkApplication *app, bool expert_mode)
28bab8
 
28bab8
     g_expert_mode = expert_mode;
28bab8
 
28bab8
-    g_monospace_font = pango_font_description_from_string("monospace");
28bab8
-
28bab8
     g_assistant = GTK_NOTEBOOK(gtk_notebook_new());
28bab8
 
28bab8
     /* Show tabs only in verbose expert mode
28bab8
-- 
28bab8
2.21.0
28bab8