static void gimp_temporary_procedure_execute_async (GimpProcedure *procedure, Gimp *gimp, GimpContext *context, GimpProgress *progress, GimpValueArray *args, GimpObject *display) { GimpTemporaryProcedure *temp_procedure = GIMP_TEMPORARY_PROCEDURE (procedure); GimpValueArray *return_vals; return_vals = gimp_plug_in_manager_call_run_temp (gimp->plug_in_manager, context, progress, temp_procedure, args); if (return_vals) { GimpPlugInProcedure *proc = GIMP_PLUG_IN_PROCEDURE (procedure); gimp_plug_in_procedure_handle_return_values (proc, gimp, progress, return_vals); gimp_value_array_unref (return_vals); } }
void plug_in_repeat_cmd_callback (GtkAction *action, gint value, gpointer data) { GimpPlugInProcedure *procedure; Gimp *gimp; GimpDisplay *display; GimpRunMode run_mode; return_if_no_gimp (gimp, data); return_if_no_display (display, data); run_mode = (GimpRunMode) value; procedure = gimp_plug_in_manager_history_nth (gimp->plug_in_manager, 0); if (procedure) { GimpValueArray *args; gint n_args; args = gimp_procedure_get_arguments (GIMP_PROCEDURE (procedure)); g_value_set_int (gimp_value_array_index (args, 0), run_mode); n_args = plug_in_collect_display_args (action, display, GIMP_PROCEDURE (procedure)->args, args, 1); plug_in_procedure_execute (procedure, gimp, display, args, n_args); gimp_value_array_unref (args); } }
static void gimp_procedure_real_execute_async (GimpProcedure *procedure, Gimp *gimp, GimpContext *context, GimpProgress *progress, GimpValueArray *args, GimpObject *display) { GimpValueArray *return_vals; GError *error = NULL; g_return_if_fail (gimp_value_array_length (args) >= procedure->num_args); return_vals = GIMP_PROCEDURE_GET_CLASS (procedure)->execute (procedure, gimp, context, progress, args, &error); gimp_value_array_unref (return_vals); if (error) { gimp_message_literal (gimp, G_OBJECT (progress), GIMP_MESSAGE_ERROR, error->message); g_error_free (error); } }
GimpValueArray * procedure_commands_get_data_args (GimpProcedure *procedure, GimpObject *object) { GimpValueArray *args; gint n_args = 0; args = gimp_procedure_get_arguments (procedure); /* initialize the first argument */ g_value_set_int (gimp_value_array_index (args, n_args), GIMP_RUN_INTERACTIVE); n_args++; if (gimp_value_array_length (args) > n_args && GIMP_IS_PARAM_SPEC_STRING (procedure->args[n_args])) { if (object) { g_value_set_string (gimp_value_array_index (args, n_args), gimp_object_get_name (object)); n_args++; } else { g_warning ("Uh-oh, no active data object for the plug-in!"); gimp_value_array_unref (args); return NULL; } } gimp_value_array_truncate (args, n_args); return args; }
gboolean plug_in_icc_profile_info (GimpImage *image, GimpContext *context, GimpProgress *progress, gchar **name, gchar **desc, gchar **info, GError **error) { Gimp *gimp; GimpProcedure *procedure; g_return_val_if_fail (GIMP_IS_IMAGE (image), FALSE); g_return_val_if_fail (GIMP_IS_CONTEXT (context), FALSE); g_return_val_if_fail (progress == NULL || GIMP_IS_PROGRESS (progress), FALSE); g_return_val_if_fail (error == NULL || *error == NULL, FALSE); gimp = image->gimp; procedure = gimp_pdb_lookup_procedure (gimp->pdb, ICC_PROFILE_INFO_PROC); if (procedure && procedure->num_args >= 1 && GIMP_IS_PARAM_SPEC_IMAGE_ID (procedure->args[0])) { GimpValueArray *return_vals; GimpPDBStatusType status; return_vals = gimp_pdb_execute_procedure_by_name (gimp->pdb, context, progress, error, ICC_PROFILE_INFO_PROC, GIMP_TYPE_IMAGE_ID, gimp_image_get_ID (image), G_TYPE_NONE); status = g_value_get_enum (gimp_value_array_index (return_vals, 0)); switch (status) { case GIMP_PDB_SUCCESS: plug_in_icc_profile_info_return (return_vals, name, desc, info); break; default: if (error && *error == NULL) g_set_error (error, GIMP_PLUG_IN_ERROR, GIMP_PLUG_IN_FAILED, _("Error running '%s'"), ICC_PROFILE_INFO_PROC); break; } gimp_value_array_unref (return_vals); return (status == GIMP_PDB_SUCCESS); } g_set_error (error, GIMP_PLUG_IN_ERROR, GIMP_PLUG_IN_FAILED, _("Plug-In missing (%s)"), ICC_PROFILE_INFO_PROC); return FALSE; }
GimpValueArray * procedure_commands_get_image_args (GimpProcedure *procedure, GimpImage *image) { GimpValueArray *args; gint n_args = 0; args = gimp_procedure_get_arguments (procedure); /* initialize the first argument */ g_value_set_int (gimp_value_array_index (args, n_args), GIMP_RUN_INTERACTIVE); n_args++; if (gimp_value_array_length (args) > n_args && GIMP_IS_PARAM_SPEC_IMAGE_ID (procedure->args[n_args])) { if (image) { gimp_value_set_image (gimp_value_array_index (args, n_args), image); n_args++; } else { g_warning ("Uh-oh, no active image for the plug-in!"); gimp_value_array_unref (args); return NULL; } } gimp_value_array_truncate (args, n_args); return args; }
static GimpValueArray * file_save_invoker (GimpProcedure *procedure, Gimp *gimp, GimpContext *context, GimpProgress *progress, const GimpValueArray *args, GError **error) { GimpValueArray *new_args; GimpValueArray *return_vals; GimpPlugInProcedure *file_proc; GimpProcedure *proc; gchar *uri; gint i; uri = file_utils_filename_to_uri (gimp, g_value_get_string (gimp_value_array_index (args, 3)), error); if (! uri) return gimp_procedure_get_return_values (procedure, FALSE, error ? *error : NULL); file_proc = file_procedure_find (gimp->plug_in_manager->save_procs, uri, NULL); if (! file_proc) file_proc = file_procedure_find (gimp->plug_in_manager->export_procs, uri, error); g_free (uri); if (! file_proc) return gimp_procedure_get_return_values (procedure, FALSE, error ? *error : NULL); proc = GIMP_PROCEDURE (file_proc); new_args = gimp_procedure_get_arguments (proc); for (i = 0; i < 5; i++) g_value_transform (gimp_value_array_index (args, i), gimp_value_array_index (new_args, i)); for (i = 5; i < proc->num_args; i++) if (G_IS_PARAM_SPEC_STRING (proc->args[i])) g_value_set_static_string (gimp_value_array_index (new_args, i), ""); return_vals = gimp_pdb_execute_procedure_by_name_args (gimp->pdb, context, progress, error, gimp_object_get_name (proc), new_args); gimp_value_array_unref (new_args); return return_vals; }
void vectors_selection_to_vectors_cmd_callback (GtkAction *action, gint value, gpointer data) { GimpImage *image; GtkWidget *widget; GimpProcedure *procedure; GimpValueArray *args; GimpDisplay *display; GError *error = NULL; return_if_no_image (image, data); return_if_no_widget (widget, data); if (value) procedure = gimp_pdb_lookup_procedure (image->gimp->pdb, "plug-in-sel2path-advanced"); else procedure = gimp_pdb_lookup_procedure (image->gimp->pdb, "plug-in-sel2path"); if (! procedure) { gimp_message_literal (image->gimp, G_OBJECT (widget), GIMP_MESSAGE_ERROR, "Selection to path procedure lookup failed."); return; } display = gimp_context_get_display (action_data_get_context (data)); args = gimp_procedure_get_arguments (procedure); gimp_value_array_truncate (args, 2); g_value_set_int (gimp_value_array_index (args, 0), GIMP_RUN_INTERACTIVE); gimp_value_set_image (gimp_value_array_index (args, 1), image); gimp_procedure_execute_async (procedure, image->gimp, action_data_get_context (data), GIMP_PROGRESS (display), args, GIMP_OBJECT (display), &error); gimp_value_array_unref (args); if (error) { gimp_message_literal (image->gimp, G_OBJECT (widget), GIMP_MESSAGE_ERROR, error->message); g_error_free (error); } }
static void gimp_plug_in_manager_add_to_db (GimpPlugInManager *manager, GimpContext *context, GimpPlugInProcedure *proc) { gimp_pdb_register_procedure (manager->gimp->pdb, GIMP_PROCEDURE (proc)); if (proc->file_proc) { GimpValueArray *return_vals; GError *error = NULL; if (proc->image_types) { return_vals = gimp_pdb_execute_procedure_by_name (manager->gimp->pdb, context, NULL, &error, "gimp-register-save-handler", G_TYPE_STRING, gimp_object_get_name (proc), G_TYPE_STRING, proc->extensions, G_TYPE_STRING, proc->prefixes, G_TYPE_NONE); } else { return_vals = gimp_pdb_execute_procedure_by_name (manager->gimp->pdb, context, NULL, &error, "gimp-register-magic-load-handler", G_TYPE_STRING, gimp_object_get_name (proc), G_TYPE_STRING, proc->extensions, G_TYPE_STRING, proc->prefixes, G_TYPE_STRING, proc->magics, G_TYPE_NONE); } gimp_value_array_unref (return_vals); if (error) { gimp_message_literal (manager->gimp, NULL, GIMP_MESSAGE_ERROR, error->message); g_error_free (error); } } }
static gdouble gimp_pdb_progress_run_callback (GimpPdbProgress *progress, GimpProgressCommand command, const gchar *text, gdouble value) { gdouble retval = 0; if (progress->callback_name && ! progress->callback_busy) { GimpValueArray *return_vals; progress->callback_busy = TRUE; return_vals = gimp_pdb_execute_procedure_by_name (progress->pdb, progress->context, NULL, NULL, progress->callback_name, GIMP_TYPE_INT32, command, G_TYPE_STRING, text, G_TYPE_DOUBLE, value, G_TYPE_NONE); if (g_value_get_enum (gimp_value_array_index (return_vals, 0)) != GIMP_PDB_SUCCESS) { gimp_message (progress->context->gimp, NULL, GIMP_MESSAGE_ERROR, _("Unable to run %s callback. " "The corresponding plug-in may have crashed."), g_type_name (G_TYPE_FROM_INSTANCE (progress))); } else if (gimp_value_array_length (return_vals) >= 2 && G_VALUE_HOLDS_DOUBLE (gimp_value_array_index (return_vals, 1))) { retval = g_value_get_double (gimp_value_array_index (return_vals, 1)); } gimp_value_array_unref (return_vals); progress->callback_busy = FALSE; } return retval; }
void plug_in_history_cmd_callback (GtkAction *action, GimpPlugInProcedure *procedure, gpointer data) { Gimp *gimp; GimpDisplay *display; GimpValueArray *args; gint n_args; return_if_no_gimp (gimp, data); return_if_no_display (display, data); args = gimp_procedure_get_arguments (GIMP_PROCEDURE (procedure)); g_value_set_int (gimp_value_array_index (args, 0), GIMP_RUN_INTERACTIVE); n_args = plug_in_collect_display_args (action, display, GIMP_PROCEDURE (procedure)->args, args, 1); plug_in_procedure_execute (procedure, gimp, display, args, n_args); gimp_value_array_unref (args); }
GimpImage * file_open_image (Gimp *gimp, GimpContext *context, GimpProgress *progress, const gchar *uri, const gchar *entered_filename, gboolean as_new, GimpPlugInProcedure *file_proc, GimpRunMode run_mode, GimpPDBStatusType *status, const gchar **mime_type, GError **error) { GimpValueArray *return_vals; gchar *filename; GimpImage *image = 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 (status != NULL, NULL); g_return_val_if_fail (error == NULL || *error == NULL, NULL); *status = GIMP_PDB_EXECUTION_ERROR; if (! file_proc) file_proc = file_procedure_find (gimp->plug_in_manager->load_procs, uri, error); if (! file_proc) return NULL; filename = file_utils_filename_from_uri (uri); if (filename) { /* check if we are opening a file */ if (g_file_test (filename, G_FILE_TEST_EXISTS)) { if (! g_file_test (filename, G_FILE_TEST_IS_REGULAR)) { g_free (filename); g_set_error_literal (error, G_FILE_ERROR, G_FILE_ERROR_FAILED, _("Not a regular file")); return NULL; } if (g_access (filename, R_OK) != 0) { g_free (filename); g_set_error_literal (error, G_FILE_ERROR, G_FILE_ERROR_ACCES, g_strerror (errno)); return NULL; } } if (file_proc->handles_uri) { g_free (filename); filename = g_strdup (uri); } } else { filename = g_strdup (uri); } 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, filename, G_TYPE_STRING, entered_filename, G_TYPE_NONE); g_free (filename); *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 (image) { file_open_sanitize_image (image, as_new); /* 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_plug_in_procedure_get_label (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_plug_in_procedure_get_label (file_proc)); } gimp_value_array_unref (return_vals); if (image) { file_open_handle_color_profile (image, context, progress, run_mode); if (file_open_file_proc_is_import (file_proc)) { /* Remember the import source */ gimp_image_set_imported_uri (image, uri); /* We shall treat this file as an Untitled file */ gimp_image_set_uri (image, NULL); } } return image; }
GimpValueArray * procedure_commands_get_display_args (GimpProcedure *procedure, GimpDisplay *display) { GimpValueArray *args; gint n_args = 0; args = gimp_procedure_get_arguments (procedure); /* initialize the first argument */ g_value_set_int (gimp_value_array_index (args, n_args), GIMP_RUN_INTERACTIVE); n_args++; if (gimp_value_array_length (args) > n_args && GIMP_IS_PARAM_SPEC_DISPLAY_ID (procedure->args[n_args])) { if (display) { gimp_value_set_display (gimp_value_array_index (args, n_args), GIMP_OBJECT (display)); n_args++; } else { g_warning ("Uh-oh, no active display for the plug-in!"); gimp_value_array_unref (args); return NULL; } } if (gimp_value_array_length (args) > n_args && GIMP_IS_PARAM_SPEC_IMAGE_ID (procedure->args[n_args])) { GimpImage *image = display ? gimp_display_get_image (display) : NULL; if (image) { gimp_value_set_image (gimp_value_array_index (args, n_args), image); n_args++; if (gimp_value_array_length (args) > n_args && GIMP_IS_PARAM_SPEC_DRAWABLE_ID (procedure->args[n_args])) { GimpDrawable *drawable = gimp_image_get_active_drawable (image); if (drawable) { gimp_value_set_drawable (gimp_value_array_index (args, n_args), drawable); n_args++; } else { g_warning ("Uh-oh, no active drawable for the plug-in!"); gimp_value_array_unref (args); return NULL; } } } } gimp_value_array_truncate (args, n_args); return args; }
static GimpValueArray * file_load_invoker (GimpProcedure *procedure, Gimp *gimp, GimpContext *context, GimpProgress *progress, const GimpValueArray *args, GError **error) { GimpValueArray *new_args; GimpValueArray *return_vals; GimpPlugInProcedure *file_proc; GimpProcedure *proc; gchar *uri; gint i; uri = file_utils_filename_to_uri (gimp, g_value_get_string (gimp_value_array_index (args, 1)), error); if (! uri) return gimp_procedure_get_return_values (procedure, FALSE, error ? *error : NULL); file_proc = file_procedure_find (gimp->plug_in_manager->load_procs, uri, error); g_free (uri); if (! file_proc) return gimp_procedure_get_return_values (procedure, FALSE, error ? *error : NULL); proc = GIMP_PROCEDURE (file_proc); new_args = gimp_procedure_get_arguments (proc); for (i = 0; i < 3; i++) g_value_transform (gimp_value_array_index (args, i), gimp_value_array_index (new_args, i)); for (i = 3; i < proc->num_args; i++) if (G_IS_PARAM_SPEC_STRING (proc->args[i])) g_value_set_static_string (gimp_value_array_index (new_args, i), ""); return_vals = gimp_pdb_execute_procedure_by_name_args (gimp->pdb, context, progress, error, gimp_object_get_name (proc), new_args); gimp_value_array_unref (new_args); if (g_value_get_enum (gimp_value_array_index (return_vals, 0)) == GIMP_PDB_SUCCESS) { if (gimp_value_array_length (return_vals) > 1 && GIMP_VALUE_HOLDS_IMAGE_ID (gimp_value_array_index (return_vals, 1))) { GimpImage *image = gimp_value_get_image (gimp_value_array_index (return_vals, 1), gimp); gimp_image_set_load_proc (image, file_proc); } } return return_vals; }
gboolean plug_in_icc_profile_apply_rgb (GimpImage *image, GimpContext *context, GimpProgress *progress, GimpRunMode run_mode, GError **error) { Gimp *gimp; GimpProcedure *procedure; g_return_val_if_fail (GIMP_IS_IMAGE (image), FALSE); g_return_val_if_fail (GIMP_IS_CONTEXT (context), FALSE); g_return_val_if_fail (progress == NULL || GIMP_IS_PROGRESS (progress), FALSE); g_return_val_if_fail (error == NULL || *error == NULL, FALSE); gimp = image->gimp; if (gimp_image_get_base_type (image) == GIMP_GRAY) { g_set_error (error, GIMP_PLUG_IN_ERROR, GIMP_PLUG_IN_EXECUTION_FAILED, _("Can't apply color profile to grayscale image (%s)"), ICC_PROFILE_APPLY_RGB_PROC); return FALSE; } procedure = gimp_pdb_lookup_procedure (gimp->pdb, ICC_PROFILE_APPLY_RGB_PROC); if (procedure && procedure->num_args >= 2 && GIMP_IS_PARAM_SPEC_INT32 (procedure->args[0]) && GIMP_IS_PARAM_SPEC_IMAGE_ID (procedure->args[1])) { GimpValueArray *return_vals; GimpPDBStatusType status; GimpColorProfilePolicy policy = GIMP_COLOR_PROFILE_POLICY_ASK; gboolean success; return_vals = gimp_pdb_execute_procedure_by_name (gimp->pdb, context, progress, error, ICC_PROFILE_APPLY_RGB_PROC, GIMP_TYPE_INT32, run_mode, GIMP_TYPE_IMAGE_ID, gimp_image_get_ID (image), G_TYPE_NONE); status = g_value_get_enum (gimp_value_array_index (return_vals, 0)); switch (status) { case GIMP_PDB_SUCCESS: policy = GIMP_COLOR_PROFILE_POLICY_CONVERT; success = TRUE; break; case GIMP_PDB_CANCEL: policy = GIMP_COLOR_PROFILE_POLICY_KEEP; success = TRUE; break; default: if (error && *error == NULL) g_set_error (error, GIMP_PLUG_IN_ERROR, GIMP_PLUG_IN_EXECUTION_FAILED, _("Error running '%s'"), ICC_PROFILE_APPLY_RGB_PROC); success = FALSE; break; } if (success && gimp_value_array_length (return_vals) > 1) { GValue *value = gimp_value_array_index (return_vals, 1); if (GIMP_VALUE_HOLDS_INT32 (value) && g_value_get_int (value)) { g_object_set (G_OBJECT (gimp->config), "color-profile-policy", policy, NULL); } } gimp_value_array_unref (return_vals); return success; } g_set_error (error, GIMP_PLUG_IN_ERROR, GIMP_PLUG_IN_NOT_FOUND, _("Plug-In missing (%s)"), ICC_PROFILE_APPLY_RGB_PROC); return FALSE; }
GimpPDBStatusType file_save (Gimp *gimp, GimpImage *image, GimpProgress *progress, GFile *file, GimpPlugInProcedure *file_proc, GimpRunMode run_mode, gboolean change_saved_state, gboolean export_backward, gboolean export_forward, GError **error) { GimpDrawable *drawable; GimpValueArray *return_vals; GimpPDBStatusType status = GIMP_PDB_EXECUTION_ERROR; GFile *local_file = NULL; gchar *path = NULL; gchar *uri = NULL; gint32 image_ID; gint32 drawable_ID; GError *my_error = NULL; g_return_val_if_fail (GIMP_IS_GIMP (gimp), GIMP_PDB_CALLING_ERROR); g_return_val_if_fail (GIMP_IS_IMAGE (image), GIMP_PDB_CALLING_ERROR); g_return_val_if_fail (progress == NULL || GIMP_IS_PROGRESS (progress), GIMP_PDB_CALLING_ERROR); g_return_val_if_fail (G_IS_FILE (file), GIMP_PDB_CALLING_ERROR); g_return_val_if_fail (GIMP_IS_PLUG_IN_PROCEDURE (file_proc), GIMP_PDB_CALLING_ERROR); g_return_val_if_fail ((export_backward && export_forward) == FALSE, GIMP_PDB_CALLING_ERROR); g_return_val_if_fail (error == NULL || *error == NULL, GIMP_PDB_CALLING_ERROR); /* ref image and file, so they can't get deleted during save */ g_object_ref (image); g_object_ref (file); drawable = gimp_image_get_active_drawable (image); if (! drawable) goto out; /* 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_WRITE, G_FILE_QUERY_INFO_NONE, NULL, error); if (! info) goto out; 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); goto out; } if (! g_file_info_get_attribute_boolean (info, G_FILE_ATTRIBUTE_ACCESS_CAN_WRITE)) { g_set_error_literal (error, G_FILE_ERROR, G_FILE_ERROR_FAILED, _("Permission denied")); g_object_unref (info); goto out; } g_object_unref (info); } 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; goto out; } if (! file_proc->handles_uri) { path = g_file_get_path (file); if (! path) { local_file = file_remote_upload_image_prepare (gimp, file, progress, &my_error); if (! local_file) { if (my_error) g_propagate_error (error, my_error); else status = GIMP_PDB_CANCEL; goto out; } path = g_file_get_path (local_file); } } if (! path) path = g_file_get_uri (file); uri = g_file_get_uri (file); image_ID = gimp_image_get_ID (image); drawable_ID = gimp_item_get_ID (GIMP_ITEM (drawable)); return_vals = gimp_pdb_execute_procedure_by_name (image->gimp->pdb, gimp_get_user_context (gimp), progress, error, gimp_object_get_name (file_proc), GIMP_TYPE_INT32, run_mode, GIMP_TYPE_IMAGE_ID, image_ID, GIMP_TYPE_DRAWABLE_ID, drawable_ID, G_TYPE_STRING, path, G_TYPE_STRING, uri, G_TYPE_NONE); status = g_value_get_enum (gimp_value_array_index (return_vals, 0)); gimp_value_array_unref (return_vals); if (local_file) { if (status == GIMP_PDB_SUCCESS) { GError *my_error = NULL; if (! file_remote_upload_image_finish (gimp, file, local_file, progress, &my_error)) { status = GIMP_PDB_EXECUTION_ERROR; if (my_error) g_propagate_error (error, my_error); else status = GIMP_PDB_CANCEL; } } g_file_delete (local_file, NULL, NULL); g_object_unref (local_file); } if (status == GIMP_PDB_SUCCESS) { GimpDocumentList *documents; GimpImagefile *imagefile; if (change_saved_state) { gimp_image_set_file (image, file); gimp_image_set_save_proc (image, file_proc); /* Forget the import source when we save. We interpret a * save as that the user is not interested in being able * to quickly export back to the original any longer */ gimp_image_set_imported_file (image, NULL); gimp_image_clean_all (image); } else if (export_backward) { /* We exported the image back to its imported source, * change nothing about export/import flags, only set * the export state to clean */ gimp_image_export_clean_all (image); gimp_object_name_changed (GIMP_OBJECT (image)); } else if (export_forward) { /* Remember the last entered Export URI for the image. We * only need to do this explicitly when exporting. It * happens implicitly when saving since the GimpObject name * of a GimpImage is the last-save URI */ gimp_image_set_exported_file (image, file); gimp_image_set_export_proc (image, file_proc); /* An image can not be considered both exported and imported * at the same time, so stop consider it as imported now * that we consider it exported. */ gimp_image_set_imported_file (image, NULL); gimp_image_export_clean_all (image); } if (export_backward || export_forward) gimp_image_exported (image, file); else gimp_image_saved (image, file); documents = GIMP_DOCUMENT_LIST (image->gimp->documents); imagefile = gimp_document_list_add_file (documents, file, file_proc->mime_type); /* only save a thumbnail if we are saving as XCF, see bug #25272 */ if (GIMP_PROCEDURE (file_proc)->proc_type == GIMP_INTERNAL) gimp_imagefile_save_thumbnail (imagefile, file_proc->mime_type, image, NULL); } else if (status != GIMP_PDB_CANCEL) { if (error && *error == NULL) { g_set_error (error, G_FILE_ERROR, G_FILE_ERROR_FAILED, _("%s plug-in could not save image"), gimp_plug_in_procedure_get_label (file_proc)); } } gimp_image_flush (image); out: g_object_unref (file); g_object_unref (image); g_free (path); g_free (uri); return status; }
static void gimp_plug_in_handle_proc_run (GimpPlugIn *plug_in, GPProcRun *proc_run) { GimpPlugInProcFrame *proc_frame; gchar *canonical; const gchar *proc_name = NULL; GimpProcedure *procedure; GimpValueArray *args = NULL; GimpValueArray *return_vals = NULL; GError *error = NULL; g_return_if_fail (proc_run != NULL); g_return_if_fail (proc_run->name != NULL); canonical = gimp_canonicalize_identifier (proc_run->name); proc_frame = gimp_plug_in_get_proc_frame (plug_in); procedure = gimp_pdb_lookup_procedure (plug_in->manager->gimp->pdb, canonical); if (! procedure) { proc_name = gimp_pdb_lookup_compat_proc_name (plug_in->manager->gimp->pdb, canonical); if (proc_name) { procedure = gimp_pdb_lookup_procedure (plug_in->manager->gimp->pdb, proc_name); if (plug_in->manager->gimp->pdb_compat_mode == GIMP_PDB_COMPAT_WARN) { gimp_message (plug_in->manager->gimp, NULL, GIMP_MESSAGE_WARNING, "Plug-In \"%s\"\n(%s)\n" "called deprecated procedure '%s'.\n" "It should call '%s' instead!", gimp_object_get_name (plug_in), gimp_file_get_utf8_name (plug_in->file), canonical, proc_name); } } } else if (procedure->deprecated) { if (plug_in->manager->gimp->pdb_compat_mode == GIMP_PDB_COMPAT_WARN) { if (! strcmp (procedure->deprecated, "NONE")) { gimp_message (plug_in->manager->gimp, NULL, GIMP_MESSAGE_WARNING, "Plug-In \"%s\"\n(%s)\n" "called deprecated procedure '%s'.", gimp_object_get_name (plug_in), gimp_file_get_utf8_name (plug_in->file), canonical); } else { gimp_message (plug_in->manager->gimp, NULL, GIMP_MESSAGE_WARNING, "WARNING: Plug-In \"%s\"\n(%s)\n" "called deprecated procedure '%s'.\n" "It should call '%s' instead!", gimp_object_get_name (plug_in), gimp_file_get_utf8_name (plug_in->file), canonical, procedure->deprecated); } } } if (! proc_name) proc_name = canonical; args = plug_in_params_to_args (procedure ? procedure->args : NULL, procedure ? procedure->num_args : 0, proc_run->params, proc_run->nparams, FALSE, FALSE); /* Execute the procedure even if gimp_pdb_lookup_procedure() * returned NULL, gimp_pdb_execute_procedure_by_name_args() will * return appropriate error return_vals. */ gimp_plug_in_manager_plug_in_push (plug_in->manager, plug_in); return_vals = gimp_pdb_execute_procedure_by_name_args (plug_in->manager->gimp->pdb, proc_frame->context_stack ? proc_frame->context_stack->data : proc_frame->main_context, proc_frame->progress, &error, proc_name, args); gimp_plug_in_manager_plug_in_pop (plug_in->manager); gimp_value_array_unref (args); if (error) { gimp_plug_in_handle_proc_error (plug_in, proc_frame, canonical, error); g_error_free (error); } g_free (canonical); /* Don't bother to send the return value if executing the procedure * closed the plug-in (e.g. if the procedure is gimp-quit) */ if (plug_in->open) { GPProcReturn proc_return; /* Return the name we got called with, *not* proc_name or canonical, * since proc_name may have been remapped by gimp->procedural_compat_ht * and canonical may be different too. */ proc_return.name = proc_run->name; proc_return.nparams = gimp_value_array_length (return_vals); proc_return.params = plug_in_args_to_params (return_vals, FALSE); if (! gp_proc_return_write (plug_in->my_write, &proc_return, plug_in)) { gimp_message (plug_in->manager->gimp, NULL, GIMP_MESSAGE_ERROR, "%s: ERROR", G_STRFUNC); gimp_plug_in_close (plug_in, TRUE); } g_free (proc_return.params); } gimp_value_array_unref (return_vals); }
GimpPDBStatusType file_save (Gimp *gimp, GimpImage *image, GimpProgress *progress, const gchar *uri, GimpPlugInProcedure *file_proc, GimpRunMode run_mode, gboolean change_saved_state, gboolean export_backward, gboolean export_forward, GError **error) { GimpDrawable *drawable; GimpValueArray *return_vals; GimpPDBStatusType status; gchar *filename; gint32 image_ID; gint32 drawable_ID; g_return_val_if_fail (GIMP_IS_GIMP (gimp), GIMP_PDB_CALLING_ERROR); g_return_val_if_fail (GIMP_IS_IMAGE (image), GIMP_PDB_CALLING_ERROR); g_return_val_if_fail (progress == NULL || GIMP_IS_PROGRESS (progress), GIMP_PDB_CALLING_ERROR); g_return_val_if_fail (uri != NULL, GIMP_PDB_CALLING_ERROR); g_return_val_if_fail (GIMP_IS_PLUG_IN_PROCEDURE (file_proc), GIMP_PDB_CALLING_ERROR); g_return_val_if_fail ((export_backward && export_forward) == FALSE, GIMP_PDB_CALLING_ERROR); g_return_val_if_fail (error == NULL || *error == NULL, GIMP_PDB_CALLING_ERROR); drawable = gimp_image_get_active_drawable (image); if (! drawable) return GIMP_PDB_EXECUTION_ERROR; filename = file_utils_filename_from_uri (uri); if (filename) { /* check if we are saving to a file */ if (g_file_test (filename, G_FILE_TEST_EXISTS)) { if (! g_file_test (filename, G_FILE_TEST_IS_REGULAR)) { g_set_error_literal (error, G_FILE_ERROR, G_FILE_ERROR_FAILED, _("Not a regular file")); status = GIMP_PDB_EXECUTION_ERROR; goto out; } if (g_access (filename, W_OK) != 0) { g_set_error_literal (error, G_FILE_ERROR, G_FILE_ERROR_ACCES, g_strerror (errno)); status = GIMP_PDB_EXECUTION_ERROR; goto out; } } if (file_proc->handles_uri) { g_free (filename); filename = g_strdup (uri); } } else { filename = g_strdup (uri); } /* ref the image, so it can't get deleted during save */ g_object_ref (image); image_ID = gimp_image_get_ID (image); drawable_ID = gimp_item_get_ID (GIMP_ITEM (drawable)); return_vals = gimp_pdb_execute_procedure_by_name (image->gimp->pdb, gimp_get_user_context (gimp), progress, error, gimp_object_get_name (file_proc), GIMP_TYPE_INT32, run_mode, GIMP_TYPE_IMAGE_ID, image_ID, GIMP_TYPE_DRAWABLE_ID, drawable_ID, G_TYPE_STRING, filename, G_TYPE_STRING, uri, G_TYPE_NONE); status = g_value_get_enum (gimp_value_array_index (return_vals, 0)); gimp_value_array_unref (return_vals); if (status == GIMP_PDB_SUCCESS) { GimpDocumentList *documents; GimpImagefile *imagefile; if (change_saved_state) { gimp_image_set_uri (image, uri); gimp_image_set_save_proc (image, file_proc); /* Forget the import source when we save. We interpret a * save as that the user is not interested in being able * to quickly export back to the original any longer */ gimp_image_set_imported_uri (image, NULL); gimp_image_clean_all (image); } else if (export_backward) { /* We exported the image back to its imported source, * change nothing about export/import flags, only set * the export state to clean */ gimp_image_export_clean_all (image); gimp_object_name_changed (GIMP_OBJECT (image)); } else if (export_forward) { /* Remember the last entered Export URI for the image. We * only need to do this explicitly when exporting. It * happens implicitly when saving since the GimpObject name * of a GimpImage is the last-save URI */ gimp_image_set_exported_uri (image, uri); /* An image can not be considered both exported and imported * at the same time, so stop consider it as imported now * that we consider it exported. */ gimp_image_set_imported_uri (image, NULL); gimp_image_export_clean_all (image); } if (export_backward || export_forward) gimp_image_exported (image, uri); else gimp_image_saved (image, uri); documents = GIMP_DOCUMENT_LIST (image->gimp->documents); imagefile = gimp_document_list_add_uri (documents, uri, file_proc->mime_type); /* only save a thumbnail if we are saving as XCF, see bug #25272 */ if (GIMP_PROCEDURE (file_proc)->proc_type == GIMP_INTERNAL) gimp_imagefile_save_thumbnail (imagefile, file_proc->mime_type, image); } else if (status != GIMP_PDB_CANCEL) { if (error && *error == NULL) { g_set_error (error, G_FILE_ERROR, G_FILE_ERROR_FAILED, _("%s plug-in could not save image"), gimp_plug_in_procedure_get_label (file_proc)); } } gimp_image_flush (image); g_object_unref (image); out: g_free (filename); return status; }
GimpValueArray * gimp_pdb_execute_procedure_by_name_args (GimpPDB *pdb, GimpContext *context, GimpProgress *progress, GError **error, const gchar *name, GimpValueArray *args) { GimpValueArray *return_vals = NULL; GList *list; g_return_val_if_fail (GIMP_IS_PDB (pdb), 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 (error == NULL || *error == NULL, NULL); g_return_val_if_fail (name != NULL, NULL); list = g_hash_table_lookup (pdb->procedures, name); if (list == NULL) { GError *pdb_error = g_error_new (GIMP_PDB_ERROR, GIMP_PDB_ERROR_PROCEDURE_NOT_FOUND, _("Procedure '%s' not found"), name); return_vals = gimp_procedure_get_return_values (NULL, FALSE, pdb_error); g_propagate_error (error, pdb_error); return return_vals; } g_return_val_if_fail (args != NULL, NULL); for (; list; list = g_list_next (list)) { GimpProcedure *procedure = list->data; g_return_val_if_fail (GIMP_IS_PROCEDURE (procedure), NULL); return_vals = gimp_procedure_execute (procedure, pdb->gimp, context, progress, args, error); if (g_value_get_enum (gimp_value_array_index (return_vals, 0)) == GIMP_PDB_PASS_THROUGH) { /* If the return value is GIMP_PDB_PASS_THROUGH and there is * a next procedure in the list, destroy the return values * and run the next procedure. */ if (g_list_next (list)) { gimp_value_array_unref (return_vals); g_clear_error (error); } } else { /* No GIMP_PDB_PASS_THROUGH, break out of the list of * procedures and return the current return values. */ break; } } return return_vals; }
/* run automatically started extensions */ static void gimp_plug_in_manager_run_extensions (GimpPlugInManager *manager, GimpContext *context, GimpInitStatusFunc status_callback) { Gimp *gimp = manager->gimp; GSList *list; GList *extensions = NULL; gint n_extensions; /* build list of automatically started extensions */ for (list = manager->plug_in_procedures; list; list = list->next) { GimpPlugInProcedure *proc = list->data; if (proc->file && GIMP_PROCEDURE (proc)->proc_type == GIMP_EXTENSION && GIMP_PROCEDURE (proc)->num_args == 0) { extensions = g_list_prepend (extensions, proc); } } extensions = g_list_reverse (extensions); n_extensions = g_list_length (extensions); /* run the available extensions */ if (extensions) { GList *list; gint nth; status_callback (_("Starting Extensions"), "", 0.0); for (list = extensions, nth = 0; list; list = g_list_next (list), nth++) { GimpPlugInProcedure *proc = list->data; GimpValueArray *args; GError *error = NULL; if (gimp->be_verbose) g_print ("Starting extension: '%s'\n", gimp_object_get_name (proc)); status_callback (NULL, gimp_object_get_name (proc), (gdouble) nth / (gdouble) n_extensions); args = gimp_value_array_new (0); gimp_procedure_execute_async (GIMP_PROCEDURE (proc), gimp, context, NULL, args, NULL, &error); gimp_value_array_unref (args); if (error) { gimp_message_literal (gimp, NULL, GIMP_MESSAGE_ERROR, error->message); g_clear_error (&error); } } g_list_free (extensions); status_callback (NULL, "", 1.0); } }
void plug_in_run_cmd_callback (GtkAction *action, GimpPlugInProcedure *proc, gpointer data) { GimpProcedure *procedure = GIMP_PROCEDURE (proc); Gimp *gimp; GimpValueArray *args; gint n_args = 0; GimpDisplay *display = NULL; return_if_no_gimp (gimp, data); args = gimp_procedure_get_arguments (procedure); /* initialize the first argument */ g_value_set_int (gimp_value_array_index (args, n_args), GIMP_RUN_INTERACTIVE); n_args++; switch (procedure->proc_type) { case GIMP_EXTENSION: break; case GIMP_PLUGIN: case GIMP_TEMPORARY: if (GIMP_IS_DATA_FACTORY_VIEW (data) || GIMP_IS_FONT_VIEW (data) || GIMP_IS_BUFFER_VIEW (data)) { GimpContainerEditor *editor = GIMP_CONTAINER_EDITOR (data); GimpContainer *container; GimpContext *context; GimpObject *object; container = gimp_container_view_get_container (editor->view); context = gimp_container_view_get_context (editor->view); object = gimp_context_get_by_type (context, gimp_container_get_children_type (container)); n_args = plug_in_collect_data_args (action, object, procedure->args, args, n_args); } else if (GIMP_IS_IMAGE_EDITOR (data)) { GimpImageEditor *editor = GIMP_IMAGE_EDITOR (data); GimpImage *image; image = gimp_image_editor_get_image (editor); n_args = plug_in_collect_image_args (action, image, procedure->args, args, n_args); } else if (GIMP_IS_ITEM_TREE_VIEW (data)) { GimpItemTreeView *view = GIMP_ITEM_TREE_VIEW (data); GimpImage *image; GimpItem *item; image = gimp_item_tree_view_get_image (view); if (image) item = GIMP_ITEM_TREE_VIEW_GET_CLASS (view)->get_active_item (image); else item = NULL; n_args = plug_in_collect_item_args (action, image, item, procedure->args, args, n_args); } else { display = action_data_get_display (data); n_args = plug_in_collect_display_args (action, display, procedure->args, args, n_args); } break; case GIMP_INTERNAL: g_warning ("Unhandled procedure type."); n_args = -1; break; } if (n_args >= 1) plug_in_procedure_execute (proc, gimp, display, args, n_args); gimp_value_array_unref (args); }
GimpValueArray * gimp_pdb_execute_procedure_by_name (GimpPDB *pdb, GimpContext *context, GimpProgress *progress, GError **error, const gchar *name, ...) { GimpProcedure *procedure; GimpValueArray *args; GimpValueArray *return_vals; va_list va_args; gint i; g_return_val_if_fail (GIMP_IS_PDB (pdb), 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 (error == NULL || *error == NULL, NULL); g_return_val_if_fail (name != NULL, NULL); procedure = gimp_pdb_lookup_procedure (pdb, name); if (! procedure) { GError *pdb_error = g_error_new (GIMP_PDB_ERROR, GIMP_PDB_ERROR_PROCEDURE_NOT_FOUND, _("Procedure '%s' not found"), name); return_vals = gimp_procedure_get_return_values (NULL, FALSE, pdb_error); g_propagate_error (error, pdb_error); return return_vals; } args = gimp_procedure_get_arguments (procedure); va_start (va_args, name); for (i = 0; i < procedure->num_args; i++) { GValue *value; GType arg_type; gchar *error_msg = NULL; arg_type = va_arg (va_args, GType); if (arg_type == G_TYPE_NONE) break; value = gimp_value_array_index (args, i); if (arg_type != G_VALUE_TYPE (value)) { GError *pdb_error; const gchar *expected = g_type_name (G_VALUE_TYPE (value)); const gchar *got = g_type_name (arg_type); gimp_value_array_unref (args); pdb_error = g_error_new (GIMP_PDB_ERROR, GIMP_PDB_ERROR_INVALID_ARGUMENT, _("Procedure '%s' has been called with a " "wrong type for argument #%d. " "Expected %s, got %s."), gimp_object_get_name (procedure), i + 1, expected, got); return_vals = gimp_procedure_get_return_values (procedure, FALSE, pdb_error); g_propagate_error (error, pdb_error); va_end (va_args); return return_vals; } G_VALUE_COLLECT (value, va_args, G_VALUE_NOCOPY_CONTENTS, &error_msg); if (error_msg) { GError *pdb_error = g_error_new_literal (GIMP_PDB_ERROR, GIMP_PDB_ERROR_INTERNAL_ERROR, error_msg); g_warning ("%s: %s", G_STRFUNC, error_msg); g_free (error_msg); gimp_value_array_unref (args); return_vals = gimp_procedure_get_return_values (procedure, FALSE, pdb_error); g_propagate_error (error, pdb_error); va_end (va_args); return return_vals; } } va_end (va_args); return_vals = gimp_pdb_execute_procedure_by_name_args (pdb, context, progress, error, name, args); gimp_value_array_unref (args); return return_vals; }
/** * 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 = file_procedure_find (gimp->plug_in_manager->load_procs, 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 = file_procedure_find (gimp->plug_in_manager->load_procs, file, error); if (! file_proc) return NULL; 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->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; } 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); 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); 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) { file_open_sanitize_image (image, as_new); /* 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_plug_in_procedure_get_label (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_plug_in_procedure_get_label (file_proc)); } gimp_value_array_unref (return_vals); if (image) { file_open_handle_color_profile (image, context, progress, run_mode); 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); } } return image; }
static void gimp_batch_run_cmd (Gimp *gimp, const gchar *proc_name, GimpProcedure *procedure, GimpRunMode run_mode, const gchar *cmd) { GimpValueArray *args; GimpValueArray *return_vals; GError *error = NULL; gint i = 0; args = gimp_procedure_get_arguments (procedure); if (procedure->num_args > i && GIMP_IS_PARAM_SPEC_INT32 (procedure->args[i])) g_value_set_int (gimp_value_array_index (args, i++), run_mode); if (procedure->num_args > i && GIMP_IS_PARAM_SPEC_STRING (procedure->args[i])) g_value_set_static_string (gimp_value_array_index (args, i++), cmd); return_vals = gimp_pdb_execute_procedure_by_name_args (gimp->pdb, gimp_get_user_context (gimp), NULL, &error, proc_name, args); switch (g_value_get_enum (gimp_value_array_index (return_vals, 0))) { case GIMP_PDB_EXECUTION_ERROR: if (error) { g_printerr ("batch command experienced an execution error:\n" "%s\n", error->message); } else { g_printerr ("batch command experienced an execution error\n"); } break; case GIMP_PDB_CALLING_ERROR: if (error) { g_printerr ("batch command experienced a calling error:\n" "%s\n", error->message); } else { g_printerr ("batch command experienced a calling error\n"); } break; case GIMP_PDB_SUCCESS: g_printerr ("batch command executed successfully\n"); break; } gimp_value_array_unref (return_vals); gimp_value_array_unref (args); if (error) g_error_free (error); return; }