changeset 9489:85caa0722dfc

[gaim-migrate @ 10314] Conversation->Save as... uses the gtk 2.4 file chooser now. And I made a few more tweaks to the debug window save dialog. This code should be pretty diesel. committer: Tailor Script <tailor@pidgin.im>
author Mark Doliner <mark@kingant.net>
date Fri, 09 Jul 2004 00:36:35 +0000
parents 2770a0e659ca
children a5aa8c659974
files src/gtkconv.c src/gtkdebug.c
diffstat 2 files changed, 158 insertions(+), 102 deletions(-) [+]
line wrap: on
line diff
--- a/src/gtkconv.c	Thu Jul 08 18:45:01 2004 +0000
+++ b/src/gtkconv.c	Fri Jul 09 00:36:35 2004 +0000
@@ -131,67 +131,10 @@
 static void update_typing_icon(GaimConversation *conv);
 static gboolean update_send_as_selection(GaimConvWindow *win);
 static char *item_factory_translate_func (const char *path, gpointer func_data);
-static void save_convo(GtkWidget *save, GaimConversation *c);
 
 /**************************************************************************
  * Callbacks
  **************************************************************************/
-static void
-do_save_convo(GtkWidget *wid)
-{
-	GaimConversation *conv;
-	const char *name;
-	const char *filename;
-	FILE *fp;
-
-	conv = g_object_get_data(G_OBJECT(GTK_FILE_SELECTION(wid)->ok_button),
-							 "gaim_conversation");
-
-	filename = gtk_file_selection_get_filename(GTK_FILE_SELECTION(wid));
-
-	if (!((gaim_conversation_get_type(conv) != GAIM_CONV_CHAT &&
-		   g_list_find(gaim_get_ims(), conv)) ||
-		  (gaim_conversation_get_type(conv) == GAIM_CONV_CHAT &&
-		   g_list_find(gaim_get_chats(), conv))))
-		filename = NULL;
-
-	gtk_widget_destroy(wid);
-
-	if (filename == NULL)
-		return;
-
-	if ((fp = fopen(filename, "w+")) == NULL)
-		return;
-
-	name = gaim_conversation_get_name(conv);
-
-	fprintf(fp, _("<h1>Conversation with %s</h1>\n"), name);
-	fprintf(fp, "%s", conv->history->str);
-
-	fclose(fp);
-}
-
-static void
-do_check_save_convo(GObject *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_convo), NULL);
-	}
-	else
-		do_save_convo(wid);
-}
-
-
 static gint
 close_win_cb(GtkWidget *w, GdkEventAny *e, gpointer d)
 {
@@ -847,11 +790,135 @@
 }
 
 static void
+savelog_writefile_cb(GaimConversation *conv, gint id)
+{
+	GaimGtkConversation *gtkconv = GAIM_GTK_CONVERSATION(conv);
+	const char *filename;
+	FILE *fp;
+	const char *name;
+
+#if GTK_CHECK_VERSION(2,4,0) /* FILECHOOSER */
+	filename = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(gtkconv->dialogs.savelog));
+#else /* FILECHOOSER */
+	filename = gtk_file_selection_get_filename(GTK_FILE_SELECTION(gtkconv->dialogs.save));
+#endif /* FILECHOOSER */
+
+	gaim_notify_close_with_handle(gtkconv->dialogs.savelog);
+
+	if (filename == NULL) {
+		gaim_notify_error(gtkconv->dialogs.savelog, NULL, _("Invalid file name."), NULL);
+		return;
+	}
+
+	if ((fp = fopen(filename, "w+")) == NULL) {
+		gaim_notify_error(gtkconv->dialogs.savelog, NULL, _("Unable to open file."), NULL);
+		return;
+	}
+
+	name = gaim_conversation_get_name(conv);
+
+	fprintf(fp, _("<h1>Conversation with %s</h1>\n"), name);
+	fprintf(fp, "%s", conv->history->str);
+
+	fclose(fp);
+
+	gtk_widget_destroy(gtkconv->dialogs.savelog);
+	gtkconv->dialogs.savelog = NULL;
+}
+
+#if GTK_CHECK_VERSION(2,4,0) /* FILECHOOSER */
+static void
+savelog_checkfile_cb(GtkWidget *widget, gint response, GaimConversation *conv)
+{
+	GaimGtkConversation *gtkconv = GAIM_GTK_CONVERSATION(conv);
+	const char *filename;
+
+	if (response != GTK_RESPONSE_ACCEPT) {
+		gaim_notify_close_with_handle(gtkconv->dialogs.savelog);
+		gaim_request_close_with_handle(gtkconv->dialogs.savelog);
+		if (response == GTK_RESPONSE_CANCEL)
+			gtk_widget_destroy(gtkconv->dialogs.savelog);
+		gtkconv->dialogs.savelog = NULL;
+		return;
+	}
+
+	filename = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(widget));
+#else /* FILECHOOSER */
+static void
+savelog_checkfile_cb(GtkWidget *widget, GaimConversation *conv)
+{
+	GaimGtkConversation *gtkconv = GAIM_GTK_CONVERSATION(conv);
+	const char *filename;
+
+	filename = gtk_file_selection_get_filename(GTK_FILE_SELECTION(gtkconv->dialogs.savelog));
+	if (gaim_gtk_check_if_dir(filename, GTK_FILE_SELECTION(gtkconv->dialogs.savelog))) {
+		return;
+	}
+#endif /* FILECHOOSER */
+
+	gaim_request_close_with_handle(gtkconv->dialogs.savelog);
+
+	if (g_file_test(filename, G_FILE_TEST_EXISTS))
+	{
+		gaim_request_yes_no(gtkconv->dialogs.savelog, NULL, _("That file already exists"),
+							_("Would you like to overwrite it?"), 1,
+							conv, G_CALLBACK(savelog_writefile_cb), NULL);
+	}
+	else
+		savelog_writefile_cb(conv, 1);
+}
+
+#if !GTK_CHECK_VERSION(2,4,0) /* FILECHOOSER */
+static void
+savelog_destroy_cb(GtkWidget *widget, GtkConversation *gtkconv)
+{
+	if (gtkconv->save != NULL) {
+		gaim_notify_close_with_handle(gtkconv->dialogs.savelog);
+		gaim_request_close_with_handle(gtkconv->dialogs.savelog);
+		gtk_widget_destroy(gtkconv->dialogs.savelog);
+		gtkconv->dialogs.savelog = NULL;
+	}
+}
+#endif
+
+static void
 menu_save_as_cb(gpointer data, guint action, GtkWidget *widget)
 {
 	GaimConvWindow *win = (GaimConvWindow *)data;
-
-	save_convo(NULL, gaim_conv_window_get_active_conversation(win));
+	GaimConversation *conv = gaim_conv_window_get_active_conversation(win);
+	GaimGtkConversation *gtkconv = GAIM_GTK_CONVERSATION(conv);
+	gchar *buf;
+
+#if GTK_CHECK_VERSION(2,4,0) /* FILECHOOSER */
+	buf = g_strdup_printf("%s.html", gaim_normalize(conv->account, conv->name));
+	gtkconv->dialogs.savelog = gtk_file_chooser_dialog_new(_("Save Conversation"),
+					GTK_WINDOW(GAIM_GTK_WINDOW(win)->window),
+					GTK_FILE_CHOOSER_ACTION_SAVE,
+					GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
+					GTK_STOCK_SAVE, GTK_RESPONSE_ACCEPT,
+					NULL);
+	gtk_dialog_set_default_response(GTK_DIALOG(gtkconv->dialogs.savelog),
+									GTK_RESPONSE_ACCEPT);
+	gtk_file_chooser_set_current_name(GTK_FILE_CHOOSER(gtkconv->dialogs.savelog),
+									  buf);
+	g_signal_connect(G_OBJECT(gtkconv->dialogs.savelog), "response",
+					 G_CALLBACK(savelog_checkfile_cb), conv);
+#else /* FILECHOOSER */
+	buf = g_strdup_printf("%s" G_DIR_SEPARATOR_S "%s.html", gaim_home_dir(),
+						  gaim_normalize(c->account, c->name));
+	gtkconv->dialogs.savelog = gtk_file_selection_new(_("Save Conversation"));
+	gtk_file_selection_set_filename(GTK_FILE_SELECTION(gtkconv->dialogs.savelog), buf);
+	g_signal_connect(G_OBJECT(GTK_FILE_SELECTION(gtkconv->dialogs.savelog)->ok_button),
+					 "clicked", G_CALLBACK(savelog_checkfile_cb), conv);
+	g_signal_connect(G_OBJECT(GTK_FILE_SELECTION(gtkconv->dialogs.savelog)->cancel_button),
+					 "clicked", G_CALLBACK(savelog_destroy_cb), conv);
+	g_signal_connect(G_OBJECT(gtkconv->dialogs.savelog),
+					 "clicked", G_CALLBACK(savelog_destroy_cb), conv);
+#endif /* FILECHOOSER */
+
+	g_free(buf);
+
+	gtk_widget_show_all(GTK_WIDGET(gtkconv->dialogs.savelog));
 }
 
 static void
@@ -3410,26 +3477,6 @@
 	g_free(partial);
 }
 
-static void
-save_convo(GtkWidget *save, GaimConversation *c)
-{
-	char buf[BUF_LONG];
-	GtkWidget *window;
-
-	window = gtk_file_selection_new(_("Save Conversation"));
-
-	g_snprintf(buf, sizeof(buf), "%s" G_DIR_SEPARATOR_S "%s.html",
-			   gaim_home_dir(), gaim_normalize(c->account, c->name));
-	gtk_file_selection_set_filename(GTK_FILE_SELECTION(window), buf);
-	g_object_set_data(G_OBJECT(GTK_FILE_SELECTION(window)->ok_button),
-			"gaim_conversation", c);
-	g_signal_connect(G_OBJECT(GTK_FILE_SELECTION(window)->ok_button),
-			   "clicked", G_CALLBACK(do_check_save_convo), 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 GtkItemFactoryEntry menu_items[] =
 {
 	/* Conversation menu */
@@ -4778,8 +4825,11 @@
 {
 	GaimGtkConversation *gtkconv = GAIM_GTK_CONVERSATION(conv);
 
-	if (gtkconv->dialogs.log != NULL)
-		gtk_widget_destroy(gtkconv->dialogs.log);
+	if (gtkconv->dialogs.savelog != NULL) {
+		gaim_notify_close_with_handle(gtkconv->dialogs.savelog);
+		gaim_request_close_with_handle(gtkconv->dialogs.savelog);
+		gtk_widget_destroy(gtkconv->dialogs.savelog);
+	}
 
 	gtk_widget_destroy(gtkconv->tab_cont);
 	g_object_unref(gtkconv->tab_cont);
--- a/src/gtkdebug.c	Thu Jul 08 18:45:01 2004 +0000
+++ b/src/gtkdebug.c	Fri Jul 09 00:36:35 2004 +0000
@@ -73,8 +73,11 @@
 {
 	if (debug_win->timestamps_handle != 0)
 		gaim_prefs_disconnect_callback(debug_win->timestamps_handle);
-	if (debug_win->save != NULL)
+	if (debug_win->save != NULL) {
+		gaim_notify_close_with_handle(debug_win->save);
+		gaim_request_close_with_handle(debug_win->save);
 		gtk_widget_destroy(debug_win->save);
+	}
 
 	g_free(debug_win);
 	debug_win = NULL;
@@ -172,41 +175,39 @@
 }
 
 static void
-save_writefile_cb(GtkWidget *widget)
+save_writefile_cb(DebugWindow *win, gint id)
 {
 	const char *filename;
+	FILE *fp;
 	char *tmp;
-	FILE *fp;
-
-	g_return_if_fail(debug_win != NULL);
 
 #if GTK_CHECK_VERSION(2,4,0) /* FILECHOOSER */
-	filename = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(debug_win->save));
+	filename = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(win->save));
 #else /* FILECHOOSER */
-	filename = gtk_file_selection_get_filename(GTK_FILE_SELECTION(debug_win->save));
+	filename = gtk_file_selection_get_filename(GTK_FILE_SELECTION(win->save));
 #endif /* FILECHOOSER */
 
-	gaim_notify_close_with_handle(debug_win->save);
+	gaim_notify_close_with_handle(win->save);
 
 	if (filename == NULL) {
-		gaim_notify_error(debug_win->save, NULL, _("Invalid file name."), NULL);
+		gaim_notify_error(win->save, NULL, _("Invalid file name."), NULL);
 		return;
 	}
 
 	if ((fp = fopen(filename, "w+")) == NULL) {
-		gaim_notify_error(debug_win->save, NULL, _("Unable to open file."), NULL);
+		gaim_notify_error(win->save, NULL, _("Unable to open file."), NULL);
 		return;
 	}
 
-	tmp = gtk_imhtml_get_text(GTK_IMHTML(debug_win->text), NULL, NULL);
+	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);
 
-	gtk_widget_destroy(debug_win->save);
-	debug_win->save = NULL;
+	gtk_widget_destroy(win->save);
+	win->save = NULL;
 }
 
 #if GTK_CHECK_VERSION(2,4,0) /* FILECHOOSER */
@@ -216,6 +217,8 @@
 	const char *filename;
 
 	if (response != GTK_RESPONSE_ACCEPT) {
+		gaim_notify_close_with_handle(win->save);
+		gaim_request_close_with_handle(win->save);
 		if (response == GTK_RESPONSE_CANCEL)
 			gtk_widget_destroy(win->save);
 		win->save = NULL;
@@ -236,25 +239,28 @@
 	}
 #endif /* FILECHOOSER */
 
+	gaim_request_close_with_handle(win->save);
+
 	if (g_file_test(filename, G_FILE_TEST_EXISTS))
 	{
-		gaim_request_close_with_handle(win->save);
 		gaim_request_yes_no(win->save, NULL, _("That file already exists"),
 							_("Would you like to overwrite it?"), 1,
-							win->save, G_CALLBACK(save_writefile_cb), NULL);
+							win, G_CALLBACK(save_writefile_cb), NULL);
 	}
 	else
-		save_writefile_cb(win->save);
+		save_writefile_cb(win, 1);
 }
 
 #if !GTK_CHECK_VERSION(2,4,0) /* FILECHOOSER */
 static void
 save_destroy_cb(GtkWidget *widget, DebugWindow *win)
 {
-	if (win->save != NULL)
+	if (win->save != NULL) {
+		gaim_notify_close_with_handle(win->save);
+		gaim_request_close_with_handle(win->save);
 		gtk_widget_destroy(win->save);
-
-	win->save = NULL;
+		win->save = NULL;
+	}
 }
 #endif
 
@@ -283,17 +289,17 @@
 	g_signal_connect(G_OBJECT(win->save), "response",
 					 G_CALLBACK(save_checkfile_cb), win);
 #else /* FILECHOOSER */
-	win->save = gtk_file_selection_new(_("Save Debug Log"));
 	buf = g_strdup_printf("%s" G_DIR_SEPARATOR_S "gaim-debug.log",
 						  gaim_home_dir());
+	win->save = gtk_file_selection_new(_("Save Debug Log"));
 	gtk_file_selection_set_filename(GTK_FILE_SELECTION(win->save), buf);
-	g_free(buf);
 	g_signal_connect(G_OBJECT(GTK_FILE_SELECTION(win->save)->ok_button),
 					 "clicked", G_CALLBACK(save_checkfile_cb), win);
 	g_signal_connect(G_OBJECT(GTK_FILE_SELECTION(win->save)->cancel_button),
 					 "clicked", G_CALLBACK(save_destroy_cb), win);
 	g_signal_connect(G_OBJECT(win->save),
 					 "destroy", G_CALLBACK(save_destroy_cb), win);
+	g_free(buf);
 #endif /* FILECHOOSER */
 
 	gtk_widget_show_all(GTK_WIDGET(win->save));