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; }
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; }
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 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); } }
GimpValueArray * procedure_commands_get_run_mode_arg (GimpProcedure *procedure) { GimpValueArray *args; gint n_args = 0; args = gimp_procedure_get_arguments (procedure); /* initialize the first argument */ if (gimp_value_array_length (args) > n_args && GIMP_IS_PARAM_SPEC_INT32 (procedure->args[n_args])) { g_value_set_int (gimp_value_array_index (args, n_args), GIMP_RUN_INTERACTIVE); n_args++; } gimp_value_array_truncate (args, n_args); return args; }
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); }
static void gimp_help_call (Gimp *gimp, const gchar *procedure_name, const gchar *help_domain, const gchar *help_locales, const gchar *help_id) { GimpProcedure *procedure; /* Special case the help browser */ if (! strcmp (procedure_name, "extension-gimp-help-browser-temp")) { GValueArray *return_vals; return_vals = gimp_pdb_execute_procedure_by_name (gimp->pdb, gimp_get_user_context (gimp), NULL, procedure_name, G_TYPE_STRING, help_domain, G_TYPE_STRING, help_locales, G_TYPE_STRING, help_id, G_TYPE_NONE); g_value_array_free (return_vals); return; } /* Check if a help parser is already running */ procedure = gimp_pdb_lookup_procedure (gimp->pdb, "extension-gimp-help-temp"); if (! procedure) { GValueArray *args = NULL; gint n_domains = 0; gchar **help_domains = NULL; gchar **help_uris = NULL; procedure = gimp_pdb_lookup_procedure (gimp->pdb, "extension-gimp-help"); if (! procedure) /* FIXME: error msg */ return; n_domains = gimp_plug_in_manager_get_help_domains (gimp->plug_in_manager, &help_domains, &help_uris); args = gimp_procedure_get_arguments (procedure); gimp_value_array_truncate (args, 4); g_value_set_int (&args->values[0], n_domains); gimp_value_take_stringarray (&args->values[1], help_domains, n_domains); g_value_set_int (&args->values[2], n_domains); gimp_value_take_stringarray (&args->values[3], help_uris, n_domains); gimp_procedure_execute_async (procedure, gimp, gimp_get_user_context (gimp), NULL, args, NULL); g_value_array_free (args); } /* Check if the help parser started properly */ procedure = gimp_pdb_lookup_procedure (gimp->pdb, "extension-gimp-help-temp"); if (procedure) { GValueArray *return_vals; #ifdef GIMP_HELP_DEBUG g_printerr ("Calling help via %s: %s %s %s\n", procedure_name, help_domain ? help_domain : "(null)", help_locales ? help_locales : "(null)", help_id ? help_id : "(null)"); #endif return_vals = gimp_pdb_execute_procedure_by_name (gimp->pdb, gimp_get_user_context (gimp), NULL, "extension-gimp-help-temp", G_TYPE_STRING, procedure_name, G_TYPE_STRING, help_domain, G_TYPE_STRING, help_locales, G_TYPE_STRING, help_id, G_TYPE_NONE); g_value_array_free (return_vals); } }
static gboolean gimp_help_browser (Gimp *gimp) { static gboolean busy = FALSE; GimpProcedure *procedure; if (busy) return TRUE; busy = TRUE; /* Check if a help browser is already running */ procedure = gimp_pdb_lookup_procedure (gimp->pdb, "extension-gimp-help-browser-temp"); if (! procedure) { GValueArray *args = NULL; gint n_domains = 0; gchar **help_domains = NULL; gchar **help_uris = NULL; procedure = gimp_pdb_lookup_procedure (gimp->pdb, "extension-gimp-help-browser"); if (! procedure) { gimp_help_browser_error (gimp, _("Help browser not found"), _("Could not find GIMP help browser."), _("The GIMP help browser plug-in appears " "to be missing from your installation.")); busy = FALSE; return FALSE; } n_domains = gimp_plug_in_manager_get_help_domains (gimp->plug_in_manager, &help_domains, &help_uris); args = gimp_procedure_get_arguments (procedure); gimp_value_array_truncate (args, 5); g_value_set_int (&args->values[0], GIMP_RUN_INTERACTIVE); g_value_set_int (&args->values[1], n_domains); gimp_value_take_stringarray (&args->values[2], help_domains, n_domains); g_value_set_int (&args->values[3], n_domains); gimp_value_take_stringarray (&args->values[4], help_uris, n_domains); gimp_procedure_execute_async (procedure, gimp, gimp_get_user_context (gimp), NULL, args, NULL); g_value_array_free (args); } /* Check if the help browser started properly */ procedure = gimp_pdb_lookup_procedure (gimp->pdb, "extension-gimp-help-browser-temp"); if (! procedure) { gimp_help_browser_error (gimp, _("Help browser doesn't start"), _("Could not start the GIMP help browser plug-in."), NULL); busy = FALSE; return FALSE; } busy = FALSE; return TRUE; }
static void batch_run_cmd (Gimp *gimp, const gchar *proc_name, GimpProcedure *procedure, GimpRunMode run_mode, const gchar *cmd) { GValueArray *args; GValueArray *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 (&args->values[i++], run_mode); if (procedure->num_args > i && GIMP_IS_PARAM_SPEC_STRING (procedure->args[i])) g_value_set_static_string (&args->values[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 (&return_vals->values[0])) { case GIMP_PDB_EXECUTION_ERROR: if (error) { g_printerr ("batch command experienced an execution error: %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: %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; } g_value_array_free (return_vals); g_value_array_free (args); if (error) g_error_free (error); return; }
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; }
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; }
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); }
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; }