gboolean gimp_pdb_proc_info (GimpPDB *pdb, const gchar *proc_name, gchar **blurb, gchar **help, gchar **author, gchar **copyright, gchar **date, GimpPDBProcType *proc_type, gint *num_args, gint *num_values, GError **error) { GimpProcedure *procedure; PDBStrings strings; g_return_val_if_fail (GIMP_IS_PDB (pdb), FALSE); g_return_val_if_fail (proc_name != NULL, FALSE); g_return_val_if_fail (error == NULL || *error == NULL, FALSE); procedure = gimp_pdb_lookup_procedure (pdb, proc_name); if (procedure) { gimp_pdb_get_strings (&strings, procedure, FALSE); } else { const gchar *compat_name; compat_name = gimp_pdb_lookup_compat_proc_name (pdb, proc_name); if (compat_name) { procedure = gimp_pdb_lookup_procedure (pdb, compat_name); if (procedure) gimp_pdb_get_strings (&strings, procedure, TRUE); } } if (procedure) { *blurb = strings.compat ? strings.blurb : g_strdup (strings.blurb); *help = strings.compat ? strings.help : g_strdup (strings.help); *author = strings.compat ? strings.author : g_strdup (strings.author); *copyright = strings.compat ? strings.copyright : g_strdup (strings.copyright); *date = strings.compat ? strings.date : g_strdup (strings.date); *proc_type = procedure->proc_type; *num_args = procedure->num_args; *num_values = procedure->num_values; return TRUE; } g_set_error (error, GIMP_PDB_ERROR, GIMP_PDB_PROCEDURE_NOT_FOUND, _("Procedure '%s' not found"), proc_name); return FALSE; }
/** * gimp_pdb_get_deprecated_procedures: * @pdb: * * Returns: A new #GList with the deprecated procedures. Free with * g_list_free(). **/ GList * gimp_pdb_get_deprecated_procedures (GimpPDB *pdb) { GList *result = NULL; GList *procs; GList *iter; g_return_val_if_fail (GIMP_IS_PDB (pdb), NULL); procs = g_hash_table_get_values (pdb->procedures); for (iter = procs; iter; iter = g_list_next (iter)) { GList *proc_list = iter->data; /* Only care about the first procedure in the list */ GimpProcedure *procedure = GIMP_PROCEDURE (proc_list->data); if (procedure->deprecated) result = g_list_prepend (result, procedure); } result = g_list_sort (result, (GCompareFunc) gimp_procedure_name_compare); g_list_free (procs); return result; }
gboolean gimp_pdb_dump (GimpPDB *pdb, const gchar *filename) { PDBDump pdb_dump; g_return_val_if_fail (GIMP_IS_PDB (pdb), FALSE); g_return_val_if_fail (filename != NULL, FALSE); pdb_dump.pdb = pdb; pdb_dump.file = g_fopen (filename, "w"); if (! pdb_dump.file) return FALSE; pdb_dump.dumping_compat = FALSE; g_hash_table_foreach (pdb->procedures, gimp_pdb_print_entry, &pdb_dump); pdb_dump.dumping_compat = TRUE; g_hash_table_foreach (pdb->compat_proc_names, gimp_pdb_print_entry, &pdb_dump); fclose (pdb_dump.file); return TRUE; }
void internal_procs_init (GimpPDB *pdb) { g_return_if_fail (GIMP_IS_PDB (pdb)); register_brush_procs (pdb); register_brush_select_procs (pdb); register_brushes_procs (pdb); register_buffer_procs (pdb); register_channel_procs (pdb); register_color_procs (pdb); register_context_procs (pdb); register_display_procs (pdb); register_drawable_procs (pdb); register_drawable_color_procs (pdb); register_drawable_transform_procs (pdb); register_dynamics_procs (pdb); register_edit_procs (pdb); register_fileops_procs (pdb); register_floating_sel_procs (pdb); register_font_select_procs (pdb); register_fonts_procs (pdb); register_gimp_procs (pdb); register_gimprc_procs (pdb); register_gradient_procs (pdb); register_gradient_select_procs (pdb); register_gradients_procs (pdb); register_help_procs (pdb); register_image_procs (pdb); register_image_color_profile_procs (pdb); register_image_convert_procs (pdb); register_image_grid_procs (pdb); register_image_guides_procs (pdb); register_image_select_procs (pdb); register_image_transform_procs (pdb); register_image_undo_procs (pdb); register_item_procs (pdb); register_item_transform_procs (pdb); register_layer_procs (pdb); register_message_procs (pdb); register_paint_tools_procs (pdb); register_palette_procs (pdb); register_palette_select_procs (pdb); register_palettes_procs (pdb); register_paths_procs (pdb); register_pattern_procs (pdb); register_pattern_select_procs (pdb); register_patterns_procs (pdb); register_plug_in_procs (pdb); register_plug_in_compat_procs (pdb); register_procedural_db_procs (pdb); register_progress_procs (pdb); register_selection_procs (pdb); register_selection_tools_procs (pdb); register_text_layer_procs (pdb); register_text_tool_procs (pdb); register_transform_tools_procs (pdb); register_unit_procs (pdb); register_vectors_procs (pdb); }
const gchar * gimp_pdb_lookup_compat_proc_name (GimpPDB *pdb, const gchar *old_name) { g_return_val_if_fail (GIMP_IS_PDB (pdb), NULL); g_return_val_if_fail (old_name != NULL, NULL); return g_hash_table_lookup (pdb->compat_proc_names, old_name); }
void gimp_pdb_unregister_procedure (GimpPDB *pdb, GimpProcedure *procedure) { g_return_if_fail (GIMP_IS_PDB (pdb)); g_return_if_fail (GIMP_IS_PROCEDURE (procedure)); g_signal_emit (pdb, gimp_pdb_signals[UNREGISTER_PROCEDURE], 0, procedure); }
static void gimp_pdb_progress_constructed (GObject *object) { GimpPdbProgress *progress = GIMP_PDB_PROGRESS (object); G_OBJECT_CLASS (parent_class)->constructed (object); g_assert (GIMP_IS_PDB (progress->pdb)); g_assert (GIMP_IS_CONTEXT (progress->context)); }
void gimp_pdb_register_compat_proc_name (GimpPDB *pdb, const gchar *old_name, const gchar *new_name) { g_return_if_fail (GIMP_IS_PDB (pdb)); g_return_if_fail (old_name != NULL); g_return_if_fail (new_name != NULL); g_hash_table_insert (pdb->compat_proc_names, (gpointer) old_name, (gpointer) new_name); }
void gimp_pdb_register_procedure (GimpPDB *pdb, GimpProcedure *procedure) { g_return_if_fail (GIMP_IS_PDB (pdb)); g_return_if_fail (GIMP_IS_PROCEDURE (procedure)); if (! procedure->deprecated || pdb->gimp->pdb_compat_mode != GIMP_PDB_COMPAT_OFF) { g_signal_emit (pdb, gimp_pdb_signals[REGISTER_PROCEDURE], 0, procedure); } }
GimpProcedure * gimp_pdb_lookup_procedure (GimpPDB *pdb, const gchar *name) { GList *list; g_return_val_if_fail (GIMP_IS_PDB (pdb), NULL); g_return_val_if_fail (name != NULL, NULL); list = g_hash_table_lookup (pdb->procedures, name); if (list) return list->data; return NULL; }
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 * 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; }
gboolean gimp_pdb_query (GimpPDB *pdb, const gchar *name, const gchar *blurb, const gchar *help, const gchar *author, const gchar *copyright, const gchar *date, const gchar *proc_type, gint *num_procs, gchar ***procs, GError **error) { PDBQuery pdb_query = { 0, }; gboolean success = FALSE; g_return_val_if_fail (GIMP_IS_PDB (pdb), FALSE); g_return_val_if_fail (name != NULL, FALSE); g_return_val_if_fail (blurb != NULL, FALSE); g_return_val_if_fail (help != NULL, FALSE); g_return_val_if_fail (author != NULL, FALSE); g_return_val_if_fail (copyright != NULL, FALSE); g_return_val_if_fail (date != NULL, FALSE); g_return_val_if_fail (proc_type != NULL, FALSE); g_return_val_if_fail (num_procs != NULL, FALSE); g_return_val_if_fail (procs != NULL, FALSE); g_return_val_if_fail (error == NULL || *error == NULL, FALSE); *num_procs = 0; *procs = NULL; pdb_query.name_regex = g_regex_new (name, PDB_REGEX_FLAGS, 0, error); if (! pdb_query.name_regex) goto cleanup; pdb_query.blurb_regex = g_regex_new (blurb, PDB_REGEX_FLAGS, 0, error); if (! pdb_query.blurb_regex) goto cleanup; pdb_query.help_regex = g_regex_new (help, PDB_REGEX_FLAGS, 0, error); if (! pdb_query.help_regex) goto cleanup; pdb_query.author_regex = g_regex_new (author, PDB_REGEX_FLAGS, 0, error); if (! pdb_query.author_regex) goto cleanup; pdb_query.copyright_regex = g_regex_new (copyright, PDB_REGEX_FLAGS, 0, error); if (! pdb_query.copyright_regex) goto cleanup; pdb_query.date_regex = g_regex_new (date, PDB_REGEX_FLAGS, 0, error); if (! pdb_query.date_regex) goto cleanup; pdb_query.proc_type_regex = g_regex_new (proc_type, PDB_REGEX_FLAGS, 0, error); if (! pdb_query.proc_type_regex) goto cleanup; success = TRUE; pdb_query.pdb = pdb; pdb_query.list_of_procs = NULL; pdb_query.num_procs = 0; pdb_query.querying_compat = FALSE; g_hash_table_foreach (pdb->procedures, gimp_pdb_query_entry, &pdb_query); pdb_query.querying_compat = TRUE; g_hash_table_foreach (pdb->compat_proc_names, gimp_pdb_query_entry, &pdb_query); cleanup: if (pdb_query.proc_type_regex) g_regex_unref (pdb_query.proc_type_regex); if (pdb_query.date_regex) g_regex_unref (pdb_query.date_regex); if (pdb_query.copyright_regex) g_regex_unref (pdb_query.copyright_regex); if (pdb_query.author_regex) g_regex_unref (pdb_query.author_regex); if (pdb_query.help_regex) g_regex_unref (pdb_query.help_regex); if (pdb_query.blurb_regex) g_regex_unref (pdb_query.blurb_regex); if (pdb_query.name_regex) g_regex_unref (pdb_query.name_regex); if (success) { *num_procs = pdb_query.num_procs; *procs = pdb_query.list_of_procs; } return success; }