changeset 17000:531a4585d437

Now that timestamps are gone, let's allow filter strings in the debug window.
author Sadrul Habib Chowdhury <imadil@gmail.com>
date Thu, 10 May 2007 03:35:52 +0000
parents 2f9e5cde6f97
children d0319a3fe7d6
files finch/gntdebug.c
diffstat 1 files changed, 40 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/finch/gntdebug.c	Thu May 10 03:00:31 2007 +0000
+++ b/finch/gntdebug.c	Thu May 10 03:35:52 2007 +0000
@@ -24,10 +24,12 @@
  */
 #include <gnt.h>
 #include <gntbox.h>
-#include <gnttextview.h>
 #include <gntbutton.h>
 #include <gntcheckbox.h>
+#include <gntentry.h>
+#include <gntlabel.h>
 #include <gntline.h>
+#include <gnttextview.h>
 
 #include "gntdebug.h"
 #include "finch.h"
@@ -42,14 +44,28 @@
 {
 	GntWidget *window;
 	GntWidget *tview;
+	GntWidget *search;
 	gboolean paused;
 } debug;
 
+static gboolean
+match_string(const char *category, const char *args)
+{
+	const char *str = gnt_entry_get_text(GNT_ENTRY(debug.search));
+	if (!str || !*str)
+		return TRUE;
+	if (g_ascii_strcasecmp(str, category) == 0)
+		return TRUE;
+	if (g_ascii_strcasecmp(str, args) == 0)
+		return TRUE;
+	return FALSE;
+}
+
 static void
 finch_debug_print(PurpleDebugLevel level, const char *category,
 		const char *args)
 {
-	if (debug.window && !debug.paused)
+	if (debug.window && !debug.paused && match_string(category, args))
 	{
 		int pos = gnt_text_view_get_lines_below(GNT_TEXT_VIEW(debug.tview));
 		GntTextFormatFlags flag = GNT_TEXT_FLAG_NORMAL;
@@ -108,7 +124,7 @@
 static void
 reset_debug_win(GntWidget *w, gpointer null)
 {
-	debug.window = debug.tview = NULL;
+	debug.window = debug.tview = debug.search = NULL;
 }
 
 static void
@@ -188,6 +204,21 @@
 	purple_prefs_set_int(PREF_ROOT "/size/height", h);
 }
 
+static gboolean
+for_real(gpointer entry)
+{
+	purple_prefs_set_string(PREF_ROOT "/filter", gnt_entry_get_text(entry));
+	return FALSE;
+}
+
+static void
+update_filter_string(GntEntry *entry, gpointer null)
+{
+	int id = g_timeout_add(1000, for_real, entry);
+	g_object_set_data_full(G_OBJECT(entry), "update-filter", GINT_TO_POINTER(id),
+					(GDestroyNotify)g_source_remove);
+}
+
 void finch_debug_window_show()
 {
 	debug.paused = FALSE;
@@ -222,6 +253,11 @@
 		GNT_WIDGET_SET_FLAGS(wid, GNT_WIDGET_GROW_Y);
 		gnt_box_add_widget(GNT_BOX(box), wid);
 
+		debug.search = gnt_entry_new(purple_prefs_get_string(PREF_ROOT "/filter"));
+		gnt_box_add_widget(GNT_BOX(box), gnt_label_new(_("Filter: ")));
+		gnt_box_add_widget(GNT_BOX(box), debug.search);
+		g_signal_connect(G_OBJECT(debug.search), "text_changed", G_CALLBACK(update_filter_string), NULL);
+
 		wid = gnt_check_box_new(_("Pause"));
 		g_signal_connect(G_OBJECT(wid), "toggled", G_CALLBACK(toggle_pause), NULL);
 		GNT_WIDGET_SET_FLAGS(wid, GNT_WIDGET_GROW_Y);
@@ -265,6 +301,7 @@
 	g_set_printerr_handler(suppress_error_messages);
 
 	purple_prefs_add_none(PREF_ROOT);
+	purple_prefs_add_string(PREF_ROOT "/filter", "");
 	purple_prefs_add_none(PREF_ROOT "/size");
 	purple_prefs_add_int(PREF_ROOT "/size/width", 60);
 	purple_prefs_add_int(PREF_ROOT "/size/height", 15);