gboolean file_utils_save_thumbnail (GimpImage *image, const gchar *filename) { GFile *file; gboolean success = FALSE; g_return_val_if_fail (GIMP_IS_IMAGE (image), FALSE); g_return_val_if_fail (filename != NULL, FALSE); file = gimp_image_get_file (image); if (file) { gchar *image_uri = g_file_get_uri (file); gchar *uri = g_filename_to_uri (filename, NULL, NULL); if (uri && image_uri && ! strcmp (uri, image_uri)) { GimpImagefile *imagefile; imagefile = gimp_imagefile_new (image->gimp, file); success = gimp_imagefile_save_thumbnail (imagefile, NULL, image, NULL); g_object_unref (imagefile); } g_free (image_uri); g_free (uri); } return success; }
static void gimp_image_duplicate_save_source_file (GimpImage *image, GimpImage *new_image) { GFile *file = gimp_image_get_file (image); if (file) g_object_set_data_full (G_OBJECT (new_image), "gimp-image-source-file", g_object_ref (file), (GDestroyNotify) g_object_unref); }
void file_actions_update (GimpActionGroup *group, gpointer data) { Gimp *gimp = action_data_get_gimp (data); GimpImage *image = action_data_get_image (data); GimpDrawable *drawable = NULL; GFile *file = NULL; GFile *source = NULL; GFile *export = NULL; gboolean show_overwrite = FALSE; if (image) { drawable = gimp_image_get_active_drawable (image); file = gimp_image_get_file (image); source = gimp_image_get_imported_file (image); export = gimp_image_get_exported_file (image); }
static void gimp_image_prop_view_label_set_filetype (GtkWidget *label, GimpImage *image) { GimpPlugInManager *manager = image->gimp->plug_in_manager; GimpPlugInProcedure *proc; proc = gimp_image_get_save_proc (image); if (! proc) proc = gimp_image_get_load_proc (image); if (! proc) { GFile *file = gimp_image_get_file (image); if (file) proc = file_procedure_find (manager->load_procs, file, NULL); } gtk_label_set_text (GTK_LABEL (label), proc ? gimp_plug_in_procedure_get_label (proc) : NULL); }
void gimp_export_dialog_set_image (GimpExportDialog *dialog, Gimp *gimp, GimpImage *image) { GFile *dir_file = NULL; GFile *name_file = NULL; GFile *ext_file = NULL; gchar *basename; g_return_if_fail (GIMP_IS_EXPORT_DIALOG (dialog)); g_return_if_fail (GIMP_IS_IMAGE (image)); GIMP_FILE_DIALOG (dialog)->image = image; gimp_file_dialog_set_file_proc (GIMP_FILE_DIALOG (dialog), NULL); /* * Priority of default paths for Export: * * 1. Last Export path * 2. Path of import source * 3. Path of XCF source * 4. Last path of any save to XCF * 5. Last Export path of any document * 6. The default path (usually the OS 'Documents' path) */ dir_file = gimp_image_get_exported_file (image); if (! dir_file) dir_file = g_object_get_data (G_OBJECT (image), "gimp-image-source-file"); if (! dir_file) dir_file = gimp_image_get_imported_file (image); if (! dir_file) dir_file = gimp_image_get_file (image); if (! dir_file) dir_file = g_object_get_data (G_OBJECT (gimp), GIMP_FILE_SAVE_LAST_FILE_KEY); if (! dir_file) dir_file = g_object_get_data (G_OBJECT (gimp), GIMP_FILE_EXPORT_LAST_FILE_KEY); if (! dir_file) dir_file = gimp_export_dialog_get_default_folder (gimp); /* Priority of default basenames for Export: * * 1. Last Export name * 3. Save URI * 2. Source file name * 3. 'Untitled' */ name_file = gimp_image_get_exported_file (image); if (! name_file) name_file = gimp_image_get_file (image); if (! name_file) name_file = gimp_image_get_imported_file (image); if (! name_file) name_file = gimp_image_get_untitled_file (image); /* Priority of default type/extension for Export: * * 1. Type of last Export * 2. Type of the image Import * 3. Type of latest Export of any document * 4. .png */ ext_file = gimp_image_get_exported_file (image); if (! ext_file) ext_file = gimp_image_get_imported_file (image); if (! ext_file) ext_file = g_object_get_data (G_OBJECT (gimp), GIMP_FILE_EXPORT_LAST_FILE_KEY); if (ext_file) g_object_ref (ext_file); else ext_file = g_file_new_for_uri ("file:///we/only/care/about/extension.png"); if (ext_file) { GFile *tmp_file = file_utils_file_with_new_ext (name_file, ext_file); basename = g_path_get_basename (gimp_file_get_utf8_name (tmp_file)); g_object_unref (tmp_file); g_object_unref (ext_file); } else { basename = g_path_get_basename (gimp_file_get_utf8_name (name_file)); } if (g_file_query_file_type (dir_file, G_FILE_QUERY_INFO_NONE, NULL) == G_FILE_TYPE_DIRECTORY) { gtk_file_chooser_set_current_folder_file (GTK_FILE_CHOOSER (dialog), dir_file, NULL); } else { GFile *parent_file = g_file_get_parent (dir_file); gtk_file_chooser_set_current_folder_file (GTK_FILE_CHOOSER (dialog), parent_file, NULL); g_object_unref (parent_file); } gtk_file_chooser_set_current_name (GTK_FILE_CHOOSER (dialog), basename); }
static void gimp_display_shell_close_dialog (GimpDisplayShell *shell, GimpImage *image) { GtkWidget *dialog; GimpMessageBox *box; GtkWidget *label; GtkAccelGroup *accel_group; GClosure *closure; GSource *source; guint accel_key; GdkModifierType accel_mods; gchar *title; gchar *accel_string; gchar *hint; gchar *markup; GFile *file; if (shell->close_dialog) { gtk_window_present (GTK_WINDOW (shell->close_dialog)); return; } file = gimp_image_get_file (image); title = g_strdup_printf (_("Close %s"), gimp_image_get_display_name (image)); shell->close_dialog = dialog = gimp_message_dialog_new (title, "document-save", GTK_WIDGET (shell), GTK_DIALOG_DESTROY_WITH_PARENT, gimp_standard_help_func, NULL, NULL); g_free (title); gtk_dialog_add_buttons (GTK_DIALOG (dialog), _("_Discard Changes"), GTK_RESPONSE_CLOSE, GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, (file ? GTK_STOCK_SAVE : GTK_STOCK_SAVE_AS), RESPONSE_SAVE, NULL); gtk_dialog_set_default_response (GTK_DIALOG (dialog), GTK_RESPONSE_CANCEL); gtk_dialog_set_alternative_button_order (GTK_DIALOG (dialog), RESPONSE_SAVE, GTK_RESPONSE_CLOSE, GTK_RESPONSE_CANCEL, -1); g_signal_connect (dialog, "destroy", G_CALLBACK (gtk_widget_destroyed), &shell->close_dialog); g_signal_connect (dialog, "response", G_CALLBACK (gimp_display_shell_close_response), shell); /* connect <Primary>D to the quit/close button */ accel_group = gtk_accel_group_new (); gtk_window_add_accel_group (GTK_WINDOW (shell->close_dialog), accel_group); g_object_unref (accel_group); closure = g_closure_new_object (sizeof (GClosure), G_OBJECT (shell->close_dialog)); g_closure_set_marshal (closure, gimp_display_shell_close_accel_marshal); gtk_accelerator_parse ("<Primary>D", &accel_key, &accel_mods); gtk_accel_group_connect (accel_group, accel_key, accel_mods, 0, closure); box = GIMP_MESSAGE_DIALOG (dialog)->box; accel_string = gtk_accelerator_get_label (accel_key, accel_mods); hint = g_strdup_printf (_("Press %s to discard all changes and close the image."), accel_string); markup = g_strdup_printf ("<i><small>%s</small></i>", hint); label = gtk_label_new (NULL); gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5); gtk_label_set_line_wrap (GTK_LABEL (label), TRUE); gtk_label_set_markup (GTK_LABEL (label), markup); gtk_box_pack_start (GTK_BOX (box), label, FALSE, FALSE, 0); gtk_widget_show (label); g_free (markup); g_free (hint); g_free (accel_string); g_signal_connect_object (image, "name-changed", G_CALLBACK (gimp_display_shell_close_name_changed), box, 0); g_signal_connect_object (image, "exported", G_CALLBACK (gimp_display_shell_close_exported), box, 0); gimp_display_shell_close_name_changed (image, box); closure = g_cclosure_new_object (G_CALLBACK (gimp_display_shell_close_time_changed), G_OBJECT (box)); /* update every 10 seconds */ source = g_timeout_source_new_seconds (10); g_source_set_closure (source, closure); g_source_attach (source, NULL); g_source_unref (source); /* The dialog is destroyed with the shell, so it should be safe * to hold an image pointer for the lifetime of the dialog. */ g_object_set_data (G_OBJECT (box), "gimp-image", image); gimp_display_shell_close_time_changed (box); gtk_widget_show (dialog); }