/pidgin/main: 788678d2e035: Fix background change in IP and debu...

Elliott Sales de Andrade qulogic at pidgin.im
Thu May 9 02:56:35 EDT 2013


Changeset: 788678d2e035926b1aa39ec4badb1637d8c25521
Author:	 Elliott Sales de Andrade <qulogic at pidgin.im>
Date:	 2013-05-08 02:39 -0400
Branch:	 default
URL: https://hg.pidgin.im/pidgin/main/rev/788678d2e035

Description:

Fix background change in IP and debug filter entries.

It uses theme colours on GTK+3, so it will fit in better, hopefully.
However, I may be abusing the "success_color" a little bit.

diffstat:

 pidgin/gtkdebug.c |  58 +++++++++++++++++++++++++++++++++++++++++++++++++-----
 pidgin/gtkprefs.c |  43 ++++++++++++++++++++++++++++++++++++++++
 2 files changed, 95 insertions(+), 6 deletions(-)

diffs (174 lines):

diff --git a/pidgin/gtkdebug.c b/pidgin/gtkdebug.c
--- a/pidgin/gtkdebug.c
+++ b/pidgin/gtkdebug.c
@@ -151,18 +151,42 @@ pause_cb(GtkWidget *w, DebugWindow *win)
  *****************************************************************************/
 static void
 regex_clear_color(GtkWidget *w) {
+#if GTK_CHECK_VERSION(3,0,0)
+	GtkStyleContext *context = gtk_widget_get_style_context(w);
+	gtk_style_context_remove_class(context, "good-filter");
+	gtk_style_context_remove_class(context, "bad-filter");
+#else
 	gtk_widget_modify_base(w, GTK_STATE_NORMAL, NULL);
+#endif
 }
 
 static void
-regex_change_color(GtkWidget *w, guint16 r, guint16 g, guint16 b) {
+regex_change_color(GtkWidget *w, gboolean success) {
+#if GTK_CHECK_VERSION(3,0,0)
+	GtkStyleContext *context = gtk_widget_get_style_context(w);
+
+	if (success) {
+		gtk_style_context_add_class(context, "good-filter");
+		gtk_style_context_remove_class(context, "bad-filter");
+	} else {
+		gtk_style_context_add_class(context, "bad-filter");
+		gtk_style_context_remove_class(context, "good-filter");
+	}
+#else
 	GdkColor color;
 
-	color.red = r;
-	color.green = g;
-	color.blue = b;
+	if (success) {
+		color.red = 0xAFFF;
+		color.green = 0xFFFF;
+		color.blue = 0xAFFF;
+	} else {
+		color.red = 0xFFFF;
+		color.green = 0xAFFF;
+		color.blue = 0xAFFF;
+	}
 
 	gtk_widget_modify_base(w, GTK_STATE_NORMAL, &color);
+#endif
 }
 
 static void
@@ -279,11 +303,11 @@ regex_changed_cb(GtkWidget *w, DebugWind
 #endif
 	if (win->regex == NULL) {
 		/* failed to compile */
-		regex_change_color(win->expression, 0xFFFF, 0xAFFF, 0xAFFF);
+		regex_change_color(win->expression, FALSE);
 		gtk_widget_set_sensitive(win->filter, FALSE);
 	} else {
 		/* compiled successfully */
-		regex_change_color(win->expression, 0xAFFF, 0xFFFF, 0xAFFF);
+		regex_change_color(win->expression, TRUE);
 		gtk_widget_set_sensitive(win->filter, TRUE);
 	}
 }
@@ -410,6 +434,21 @@ debug_window_new(void)
 	gint width, height;
 	void *handle;
 	GtkToolItem *item;
+	GtkStyleContext *context;
+	GtkCssProvider *filter_css;
+	const gchar filter_style[] =
+		".bad-filter {"
+			"color: @error_fg_color;"
+			"text-shadow: 0 1px @error_text_shadow;"
+			"background-image: none;"
+			"background-color: @error_bg_color;"
+		"}"
+		".good-filter {"
+			"color: @question_fg_color;"
+			"text-shadow: 0 1px @question_text_shadow;"
+			"background-image: none;"
+			"background-color: @success_color;"
+		"}";
 
 	win = g_new0(DebugWindow, 1);
 
@@ -503,6 +542,13 @@ debug_window_new(void)
 		gtk_container_add(GTK_CONTAINER(item), GTK_WIDGET(win->expression));
 		gtk_container_add(GTK_CONTAINER(toolbar), GTK_WIDGET(item));
 
+		filter_css = gtk_css_provider_new();
+		gtk_css_provider_load_from_data(filter_css, filter_style, -1, NULL);
+		context = gtk_widget_get_style_context(win->expression);
+		gtk_style_context_add_provider(context,
+		                               GTK_STYLE_PROVIDER(filter_css),
+		                               GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
+
 		/* this needs to be before the text is set from the pref if we want it
 		 * to colorize a stored expression.
 		 */
diff --git a/pidgin/gtkprefs.c b/pidgin/gtkprefs.c
--- a/pidgin/gtkprefs.c
+++ b/pidgin/gtkprefs.c
@@ -1869,6 +1869,26 @@ conv_page(void)
 static void
 network_ip_changed(GtkEntry *entry, gpointer data)
 {
+#if GTK_CHECK_VERSION(3,0,0)
+	const gchar *text = gtk_entry_get_text(entry);
+	GtkStyleContext *context = gtk_widget_get_style_context(GTK_WIDGET(entry));
+
+	if (text && *text) {
+		if (purple_ip_address_is_valid(text)) {
+			purple_network_set_public_ip(text);
+			gtk_style_context_add_class(context, "good-ip");
+			gtk_style_context_remove_class(context, "bad-ip");
+		} else {
+			gtk_style_context_add_class(context, "bad-ip");
+			gtk_style_context_remove_class(context, "good-ip");
+		}
+
+	} else {
+		purple_network_set_public_ip("");
+		gtk_style_context_remove_class(context, "bad-ip");
+		gtk_style_context_remove_class(context, "good-ip");
+	}
+#else
 	const gchar *text = gtk_entry_get_text(entry);
 	GdkColor color;
 
@@ -1891,6 +1911,7 @@ network_ip_changed(GtkEntry *entry, gpoi
 		purple_network_set_public_ip("");
 		gtk_widget_modify_base(GTK_WIDGET(entry), GTK_STATE_NORMAL, NULL);
 	}
+#endif
 }
 
 static gboolean
@@ -2013,6 +2034,21 @@ network_page(void)
 	GtkWidget *vbox, *hbox, *entry;
 	GtkWidget *label, *auto_ip_checkbox, *ports_checkbox, *spin_button;
 	GtkSizeGroup *sg;
+	GtkStyleContext *context;
+	GtkCssProvider *ip_css;
+	const gchar ip_style[] =
+		".bad-ip {"
+			"color: @error_fg_color;"
+			"text-shadow: 0 1px @error_text_shadow;"
+			"background-image: none;"
+			"background-color: @error_bg_color;"
+		"}"
+		".good-ip {"
+			"color: @question_fg_color;"
+			"text-shadow: 0 1px @question_text_shadow;"
+			"background-image: none;"
+			"background-color: @success_color;"
+		"}";
 
 	ret = gtk_vbox_new(FALSE, PIDGIN_HIG_CAT_SPACE);
 	gtk_container_set_border_width (GTK_CONTAINER (ret), PIDGIN_HIG_BORDER);
@@ -2054,6 +2090,13 @@ network_page(void)
 	g_signal_connect(G_OBJECT(entry), "changed",
 					 G_CALLBACK(network_ip_changed), NULL);
 
+	ip_css = gtk_css_provider_new();
+	gtk_css_provider_load_from_data(ip_css, ip_style, -1, NULL);
+	context = gtk_widget_get_style_context(entry);
+	gtk_style_context_add_provider(context,
+	                               GTK_STYLE_PROVIDER(ip_css),
+	                               GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
+
 	hbox = pidgin_add_widget_to_vbox(GTK_BOX(vbox), _("Public _IP:"),
 			sg, entry, TRUE, NULL);
 



More information about the Commits mailing list