changeset 8953:0277908e367d

[gaim-migrate @ 9726] find and save buttons for the debug window from nosnilmot committer: Tailor Script <tailor@pidgin.im>
author Luke Schierer <lschiere@pidgin.im>
date Sun, 16 May 2004 17:44:37 +0000
parents e3f4657fa555
children c60f82d78dea
files ChangeLog src/gtkdebug.c
diffstat 2 files changed, 160 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog	Sun May 16 17:43:00 2004 +0000
+++ b/ChangeLog	Sun May 16 17:44:37 2004 +0000
@@ -15,6 +15,7 @@
 	* Added support for Novell privacy settings (Mike Stoddard of Novell)
 	* Added ability to initiate multi-user conferences (chats) in Novell (Mike
 	  Stoddard of Novell)
+	* Find and Save buttons on the debug window (Stu Tomlinson)
 
 	Bug Fixes:
 	* Novell 64bit fixes, better error messages, and buddy list sync fixes
--- a/src/gtkdebug.c	Sun May 16 17:43:00 2004 +0000
+++ b/src/gtkdebug.c	Sun May 16 17:44:37 2004 +0000
@@ -25,10 +25,12 @@
 #include "gtkinternal.h"
 
 #include "prefs.h"
+#include "request.h"
 #include "util.h"
 
 #include "gtkdebug.h"
 #include "gtkimhtml.h"
+#include "gtkutils.h"
 #include "stock.h"
 
 #include "ui.h"
@@ -39,6 +41,7 @@
 {
 	GtkWidget *window;
 	GtkWidget *text;
+	GtkWidget *find;
 
 	gboolean timestamps;
 	gboolean paused;
@@ -58,6 +61,11 @@
 
 static DebugWindow *debug_win = NULL;
 
+struct _find {
+	DebugWindow *window;
+	GtkWidget *entry;
+};
+
 static gint
 debug_window_destroy(GtkWidget *w, GdkEvent *event, void *unused)
 {
@@ -84,6 +92,152 @@
 }
 
 static void
+do_find_cb(GtkWidget *widget, gint resp, struct _find *f)
+{
+	switch (resp) {
+	case GTK_RESPONSE_OK:
+	    gtk_imhtml_search_find(GTK_IMHTML(f->window->text),
+							   gtk_entry_get_text(GTK_ENTRY(f->entry)));
+		break;
+
+	case GTK_RESPONSE_DELETE_EVENT:
+	case GTK_RESPONSE_CLOSE:
+		gtk_imhtml_search_clear(GTK_IMHTML(f->window->text));
+		gtk_widget_destroy(f->window->find);
+		f->window->find = NULL;
+		g_free(f);
+		break;
+	}
+}
+
+static void
+find_cb(GtkWidget *w, DebugWindow *win)
+{
+	GtkWidget *hbox, *img, *label;
+	struct _find *f;
+
+	if(win->find)
+	{
+		gtk_window_present(GTK_WINDOW(win->find));
+		return;
+	}
+
+	f = g_malloc(sizeof(struct _find));
+	f->window = win;
+	win->find = gtk_dialog_new_with_buttons(_("Find"),
+					GTK_WINDOW(win->window), GTK_DIALOG_DESTROY_WITH_PARENT,
+					GTK_STOCK_CLOSE, GTK_RESPONSE_CLOSE,
+					GTK_STOCK_FIND, GTK_RESPONSE_OK, NULL);
+	gtk_dialog_set_default_response(GTK_DIALOG(win->find),
+					 GTK_RESPONSE_OK);
+	g_signal_connect(G_OBJECT(win->find), "response",
+					G_CALLBACK(do_find_cb), f);
+
+	gtk_container_set_border_width(GTK_CONTAINER(win->find), 6);
+	gtk_window_set_resizable(GTK_WINDOW(win->find), FALSE);
+	gtk_dialog_set_has_separator(GTK_DIALOG(win->find), FALSE);
+	gtk_box_set_spacing(GTK_BOX(GTK_DIALOG(win->find)->vbox), 12);
+	gtk_container_set_border_width(
+		GTK_CONTAINER(GTK_DIALOG(win->find)->vbox), 6);
+
+	hbox = gtk_hbox_new(FALSE, 12);
+	gtk_container_add(GTK_CONTAINER(GTK_DIALOG(win->find)->vbox),
+					  hbox);
+	img = gtk_image_new_from_stock(GAIM_STOCK_DIALOG_QUESTION,
+								   GTK_ICON_SIZE_DIALOG);
+	gtk_box_pack_start(GTK_BOX(hbox), img, FALSE, FALSE, 0);
+
+	gtk_misc_set_alignment(GTK_MISC(img), 0, 0);
+	gtk_dialog_set_response_sensitive(GTK_DIALOG(win->find),
+									  GTK_RESPONSE_OK, FALSE);
+
+	label = gtk_label_new(NULL);
+	gtk_label_set_markup_with_mnemonic(GTK_LABEL(label), _("_Search for:"));
+	gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 0);
+
+	f->entry = gtk_entry_new();
+	gtk_entry_set_activates_default(GTK_ENTRY(f->entry), TRUE);
+	gtk_label_set_mnemonic_widget(GTK_LABEL(label), GTK_WIDGET(f->entry));
+	g_signal_connect(G_OBJECT(f->entry), "changed",
+					 G_CALLBACK(gaim_gtk_set_sensitive_if_input),
+					 win->find);
+	gtk_box_pack_start(GTK_BOX(hbox), f->entry, FALSE, FALSE, 0);
+
+	gtk_widget_show_all(win->find);
+	gtk_widget_grab_focus(f->entry);
+}
+
+static void
+do_save_cb(GtkWidget *wid)
+{
+	DebugWindow *win = NULL;
+	const char *filename;
+	char *tmp;
+	FILE *fp;
+
+	win = g_object_get_data(G_OBJECT(GTK_FILE_SELECTION(wid)->ok_button),
+							"gaim_debugwin");
+
+	filename = gtk_file_selection_get_filename(GTK_FILE_SELECTION(wid));
+	gtk_widget_destroy(wid);
+
+	if (filename == NULL)
+		return;
+
+	if ((fp = fopen(filename, "w+")) == NULL)
+		return;
+
+	if (debug_win == NULL)
+		return;
+
+	tmp = gtk_imhtml_get_text(GTK_IMHTML(win->text), NULL, NULL);
+	fprintf(fp, "Gaim Debug log : %s\n", gaim_date_full());
+	fprintf(fp, "%s", tmp);
+	g_free(tmp);
+
+	fclose(fp);
+}
+
+static void
+do_check_save_cb(GtkObject *obj, GtkWidget *wid)
+{
+	const char *filename;
+
+	filename = gtk_file_selection_get_filename(GTK_FILE_SELECTION(wid));
+	if (gaim_gtk_check_if_dir(filename, GTK_FILE_SELECTION(wid)))
+		return;
+
+	if (g_file_test(filename, G_FILE_TEST_EXISTS))
+	{
+		gaim_request_yes_no(NULL, NULL, _("That file already exists"),
+							_("Would you like to overwrite it?"), 1, wid,
+							G_CALLBACK(do_save_cb), NULL);
+	}
+	else
+		do_save_cb(wid);
+}
+
+static void
+save_cb(GtkWidget *w, DebugWindow *win)
+{
+	char buf[BUF_LONG];
+	GtkWidget *window;
+
+	window = gtk_file_selection_new(_("Save Debug Log"));
+	g_snprintf(buf, sizeof(buf), "%s" G_DIR_SEPARATOR_S "gaim-debug.log",
+			   gaim_home_dir());
+	gtk_file_selection_set_filename(GTK_FILE_SELECTION(window), buf);
+	g_object_set_data(G_OBJECT(GTK_FILE_SELECTION(window)->ok_button),
+					  "gaim_debugwin", win);
+	g_signal_connect(G_OBJECT(GTK_FILE_SELECTION(window)->ok_button),
+					 "clicked", G_CALLBACK(do_check_save_cb), window);
+	g_signal_connect_swapped(G_OBJECT(GTK_FILE_SELECTION(window)->cancel_button),
+							 "clicked", G_CALLBACK(gtk_widget_destroy), (gpointer)window);
+
+	gtk_widget_show(window);
+}
+
+static void
 clear_cb(GtkWidget *w, DebugWindow *win)
 {
 	gtk_imhtml_clear(GTK_IMHTML(win->text));
@@ -152,15 +306,13 @@
 
 		gtk_box_pack_start(GTK_BOX(vbox), toolbar, FALSE, FALSE, 0);
 
-#if 0
 		/* Find button */
 		gtk_toolbar_insert_stock(GTK_TOOLBAR(toolbar), GTK_STOCK_FIND,
-								 NULL, NULL, NULL, NULL, -1);
+								 NULL, NULL, G_CALLBACK(find_cb), win, -1);
 
 		/* Save */
 		gtk_toolbar_insert_stock(GTK_TOOLBAR(toolbar), GTK_STOCK_SAVE,
-								 NULL, NULL, NULL, NULL, -1);
-#endif
+								 NULL, NULL, G_CALLBACK(save_cb), win, -1);
 
 		/* Clear button */
 		gtk_toolbar_insert_stock(GTK_TOOLBAR(toolbar), GTK_STOCK_CLEAR,
@@ -181,10 +333,10 @@
 											NULL, _("Timestamps"), NULL, NULL,
 											NULL, G_CALLBACK(timestamps_cb),
 											win);
-		
-		gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(button), 
+
+		gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(button),
 						gaim_prefs_get_bool("/gaim/gtk/debug/timestamps"));
-						
+
 		win->timestamps_handle =
 			gaim_prefs_connect_callback("/gaim/gtk/debug/timestamps",
 										timestamps_pref_cb, button);