Commit 7c811a36de4a8a12c4dd34c0612199b828b26483
1 parent
81955deb
Exists in
master
and in
1 other branch
Working on trace window.
Showing
8 changed files
with
102 additions
and
13 deletions
Show diff stats
src/filetransfer/activitylist.c
... | ... | @@ -270,7 +270,7 @@ |
270 | 270 | { |
271 | 271 | V3270FTActivityList * list = GTK_V3270_FT_ACTIVITY_LIST(widget); |
272 | 272 | |
273 | - gchar * filename = v3270ft_select_file( | |
273 | + gchar * filename = v3270_select_file( | |
274 | 274 | widget, |
275 | 275 | _("Load queue from file"), |
276 | 276 | _("Load"), GTK_FILE_CHOOSER_ACTION_OPEN, |
... | ... | @@ -370,7 +370,7 @@ |
370 | 370 | { |
371 | 371 | V3270FTActivityList * list = GTK_V3270_FT_ACTIVITY_LIST(widget); |
372 | 372 | |
373 | - gchar * filename = v3270ft_select_file( | |
373 | + gchar * filename = v3270_select_file( | |
374 | 374 | widget, |
375 | 375 | _("Save queue to file"), |
376 | 376 | _("Save"), | ... | ... |
src/filetransfer/select.c
... | ... | @@ -37,7 +37,7 @@ |
37 | 37 | |
38 | 38 | /*--[ Implement ]------------------------------------------------------------------------------------*/ |
39 | 39 | |
40 | -gchar * v3270ft_select_file(GtkWidget *dialog, const gchar *title, const gchar *button, GtkFileChooserAction action, const gchar *filename, G_GNUC_UNUSED const gchar *filter, ...) { | |
40 | +gchar * v3270_select_file(GtkWidget *dialog, const gchar *title, const gchar *button, GtkFileChooserAction action, const gchar *filename, G_GNUC_UNUSED const gchar *filter, ...) { | |
41 | 41 | |
42 | 42 | gchar *rc = NULL; |
43 | 43 | ... | ... |
src/filetransfer/settings.c
... | ... | @@ -202,7 +202,7 @@ static gboolean spin_format(GtkSpinButton *spin, G_GNUC_UNUSED gpointer data) { |
202 | 202 | static void open_select_file_dialog(GtkEntry *entry, G_GNUC_UNUSED GtkEntryIconPosition icon_pos, G_GNUC_UNUSED GdkEvent *event, GtkWidget *widget) |
203 | 203 | { |
204 | 204 | v3270_autofree gchar *filename = |
205 | - v3270ft_select_file( | |
205 | + v3270_select_file( | |
206 | 206 | gtk_widget_get_toplevel(widget), |
207 | 207 | _("Select local file"), |
208 | 208 | _("Select"), | ... | ... |
src/filetransfer/v3270ft.c
... | ... | @@ -190,7 +190,7 @@ static void remove_file(G_GNUC_UNUSED GtkButton *button, v3270ft *dialog) { |
190 | 190 | |
191 | 191 | static void load_file(G_GNUC_UNUSED GtkButton *button, v3270ft *dialog) { |
192 | 192 | |
193 | - gchar * filename = v3270ft_select_file( | |
193 | + gchar * filename = v3270_select_file( | |
194 | 194 | GTK_WIDGET(dialog), |
195 | 195 | _("Load queue from file"), |
196 | 196 | _("Load"), GTK_FILE_CHOOSER_ACTION_OPEN, |
... | ... | @@ -209,7 +209,7 @@ static void load_file(G_GNUC_UNUSED GtkButton *button, v3270ft *dialog) { |
209 | 209 | |
210 | 210 | static void save_file(G_GNUC_UNUSED GtkButton *button, v3270ft *dialog) { |
211 | 211 | |
212 | - gchar * filename = v3270ft_select_file( | |
212 | + gchar * filename = v3270_select_file( | |
213 | 213 | GTK_WIDGET(dialog), |
214 | 214 | _("Save queue to file"), |
215 | 215 | _("Save"), |
... | ... | @@ -297,7 +297,7 @@ static void select_local_file(GtkButton G_GNUC_UNUSED(*button), v3270ft *dialog) |
297 | 297 | static void icon_press(G_GNUC_UNUSED GtkEntry *entry, G_GNUC_UNUSED GtkEntryIconPosition icon_pos, G_GNUC_UNUSED GdkEvent *event, v3270ft *dialog) { |
298 | 298 | #endif // WIN32 |
299 | 299 | |
300 | - gchar *filename = v3270ft_select_file( | |
300 | + gchar *filename = v3270_select_file( | |
301 | 301 | GTK_WIDGET(dialog), |
302 | 302 | _("Select local file"), |
303 | 303 | _("Select"), | ... | ... |
src/include/internals.h
... | ... | @@ -73,6 +73,8 @@ |
73 | 73 | G_GNUC_INTERNAL void v3270_activity_list_save(GtkWidget *widget); |
74 | 74 | G_GNUC_INTERNAL void v3270_activity_list_save_as(GtkWidget *widget); |
75 | 75 | |
76 | + G_GNUC_INTERNAL gchar * v3270_select_file(GtkWidget *dialog, const gchar *title, const gchar *button, GtkFileChooserAction action, const gchar *filename, const gchar *filter, ... ) G_GNUC_NULL_TERMINATED; | |
77 | + | |
76 | 78 | G_END_DECLS |
77 | 79 | |
78 | 80 | #endif // V3270_INTERNALS_H_INCLUDED | ... | ... |
src/include/v3270/filetransfer.h
... | ... | @@ -77,8 +77,6 @@ |
77 | 77 | void v3270ft_append_file(GtkWidget *widget, const gchar *filename, gboolean text); |
78 | 78 | guint v3270ft_append_selection(GtkWidget *widget, GtkSelectionData *data); |
79 | 79 | |
80 | - gchar * v3270ft_select_file(GtkWidget *dialog, const gchar *title, const gchar *button, GtkFileChooserAction action, const gchar *filename, const gchar *filter, ... ) G_GNUC_NULL_TERMINATED; | |
81 | - | |
82 | 80 | gint v3270ft_transfer(GtkWidget *dialog, H3270 *session); |
83 | 81 | |
84 | 82 | // FT Settings widget | ... | ... |
src/include/v3270/trace.h
... | ... | @@ -52,6 +52,9 @@ |
52 | 52 | LIB3270_EXPORT void v3270_trace_vprintf(GtkWidget *widget, const char *fmt, va_list args); |
53 | 53 | LIB3270_EXPORT void v3270_trace_printf(GtkWidget *widget, const char *fmt, ... ); |
54 | 54 | |
55 | + LIB3270_EXPORT void v3270_trace_save(GtkWidget *widget); | |
56 | + LIB3270_EXPORT void v3270_trace_select_file(GtkWidget *widget); | |
57 | + | |
55 | 58 | G_END_DECLS |
56 | 59 | |
57 | 60 | #endif // V3270_H_INCLUDED | ... | ... |
src/trace/widget.c
... | ... | @@ -50,6 +50,7 @@ |
50 | 50 | #include <lib3270/trace.h> |
51 | 51 | #include <lib3270/properties.h> |
52 | 52 | #include <v3270/trace.h> |
53 | + #include <internals.h> | |
53 | 54 | |
54 | 55 | #if defined( HAVE_SYSLOG ) |
55 | 56 | #include <syslog.h> |
... | ... | @@ -74,6 +75,8 @@ |
74 | 75 | GtkTextBuffer * text; ///< @brief Trace window contents. |
75 | 76 | GtkEntry * entry; ///< @brief Command line entry. |
76 | 77 | |
78 | + gchar * filename; ///< @brief Selected file name. | |
79 | + | |
77 | 80 | guint log_handler; ///< @brief GTK Log Handler. |
78 | 81 | |
79 | 82 | /// @brief lib3270's saved trace handler. |
... | ... | @@ -124,6 +127,12 @@ |
124 | 127 | |
125 | 128 | V3270Trace *trace = GTK_V3270_TRACE(object); |
126 | 129 | |
130 | + if(trace->filename) | |
131 | + { | |
132 | + g_free(trace->filename); | |
133 | + trace->filename = NULL; | |
134 | + } | |
135 | + | |
127 | 136 | if(trace->log_handler) |
128 | 137 | { |
129 | 138 | g_log_remove_handler(NULL,trace->log_handler); |
... | ... | @@ -324,6 +333,9 @@ |
324 | 333 | |
325 | 334 | static void bg_append_text(struct _append_text *cfg) |
326 | 335 | { |
336 | + if(!GTK_IS_TEXT_BUFFER(cfg->widget->text)) | |
337 | + return; | |
338 | + | |
327 | 339 | GtkTextIter itr; |
328 | 340 | gtk_text_buffer_get_end_iter(cfg->widget->text,&itr); |
329 | 341 | |
... | ... | @@ -379,9 +391,14 @@ |
379 | 391 | g_signal_connect(G_OBJECT(widget), "activate", callback, data); |
380 | 392 | } |
381 | 393 | |
382 | - static void menu_save_as(G_GNUC_UNUSED GtkWidget *button, V3270Trace *trace) | |
394 | + static void menu_save(G_GNUC_UNUSED GtkWidget *button, GtkWidget *trace) | |
383 | 395 | { |
384 | - debug("%s",__FUNCTION__); | |
396 | + v3270_trace_save(trace); | |
397 | + } | |
398 | + | |
399 | + static void menu_save_as(G_GNUC_UNUSED GtkWidget *button, GtkWidget *trace) | |
400 | + { | |
401 | + v3270_trace_select_file(trace); | |
385 | 402 | } |
386 | 403 | |
387 | 404 | static void menu_close(G_GNUC_UNUSED GtkWidget *button, GtkWidget *window) |
... | ... | @@ -396,7 +413,7 @@ |
396 | 413 | |
397 | 414 | GtkWidget * window = gtk_window_new(GTK_WINDOW_TOPLEVEL); |
398 | 415 | GtkWidget * vbox = gtk_box_new(GTK_ORIENTATION_VERTICAL,0); |
399 | - V3270Trace * trace = v3270_trace_new(widget); | |
416 | + GtkWidget * trace = v3270_trace_new(widget); | |
400 | 417 | |
401 | 418 | // Set window title and default size |
402 | 419 | { |
... | ... | @@ -406,7 +423,7 @@ |
406 | 423 | if(url) |
407 | 424 | title = g_strdup_printf("%s - %s - Trace", v3270_get_session_name(widget), url); |
408 | 425 | else |
409 | - title = g_strdup_printf("%s - Trace", v3270_get_session_name(widget), url); | |
426 | + title = g_strdup_printf("%s - Trace", v3270_get_session_name(widget)); | |
410 | 427 | |
411 | 428 | gtk_window_set_title(GTK_WINDOW(window), title); |
412 | 429 | gtk_window_set_default_size(GTK_WINDOW(widget),590,430); |
... | ... | @@ -421,6 +438,7 @@ |
421 | 438 | gtk_menu_item_set_submenu(GTK_MENU_ITEM(topitem), submenu); |
422 | 439 | gtk_menu_shell_append(GTK_MENU_SHELL(menubar), topitem); |
423 | 440 | |
441 | + menu_item_new(submenu,_("_Save"),G_CALLBACK(menu_save),trace); | |
424 | 442 | menu_item_new(submenu,_("Save _As"),G_CALLBACK(menu_save_as),trace); |
425 | 443 | menu_item_new(submenu,_("_Close"),G_CALLBACK(menu_close),window); |
426 | 444 | |
... | ... | @@ -435,3 +453,71 @@ |
435 | 453 | return window; |
436 | 454 | } |
437 | 455 | |
456 | + LIB3270_EXPORT void v3270_trace_save(GtkWidget *widget) | |
457 | + { | |
458 | + V3270Trace * trace = GTK_V3270_TRACE(widget); | |
459 | + | |
460 | + if(trace && trace->filename) | |
461 | + { | |
462 | + GError * error = NULL; | |
463 | + gchar * text; | |
464 | + GtkTextIter start; | |
465 | + GtkTextIter end; | |
466 | + | |
467 | + gtk_text_buffer_get_start_iter(trace->text,&start); | |
468 | + gtk_text_buffer_get_end_iter(trace->text,&end); | |
469 | + text = gtk_text_buffer_get_text(trace->text,&start,&end,FALSE); | |
470 | + | |
471 | + g_file_set_contents(trace->filename,text,-1,&error); | |
472 | + | |
473 | + g_free(text); | |
474 | + | |
475 | + if(error) | |
476 | + { | |
477 | + GtkWidget *popup = | |
478 | + gtk_message_dialog_new_with_markup( | |
479 | + GTK_WINDOW(gtk_widget_get_toplevel(widget)), | |
480 | + GTK_DIALOG_MODAL|GTK_DIALOG_DESTROY_WITH_PARENT, | |
481 | + GTK_MESSAGE_ERROR, | |
482 | + GTK_BUTTONS_CLOSE, | |
483 | + _( "Can't save %s" ), | |
484 | + trace->filename | |
485 | + ); | |
486 | + | |
487 | + gtk_window_set_title(GTK_WINDOW(popup),_("Can't save file")); | |
488 | + | |
489 | + gtk_message_dialog_format_secondary_markup(GTK_MESSAGE_DIALOG(popup),"%s",error->message); | |
490 | + g_error_free(error); | |
491 | + | |
492 | + gtk_dialog_run(GTK_DIALOG(popup)); | |
493 | + gtk_widget_destroy(popup); | |
494 | + | |
495 | + } | |
496 | + | |
497 | + } | |
498 | + | |
499 | + } | |
500 | + | |
501 | + LIB3270_EXPORT void v3270_trace_select_file(GtkWidget *widget) | |
502 | + { | |
503 | + V3270Trace * trace = GTK_V3270_TRACE(widget); | |
504 | + | |
505 | + gchar * filename = | |
506 | + v3270_select_file( | |
507 | + GTK_WIDGET(trace), | |
508 | + _("Save trace to file"), | |
509 | + _("Save"), | |
510 | + GTK_FILE_CHOOSER_ACTION_SAVE, | |
511 | + trace->filename, | |
512 | + N_("Text file"), "*.txt", | |
513 | + NULL | |
514 | + ); | |
515 | + | |
516 | + if(filename) { | |
517 | + g_free(trace->filename); | |
518 | + trace->filename = filename; | |
519 | + v3270_trace_save(widget); | |
520 | + } | |
521 | + | |
522 | + } | |
523 | + | ... | ... |