Commit b35da6da877cbd59c6bf4861a5d5e95d21fcf519
1 parent
42d789e9
Exists in
master
and in
1 other branch
Working on the new "save" dialog.
Showing
7 changed files
with
186 additions
and
27 deletions
Show diff stats
src/dialogs/linux/select.c
| @@ -43,7 +43,7 @@ gchar * v3270_select_file(GtkWidget *widget, const gchar *title, const gchar *bu | @@ -43,7 +43,7 @@ gchar * v3270_select_file(GtkWidget *widget, const gchar *title, const gchar *bu | ||
| 43 | gtk_file_chooser_native_new | 43 | gtk_file_chooser_native_new |
| 44 | ( | 44 | ( |
| 45 | title, | 45 | title, |
| 46 | - GTK_WINDOW(gtk_widget_get_toplevel(widget)), | 46 | + GTK_WINDOW(widget), |
| 47 | action, | 47 | action, |
| 48 | button, | 48 | button, |
| 49 | _( "_Cancel" ) | 49 | _( "_Cancel" ) |
| @@ -88,7 +88,7 @@ gchar * v3270_select_file(GtkWidget *widget, const gchar *title, const gchar *bu | @@ -88,7 +88,7 @@ gchar * v3270_select_file(GtkWidget *widget, const gchar *title, const gchar *bu | ||
| 88 | gtk_file_chooser_dialog_new | 88 | gtk_file_chooser_dialog_new |
| 89 | ( | 89 | ( |
| 90 | title, | 90 | title, |
| 91 | - GTK_WINDOW(gtk_widget_get_toplevel(widget)), | 91 | + GTK_WINDOW(widget), |
| 92 | action, | 92 | action, |
| 93 | _("_Cancel" ), GTK_RESPONSE_CANCEL, | 93 | _("_Cancel" ), GTK_RESPONSE_CANCEL, |
| 94 | button, GTK_RESPONSE_ACCEPT, | 94 | button, GTK_RESPONSE_ACCEPT, |
src/dialogs/save/save.c
| @@ -29,6 +29,10 @@ | @@ -29,6 +29,10 @@ | ||
| 29 | 29 | ||
| 30 | 30 | ||
| 31 | #include "private.h" | 31 | #include "private.h" |
| 32 | + #include <internals.h> | ||
| 33 | + #include <lib3270.h> | ||
| 34 | + #include <lib3270/selection.h> | ||
| 35 | + #include <clipboard.h> | ||
| 32 | #include <limits.h> | 36 | #include <limits.h> |
| 33 | 37 | ||
| 34 | /*--[ GTK Requires ]---------------------------------------------------------------------------------*/ | 38 | /*--[ GTK Requires ]---------------------------------------------------------------------------------*/ |
| @@ -57,6 +61,18 @@ | @@ -57,6 +61,18 @@ | ||
| 57 | } | 61 | } |
| 58 | }; | 62 | }; |
| 59 | 63 | ||
| 64 | + static const struct _charsets | ||
| 65 | + { | ||
| 66 | + const gchar *name; | ||
| 67 | + const gchar *description; | ||
| 68 | + } charsets[] = | ||
| 69 | + { | ||
| 70 | + // http://en.wikipedia.org/wiki/Character_encoding | ||
| 71 | + { "UTF-8", N_( "UTF-8" ) }, | ||
| 72 | + { "ISO-8859-1", N_( "Western Europe (ISO 8859-1)" ) }, | ||
| 73 | + { "CP1252", N_( "Windows Western languages (CP1252)" ) }, | ||
| 74 | + }; | ||
| 75 | + | ||
| 60 | /*--[ Implement ]------------------------------------------------------------------------------------*/ | 76 | /*--[ Implement ]------------------------------------------------------------------------------------*/ |
| 61 | 77 | ||
| 62 | /* | 78 | /* |
| @@ -84,6 +100,31 @@ | @@ -84,6 +100,31 @@ | ||
| 84 | gtk_dialog_response(dialog,GTK_RESPONSE_APPLY); | 100 | gtk_dialog_response(dialog,GTK_RESPONSE_APPLY); |
| 85 | } | 101 | } |
| 86 | 102 | ||
| 103 | +#ifdef WIN32 | ||
| 104 | +static void select_local_file(GtkButton G_GNUC_UNUSED(*button), v3270ft *dialog) { | ||
| 105 | +#else | ||
| 106 | +static void icon_press(G_GNUC_UNUSED GtkEntry *entry, G_GNUC_UNUSED GtkEntryIconPosition icon_pos, G_GNUC_UNUSED GdkEvent *event, V3270SaveDialog *dialog) { | ||
| 107 | +#endif // WIN32 | ||
| 108 | + | ||
| 109 | + gint format = gtk_combo_box_get_active(GTK_COMBO_BOX(dialog->format)); | ||
| 110 | + g_autofree gchar * extension = g_strconcat("*",formats[format].extension,NULL); | ||
| 111 | + | ||
| 112 | + g_autofree gchar *filename = | ||
| 113 | + v3270_select_file( | ||
| 114 | + GTK_WIDGET(dialog), | ||
| 115 | + _("Select file to save"), | ||
| 116 | + _("Select"), | ||
| 117 | + GTK_FILE_CHOOSER_ACTION_SAVE, | ||
| 118 | + gtk_entry_get_text(GTK_ENTRY(dialog->filename)), | ||
| 119 | + gettext(formats[format].name), extension, | ||
| 120 | + NULL | ||
| 121 | + ); | ||
| 122 | + | ||
| 123 | + if(filename) | ||
| 124 | + gtk_entry_set_text(GTK_ENTRY(dialog->filename),filename); | ||
| 125 | + | ||
| 126 | + } | ||
| 127 | + | ||
| 87 | static void V3270SaveDialog_init(V3270SaveDialog *dialog) | 128 | static void V3270SaveDialog_init(V3270SaveDialog *dialog) |
| 88 | { | 129 | { |
| 89 | // 0--------1---------------------2-------3------------------ | 130 | // 0--------1---------------------2-------3------------------ |
| @@ -122,13 +163,13 @@ | @@ -122,13 +163,13 @@ | ||
| 122 | 163 | ||
| 123 | #ifdef WIN32 | 164 | #ifdef WIN32 |
| 124 | widget = gtk_button_new_from_icon_name("document-open",GTK_ICON_SIZE_BUTTON); | 165 | widget = gtk_button_new_from_icon_name("document-open",GTK_ICON_SIZE_BUTTON); |
| 125 | - //g_signal_connect(G_OBJECT(widget),"clicked",G_CALLBACK(select_local_file),dialog); | 166 | + g_signal_connect(G_OBJECT(widget),"clicked",G_CALLBACK(select_local_file),dialog); |
| 126 | gtk_grid_attach(grid,widget,6,0,1,1); | 167 | gtk_grid_attach(grid,widget,6,0,1,1); |
| 127 | #else | 168 | #else |
| 128 | gtk_entry_set_icon_from_icon_name(GTK_ENTRY(dialog->filename),GTK_ENTRY_ICON_SECONDARY,"document-open"); | 169 | gtk_entry_set_icon_from_icon_name(GTK_ENTRY(dialog->filename),GTK_ENTRY_ICON_SECONDARY,"document-open"); |
| 129 | gtk_entry_set_icon_activatable(GTK_ENTRY(dialog->filename),GTK_ENTRY_ICON_SECONDARY,TRUE); | 170 | gtk_entry_set_icon_activatable(GTK_ENTRY(dialog->filename),GTK_ENTRY_ICON_SECONDARY,TRUE); |
| 130 | gtk_entry_set_icon_tooltip_text(GTK_ENTRY(dialog->filename),GTK_ENTRY_ICON_SECONDARY,_("Select file")); | 171 | gtk_entry_set_icon_tooltip_text(GTK_ENTRY(dialog->filename),GTK_ENTRY_ICON_SECONDARY,_("Select file")); |
| 131 | - // g_signal_connect(G_OBJECT(dialog->filename),"icon-press",G_CALLBACK(icon_press),dialog); | 172 | + g_signal_connect(G_OBJECT(dialog->filename),"icon-press",G_CALLBACK(icon_press),dialog); |
| 132 | #endif // WIN32 | 173 | #endif // WIN32 |
| 133 | 174 | ||
| 134 | gtk_entry_set_width_chars(GTK_ENTRY(dialog->filename),60); | 175 | gtk_entry_set_width_chars(GTK_ENTRY(dialog->filename),60); |
| @@ -138,18 +179,6 @@ | @@ -138,18 +179,6 @@ | ||
| 138 | 179 | ||
| 139 | // Charset drop-down | 180 | // Charset drop-down |
| 140 | { | 181 | { |
| 141 | - static const struct _charsets | ||
| 142 | - { | ||
| 143 | - const gchar *name; | ||
| 144 | - const gchar *description; | ||
| 145 | - } charsets[] = | ||
| 146 | - { | ||
| 147 | - // http://en.wikipedia.org/wiki/Character_encoding | ||
| 148 | - { "UTF-8", N_( "UTF-8" ) }, | ||
| 149 | - { "ISO-8859-1", N_( "Western Europe (ISO 8859-1)" ) }, | ||
| 150 | - { "CP1252", N_( "Windows Western languages (CP1252)" ) }, | ||
| 151 | - }; | ||
| 152 | - | ||
| 153 | size_t ix; | 182 | size_t ix; |
| 154 | const gchar * scharset = NULL; | 183 | const gchar * scharset = NULL; |
| 155 | 184 | ||
| @@ -251,6 +280,8 @@ | @@ -251,6 +280,8 @@ | ||
| 251 | 280 | ||
| 252 | GtkWidget * v3270_save_dialog_new(GtkWidget *widget, LIB3270_CONTENT_OPTION mode, const gchar *filename) | 281 | GtkWidget * v3270_save_dialog_new(GtkWidget *widget, LIB3270_CONTENT_OPTION mode, const gchar *filename) |
| 253 | { | 282 | { |
| 283 | + g_return_val_if_fail(GTK_IS_V3270(widget),NULL); | ||
| 284 | + | ||
| 254 | static const gchar * titles[] = | 285 | static const gchar * titles[] = |
| 255 | { | 286 | { |
| 256 | N_("Save terminal contents"), | 287 | N_("Save terminal contents"), |
| @@ -269,7 +300,8 @@ | @@ -269,7 +300,8 @@ | ||
| 269 | NULL) | 300 | NULL) |
| 270 | ); | 301 | ); |
| 271 | 302 | ||
| 272 | - dialog->mode = mode; | 303 | + dialog->mode = mode; |
| 304 | + dialog->terminal = widget; | ||
| 273 | 305 | ||
| 274 | if( (size_t) mode < G_N_ELEMENTS(titles)) | 306 | if( (size_t) mode < G_N_ELEMENTS(titles)) |
| 275 | { | 307 | { |
| @@ -286,9 +318,117 @@ | @@ -286,9 +318,117 @@ | ||
| 286 | return GTK_WIDGET(dialog); | 318 | return GTK_WIDGET(dialog); |
| 287 | } | 319 | } |
| 288 | 320 | ||
| 321 | + void v3270_save_dialog_apply(GtkWidget *widget, GError **error) | ||
| 322 | + { | ||
| 323 | + V3270SaveDialog * dialog = V3270_SAVE_DIALOG(widget); | ||
| 324 | + | ||
| 325 | + if(!v3270_is_connected(dialog->terminal)) | ||
| 326 | + { | ||
| 327 | + *error = g_error_new(g_quark_from_static_string(PACKAGE_NAME),ENOTCONN,"%s",strerror(ENOTCONN)); | ||
| 328 | + return; | ||
| 329 | + } | ||
| 330 | + | ||
| 331 | + // Get selection | ||
| 332 | + GList * dynamic = NULL; | ||
| 333 | + const GList * selection = NULL; | ||
| 334 | + | ||
| 335 | + switch(dialog->mode) | ||
| 336 | + { | ||
| 337 | + case LIB3270_CONTENT_ALL: | ||
| 338 | + break; | ||
| 339 | + | ||
| 340 | + case LIB3270_CONTENT_COPY: | ||
| 341 | + selection = v3270_get_selection_blocks(dialog->terminal); | ||
| 342 | + break; | ||
| 343 | + | ||
| 344 | + case LIB3270_CONTENT_SELECTED: | ||
| 345 | + dynamic = g_new0(GList,1); | ||
| 346 | + dynamic->data = (gpointer) lib3270_get_selection(v3270_get_session(dialog->terminal),0); | ||
| 347 | + selection = dynamic; | ||
| 348 | + break; | ||
| 349 | + | ||
| 350 | + default: | ||
| 351 | + *error = g_error_new(g_quark_from_static_string(PACKAGE_NAME),ENOTCONN,_( "Unexpected mode %d" ),(int) dialog->mode); | ||
| 352 | + return; | ||
| 353 | + } | ||
| 354 | + | ||
| 355 | + if(!selection) | ||
| 356 | + { | ||
| 357 | + *error = g_error_new(g_quark_from_static_string(PACKAGE_NAME),ENOTCONN,"%s",strerror(ENODATA)); | ||
| 358 | + } | ||
| 359 | + else | ||
| 360 | + { | ||
| 361 | + const gchar * encoding = gtk_combo_box_get_active_id(GTK_COMBO_BOX(dialog->charset)); | ||
| 362 | + g_autofree gchar * text = NULL; | ||
| 363 | + | ||
| 364 | + debug("Encoding: %s",encoding); | ||
| 365 | + | ||
| 366 | + switch(gtk_combo_box_get_active(GTK_COMBO_BOX(dialog->format))) | ||
| 367 | + { | ||
| 368 | + case 0: // "Plain text" | ||
| 369 | + text = v3270_get_selection_as_text(GTK_V3270(dialog->terminal), selection, encoding); | ||
| 370 | + break; | ||
| 371 | + | ||
| 372 | + case 1: // "Comma-separated values (CSV)" | ||
| 373 | + text = v3270_get_selection_as_table(GTK_V3270(dialog->terminal),selection,";",encoding); | ||
| 374 | + break; | ||
| 375 | + | ||
| 376 | + case 2: // "HyperText Markup Language (HTML)" | ||
| 377 | + text = v3270_get_selection_as_html_div(GTK_V3270(dialog->terminal),selection,encoding); | ||
| 378 | + break; | ||
| 379 | + | ||
| 380 | + default: | ||
| 381 | + *error = g_error_new(g_quark_from_static_string(PACKAGE_NAME),ENOTCONN,_( "Unexpected format %d" ),(int) gtk_combo_box_get_active(GTK_COMBO_BOX(dialog->format))); | ||
| 382 | + } | ||
| 383 | + | ||
| 384 | + if(text) | ||
| 385 | + { | ||
| 386 | + debug("%s",text); | ||
| 387 | + | ||
| 388 | + g_file_set_contents( | ||
| 389 | + gtk_entry_get_text(GTK_ENTRY(dialog->filename)), | ||
| 390 | + text, | ||
| 391 | + -1, | ||
| 392 | + error | ||
| 393 | + ); | ||
| 394 | + | ||
| 395 | + } | ||
| 396 | + | ||
| 397 | + } | ||
| 398 | + | ||
| 399 | + if(dynamic) | ||
| 400 | + g_list_free_full(dynamic,(GDestroyNotify) lib3270_free); | ||
| 401 | + | ||
| 402 | + } | ||
| 403 | + | ||
| 289 | void v3270_save_dialog_run(GtkWidget *widget) | 404 | void v3270_save_dialog_run(GtkWidget *widget) |
| 290 | { | 405 | { |
| 291 | - gtk_dialog_run(GTK_DIALOG(widget)); | 406 | + if(gtk_dialog_run(GTK_DIALOG(widget)) == GTK_RESPONSE_APPLY) |
| 407 | + { | ||
| 408 | + GError * error = NULL; | ||
| 409 | + v3270_save_dialog_apply(widget,&error); | ||
| 410 | + | ||
| 411 | + if(error) | ||
| 412 | + { | ||
| 413 | + GtkWidget *popup = gtk_message_dialog_new_with_markup( | ||
| 414 | + GTK_WINDOW(gtk_widget_get_toplevel(widget)), | ||
| 415 | + GTK_DIALOG_MODAL|GTK_DIALOG_DESTROY_WITH_PARENT, | ||
| 416 | + GTK_MESSAGE_ERROR,GTK_BUTTONS_CLOSE, | ||
| 417 | + _("Can't save %s"),gtk_entry_get_text(GTK_ENTRY(V3270_SAVE_DIALOG(widget)->filename)) | ||
| 418 | + ); | ||
| 419 | + | ||
| 420 | + gtk_window_set_title(GTK_WINDOW(popup),_("Operation has failed")); | ||
| 421 | + | ||
| 422 | + gtk_message_dialog_format_secondary_markup(GTK_MESSAGE_DIALOG(popup),"%s",error->message); | ||
| 423 | + g_error_free(error); | ||
| 424 | + | ||
| 425 | + gtk_dialog_run(GTK_DIALOG(popup)); | ||
| 426 | + gtk_widget_destroy(popup); | ||
| 427 | + | ||
| 428 | + } | ||
| 429 | + | ||
| 430 | + } | ||
| 431 | + | ||
| 292 | } | 432 | } |
| 293 | 433 | ||
| 294 | 434 |
src/filetransfer/activitylist.c
| @@ -455,7 +455,7 @@ | @@ -455,7 +455,7 @@ | ||
| 455 | V3270FTActivityList * list = GTK_V3270_FT_ACTIVITY_LIST(widget); | 455 | V3270FTActivityList * list = GTK_V3270_FT_ACTIVITY_LIST(widget); |
| 456 | 456 | ||
| 457 | gchar * filename = v3270_select_file( | 457 | gchar * filename = v3270_select_file( |
| 458 | - widget, | 458 | + gtk_widget_get_toplevel(widget), |
| 459 | _("Save queue to file"), | 459 | _("Save queue to file"), |
| 460 | _("Save"), | 460 | _("Save"), |
| 461 | GTK_FILE_CHOOSER_ACTION_SAVE, | 461 | GTK_FILE_CHOOSER_ACTION_SAVE, |
src/include/clipboard.h
| @@ -92,8 +92,10 @@ | @@ -92,8 +92,10 @@ | ||
| 92 | /// @brief Get contents. | 92 | /// @brief Get contents. |
| 93 | G_GNUC_INTERNAL gchar * v3270_get_selection_as_text(v3270 * terminal, const GList *selection, const gchar *encoding); | 93 | G_GNUC_INTERNAL gchar * v3270_get_selection_as_text(v3270 * terminal, const GList *selection, const gchar *encoding); |
| 94 | G_GNUC_INTERNAL gchar * v3270_get_selection_as_table(v3270 * terminal, const GList *selection, const gchar *delimiter, const gchar *encoding); | 94 | G_GNUC_INTERNAL gchar * v3270_get_selection_as_table(v3270 * terminal, const GList *selection, const gchar *delimiter, const gchar *encoding); |
| 95 | + G_GNUC_INTERNAL gchar * v3270_get_selection_as_html_div(v3270 * terminal, const GList *selection, const gchar *encoding); | ||
| 96 | + G_GNUC_INTERNAL gchar * v3270_get_selection_as_html_table(v3270 * terminal, const GList *selection, const gchar *encoding); | ||
| 95 | 97 | ||
| 96 | - | 98 | + G_GNUC_INTERNAL const GList * v3270_get_selection_blocks(GtkWidget *widget); |
| 97 | 99 | ||
| 98 | G_GNUC_INTERNAL gchar * v3270_get_copy_as_text(v3270 * terminal, const gchar *encoding); | 100 | G_GNUC_INTERNAL gchar * v3270_get_copy_as_text(v3270 * terminal, const gchar *encoding); |
| 99 | G_GNUC_INTERNAL gchar * v3270_get_copy_as_html(v3270 * terminal, const gchar *encoding); | 101 | G_GNUC_INTERNAL gchar * v3270_get_copy_as_html(v3270 * terminal, const gchar *encoding); |
src/selection/html.c
| @@ -214,14 +214,24 @@ static gchar * get_as_table(v3270 * terminal, const GList *selection) | @@ -214,14 +214,24 @@ static gchar * get_as_table(v3270 * terminal, const GList *selection) | ||
| 214 | 214 | ||
| 215 | } | 215 | } |
| 216 | 216 | ||
| 217 | +gchar * v3270_get_selection_as_html_div(v3270 * terminal, const GList *selection, const gchar *encoding) | ||
| 218 | +{ | ||
| 219 | + g_autofree char * text = get_as_div(terminal, selection); | ||
| 220 | + return g_convert(text, -1, (encoding ? encoding : "UTF-8"), lib3270_get_display_charset(terminal->host), NULL, NULL, NULL); | ||
| 221 | +} | ||
| 222 | + | ||
| 223 | +gchar * v3270_get_selection_as_html_table(v3270 * terminal, const GList *selection, const gchar *encoding) | ||
| 224 | +{ | ||
| 225 | + g_autofree char * text = get_as_table(terminal, selection); | ||
| 226 | + return g_convert(text, -1, (encoding ? encoding : "UTF-8"), lib3270_get_display_charset(terminal->host), NULL, NULL, NULL); | ||
| 227 | +} | ||
| 228 | + | ||
| 217 | gchar * v3270_get_copy_as_html(v3270 * terminal, const gchar *encoding) | 229 | gchar * v3270_get_copy_as_html(v3270 * terminal, const gchar *encoding) |
| 218 | { | 230 | { |
| 219 | - g_autofree char * text = NULL; | ||
| 220 | 231 | ||
| 221 | if(terminal->selection.format == V3270_SELECT_TABLE) | 232 | if(terminal->selection.format == V3270_SELECT_TABLE) |
| 222 | - text = get_as_table(terminal, terminal->selection.blocks); | ||
| 223 | - else | ||
| 224 | - text = get_as_div(terminal, terminal->selection.blocks); | 233 | + return v3270_get_selection_as_html_table(terminal, terminal->selection.blocks, encoding); |
| 234 | + | ||
| 235 | + return v3270_get_selection_as_html_div(terminal, terminal->selection.blocks, encoding); | ||
| 225 | 236 | ||
| 226 | - return g_convert(text, -1, (encoding ? encoding : "UTF-8"), lib3270_get_display_charset(terminal->host), NULL, NULL, NULL); | ||
| 227 | } | 237 | } |
src/selection/selection.c
| @@ -47,6 +47,13 @@ void v3270_clear_selection(v3270 *terminal) | @@ -47,6 +47,13 @@ void v3270_clear_selection(v3270 *terminal) | ||
| 47 | } | 47 | } |
| 48 | } | 48 | } |
| 49 | 49 | ||
| 50 | +const GList * v3270_get_selection_blocks(GtkWidget *widget) | ||
| 51 | +{ | ||
| 52 | + g_return_val_if_fail(GTK_IS_V3270(widget),NULL); | ||
| 53 | + return GTK_V3270(widget)->selection.blocks; | ||
| 54 | +} | ||
| 55 | + | ||
| 56 | + | ||
| 50 | /** | 57 | /** |
| 51 | * Get lib3270 selection as a g_malloc buffer. | 58 | * Get lib3270 selection as a g_malloc buffer. |
| 52 | * | 59 | * |
src/testprogram/toolbar.c
| @@ -129,12 +129,12 @@ static void save_all_clicked(GtkButton G_GNUC_UNUSED(*button), GtkWidget *termin | @@ -129,12 +129,12 @@ static void save_all_clicked(GtkButton G_GNUC_UNUSED(*button), GtkWidget *termin | ||
| 129 | 129 | ||
| 130 | } | 130 | } |
| 131 | 131 | ||
| 132 | - static void paste_clicked(GtkButton *button, GtkWidget *terminal) | 132 | + static void paste_clicked(GtkButton G_GNUC_UNUSED(*button), GtkWidget *terminal) |
| 133 | { | 133 | { |
| 134 | v3270_paste(terminal); | 134 | v3270_paste(terminal); |
| 135 | } | 135 | } |
| 136 | 136 | ||
| 137 | - static void copy_clicked(GtkButton *button, GtkWidget *terminal) | 137 | + static void copy_clicked(GtkButton G_GNUC_UNUSED(*button), GtkWidget *terminal) |
| 138 | { | 138 | { |
| 139 | v3270_copy_selection(terminal,V3270_SELECT_TEXT,FALSE); | 139 | v3270_copy_selection(terminal,V3270_SELECT_TEXT,FALSE); |
| 140 | } | 140 | } |