# HG changeset patch
# Node ID ab4da6573111
# Parent  7a52387e60ae
diff --git a/pidgin/pidgindebug.c b/pidgin/pidgindebug.c
--- a/pidgin/pidgindebug.c
+++ b/pidgin/pidgindebug.c
@@ -82,24 +82,6 @@ static guint debug_enabled_timer = 0;
 
 G_DEFINE_TYPE(PidginDebugWindow, pidgin_debug_window, GTK_TYPE_WINDOW);
 
-static gint
-debug_window_destroy(GtkWidget *w, GdkEvent *event, void *unused)
-{
-	purple_prefs_disconnect_by_handle(pidgin_debug_get_handle());
-
-	if (debug_win->regex != NULL)
-		g_regex_unref(debug_win->regex);
-
-	/* If the "Save Log" dialog is open then close it */
-	purple_request_close_with_handle(debug_win);
-
-	debug_win = NULL;
-
-	purple_prefs_set_bool(PIDGIN_PREFS_ROOT "/debug/enabled", FALSE);
-
-	return FALSE;
-}
-
 static gboolean
 save_default_size_cb(GObject *gobject, G_GNUC_UNUSED GParamSpec *pspec,
                      G_GNUC_UNUSED gpointer data)
@@ -125,32 +107,80 @@ view_near_bottom(PidginDebugWindow *win)
 }
 
 static void
-save_writefile_cb(void *user_data, const char *filename)
+save_response_cb(GtkNativeDialog *self, gint response_id, gpointer data)
 {
-	PidginDebugWindow *win = (PidginDebugWindow *)user_data;
-	FILE *fp;
-	GtkTextIter start, end;
-	char *tmp;
+	PidginDebugWindow *win = (PidginDebugWindow *)data;
+
+	if(response_id == GTK_RESPONSE_ACCEPT) {
+		GFile *file = NULL;
+		GFileOutputStream *output = NULL;
+		GtkTextIter start, end;
+		gchar *tmp = NULL;
+		GError *error = NULL;
+
+		file = gtk_file_chooser_get_file(GTK_FILE_CHOOSER(self));
+		output = g_file_create(file, G_FILE_CREATE_NONE, NULL, &error);
+		g_object_unref(file);
+
+		if(output == NULL) {
+			purple_debug_error("debug",
+			                   "Unable to open file to save debug log: %s",
+			                   error->message);
+			g_error_free(error);
+			g_object_unref(self);
+			return;
+		}
 
-	if ((fp = g_fopen(filename, "w+")) == NULL) {
-		purple_notify_error(win, NULL, _("Unable to open file."), NULL, NULL);
-		return;
+		tmp = g_strdup_printf("Pidgin Debug Log : %s\n", purple_date_format_full(NULL));
+		g_output_stream_write_all(G_OUTPUT_STREAM(output), tmp, strlen(tmp),
+		                          NULL, NULL, &error);
+		g_free(tmp);
+
+		if(error != NULL) {
+			purple_debug_error("debug", "Unable to save debug log: %s",
+			                   error->message);
+			g_error_free(error);
+			g_object_unref(output);
+			g_object_unref(self);
+			return;
+		}
+
+		gtk_text_buffer_get_bounds(win->buffer, &start, &end);
+		tmp = gtk_text_buffer_get_text(win->buffer, &start, &end, TRUE);
+		g_output_stream_write_all(G_OUTPUT_STREAM(output), tmp, strlen(tmp),
+		                          NULL, NULL, &error);
+		g_free(tmp);
+
+		if(error != NULL) {
+			purple_debug_error("debug", "Unable to save debug log: %s",
+			                   error->message);
+			g_error_free(error);
+			g_object_unref(output);
+			g_object_unref(self);
+			return;
+		}
+
+		g_object_unref(output);
 	}
 
-	gtk_text_buffer_get_bounds(win->buffer, &start, &end);
-	tmp = gtk_text_buffer_get_text(win->buffer, &start, &end, TRUE);
-	fprintf(fp, "Pidgin Debug Log : %s\n", purple_date_format_full(NULL));
-	fprintf(fp, "%s", tmp);
-	g_free(tmp);
-
-	fclose(fp);
+	g_object_unref(self);
 }
 
 static void
 save_cb(GtkWidget *w, PidginDebugWindow *win)
 {
-	purple_request_file(win, _("Save Debug Log"), "purple-debug.log", TRUE,
-		G_CALLBACK(save_writefile_cb), NULL, NULL, win);
+	GtkFileChooserNative *filesel;
+
+	filesel = gtk_file_chooser_native_new(_("Save Debug Log"), GTK_WINDOW(win),
+	                                      GTK_FILE_CHOOSER_ACTION_SAVE,
+	                                      _("_Save"), _("_Cancel"));
+
+	gtk_file_chooser_set_current_name(GTK_FILE_CHOOSER(filesel),
+	                                  "purple-debug.log");
+
+	g_signal_connect(filesel, "response", G_CALLBACK(save_response_cb), win);
+
+	gtk_native_dialog_show(GTK_NATIVE_DIALOG(filesel));
 }
 
 static void
@@ -180,8 +210,7 @@ pause_cb(GtkWidget *w, PidginDebugWindow
 static void
 regex_clear_color(GtkWidget *w) {
 	GtkStyleContext *context = gtk_widget_get_style_context(w);
-	gtk_style_context_remove_class(context, "good-filter");
-	gtk_style_context_remove_class(context, "bad-filter");
+	gtk_style_context_remove_class(context, "error");
 }
 
 static void
@@ -189,11 +218,9 @@ regex_change_color(GtkWidget *w, gboolea
 	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");
+		gtk_style_context_remove_class(context, "error");
 	} else {
-		gtk_style_context_add_class(context, "bad-filter");
-		gtk_style_context_remove_class(context, "good-filter");
+		gtk_style_context_add_class(context, "error");
 	}
 }
 
@@ -301,16 +328,6 @@ regex_pref_filter_cb(const gchar *name, 
 }
 
 static void
-regex_pref_expression_cb(const gchar *name, PurplePrefType type,
-						 gconstpointer val, gpointer data)
-{
-	PidginDebugWindow *win = (PidginDebugWindow *)data;
-	const gchar *exp = (const gchar *)val;
-
-	gtk_editable_set_text(GTK_EDITABLE(win->expression), exp);
-}
-
-static void
 regex_pref_invert_cb(const gchar *name, PurplePrefType type,
 					 gconstpointer val, gpointer data)
 {
@@ -472,9 +489,30 @@ filter_level_changed_cb(GtkWidget *combo
 }
 
 static void
+pidgin_debug_window_finalize(GObject *object)
+{
+	PidginDebugWindow *win = PIDGIN_DEBUG_WINDOW(object);
+
+	purple_prefs_disconnect_by_handle(pidgin_debug_get_handle());
+
+	g_clear_pointer(&win->regex, g_regex_unref);
+
+	/* If the "Save Log" dialog is open then close it */
+	purple_request_close_with_handle(win);
+
+	debug_win = NULL;
+	purple_prefs_set_bool(PIDGIN_PREFS_ROOT "/debug/enabled", FALSE);
+
+	G_OBJECT_CLASS(pidgin_debug_window_parent_class)->finalize(object);
+}
+
+static void
 pidgin_debug_window_class_init(PidginDebugWindowClass *klass) {
+	GObjectClass *obj_class = G_OBJECT_CLASS(klass);
 	GtkWidgetClass *widget_class = GTK_WIDGET_CLASS(klass);
 
+	obj_class->finalize = pidgin_debug_window_finalize;
+
 	gtk_widget_class_set_template_from_resource(
 		widget_class,
 		"/im/pidgin/Pidgin3/Debug/debug.ui"
@@ -543,9 +581,6 @@ pidgin_debug_window_init(PidginDebugWind
 	gint width, height;
 	void *handle;
 	GtkTextIter end;
-	GtkStyleContext *context;
-	GtkCssProvider *filter_css;
-	const gchar *res = "/im/pidgin/Pidgin3/Debug/filter.css";
 
 	gtk_widget_init_template(GTK_WIDGET(win));
 
@@ -557,8 +592,6 @@ pidgin_debug_window_init(PidginDebugWind
 
 	gtk_window_set_default_size(GTK_WINDOW(win), width, height);
 
-	g_signal_connect(G_OBJECT(win), "delete_event",
-	                 G_CALLBACK(debug_window_destroy), NULL);
 	g_signal_connect(G_OBJECT(win), "notify::default-width",
 	                 G_CALLBACK(save_default_size_cb), NULL);
 	g_signal_connect(G_OBJECT(win), "notify::default-height",
@@ -580,18 +613,8 @@ pidgin_debug_window_init(PidginDebugWind
 									regex_pref_filter_cb, win);
 
 		/* regex entry */
-		filter_css = gtk_css_provider_new();
-		gtk_css_provider_load_from_resource(filter_css, res);
-
-		context = gtk_widget_get_style_context(win->expression);
-		gtk_style_context_add_provider(context,
-		                               GTK_STYLE_PROVIDER(filter_css),
-		                               GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
-
 		gtk_editable_set_text(GTK_EDITABLE(win->expression),
 		                      purple_prefs_get_string(PIDGIN_PREFS_ROOT "/debug/regex"));
-		purple_prefs_connect_callback(handle, PIDGIN_PREFS_ROOT "/debug/regex",
-									regex_pref_expression_cb, win);
 
 		/* connect the rest of our pref callbacks */
 		win->invert = purple_prefs_get_bool(PIDGIN_PREFS_ROOT "/debug/invert");
@@ -608,10 +631,10 @@ pidgin_debug_window_init(PidginDebugWind
 		purple_prefs_connect_callback(handle, PIDGIN_PREFS_ROOT "/debug/filterlevel",
 						filter_level_pref_changed, win);
 
-		gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(win->popover_invert),
-				win->invert);
-		gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(win->popover_highlight),
-				win->highlight);
+		gtk_check_button_set_active(GTK_CHECK_BUTTON(win->popover_invert),
+		                            win->invert);
+		gtk_check_button_set_active(GTK_CHECK_BUTTON(win->popover_highlight),
+		                            win->highlight);
 	}
 
 	/* The *start* and *end* marks bound the beginning and end of an
@@ -827,7 +850,6 @@ pidgin_debug_window_hide(void)
 {
 	if (debug_win != NULL) {
 		gtk_window_destroy(GTK_WINDOW(debug_win));
-		debug_window_destroy(NULL, NULL, NULL);
 	}
 }
 
diff --git a/pidgin/resources/Debug/debug.ui b/pidgin/resources/Debug/debug.ui
--- a/pidgin/resources/Debug/debug.ui
+++ b/pidgin/resources/Debug/debug.ui
@@ -69,32 +69,32 @@ funky is going on. The raw text is below
   <object class="GtkTextTagTable" id="message-format">
     <child type="tag">
       <object class="GtkTextTag" id="tags.level[0]">
-        <property name="foreground-rgba">rgb(0,0,0)</property>
+        <property name="foreground">rgb(0,0,0)</property>
       </object>
     </child>
     <child type="tag">
       <object class="GtkTextTag" id="tags.level[1]">
-        <property name="foreground-rgba">rgb(102,102,102)</property>
+        <property name="foreground">rgb(102,102,102)</property>
       </object>
     </child>
     <child type="tag">
       <object class="GtkTextTag" id="tags.level[2]">
-        <property name="foreground-rgba">rgb(0,0,0)</property>
+        <property name="foreground">rgb(0,0,0)</property>
       </object>
     </child>
     <child type="tag">
       <object class="GtkTextTag" id="tags.level[3]">
-        <property name="foreground-rgba">rgb(102,0,0)</property>
+        <property name="foreground">rgb(102,0,0)</property>
       </object>
     </child>
     <child type="tag">
       <object class="GtkTextTag" id="tags.level[4]">
-        <property name="foreground-rgba">rgb(255,0,0)</property>
+        <property name="foreground">rgb(255,0,0)</property>
       </object>
     </child>
     <child type="tag">
       <object class="GtkTextTag" id="tags.level[5]">
-        <property name="foreground-rgba">rgb(255,0,0)</property>
+        <property name="foreground">rgb(255,0,0)</property>
         <property name="weight">700</property>
       </object>
     </child>
@@ -116,7 +116,7 @@ funky is going on. The raw text is below
     </child>
     <child type="tag">
       <object class="GtkTextTag" id="tags.match">
-        <property name="background-rgba">rgb(255,175,175)</property>
+        <property name="background">rgb(255,175,175)</property>
         <property name="weight">700</property>
       </object>
     </child>
@@ -130,7 +130,7 @@ funky is going on. The raw text is below
     <property name="tag-table">message-format</property>
   </object>
   <template class="PidginDebugWindow" parent="GtkWindow">
-    <property name="title" translatable="yes">Debug Window</property>
+    <property name="title" translatable="1">Debug Window</property>
     <property name="child">
       <object class="GtkBox">
         <property name="orientation">vertical</property>
@@ -141,8 +141,8 @@ funky is going on. The raw text is below
             </style>
             <child>
               <object class="GtkButton" id="save">
-                <property name="tooltip-text" translatable="yes">Save</property>
-                <property name="label" translatable="yes">_Save...</property>
+                <property name="tooltip-text" translatable="1">Save</property>
+                <property name="label" translatable="1">_Save...</property>
                 <property name="use-underline">1</property>
                 <property name="icon-name">document-save</property>
                 <signal name="clicked" handler="save_cb" object="PidginDebugWindow" swapped="no"/>
@@ -150,8 +150,8 @@ funky is going on. The raw text is below
             </child>
             <child>
               <object class="GtkButton" id="clear">
-                <property name="tooltip-text" translatable="yes">Clear</property>
-                <property name="label" translatable="yes">_Clear</property>
+                <property name="tooltip-text" translatable="1">Clear</property>
+                <property name="label" translatable="1">_Clear</property>
                 <property name="use-underline">1</property>
                 <property name="icon-name">edit-clear</property>
                 <signal name="clicked" handler="clear_cb" object="PidginDebugWindow" swapped="no"/>
@@ -164,8 +164,8 @@ funky is going on. The raw text is below
             </child>
             <child>
               <object class="GtkToggleButton" id="pause">
-                <property name="tooltip-text" translatable="yes">Pause</property>
-                <property name="label" translatable="yes">_Pause</property>
+                <property name="tooltip-text" translatable="1">Pause</property>
+                <property name="label" translatable="1">_Pause</property>
                 <property name="use-underline">1</property>
                 <property name="icon-name">media-playback-pause</property>
                 <signal name="clicked" handler="pause_cb" object="PidginDebugWindow" swapped="no"/>
@@ -178,11 +178,11 @@ funky is going on. The raw text is below
             </child>
             <child>
               <object class="GtkToggleButton" id="filter">
-                <property name="tooltip-text" translatable="yes">Filter</property>
-                <property name="label" translatable="yes">_Filter</property>
+                <property name="tooltip-text" translatable="1">Filter</property>
+                <property name="label" translatable="1">_Filter</property>
                 <property name="use-underline">1</property>
                 <property name="icon-name">edit-find</property>
-                <signal name="clicked" handler="regex_filter_toggled_cb" object="PidginDebugWindow" swapped="no"/>
+                <signal name="toggled" handler="regex_filter_toggled_cb" object="PidginDebugWindow" swapped="no"/>
               </object>
             </child>
             <child>
@@ -193,9 +193,6 @@ funky is going on. The raw text is below
                   </object>
                 </child>
                 <property name="focusable">1</property>
-                <property name="primary-icon-tooltip-text" translatable="yes">Click for more options.</property>
-                <!--<signal name="icon-press" handler="regex_popup_cb" object="PidginDebugWindow" swapped="no"/>-->
-                <property name="sensitive">0</property>
                 <signal name="search-changed" handler="regex_changed_cb" object="PidginDebugWindow" swapped="no"/>
               </object>
             </child>
@@ -205,16 +202,13 @@ funky is going on. The raw text is below
               </object>
             </child>
             <child>
-              <object class="GtkLabel">
-                <property name="label" translatable="yes">Level </property>
-                <accessibility>
-                  <relation type="label-for" target="filterlevel"/>
-                </accessibility>
+              <object class="GtkLabel" id="filterlevel-label">
+                <property name="label" translatable="1">Level </property>
               </object>
             </child>
             <child>
-            <object class="GtkComboBoxText" id="filterlevel">
-                <property name="tooltip-text" translatable="yes">Select the debug filter level.</property>
+              <object class="GtkComboBoxText" id="filterlevel">
+                <property name="tooltip-text" translatable="1">Select the debug filter level.</property>
                 <property name="active">0</property>
                 <items>
                   <item translatable="yes">All</item>
@@ -225,6 +219,9 @@ funky is going on. The raw text is below
                   <item translatable="yes">Fatal Error</item>
                 </items>
                 <signal name="changed" handler="filter_level_changed_cb" object="PidginDebugWindow" swapped="no"/>
+                <accessibility>
+                  <relation name="labelled-by">filterlevel-label</relation>
+                </accessibility>
               </object>
             </child>
           </object>
@@ -252,14 +249,14 @@ funky is going on. The raw text is below
         <property name="orientation">vertical</property>
         <child>
           <object class="GtkCheckButton" id="popover_invert">
-            <property name="label" translatable="yes">Invert</property>
+            <property name="label" translatable="1">Invert</property>
             <property name="focusable">1</property>
             <signal name="toggled" handler="regex_menu_cb" object="PidginDebugWindow" swapped="no"/>
           </object>
         </child>
         <child>
           <object class="GtkCheckButton" id="popover_highlight">
-            <property name="label" translatable="yes">Highlight matches</property>
+            <property name="label" translatable="1">Highlight matches</property>
             <property name="focusable">1</property>
             <signal name="toggled" handler="regex_menu_cb" object="PidginDebugWindow" swapped="no"/>
           </object>
diff --git a/pidgin/resources/Debug/filter.css b/pidgin/resources/Debug/filter.css
deleted file mode 100644
--- a/pidgin/resources/Debug/filter.css
+++ /dev/null
@@ -1,13 +0,0 @@
-.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;
-}
diff --git a/pidgin/resources/pidgin.gresource.xml b/pidgin/resources/pidgin.gresource.xml
--- a/pidgin/resources/pidgin.gresource.xml
+++ b/pidgin/resources/pidgin.gresource.xml
@@ -17,7 +17,6 @@
     <file compressed="true">Conversations/tab-label.css</file>
     <file compressed="true">Conversations/window.ui</file>
     <file compressed="true">Debug/debug.ui</file>
-    <file compressed="true">Debug/filter.css</file>
     <file compressed="true">Dialogs/addbuddy.ui</file>
     <file compressed="true">Dialogs/addchat.ui</file>
     <file compressed="true">Keypad/keypad.ui</file>
