static void cb_format_combo_changed (GtkComboBox *combo, GtkWidget *expander) { GOImageFormatInfo const *format_info; format_info = go_image_get_format_info (gtk_combo_box_get_active (combo)); gtk_widget_set_sensitive (expander, format_info != NULL && format_info->is_dpi_useful); }
static void soi_cb_save_as (SheetObject *so, SheetControl *sc) { WBCGtk *wbcg; char *uri; GsfOutput *output; GSList *l = NULL; GOImageFormat sel_fmt; GOImageFormatInfo const *format_info; GdkPixbuf *pixbuf = NULL; GError *err = NULL; SheetObjectImage *soi = SHEET_OBJECT_IMAGE (so); g_return_if_fail (soi != NULL); sel_fmt = go_image_get_format_from_name (soi->type); if ((pixbuf = go_image_get_pixbuf (soi->image)) != NULL) l = go_image_get_formats_with_pixbuf_saver (); /* Move original format first in menu */ if (sel_fmt != GO_IMAGE_FORMAT_UNKNOWN) { l = g_slist_remove (l, GUINT_TO_POINTER (sel_fmt)); l = g_slist_prepend (l, GUINT_TO_POINTER (sel_fmt)); } wbcg = scg_wbcg (SHEET_CONTROL_GUI (sc)); uri = go_gui_get_image_save_info (wbcg_toplevel (wbcg), l, &sel_fmt, NULL); if (!uri) goto out; output = go_file_create (uri, &err); if (!output) goto out; format_info = go_image_get_format_info (sel_fmt); sheet_object_write_image (so, (format_info? format_info->name: NULL), -1.0, output, &err); gsf_output_close (output); g_object_unref (output); if (err != NULL) go_cmd_context_error (GO_CMD_CONTEXT (wbcg), err); out: if (pixbuf) g_object_unref (pixbuf); g_free (uri); g_slist_free (l); }
char * gui_get_image_save_info (GtkWindow *toplevel, GSList *supported_formats, GOImageFormat *ret_format, double *resolution) { GOImageFormat format; GOImageFormatInfo const *format_info; GtkComboBox *format_combo = NULL; GtkFileChooser *fsel = gui_image_chooser_new (TRUE); GtkWidget *expander = NULL; GtkWidget *resolution_spin = NULL; GtkWidget *resolution_table; GladeXML *gui; SaveInfoState *state; const char *key = "gui_get_image_save_info"; char *uri = NULL; state = g_object_get_data (G_OBJECT (toplevel), key); if (state == NULL) { state = g_new (SaveInfoState, 1); g_return_val_if_fail (state != NULL, NULL); state->uri = NULL; state->resolution = 150.0; state->is_expanded = FALSE; state->format = GO_IMAGE_FORMAT_SVG; g_object_set_data_full (G_OBJECT (toplevel), key, state, (GDestroyNotify) save_info_state_free); } g_object_set (G_OBJECT (fsel), "title", _("Save as"), NULL); gui = go_libglade_new ("go-image-save-dialog-extra.glade", "image_save_dialog_extra", GETTEXT_PACKAGE, NULL); if (gui != NULL) { GtkWidget *widget; /* Format selection UI */ if (supported_formats != NULL && ret_format != NULL) { int i; GSList *l; format_combo = GTK_COMBO_BOX (glade_xml_get_widget (gui, "format_combo")); for (l = supported_formats, i = 0; l != NULL; l = l->next, i++) { format = GPOINTER_TO_UINT (l->data); format_info = go_image_get_format_info (format); gtk_combo_box_append_text (format_combo, _(format_info->desc)); if (format == state->format) gtk_combo_box_set_active (format_combo, i); } if (gtk_combo_box_get_active (format_combo) < 0) gtk_combo_box_set_active (format_combo, 0); } else { widget = glade_xml_get_widget (gui, "file_type_box"); gtk_widget_hide (widget); } /* Export setting expander */ expander = glade_xml_get_widget (gui, "export_expander"); if (resolution != NULL) { gtk_expander_set_expanded (GTK_EXPANDER (expander), state->is_expanded); resolution_spin = glade_xml_get_widget (gui, "resolution_spin"); gtk_spin_button_set_value (GTK_SPIN_BUTTON (resolution_spin), state->resolution); } else gtk_widget_hide (expander); if (resolution != NULL && supported_formats != NULL && ret_format != NULL) { widget = glade_xml_get_widget (gui, "image_save_dialog_extra"); gtk_file_chooser_set_extra_widget (fsel, widget); resolution_table = glade_xml_get_widget (gui, "resolution_table"); cb_format_combo_changed (format_combo, resolution_table); g_signal_connect (GTK_WIDGET (format_combo), "changed", G_CALLBACK (cb_format_combo_changed), resolution_table); } g_object_unref (G_OBJECT (gui)); } if (state->uri != NULL) { gtk_file_chooser_set_uri (fsel, state->uri); gtk_file_chooser_unselect_all (fsel); } /* Show file selector */ loop: if (!go_gtk_file_sel_dialog (toplevel, GTK_WIDGET (fsel))) goto out; uri = gtk_file_chooser_get_uri (fsel); if (format_combo) { char *new_uri = NULL; format = GPOINTER_TO_UINT (g_slist_nth_data (supported_formats, gtk_combo_box_get_active (format_combo))); format_info = go_image_get_format_info (format); if (!go_url_check_extension (uri, format_info->ext, &new_uri) && !go_gtk_query_yes_no (GTK_WINDOW (fsel), TRUE, _("The given file extension does not match the" " chosen file type. Do you want to use this name" " anyway?"))) { g_free (new_uri); g_free (uri); uri = NULL; goto out; } else { g_free (uri); uri = new_uri; } *ret_format = format; } if (!go_gtk_url_is_writeable (GTK_WINDOW (fsel), uri, TRUE)) { g_free (uri); uri = NULL; goto loop; } out: if (uri != NULL) { g_free (state->uri); state->uri = g_strdup (uri); state->format = *ret_format; if (resolution != NULL) { state->is_expanded = gtk_expander_get_expanded (GTK_EXPANDER (expander)); *resolution = gtk_spin_button_get_value (GTK_SPIN_BUTTON (resolution_spin)); state->resolution = *resolution; } } gtk_widget_destroy (GTK_WIDGET (fsel)); return uri; }