comparison src/gtkdebug.c @ 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 59d986a931d4
children d95e134da0ac
comparison
equal deleted inserted replaced
9488:2770a0e659ca 9489:85caa0722dfc
71 static gint 71 static gint
72 debug_window_destroy(GtkWidget *w, GdkEvent *event, void *unused) 72 debug_window_destroy(GtkWidget *w, GdkEvent *event, void *unused)
73 { 73 {
74 if (debug_win->timestamps_handle != 0) 74 if (debug_win->timestamps_handle != 0)
75 gaim_prefs_disconnect_callback(debug_win->timestamps_handle); 75 gaim_prefs_disconnect_callback(debug_win->timestamps_handle);
76 if (debug_win->save != NULL) 76 if (debug_win->save != NULL) {
77 gaim_notify_close_with_handle(debug_win->save);
78 gaim_request_close_with_handle(debug_win->save);
77 gtk_widget_destroy(debug_win->save); 79 gtk_widget_destroy(debug_win->save);
80 }
78 81
79 g_free(debug_win); 82 g_free(debug_win);
80 debug_win = NULL; 83 debug_win = NULL;
81 84
82 gaim_prefs_set_bool("/gaim/gtk/debug/enabled", FALSE); 85 gaim_prefs_set_bool("/gaim/gtk/debug/enabled", FALSE);
170 gtk_widget_show_all(win->find); 173 gtk_widget_show_all(win->find);
171 gtk_widget_grab_focus(f->entry); 174 gtk_widget_grab_focus(f->entry);
172 } 175 }
173 176
174 static void 177 static void
175 save_writefile_cb(GtkWidget *widget) 178 save_writefile_cb(DebugWindow *win, gint id)
176 { 179 {
177 const char *filename; 180 const char *filename;
181 FILE *fp;
178 char *tmp; 182 char *tmp;
179 FILE *fp;
180
181 g_return_if_fail(debug_win != NULL);
182 183
183 #if GTK_CHECK_VERSION(2,4,0) /* FILECHOOSER */ 184 #if GTK_CHECK_VERSION(2,4,0) /* FILECHOOSER */
184 filename = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(debug_win->save)); 185 filename = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(win->save));
185 #else /* FILECHOOSER */ 186 #else /* FILECHOOSER */
186 filename = gtk_file_selection_get_filename(GTK_FILE_SELECTION(debug_win->save)); 187 filename = gtk_file_selection_get_filename(GTK_FILE_SELECTION(win->save));
187 #endif /* FILECHOOSER */ 188 #endif /* FILECHOOSER */
188 189
189 gaim_notify_close_with_handle(debug_win->save); 190 gaim_notify_close_with_handle(win->save);
190 191
191 if (filename == NULL) { 192 if (filename == NULL) {
192 gaim_notify_error(debug_win->save, NULL, _("Invalid file name."), NULL); 193 gaim_notify_error(win->save, NULL, _("Invalid file name."), NULL);
193 return; 194 return;
194 } 195 }
195 196
196 if ((fp = fopen(filename, "w+")) == NULL) { 197 if ((fp = fopen(filename, "w+")) == NULL) {
197 gaim_notify_error(debug_win->save, NULL, _("Unable to open file."), NULL); 198 gaim_notify_error(win->save, NULL, _("Unable to open file."), NULL);
198 return; 199 return;
199 } 200 }
200 201
201 tmp = gtk_imhtml_get_text(GTK_IMHTML(debug_win->text), NULL, NULL); 202 tmp = gtk_imhtml_get_text(GTK_IMHTML(win->text), NULL, NULL);
202 fprintf(fp, "Gaim Debug log : %s\n", gaim_date_full()); 203 fprintf(fp, "Gaim Debug log : %s\n", gaim_date_full());
203 fprintf(fp, "%s", tmp); 204 fprintf(fp, "%s", tmp);
204 g_free(tmp); 205 g_free(tmp);
205 206
206 fclose(fp); 207 fclose(fp);
207 208
208 gtk_widget_destroy(debug_win->save); 209 gtk_widget_destroy(win->save);
209 debug_win->save = NULL; 210 win->save = NULL;
210 } 211 }
211 212
212 #if GTK_CHECK_VERSION(2,4,0) /* FILECHOOSER */ 213 #if GTK_CHECK_VERSION(2,4,0) /* FILECHOOSER */
213 static void 214 static void
214 save_checkfile_cb(GtkWidget *widget, gint response, DebugWindow *win) 215 save_checkfile_cb(GtkWidget *widget, gint response, DebugWindow *win)
215 { 216 {
216 const char *filename; 217 const char *filename;
217 218
218 if (response != GTK_RESPONSE_ACCEPT) { 219 if (response != GTK_RESPONSE_ACCEPT) {
220 gaim_notify_close_with_handle(win->save);
221 gaim_request_close_with_handle(win->save);
219 if (response == GTK_RESPONSE_CANCEL) 222 if (response == GTK_RESPONSE_CANCEL)
220 gtk_widget_destroy(win->save); 223 gtk_widget_destroy(win->save);
221 win->save = NULL; 224 win->save = NULL;
222 return; 225 return;
223 } 226 }
234 /* Descend into directory? */ 237 /* Descend into directory? */
235 return; 238 return;
236 } 239 }
237 #endif /* FILECHOOSER */ 240 #endif /* FILECHOOSER */
238 241
242 gaim_request_close_with_handle(win->save);
243
239 if (g_file_test(filename, G_FILE_TEST_EXISTS)) 244 if (g_file_test(filename, G_FILE_TEST_EXISTS))
240 { 245 {
241 gaim_request_close_with_handle(win->save);
242 gaim_request_yes_no(win->save, NULL, _("That file already exists"), 246 gaim_request_yes_no(win->save, NULL, _("That file already exists"),
243 _("Would you like to overwrite it?"), 1, 247 _("Would you like to overwrite it?"), 1,
244 win->save, G_CALLBACK(save_writefile_cb), NULL); 248 win, G_CALLBACK(save_writefile_cb), NULL);
245 } 249 }
246 else 250 else
247 save_writefile_cb(win->save); 251 save_writefile_cb(win, 1);
248 } 252 }
249 253
250 #if !GTK_CHECK_VERSION(2,4,0) /* FILECHOOSER */ 254 #if !GTK_CHECK_VERSION(2,4,0) /* FILECHOOSER */
251 static void 255 static void
252 save_destroy_cb(GtkWidget *widget, DebugWindow *win) 256 save_destroy_cb(GtkWidget *widget, DebugWindow *win)
253 { 257 {
254 if (win->save != NULL) 258 if (win->save != NULL) {
259 gaim_notify_close_with_handle(win->save);
260 gaim_request_close_with_handle(win->save);
255 gtk_widget_destroy(win->save); 261 gtk_widget_destroy(win->save);
256 262 win->save = NULL;
257 win->save = NULL; 263 }
258 } 264 }
259 #endif 265 #endif
260 266
261 static void 267 static void
262 save_cb(GtkWidget *w, DebugWindow *win) 268 save_cb(GtkWidget *w, DebugWindow *win)
281 gtk_file_chooser_set_current_name(GTK_FILE_CHOOSER(win->save), 287 gtk_file_chooser_set_current_name(GTK_FILE_CHOOSER(win->save),
282 "gaim-debug.log"); 288 "gaim-debug.log");
283 g_signal_connect(G_OBJECT(win->save), "response", 289 g_signal_connect(G_OBJECT(win->save), "response",
284 G_CALLBACK(save_checkfile_cb), win); 290 G_CALLBACK(save_checkfile_cb), win);
285 #else /* FILECHOOSER */ 291 #else /* FILECHOOSER */
286 win->save = gtk_file_selection_new(_("Save Debug Log"));
287 buf = g_strdup_printf("%s" G_DIR_SEPARATOR_S "gaim-debug.log", 292 buf = g_strdup_printf("%s" G_DIR_SEPARATOR_S "gaim-debug.log",
288 gaim_home_dir()); 293 gaim_home_dir());
294 win->save = gtk_file_selection_new(_("Save Debug Log"));
289 gtk_file_selection_set_filename(GTK_FILE_SELECTION(win->save), buf); 295 gtk_file_selection_set_filename(GTK_FILE_SELECTION(win->save), buf);
290 g_free(buf);
291 g_signal_connect(G_OBJECT(GTK_FILE_SELECTION(win->save)->ok_button), 296 g_signal_connect(G_OBJECT(GTK_FILE_SELECTION(win->save)->ok_button),
292 "clicked", G_CALLBACK(save_checkfile_cb), win); 297 "clicked", G_CALLBACK(save_checkfile_cb), win);
293 g_signal_connect(G_OBJECT(GTK_FILE_SELECTION(win->save)->cancel_button), 298 g_signal_connect(G_OBJECT(GTK_FILE_SELECTION(win->save)->cancel_button),
294 "clicked", G_CALLBACK(save_destroy_cb), win); 299 "clicked", G_CALLBACK(save_destroy_cb), win);
295 g_signal_connect(G_OBJECT(win->save), 300 g_signal_connect(G_OBJECT(win->save),
296 "destroy", G_CALLBACK(save_destroy_cb), win); 301 "destroy", G_CALLBACK(save_destroy_cb), win);
302 g_free(buf);
297 #endif /* FILECHOOSER */ 303 #endif /* FILECHOOSER */
298 304
299 gtk_widget_show_all(GTK_WIDGET(win->save)); 305 gtk_widget_show_all(GTK_WIDGET(win->save));
300 } 306 }
301 307