Mercurial > pidgin.yaz
changeset 9480:91856b52a391
[gaim-migrate @ 10305]
Make the debug window's save button use the gtk 2.4 file chooser.
I'll ChangeLog this when I'm done with all the dialogs.
The code isn't the prettiest thing in the world... but I don't
see a better way.
And I'm about to test this on a gtk less than 2.4, once I commit it.
committer: Tailor Script <tailor@pidgin.im>
author | Mark Doliner <mark@kingant.net> |
---|---|
date | Thu, 08 Jul 2004 01:24:48 +0000 |
parents | fababc25f270 |
children | 683660b4efeb |
files | src/gtkdebug.c |
diffstat | 1 files changed, 92 insertions(+), 33 deletions(-) [+] |
line wrap: on
line diff
--- a/src/gtkdebug.c Wed Jul 07 22:06:44 2004 +0000 +++ b/src/gtkdebug.c Thu Jul 08 01:24:48 2004 +0000 @@ -24,6 +24,7 @@ */ #include "gtkinternal.h" +#include "notify.h" #include "prefs.h" #include "request.h" #include "util.h" @@ -42,6 +43,7 @@ GtkWidget *window; GtkWidget *text; GtkWidget *find; + GtkWidget *save; gboolean timestamps; gboolean paused; @@ -71,12 +73,14 @@ { if (debug_win->timestamps_handle != 0) gaim_prefs_disconnect_callback(debug_win->timestamps_handle); - - gaim_prefs_set_bool("/gaim/gtk/debug/enabled", FALSE); + if (debug_win->save != NULL) + gtk_widget_destroy(debug_win->save); g_free(debug_win); debug_win = NULL; + gaim_prefs_set_bool("/gaim/gtk/debug/enabled", FALSE); + return FALSE; } @@ -168,73 +172,128 @@ } static void -do_save_cb(GtkWidget *wid) +do_save_cb(GtkWidget *widget) { - 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"); + g_return_if_fail(debug_win != NULL); - filename = gtk_file_selection_get_filename(GTK_FILE_SELECTION(wid)); - gtk_widget_destroy(wid); +#if GTK_CHECK_VERSION(2,4,0) /* FILECHOOSER */ + filename = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(debug_win->save)); +#else /* FILECHOOSER */ + filename = gtk_file_selection_get_filename(GTK_FILE_SELECTION(debug_win->save)); +#endif /* FILECHOOSER */ - if (filename == NULL) + if (filename == NULL) { + gaim_notify_error(NULL, NULL, _("Invalid file name."), NULL); return; - - if ((fp = fopen(filename, "w+")) == NULL) - return; + } - if (debug_win == NULL) + if ((fp = fopen(filename, "w+")) == NULL) { + gaim_notify_error(NULL, NULL, _("Unable to open file."), NULL); return; + } - tmp = gtk_imhtml_get_text(GTK_IMHTML(win->text), NULL, NULL); + tmp = gtk_imhtml_get_text(GTK_IMHTML(debug_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; } +#if GTK_CHECK_VERSION(2,4,0) /* FILECHOOSER */ static void -do_check_save_cb(GtkObject *obj, GtkWidget *wid) +do_check_save_cb(GtkWidget *widget, gint response, gpointer data) +{ + DebugWindow *win = (DebugWindow *)data; + const char *filename; + + if (response != GTK_RESPONSE_ACCEPT) { + if (response == GTK_RESPONSE_CANCEL) + gtk_widget_destroy(win->save); + win->save = NULL; + return; + } + + filename = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(win->save)); +#else /* FILECHOOSER */ +static void +do_check_save_cb(GtkWidget *widget, DebugWindow *win) { const char *filename; - filename = gtk_file_selection_get_filename(GTK_FILE_SELECTION(wid)); - if (gaim_gtk_check_if_dir(filename, GTK_FILE_SELECTION(wid))) + filename = gtk_file_selection_get_filename(GTK_FILE_SELECTION(win->save)); + if (gaim_gtk_check_if_dir(filename, GTK_FILE_SELECTION(win->save))) { + /* Descend into directory? */ return; + } +#endif /* FILECHOOSER */ 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); + _("Would you like to overwrite it?"), 1, + win->save, G_CALLBACK(do_save_cb), NULL); } else - do_save_cb(wid); + do_save_cb(win->save); } +#if !GTK_CHECK_VERSION(2,4,0) /* FILECHOOSER */ +static void +cancel_save_cb(GtkWidget *widget, DebugWindow *win) +{ + if (win->save != NULL) + gtk_widget_destroy(win->save); + + win->save = NULL; +} +#endif + static void save_cb(GtkWidget *w, DebugWindow *win) { - char buf[BUF_LONG]; - GtkWidget *window; + if (win->save != NULL) { + gtk_widget_show(win->save); + gdk_window_raise(win->save->window); + return; + } - 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); +#if GTK_CHECK_VERSION(2,4,0) /* FILECHOOSER */ + win->save = gtk_file_chooser_dialog_new(_("Save Conversation"), + 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(win->save), GTK_RESPONSE_ACCEPT); + gtk_file_chooser_set_current_name(GTK_FILE_CHOOSER(win->save), + "gaim-debug.log"); + g_signal_connect(G_OBJECT(win->save), + "response", G_CALLBACK(do_check_save_cb), win->save); +#else /* FILECHOOSER */ + gchar *buf; - gtk_widget_show(window); + win->save = gtk_file_selection_new(_("Save Debug Log")); + buf = g_strdup_printf("%s" G_DIR_SEPARATOR_S "gaim-debug.log", + gaim_home_dir()); + 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(do_check_save_cb), win); + g_signal_connect(G_OBJECT(GTK_FILE_SELECTION(win->save)->cancel_button), + "clicked", G_CALLBACK(cancel_save_cb), win); + g_signal_connect(G_OBJECT(win->save), + "destroy", G_CALLBACK(cancel_save_cb), win); +#endif /* FILECHOOSER */ + + gtk_widget_show(win->save); } static void