Commit ff9b4698 authored by Michael Natterer's avatar Michael Natterer 😴

app: move the file procedure registering functions into gimpplugin-proc.c

They are simply setting properties on GimpPlugInProcedures, just like
the other functions in gimpplugin-proc.[ch], so there is no reason to
have them elsewhere and with worse checks and error messages.
parent fba010a6
......@@ -40,7 +40,9 @@
#include "file/file-open.h"
#include "file/file-save.h"
#include "file/file-utils.h"
#include "plug-in/gimpplugin-proc.h"
#include "plug-in/gimppluginmanager-file.h"
#include "plug-in/gimppluginmanager.h"
#include "plug-in/gimppluginprocedure.h"
#include "gimppdb.h"
......@@ -422,11 +424,18 @@ register_load_handler_invoker (GimpProcedure *procedure,
if (success)
{
success = (gimp_pdb_is_canonical_procedure (procedure_name, error) &&
gimp_plug_in_manager_register_load_handler (gimp->plug_in_manager,
GimpPlugIn *plug_in = gimp->plug_in_manager->current_plug_in;
if (plug_in &&
gimp_pdb_is_canonical_procedure (procedure_name, error))
{
success = gimp_plug_in_set_file_proc_load_handler (plug_in,
procedure_name,
extensions, prefixes,
magics));
magics, error);
}
else
success = FALSE;
}
return gimp_procedure_get_return_values (procedure, success,
......@@ -452,10 +461,18 @@ register_save_handler_invoker (GimpProcedure *procedure,
if (success)
{
success = (gimp_pdb_is_canonical_procedure (procedure_name, error) &&
gimp_plug_in_manager_register_save_handler (gimp->plug_in_manager,
GimpPlugIn *plug_in = gimp->plug_in_manager->current_plug_in;
if (plug_in &&
gimp_pdb_is_canonical_procedure (procedure_name, error))
{
success = gimp_plug_in_set_file_proc_save_handler (plug_in,
procedure_name,
extensions, prefixes));
extensions, prefixes,
error);
}
else
success = FALSE;
}
return gimp_procedure_get_return_values (procedure, success,
......@@ -479,9 +496,17 @@ register_file_handler_priority_invoker (GimpProcedure *procedure,
if (success)
{
success = (gimp_pdb_is_canonical_procedure (procedure_name, error) &&
gimp_plug_in_manager_register_priority (gimp->plug_in_manager,
procedure_name, priority));
GimpPlugIn *plug_in = gimp->plug_in_manager->current_plug_in;
if (plug_in &&
gimp_pdb_is_canonical_procedure (procedure_name, error))
{
success = gimp_plug_in_set_file_proc_priority (plug_in,
procedure_name,
priority, error);
}
else
success = FALSE;
}
return gimp_procedure_get_return_values (procedure, success,
......@@ -505,10 +530,17 @@ register_file_handler_mime_invoker (GimpProcedure *procedure,
if (success)
{
success = (gimp_pdb_is_canonical_procedure (procedure_name, error) &&
gimp_plug_in_manager_register_mime_types (gimp->plug_in_manager,
GimpPlugIn *plug_in = gimp->plug_in_manager->current_plug_in;
if (plug_in &&
gimp_pdb_is_canonical_procedure (procedure_name, error))
{
success = gimp_plug_in_set_file_proc_mime_types (plug_in,
procedure_name,
mime_types));
mime_types, error);
}
else
success = FALSE;
}
return gimp_procedure_get_return_values (procedure, success,
......@@ -530,9 +562,17 @@ register_file_handler_remote_invoker (GimpProcedure *procedure,
if (success)
{
success = (gimp_pdb_is_canonical_procedure (procedure_name, error) &&
gimp_plug_in_manager_register_handles_remote (gimp->plug_in_manager,
procedure_name));
GimpPlugIn *plug_in = gimp->plug_in_manager->current_plug_in;
if (plug_in &&
gimp_pdb_is_canonical_procedure (procedure_name, error))
{
success = gimp_plug_in_set_file_proc_handles_remote (plug_in,
procedure_name,
error);
}
else
success = FALSE;
}
return gimp_procedure_get_return_values (procedure, success,
......@@ -554,9 +594,17 @@ register_file_handler_raw_invoker (GimpProcedure *procedure,
if (success)
{
success = (gimp_pdb_is_canonical_procedure (procedure_name, error) &&
gimp_plug_in_manager_register_handles_raw (gimp->plug_in_manager,
procedure_name));
GimpPlugIn *plug_in = gimp->plug_in_manager->current_plug_in;
if (plug_in &&
gimp_pdb_is_canonical_procedure (procedure_name, error))
{
success = gimp_plug_in_set_file_proc_handles_raw (plug_in,
procedure_name,
error);
}
else
success = FALSE;
}
return gimp_procedure_get_return_values (procedure, success,
......@@ -580,10 +628,18 @@ register_thumbnail_loader_invoker (GimpProcedure *procedure,
if (success)
{
success = (gimp_pdb_is_canonical_procedure (load_proc, error) &&
gimp_pdb_is_canonical_procedure (thumb_proc, error) &&
gimp_plug_in_manager_register_thumb_loader (gimp->plug_in_manager,
load_proc, thumb_proc));
GimpPlugIn *plug_in = gimp->plug_in_manager->current_plug_in;
if (plug_in &&
gimp_pdb_is_canonical_procedure (load_proc, error) &&
gimp_pdb_is_canonical_procedure (thumb_proc, error))
{
success = gimp_plug_in_set_file_proc_thumb_loader (plug_in,
load_proc, thumb_proc,
error);
}
else
success = FALSE;
}
return gimp_procedure_get_return_values (procedure, success,
......
......@@ -26,6 +26,8 @@
#include "plug-in-types.h"
#include "core/gimpparamspecs.h"
#include "pdb/gimppdberror.h"
#include "gimpplugin.h"
......@@ -39,8 +41,10 @@
/* local function prototypes */
static GimpPlugInProcedure * gimp_plug_in_proc_find (GimpPlugIn *plug_in,
const gchar *proc_name);
static GimpPlugInProcedure * gimp_plug_in_proc_find (GimpPlugIn *plug_in,
const gchar *proc_name);
static gboolean file_procedure_in_group (GimpPlugInProcedure *file_proc,
GimpFileProcedureGroup group);
/* public functions */
......@@ -248,6 +252,315 @@ gimp_plug_in_set_proc_attribution (GimpPlugIn *plug_in,
return TRUE;
}
static inline gboolean
GIMP_IS_PARAM_SPEC_RUN_MODE (GParamSpec *pspec)
{
return (G_IS_PARAM_SPEC_ENUM (pspec) &&
pspec->value_type == GIMP_TYPE_RUN_MODE);
}
gboolean
gimp_plug_in_set_file_proc_load_handler (GimpPlugIn *plug_in,
const gchar *proc_name,
const gchar *extensions,
const gchar *prefixes,
const gchar *magics,
GError **error)
{
GimpPlugInProcedure *proc;
GimpProcedure *procedure;
g_return_val_if_fail (GIMP_IS_PLUG_IN (plug_in), FALSE);
g_return_val_if_fail (proc_name != NULL, FALSE);
proc = gimp_plug_in_proc_find (plug_in, proc_name);
if (! proc)
{
g_set_error (error, GIMP_PDB_ERROR, GIMP_PDB_ERROR_PROCEDURE_NOT_FOUND,
"Plug-in \"%s\"\n(%s)\n"
"attempted to register procedure \"%s\" "
"as load handler.\n"
"It has however not installed that procedure. "
"This is not allowed.",
gimp_object_get_name (plug_in),
gimp_file_get_utf8_name (plug_in->file),
proc_name);
return FALSE;
}
procedure = GIMP_PROCEDURE (proc);
if (((procedure->num_args < 3) ||
(procedure->num_values < 1) ||
! GIMP_IS_PARAM_SPEC_RUN_MODE (procedure->args[0]) ||
! G_IS_PARAM_SPEC_STRING (procedure->args[1]) ||
! G_IS_PARAM_SPEC_STRING (procedure->args[2]) ||
(! proc->generic_file_proc &&
! GIMP_IS_PARAM_SPEC_IMAGE (procedure->values[0]))))
{
g_set_error (error, GIMP_PDB_ERROR, GIMP_PDB_ERROR_FAILED,
"load handler \"%s\" does not take the standard "
"load handler args", proc_name);
return FALSE;
}
gimp_plug_in_procedure_set_file_proc (proc, extensions, prefixes, magics);
if (! g_slist_find (plug_in->manager->load_procs, proc))
plug_in->manager->load_procs =
g_slist_prepend (plug_in->manager->load_procs, proc);
return TRUE;
}
gboolean
gimp_plug_in_set_file_proc_save_handler (GimpPlugIn *plug_in,
const gchar *proc_name,
const gchar *extensions,
const gchar *prefixes,
GError **error)
{
GimpPlugInProcedure *proc;
GimpProcedure *procedure;
g_return_val_if_fail (GIMP_IS_PLUG_IN (plug_in), FALSE);
g_return_val_if_fail (proc_name != NULL, FALSE);
proc = gimp_plug_in_proc_find (plug_in, proc_name);
if (! proc)
{
g_set_error (error, GIMP_PDB_ERROR, GIMP_PDB_ERROR_PROCEDURE_NOT_FOUND,
"Plug-in \"%s\"\n(%s)\n"
"attempted to register procedure \"%s\" "
"as save handler.\n"
"It has however not installed that procedure. "
"This is not allowed.",
gimp_object_get_name (plug_in),
gimp_file_get_utf8_name (plug_in->file),
proc_name);
return FALSE;
}
procedure = GIMP_PROCEDURE (proc);
if ((procedure->num_args < 5) ||
! GIMP_IS_PARAM_SPEC_RUN_MODE (procedure->args[0]) ||
! GIMP_IS_PARAM_SPEC_IMAGE (procedure->args[1]) ||
! GIMP_IS_PARAM_SPEC_DRAWABLE (procedure->args[2]) ||
! G_IS_PARAM_SPEC_STRING (procedure->args[3]) ||
! G_IS_PARAM_SPEC_STRING (procedure->args[4]))
{
g_set_error (error, GIMP_PDB_ERROR, GIMP_PDB_ERROR_FAILED,
"save handler \"%s\" does not take the standard "
"save handler args", proc_name);
return FALSE;
}
gimp_plug_in_procedure_set_file_proc (proc, extensions, prefixes, NULL);
if (file_procedure_in_group (proc, GIMP_FILE_PROCEDURE_GROUP_SAVE))
{
if (! g_slist_find (plug_in->manager->save_procs, proc))
plug_in->manager->save_procs =
g_slist_prepend (plug_in->manager->save_procs, proc);
}
if (file_procedure_in_group (proc, GIMP_FILE_PROCEDURE_GROUP_EXPORT))
{
if (! g_slist_find (plug_in->manager->export_procs, proc))
plug_in->manager->export_procs =
g_slist_prepend (plug_in->manager->export_procs, proc);
}
return TRUE;
}
gboolean
gimp_plug_in_set_file_proc_priority (GimpPlugIn *plug_in,
const gchar *proc_name,
gint priority,
GError **error)
{
GimpPlugInProcedure *proc;
g_return_val_if_fail (GIMP_IS_PLUG_IN (plug_in), FALSE);
g_return_val_if_fail (proc_name != NULL, FALSE);
proc = gimp_plug_in_proc_find (plug_in, proc_name);
if (! proc)
{
g_set_error (error, GIMP_PDB_ERROR, GIMP_PDB_ERROR_PROCEDURE_NOT_FOUND,
"Plug-in \"%s\"\n(%s)\n"
"attempted to register the priority "
"for procedure \"%s\".\n"
"It has however not installed that procedure. "
"This is not allowed.",
gimp_object_get_name (plug_in),
gimp_file_get_utf8_name (plug_in->file),
proc_name);
return FALSE;
}
gimp_plug_in_procedure_set_priority (proc, priority);
return TRUE;
}
gboolean
gimp_plug_in_set_file_proc_mime_types (GimpPlugIn *plug_in,
const gchar *proc_name,
const gchar *mime_types,
GError **error)
{
GimpPlugInProcedure *proc;
g_return_val_if_fail (GIMP_IS_PLUG_IN (plug_in), FALSE);
g_return_val_if_fail (proc_name != NULL, FALSE);
proc = gimp_plug_in_proc_find (plug_in, proc_name);
if (! proc)
{
g_set_error (error, GIMP_PDB_ERROR, GIMP_PDB_ERROR_PROCEDURE_NOT_FOUND,
"Plug-in \"%s\"\n(%s)\n"
"attempted to register mime types "
"for procedure \"%s\".\n"
"It has however not installed that procedure. "
"This is not allowed.",
gimp_object_get_name (plug_in),
gimp_file_get_utf8_name (plug_in->file),
proc_name);
return FALSE;
}
gimp_plug_in_procedure_set_mime_types (proc, mime_types);
return TRUE;
}
gboolean
gimp_plug_in_set_file_proc_handles_remote (GimpPlugIn *plug_in,
const gchar *proc_name,
GError **error)
{
GimpPlugInProcedure *proc;
g_return_val_if_fail (GIMP_IS_PLUG_IN (plug_in), FALSE);
g_return_val_if_fail (proc_name != NULL, FALSE);
proc = gimp_plug_in_proc_find (plug_in, proc_name);
if (! proc)
{
g_set_error (error, GIMP_PDB_ERROR, GIMP_PDB_ERROR_PROCEDURE_NOT_FOUND,
"Plug-in \"%s\"\n(%s)\n"
"attempted to register 'handles remote' "
"for procedure \"%s\".\n"
"It has however not installed that procedure. "
"This is not allowed.",
gimp_object_get_name (plug_in),
gimp_file_get_utf8_name (plug_in->file),
proc_name);
return FALSE;
}
gimp_plug_in_procedure_set_handles_remote (proc);
return TRUE;
}
gboolean
gimp_plug_in_set_file_proc_handles_raw (GimpPlugIn *plug_in,
const gchar *proc_name,
GError **error)
{
GimpPlugInProcedure *proc;
g_return_val_if_fail (GIMP_IS_PLUG_IN (plug_in), FALSE);
g_return_val_if_fail (proc_name != NULL, FALSE);
proc = gimp_plug_in_proc_find (plug_in, proc_name);
if (! proc)
{
g_set_error (error, GIMP_PDB_ERROR, GIMP_PDB_ERROR_PROCEDURE_NOT_FOUND,
"Plug-in \"%s\"\n(%s)\n"
"attempted to register 'handles raw' "
"for procedure \"%s\".\n"
"It has however not installed that procedure. "
"This is not allowed.",
gimp_object_get_name (plug_in),
gimp_file_get_utf8_name (plug_in->file),
proc_name);
return FALSE;
}
gimp_plug_in_procedure_set_handles_raw (proc);
return TRUE;
}
gboolean
gimp_plug_in_set_file_proc_thumb_loader (GimpPlugIn *plug_in,
const gchar *proc_name,
const gchar *thumb_proc_name,
GError **error)
{
GimpPlugInProcedure *proc;
GimpPlugInProcedure *thumb_proc;
g_return_val_if_fail (GIMP_IS_PLUG_IN (plug_in), FALSE);
g_return_val_if_fail (proc_name != NULL, FALSE);
g_return_val_if_fail (thumb_proc_name != NULL, FALSE);
proc = gimp_plug_in_proc_find (plug_in, proc_name);
thumb_proc = gimp_plug_in_proc_find (plug_in, thumb_proc_name);
if (! proc)
{
g_set_error (error, GIMP_PDB_ERROR, GIMP_PDB_ERROR_PROCEDURE_NOT_FOUND,
"Plug-in \"%s\"\n(%s)\n"
"attempted to register a thumbnail loader "
"for procedure \"%s\".\n"
"It has however not installed that procedure. "
"This is not allowed.",
gimp_object_get_name (plug_in),
gimp_file_get_utf8_name (plug_in->file),
proc_name);
return FALSE;
}
if (! thumb_proc)
{
g_set_error (error, GIMP_PDB_ERROR, GIMP_PDB_ERROR_PROCEDURE_NOT_FOUND,
"Plug-in \"%s\"\n(%s)\n"
"attempted to register a procedure \"%s\" "
"as thumbnail loader.\n"
"It has however not installed that procedure. "
"This is not allowed.",
gimp_object_get_name (plug_in),
gimp_file_get_utf8_name (plug_in->file),
thumb_proc_name);
return FALSE;
}
gimp_plug_in_procedure_set_thumb_loader (proc, thumb_proc_name);
return TRUE;
}
/* private functions */
static GimpPlugInProcedure *
......@@ -265,3 +578,40 @@ gimp_plug_in_proc_find (GimpPlugIn *plug_in,
return proc;
}
static gboolean
file_procedure_in_group (GimpPlugInProcedure *file_proc,
GimpFileProcedureGroup group)
{
const gchar *name = gimp_object_get_name (file_proc);
gboolean is_xcf_save = FALSE;
gboolean is_filter = FALSE;
is_xcf_save = (strcmp (name, "gimp-xcf-save") == 0);
is_filter = (strcmp (name, "file-gz-save") == 0 ||
strcmp (name, "file-bz2-save") == 0 ||
strcmp (name, "file-xz-save") == 0);
switch (group)
{
case GIMP_FILE_PROCEDURE_GROUP_NONE:
return FALSE;
case GIMP_FILE_PROCEDURE_GROUP_SAVE:
/* Only .xcf shall pass */
return is_xcf_save || is_filter;
case GIMP_FILE_PROCEDURE_GROUP_EXPORT:
/* Anything but .xcf shall pass */
return ! is_xcf_save;
case GIMP_FILE_PROCEDURE_GROUP_OPEN:
/* No filter applied for Open */
return TRUE;
default:
case GIMP_FILE_PROCEDURE_GROUP_ANY:
return TRUE;
}
}
......@@ -21,36 +21,66 @@
#define __GIMP_PLUG_IN_PROC_H__
gboolean gimp_plug_in_set_proc_image_types (GimpPlugIn *plug_in,
const gchar *proc_name,
const gchar *image_types,
GError **error);
gboolean gimp_plug_in_set_proc_menu_label (GimpPlugIn *plug_in,
const gchar *proc_name,
const gchar *menu_label,
GError **error);
gboolean gimp_plug_in_add_proc_menu_path (GimpPlugIn *plug_in,
const gchar *proc_name,
const gchar *menu_path,
GError **error);
gboolean gimp_plug_in_set_proc_icon (GimpPlugIn *plug_in,
const gchar *proc_name,
GimpIconType type,
const guint8 *data,
gint data_length,
GError **error);
gboolean gimp_plug_in_set_proc_help (GimpPlugIn *plug_in,
const gchar *proc_name,
const gchar *blurb,
const gchar *help,
const gchar *help_id,
GError **error);
gboolean gimp_plug_in_set_proc_attribution (GimpPlugIn *plug_in,
const gchar *proc_name,
const gchar *authors,
const gchar *copyright,
const gchar *date,
GError **error);
gboolean gimp_plug_in_set_proc_image_types (GimpPlugIn *plug_in,
const gchar *proc_name,
const gchar *image_types,
GError **error);
gboolean gimp_plug_in_set_proc_menu_label (GimpPlugIn *plug_in,
const gchar *proc_name,
const gchar *menu_label,
GError **error);
gboolean gimp_plug_in_add_proc_menu_path (GimpPlugIn *plug_in,
const gchar *proc_name,
const gchar *menu_path,
GError **error);
gboolean gimp_plug_in_set_proc_icon (GimpPlugIn *plug_in,
const gchar *proc_name,
GimpIconType type,
const guint8 *data,
gint data_length,
GError **error);
gboolean gimp_plug_in_set_proc_help (GimpPlugIn *plug_in,
const gchar *proc_name,
const gchar *blurb,
const gchar *help,
const gchar *help_id,
GError **error);
gboolean gimp_plug_in_set_proc_attribution (GimpPlugIn *plug_in,
const gchar *proc_name,
const gchar *authors,
const gchar *copyright,
const gchar *date,
GError **error);
gboolean gimp_plug_in_set_file_proc_load_handler (GimpPlugIn *plug_in,
const gchar *proc_name,
const gchar *extensions,
const gchar *prefixes,
const gchar *magics,
GError **error);
gboolean gimp_plug_in_set_file_proc_save_handler (GimpPlugIn *plug_in,
const gchar *proc_name,
const gchar *extensions,
const gchar *prefixes,
GError **error);
gboolean gimp_plug_in_set_file_proc_priority (GimpPlugIn *plug_in,
const gchar *proc_name,
gint priority,
GError **error);
gboolean gimp_plug_in_set_file_proc_mime_types (GimpPlugIn *plug_in,
const gchar *proc_name,
const gchar *mime_types,
GError **error);
gboolean gimp_plug_in_set_file_proc_handles_remote (GimpPlugIn *plug_in,
const gchar *proc_name,
GError **error);
gboolean gimp_plug_in_set_file_proc_handles_raw (GimpPlugIn *plug_in,
const gchar *proc_name,
GError **error);
gboolean gimp_plug_in_set_file_proc_thumb_loader (GimpPlugIn *plug_in,
const gchar *proc_name,
const gchar *thumb_proc,
GError **error);
#endif /* __GIMP_PLUG_IN_PROC_H__ */
......@@ -29,7 +29,6 @@
#include "plug-in-types.h"
#include "core/gimp.h"
#include "core/gimpparamspecs.h"
#include "gimpplugin.h"
#include "gimpplugindef.h"
......@@ -39,264 +38,8 @@
#include "gimppluginprocedure.h"
static gboolean file_procedure_in_group (GimpPlugInProcedure *file_proc,
GimpFileProcedureGroup group);
/* public functions */
static inline gboolean
GIMP_IS_PARAM_SPEC_RUN_MODE (GParamSpec *pspec)
{
return (G_IS_PARAM_SPEC_ENUM (pspec) &&
pspec->value_type == GIMP_TYPE_RUN_MODE);
}
gboolean
gimp_plug_in_manager_register_load_handler (GimpPlugInManager *manager,
const gchar *name,
const gchar *extensions,
const gchar *prefixes,
const gchar *magics)
{
GimpPlugInProcedure *file_proc;
GimpProcedure *procedure;
GSList *list;
g_return_val_if_fail (GIMP_IS_PLUG_IN_MANAGER (manager), FALSE);
g_return_val_if_fail (name != NULL, FALSE);
if (manager->current_plug_in && manager->current_plug_in->plug_in_def)
list = manager->current_plug_in->plug_in_def->procedures;
else
list = manager->plug_in_procedures;
file_proc = gimp_plug_in_procedure_find (list, name);
if (! file_proc)
{
gimp_message (manager->gimp, NULL, GIMP_MESSAGE_ERROR,
"attempt to register nonexistent load handler \"%s\"",
name);
return FALSE;
}
procedure = GIMP_PROCEDURE (file_proc);
if (((procedure->num_args < 3) ||
(procedure->num_values < 1) ||
! GIMP_IS_PARAM_SPEC_RUN_MODE (procedure->args[0]) ||
! G_IS_PARAM_SPEC_STRING (procedure->args[1]) ||
! G_IS_PARAM_SPEC_STRING (procedure->args[2]) ||
(! file_proc->generic_file_proc &&
! GIMP_IS_PARAM_SPEC_IMAGE (procedure->values[0]))))
{
gimp_message (manager->gimp, NULL, GIMP_MESSAGE_ERROR,
"load handler \"%s\" does not take the standard "
"load handler args", name);
return FALSE;
}
gimp_plug_in_procedure_set_file_proc (file_proc,
extensions, prefixes, magics);
if (! g_slist_find (manager->load_procs, file_proc))
manager->load_procs = g_slist_prepend (manager->load_procs, file_proc);
return TRUE;
}
gboolean
gimp_plug_in_manager_register_save_handler (GimpPlugInManager *manager,
const gchar *name,
const gchar *extensions,
const gchar *prefixes)
{
GimpPlugInProcedure *file_proc;
GimpProcedure *procedure;
GSList *list;
g_return_val_if_fail (GIMP_IS_PLUG_IN_MANAGER (manager), FALSE);
g_return_val_if_fail (name != NULL, FALSE);
if (manager->current_plug_in && manager->current_plug_in->plug_in_def)
list = manager->current_plug_in->plug_in_def->procedures;
else
list = manager->plug_in_procedures;
file_proc = gimp_plug_in_procedure_find (list, name);
if (! file_proc)
{