diff --git a/src/dialogs/save/save.c b/src/dialogs/save/save.c index c5c29b2..679bf1e 100644 --- a/src/dialogs/save/save.c +++ b/src/dialogs/save/save.c @@ -91,22 +91,6 @@ #ifdef WIN32 static void icon_press(GtkEntry G_GNUC_UNUSED(*entry), G_GNUC_UNUSED GtkEntryIconPosition icon_pos, G_GNUC_UNUSED GdkEvent *event, V3270SaveDialog *widget) { - /* - - GtkFileChooserNative * dialog = - gtk_file_chooser_native_new( - _( "Select destination file"), - GTK_WINDOW(widget), - GTK_FILE_CHOOSER_ACTION_SAVE, - _("Select"), - _("Cancel") - ); - - gint rc = gtk_native_dialog_run (GTK_NATIVE_DIALOG(dialog)); - - debug("rc=%d",rc); - */ - g_autofree gchar *filename = v3270_select_file( GTK_WIDGET(widget), @@ -125,9 +109,6 @@ static void icon_press(GtkEntry G_GNUC_UNUSED(*entry), G_GNUC_UNUSED GtkEntryIco static void icon_press(GtkEntry *entry, G_GNUC_UNUSED GtkEntryIconPosition icon_pos, G_GNUC_UNUSED GdkEvent *event, V3270SaveDialog *widget) { - //gint format = gtk_combo_box_get_active(GTK_COMBO_BOX(widget->format)); - //g_autofree gchar * extension = g_strconcat("*",formats[format].extension,NULL); - GtkWidget * dialog = gtk_file_chooser_dialog_new( _( "Select destination file"), @@ -195,16 +176,10 @@ static void icon_press(GtkEntry *entry, G_GNUC_UNUSED GtkEntryIconPosition icon_ gtk_grid_attach(grid,widget,0,0,1,1); gtk_label_set_mnemonic_widget(GTK_LABEL(widget),dialog->filename); -//#ifdef WIN32 -// widget = gtk_button_new_from_icon_name("document-open",GTK_ICON_SIZE_BUTTON); -// g_signal_connect(G_OBJECT(widget),"clicked",G_CALLBACK(select_file),dialog); -// gtk_grid_attach(grid,widget,4,0,1,1); -//#else - gtk_entry_set_icon_from_icon_name(GTK_ENTRY(dialog->filename),GTK_ENTRY_ICON_SECONDARY,"document-open"); + gtk_entry_set_icon_from_icon_name(GTK_ENTRY(dialog->filename),GTK_ENTRY_ICON_SECONDARY,"document-save-as"); gtk_entry_set_icon_activatable(GTK_ENTRY(dialog->filename),GTK_ENTRY_ICON_SECONDARY,TRUE); gtk_entry_set_icon_tooltip_text(GTK_ENTRY(dialog->filename),GTK_ENTRY_ICON_SECONDARY,_("Select file")); g_signal_connect(G_OBJECT(dialog->filename),"icon-press",G_CALLBACK(icon_press),dialog); -//#endif // WIN32 gtk_entry_set_width_chars(GTK_ENTRY(dialog->filename),60); gtk_entry_set_max_length(GTK_ENTRY(dialog->filename),PATH_MAX); @@ -240,7 +215,7 @@ static void icon_press(GtkEntry *entry, G_GNUC_UNUSED GtkEntryIconPosition icon_ { gtk_combo_box_text_insert( GTK_COMBO_BOX_TEXT(dialog->format), - ix, + -1, formats[ix].extension, g_dgettext(GETTEXT_PACKAGE,formats[ix].name) ); @@ -248,6 +223,26 @@ static void icon_press(GtkEntry *entry, G_GNUC_UNUSED GtkEntryIconPosition icon_ gtk_combo_box_set_active(GTK_COMBO_BOX(dialog->format),0); + // Image formats. + GSList *img_formats = gdk_pixbuf_get_formats(); + GSList *img_format; + + for(img_format = img_formats;img_format;img_format = g_slist_next(img_format)) + { + GdkPixbufFormat * pixFormat = (GdkPixbufFormat *) img_format->data; + + if (gdk_pixbuf_format_is_writable(pixFormat)) + { + gtk_combo_box_text_insert( + GTK_COMBO_BOX_TEXT(dialog->format), + -1, + gdk_pixbuf_format_get_name(pixFormat), + gdk_pixbuf_format_get_description(pixFormat) + ); + } + + } + } @@ -335,20 +330,38 @@ static void icon_press(GtkEntry *entry, G_GNUC_UNUSED GtkEntryIconPosition icon_ return GTK_WIDGET(dialog); } - void v3270_save_dialog_apply(GtkWidget *widget, GError **error) + static const gchar * get_filename(V3270SaveDialog * dialog) { - V3270SaveDialog * dialog = V3270_SAVE_DIALOG(widget); + const gchar * filename = gtk_entry_get_text(GTK_ENTRY(dialog->filename)); + gint response = GTK_RESPONSE_OK; - if(!v3270_is_connected(dialog->terminal)) + if(g_file_test(filename,G_FILE_TEST_EXISTS)) { - *error = g_error_new(g_quark_from_static_string(PACKAGE_NAME),ENOTCONN,"%s",strerror(ENOTCONN)); - return; + GtkWidget * confirmation = + gtk_message_dialog_new_with_markup( + GTK_WINDOW(dialog), + GTK_DIALOG_DESTROY_WITH_PARENT, + GTK_MESSAGE_QUESTION,GTK_BUTTONS_OK_CANCEL, + _("The file \"%s\" already exists. Replace it?"), + filename + ); + + response = gtk_dialog_run(GTK_DIALOG(confirmation)); + gtk_widget_destroy(confirmation); } + return (response == GTK_RESPONSE_OK ? filename : NULL); + + } + + static void save_as_text(V3270SaveDialog * dialog, size_t index, GError **error) + { // Get selection GList * dynamic = NULL; const GList * selection = NULL; + debug("%s",__FUNCTION__); + switch(dialog->mode) { case LIB3270_CONTENT_ALL: @@ -382,7 +395,7 @@ static void icon_press(GtkEntry *entry, G_GNUC_UNUSED GtkEntryIconPosition icon_ debug("Encoding: %s",encoding); - switch(gtk_combo_box_get_active(GTK_COMBO_BOX(dialog->format))) + switch(index) { case 0: // "Plain text" text = v3270_get_selection_as_text(GTK_V3270(dialog->terminal), selection, encoding, dialog->mode == LIB3270_CONTENT_ALL); @@ -402,25 +415,9 @@ static void icon_press(GtkEntry *entry, G_GNUC_UNUSED GtkEntryIconPosition icon_ if(text) { - const gchar * filename = gtk_entry_get_text(GTK_ENTRY(dialog->filename)); - gint response = GTK_RESPONSE_OK; - - if(g_file_test(filename,G_FILE_TEST_EXISTS)) - { - GtkWidget * confirmation = - gtk_message_dialog_new_with_markup( - GTK_WINDOW(widget), - GTK_DIALOG_DESTROY_WITH_PARENT, - GTK_MESSAGE_QUESTION,GTK_BUTTONS_OK_CANCEL, - _("The file \"%s\" already exists. Replace it?"), - filename - ); - - response = gtk_dialog_run(GTK_DIALOG(confirmation)); - gtk_widget_destroy(confirmation); - } + const gchar * filename = get_filename(dialog); - if(response == GTK_RESPONSE_OK) + if(filename) { g_file_set_contents( gtk_entry_get_text(GTK_ENTRY(dialog->filename)), @@ -445,6 +442,56 @@ static void icon_press(GtkEntry *entry, G_GNUC_UNUSED GtkEntryIconPosition icon_ #pragma GCC diagnostic pop } + static void save_as_image(V3270SaveDialog * dialog, const gchar *format, GError **error) + { + debug("%s",__FUNCTION__); + + GdkPixbuf * pixbuf = v3270_get_as_pixbuf(dialog->terminal); + + if(pixbuf) + { + const gchar * filename = get_filename(dialog); + + if(filename) + { + gdk_pixbuf_save(pixbuf,filename,format,error,NULL); + } + + g_object_unref(pixbuf); + } + + } + + void v3270_save_dialog_apply(GtkWidget *widget, GError **error) + { + size_t ix; + V3270SaveDialog * dialog = V3270_SAVE_DIALOG(widget); + + if(!v3270_is_connected(dialog->terminal)) + { + *error = g_error_new(g_quark_from_static_string(PACKAGE_NAME),ENOTCONN,"%s",strerror(ENOTCONN)); + return; + } + + // Get type ID + const gchar * format = gtk_combo_box_get_active_id(GTK_COMBO_BOX(dialog->format)); + + // Check for text formats. + for(ix=0;ixdrawing)) + return NULL; + + gint width = gtk_widget_get_allocated_width(widget); + gint height = gtk_widget_get_allocated_height(widget); + + cairo_surface_t *surface = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, width, height); + + cairo_t *cr = cairo_create(surface); + v3270_redraw(terminal, cr, width, height); + cairo_destroy (cr); + + GdkPixbuf * pixbuf = gdk_pixbuf_get_from_surface(surface,0,0,width,height); + + cairo_surface_destroy (surface); + + return pixbuf; +} + void v3270_update_char(H3270 *session, int addr, unsigned char chr, unsigned short attr, unsigned char cursor) { v3270 * terminal = GTK_V3270(lib3270_get_user_data(session)); diff --git a/v3270.cbp b/v3270.cbp index 99c6cbb..094166a 100644 --- a/v3270.cbp +++ b/v3270.cbp @@ -6,6 +6,7 @@