/** * file_open_thumbnail: * @gimp: * @context: * @progress: * @file: an image file * @size: requested size of the thumbnail * @mime_type: return location for image MIME type * @image_width: return location for image width * @image_height: return location for image height * @format: return location for image format (set to NULL if unknown) * @num_layers: return location for number of layers * (set to -1 if the number of layers is not known) * @error: * * Attempts to load a thumbnail by using a registered thumbnail loader. * * Return value: the thumbnail image */ GimpImage * file_open_thumbnail (Gimp *gimp, GimpContext *context, GimpProgress *progress, GFile *file, gint size, const gchar **mime_type, gint *image_width, gint *image_height, const Babl **format, gint *num_layers, GError **error) { GimpPlugInProcedure *file_proc; GimpProcedure *procedure; g_return_val_if_fail (GIMP_IS_GIMP (gimp), NULL); g_return_val_if_fail (GIMP_IS_CONTEXT (context), NULL); g_return_val_if_fail (progress == NULL || GIMP_IS_PROGRESS (progress), NULL); g_return_val_if_fail (G_IS_FILE (file), NULL); g_return_val_if_fail (mime_type != NULL, NULL); g_return_val_if_fail (image_width != NULL, NULL); g_return_val_if_fail (image_height != NULL, NULL); g_return_val_if_fail (format != NULL, NULL); g_return_val_if_fail (num_layers != NULL, NULL); g_return_val_if_fail (error == NULL || *error == NULL, NULL); *image_width = 0; *image_height = 0; *format = NULL; *num_layers = -1; file_proc = gimp_plug_in_manager_file_procedure_find (gimp->plug_in_manager, GIMP_FILE_PROCEDURE_GROUP_OPEN, file, NULL); if (! file_proc || ! file_proc->thumb_loader) return NULL; procedure = gimp_pdb_lookup_procedure (gimp->pdb, file_proc->thumb_loader); if (procedure && procedure->num_args >= 2 && procedure->num_values >= 1) { GimpPDBStatusType status; GimpValueArray *return_vals; GimpImage *image = NULL; gchar *path = NULL; if (! file_proc->handles_uri) path = g_file_get_path (file); if (! path) path = g_file_get_uri (file); return_vals = gimp_pdb_execute_procedure_by_name (gimp->pdb, context, progress, error, gimp_object_get_name (procedure), G_TYPE_STRING, path, GIMP_TYPE_INT32, size, G_TYPE_NONE); g_free (path); status = g_value_get_enum (gimp_value_array_index (return_vals, 0)); if (status == GIMP_PDB_SUCCESS && GIMP_VALUE_HOLDS_IMAGE_ID (gimp_value_array_index (return_vals, 1))) { image = gimp_value_get_image (gimp_value_array_index (return_vals, 1), gimp); if (gimp_value_array_length (return_vals) >= 3 && G_VALUE_HOLDS_INT (gimp_value_array_index (return_vals, 2)) && G_VALUE_HOLDS_INT (gimp_value_array_index (return_vals, 3))) { *image_width = MAX (0, g_value_get_int (gimp_value_array_index (return_vals, 2))); *image_height = MAX (0, g_value_get_int (gimp_value_array_index (return_vals, 3))); if (gimp_value_array_length (return_vals) >= 5 && G_VALUE_HOLDS_INT (gimp_value_array_index (return_vals, 4))) { gint value = g_value_get_int (gimp_value_array_index (return_vals, 4)); switch (value) { case GIMP_RGB_IMAGE: *format = gimp_babl_format (GIMP_RGB, GIMP_PRECISION_U8_GAMMA, FALSE); break; case GIMP_RGBA_IMAGE: *format = gimp_babl_format (GIMP_RGB, GIMP_PRECISION_U8_GAMMA, TRUE); break; case GIMP_GRAY_IMAGE: *format = gimp_babl_format (GIMP_GRAY, GIMP_PRECISION_U8_GAMMA, FALSE); break; case GIMP_GRAYA_IMAGE: *format = gimp_babl_format (GIMP_GRAY, GIMP_PRECISION_U8_GAMMA, TRUE); break; case GIMP_INDEXED_IMAGE: case GIMP_INDEXEDA_IMAGE: { const Babl *rgb; const Babl *rgba; babl_new_palette ("-gimp-indexed-format-dummy", &rgb, &rgba); if (value == GIMP_INDEXED_IMAGE) *format = rgb; else *format = rgba; } break; default: break; } } if (gimp_value_array_length (return_vals) >= 6 && G_VALUE_HOLDS_INT (gimp_value_array_index (return_vals, 5))) { *num_layers = MAX (0, g_value_get_int (gimp_value_array_index (return_vals, 5))); } } if (image) { file_open_sanitize_image (image, FALSE); *mime_type = file_proc->mime_type; #ifdef GIMP_UNSTABLE g_printerr ("opened thumbnail at %d x %d\n", gimp_image_get_width (image), gimp_image_get_height (image)); #endif } } gimp_value_array_unref (return_vals); return image; } return NULL; }
GimpImage * file_open_image (Gimp *gimp, GimpContext *context, GimpProgress *progress, GFile *file, GFile *entered_file, gboolean as_new, GimpPlugInProcedure *file_proc, GimpRunMode run_mode, GimpPDBStatusType *status, const gchar **mime_type, GError **error) { GimpValueArray *return_vals; GimpImage *image = NULL; GFile *local_file = NULL; gchar *path = NULL; gchar *entered_uri = NULL; GError *my_error = NULL; g_return_val_if_fail (GIMP_IS_GIMP (gimp), NULL); g_return_val_if_fail (GIMP_IS_CONTEXT (context), NULL); g_return_val_if_fail (progress == NULL || GIMP_IS_PROGRESS (progress), NULL); g_return_val_if_fail (G_IS_FILE (file), NULL); g_return_val_if_fail (G_IS_FILE (entered_file), NULL); g_return_val_if_fail (status != NULL, NULL); g_return_val_if_fail (error == NULL || *error == NULL, NULL); *status = GIMP_PDB_EXECUTION_ERROR; /* FIXME enable these tests for remote files again, needs testing */ if (g_file_is_native (file) && g_file_query_exists (file, NULL)) { GFileInfo *info; info = g_file_query_info (file, G_FILE_ATTRIBUTE_STANDARD_TYPE "," G_FILE_ATTRIBUTE_ACCESS_CAN_READ, G_FILE_QUERY_INFO_NONE, NULL, error); if (! info) return NULL; if (g_file_info_get_file_type (info) != G_FILE_TYPE_REGULAR) { g_set_error_literal (error, G_FILE_ERROR, G_FILE_ERROR_FAILED, _("Not a regular file")); g_object_unref (info); return NULL; } if (! g_file_info_get_attribute_boolean (info, G_FILE_ATTRIBUTE_ACCESS_CAN_READ)) { g_set_error_literal (error, G_FILE_ERROR, G_FILE_ERROR_FAILED, _("Permission denied")); g_object_unref (info); return NULL; } g_object_unref (info); } if (! file_proc) file_proc = gimp_plug_in_manager_file_procedure_find (gimp->plug_in_manager, GIMP_FILE_PROCEDURE_GROUP_OPEN, file, error); if (! file_proc) { /* don't bail out on remote files, they might need to be * downloaded for magic matching */ if (g_file_is_native (file)) return NULL; g_clear_error (error); } if (! g_file_is_native (file) && ! file_remote_mount_file (gimp, file, progress, &my_error)) { if (my_error) g_propagate_error (error, my_error); else *status = GIMP_PDB_CANCEL; return NULL; } if (! file_proc || ! file_proc->handles_uri) { path = g_file_get_path (file); if (! path) { local_file = file_remote_download_image (gimp, file, progress, &my_error); if (! local_file) { if (my_error) g_propagate_error (error, my_error); else *status = GIMP_PDB_CANCEL; return NULL; } /* if we don't have a file proc yet, try again on the local * file */ if (! file_proc) file_proc = gimp_plug_in_manager_file_procedure_find (gimp->plug_in_manager, GIMP_FILE_PROCEDURE_GROUP_OPEN, local_file, error); if (! file_proc) { g_file_delete (local_file, NULL, NULL); g_object_unref (local_file); return NULL; } path = g_file_get_path (local_file); } } if (! path) path = g_file_get_uri (file); entered_uri = g_file_get_uri (entered_file); if (! entered_uri) entered_uri = g_strdup (path); if (progress) g_object_add_weak_pointer (G_OBJECT (progress), (gpointer) &progress); return_vals = gimp_pdb_execute_procedure_by_name (gimp->pdb, context, progress, error, gimp_object_get_name (file_proc), GIMP_TYPE_INT32, run_mode, G_TYPE_STRING, path, G_TYPE_STRING, entered_uri, G_TYPE_NONE); if (progress) g_object_remove_weak_pointer (G_OBJECT (progress), (gpointer) &progress); g_free (path); g_free (entered_uri); *status = g_value_get_enum (gimp_value_array_index (return_vals, 0)); if (*status == GIMP_PDB_SUCCESS) image = gimp_value_get_image (gimp_value_array_index (return_vals, 1), gimp); if (local_file) { if (image) gimp_image_set_file (image, file); g_file_delete (local_file, NULL, NULL); g_object_unref (local_file); } if (*status == GIMP_PDB_SUCCESS) { if (image) { /* Only set the load procedure if it hasn't already been set. */ if (! gimp_image_get_load_proc (image)) gimp_image_set_load_proc (image, file_proc); file_proc = gimp_image_get_load_proc (image); if (mime_type) *mime_type = file_proc->mime_type; } else { if (error && ! *error) g_set_error (error, G_FILE_ERROR, G_FILE_ERROR_FAILED, _("%s plug-in returned SUCCESS but did not " "return an image"), gimp_procedure_get_label (GIMP_PROCEDURE (file_proc))); *status = GIMP_PDB_EXECUTION_ERROR; } } else if (*status != GIMP_PDB_CANCEL) { if (error && ! *error) g_set_error (error, G_FILE_ERROR, G_FILE_ERROR_FAILED, _("%s plug-In could not open image"), gimp_procedure_get_label (GIMP_PROCEDURE (file_proc))); } gimp_value_array_unref (return_vals); if (image) { gimp_image_undo_disable (image); gimp_image_import_color_profile (image, context, progress, run_mode == GIMP_RUN_INTERACTIVE ? TRUE : FALSE); if (file_open_file_proc_is_import (file_proc)) { /* Remember the import source */ gimp_image_set_imported_file (image, file); /* We shall treat this file as an Untitled file */ gimp_image_set_file (image, NULL); } /* Enables undo again */ file_open_sanitize_image (image, as_new); } return image; }
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); } show_overwrite = (source && gimp_plug_in_manager_file_procedure_find (gimp->plug_in_manager, GIMP_FILE_PROCEDURE_GROUP_EXPORT, source, NULL)); #define SET_VISIBLE(action,condition) \ gimp_action_group_set_action_visible (group, action, (condition) != 0) #define SET_SENSITIVE(action,condition) \ gimp_action_group_set_action_sensitive (group, action, (condition) != 0) SET_SENSITIVE ("file-save", drawable); SET_SENSITIVE ("file-save-as", drawable); SET_SENSITIVE ("file-save-a-copy", drawable); SET_SENSITIVE ("file-save-and-close", drawable); SET_SENSITIVE ("file-revert", file || source); SET_SENSITIVE ("file-export", drawable); SET_VISIBLE ("file-export", ! show_overwrite); SET_SENSITIVE ("file-overwrite", show_overwrite);