char * go_gtk_select_image (GtkWindow *toplevel, const char *initial) { const char *key = "go_gtk_select_image"; char *uri = NULL; GtkFileChooser *fsel; g_return_val_if_fail (GTK_IS_WINDOW (toplevel), NULL); fsel = gui_image_chooser_new (FALSE); if (!initial) initial = g_object_get_data (G_OBJECT (toplevel), key); if (initial) gtk_file_chooser_set_uri (fsel, initial); g_object_set (G_OBJECT (fsel), "title", _("Select an Image"), NULL); /* Show file selector */ if (go_gtk_file_sel_dialog (toplevel, GTK_WIDGET (fsel))) { uri = gtk_file_chooser_get_uri (fsel); g_object_set_data_full (G_OBJECT (toplevel), key, g_strdup (uri), g_free); } gtk_widget_destroy (GTK_WIDGET (fsel)); return uri; }
static void cb_pm_button_directory_add_clicked (PluginManagerGUI *pm_gui) { GtkFileChooser *fsel; fsel = GTK_FILE_CHOOSER (g_object_new (GTK_TYPE_FILE_CHOOSER_DIALOG, "action", GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER, "title", _("Select Directory"), /* We need to force local-only as plugins won't work over the network. */ "local-only", TRUE, NULL)); gtk_dialog_add_buttons (GTK_DIALOG (fsel), _("Cancel"), GTK_RESPONSE_CANCEL, _("Add"), GTK_RESPONSE_OK, NULL); gtk_dialog_set_default_response (GTK_DIALOG (fsel), GTK_RESPONSE_OK); if (go_gtk_file_sel_dialog (pm_gui->parent_window, GTK_WIDGET (fsel))) { char *path = gtk_file_chooser_get_filename (fsel); if (!g_file_test (path, G_FILE_TEST_IS_DIR)) { char *dir_name = g_path_get_dirname (path); g_free (path); path = dir_name; } if (g_slist_find_custom (gnm_conf_get_plugins_extra_dirs (), path, go_str_compare) == NULL) { GSList *extra_dirs = go_string_slist_copy (gnm_conf_get_plugins_extra_dirs ()); GO_SLIST_PREPEND (extra_dirs, path); gnm_conf_set_plugins_extra_dirs (extra_dirs); g_slist_free_full (extra_dirs, g_free); pm_gui_load_directory_page (pm_gui); cb_pm_button_rescan_directories_clicked (pm_gui); } else g_free (path); } gtk_widget_destroy (GTK_WIDGET (fsel)); }
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; }