2019-09-08 22:35:47 +08:00
|
|
|
/* GIMP - The GNU Image Manipulation Program
|
|
|
|
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
|
|
|
|
*
|
|
|
|
* gimpplugin-proc.c
|
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
|
|
|
#include <gdk-pixbuf/gdk-pixbuf.h>
|
|
|
|
#include <gegl.h>
|
|
|
|
|
|
|
|
#include "libgimpbase/gimpbase.h"
|
|
|
|
|
|
|
|
#include "plug-in-types.h"
|
|
|
|
|
2019-09-11 02:05:27 +08:00
|
|
|
#include "core/gimpparamspecs.h"
|
|
|
|
|
2019-09-09 18:10:32 +08:00
|
|
|
#include "pdb/gimppdberror.h"
|
2019-09-08 22:35:47 +08:00
|
|
|
|
|
|
|
#include "gimpplugin.h"
|
|
|
|
#include "gimpplugin-proc.h"
|
|
|
|
#include "gimpplugindef.h"
|
|
|
|
#include "gimppluginmanager.h"
|
2019-09-11 03:13:56 +08:00
|
|
|
#include "gimppluginmanager-file.h"
|
|
|
|
#include "gimppluginprocedure.h"
|
2019-09-08 22:35:47 +08:00
|
|
|
|
|
|
|
#include "gimp-intl.h"
|
|
|
|
|
|
|
|
|
2019-09-09 04:23:28 +08:00
|
|
|
/* local function prototypes */
|
|
|
|
|
2019-09-11 03:13:56 +08:00
|
|
|
static GimpPlugInProcedure * gimp_plug_in_proc_find (GimpPlugIn *plug_in,
|
|
|
|
const gchar *proc_name);
|
2019-09-09 04:23:28 +08:00
|
|
|
|
|
|
|
|
|
|
|
/* public functions */
|
|
|
|
|
2019-09-08 22:54:08 +08:00
|
|
|
gboolean
|
2019-09-09 18:10:32 +08:00
|
|
|
gimp_plug_in_set_proc_image_types (GimpPlugIn *plug_in,
|
|
|
|
const gchar *proc_name,
|
|
|
|
const gchar *image_types,
|
|
|
|
GError **error)
|
2019-09-08 22:54:08 +08:00
|
|
|
{
|
2019-09-09 04:23:28 +08:00
|
|
|
GimpPlugInProcedure *proc;
|
2019-09-08 22:54:08 +08:00
|
|
|
|
|
|
|
g_return_val_if_fail (GIMP_IS_PLUG_IN (plug_in), FALSE);
|
|
|
|
g_return_val_if_fail (proc_name != NULL, FALSE);
|
|
|
|
|
2019-09-09 04:23:28 +08:00
|
|
|
proc = gimp_plug_in_proc_find (plug_in, proc_name);
|
2019-09-08 22:54:08 +08:00
|
|
|
|
|
|
|
if (! proc)
|
|
|
|
{
|
2019-09-09 18:10:32 +08:00
|
|
|
g_set_error (error, GIMP_PDB_ERROR, GIMP_PDB_ERROR_PROCEDURE_NOT_FOUND,
|
|
|
|
"Plug-in \"%s\"\n(%s)\n"
|
|
|
|
"attempted to register images 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);
|
2019-09-08 22:54:08 +08:00
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
gimp_plug_in_procedure_set_image_types (proc, image_types);
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2021-04-02 05:49:11 +08:00
|
|
|
gboolean
|
|
|
|
gimp_plug_in_set_proc_sensitivity_mask (GimpPlugIn *plug_in,
|
|
|
|
const gchar *proc_name,
|
|
|
|
gint sensitivity_mask,
|
|
|
|
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 sensitivity mask \"%x\" "
|
|
|
|
"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),
|
|
|
|
sensitivity_mask, proc_name);
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
gimp_plug_in_procedure_set_sensitivity_mask (proc, sensitivity_mask);
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2019-09-08 23:30:54 +08:00
|
|
|
gboolean
|
2019-09-09 18:10:32 +08:00
|
|
|
gimp_plug_in_set_proc_menu_label (GimpPlugIn *plug_in,
|
|
|
|
const gchar *proc_name,
|
|
|
|
const gchar *menu_label,
|
|
|
|
GError **error)
|
2019-09-08 23:30:54 +08:00
|
|
|
{
|
2019-09-09 04:23:28 +08:00
|
|
|
GimpPlugInProcedure *proc;
|
2019-09-08 23:30:54 +08:00
|
|
|
|
|
|
|
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 (menu_label != NULL && strlen (menu_label), FALSE);
|
|
|
|
|
2019-09-09 04:23:28 +08:00
|
|
|
proc = gimp_plug_in_proc_find (plug_in, proc_name);
|
2019-09-08 23:30:54 +08:00
|
|
|
|
|
|
|
if (! proc)
|
|
|
|
{
|
2019-09-09 18:10:32 +08:00
|
|
|
g_set_error (error, GIMP_PDB_ERROR, GIMP_PDB_ERROR_PROCEDURE_NOT_FOUND,
|
|
|
|
"Plug-in \"%s\"\n(%s)\n"
|
|
|
|
"attempted to register the menu label \"%s\" "
|
|
|
|
"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),
|
|
|
|
menu_label, proc_name);
|
2019-09-08 23:30:54 +08:00
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2019-09-09 18:10:32 +08:00
|
|
|
return gimp_plug_in_procedure_set_menu_label (proc, menu_label, error);
|
2019-09-08 23:30:54 +08:00
|
|
|
}
|
|
|
|
|
2019-09-08 22:35:47 +08:00
|
|
|
gboolean
|
2019-09-09 18:10:32 +08:00
|
|
|
gimp_plug_in_add_proc_menu_path (GimpPlugIn *plug_in,
|
|
|
|
const gchar *proc_name,
|
|
|
|
const gchar *menu_path,
|
|
|
|
GError **error)
|
2019-09-08 22:35:47 +08:00
|
|
|
{
|
2019-09-09 04:23:28 +08:00
|
|
|
GimpPlugInProcedure *proc;
|
2019-09-08 22:35:47 +08:00
|
|
|
|
|
|
|
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 (menu_path != NULL, FALSE);
|
|
|
|
|
2019-09-09 04:23:28 +08:00
|
|
|
proc = gimp_plug_in_proc_find (plug_in, proc_name);
|
2019-09-08 22:35:47 +08:00
|
|
|
|
|
|
|
if (! proc)
|
|
|
|
{
|
2019-09-09 18:10:32 +08:00
|
|
|
g_set_error (error, GIMP_PDB_ERROR, GIMP_PDB_ERROR_PROCEDURE_NOT_FOUND,
|
|
|
|
"Plug-in \"%s\"\n(%s)\n"
|
|
|
|
"attempted to register the menu item \"%s\" "
|
|
|
|
"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),
|
|
|
|
menu_path, proc_name);
|
2019-09-08 22:35:47 +08:00
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2019-09-09 18:10:32 +08:00
|
|
|
return gimp_plug_in_procedure_add_menu_path (proc, menu_path, error);
|
2019-09-08 22:35:47 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
gboolean
|
2019-09-09 18:10:32 +08:00
|
|
|
gimp_plug_in_set_proc_icon (GimpPlugIn *plug_in,
|
|
|
|
const gchar *proc_name,
|
|
|
|
GimpIconType type,
|
|
|
|
const guint8 *data,
|
|
|
|
gint data_length,
|
|
|
|
GError **error)
|
2019-09-08 22:35:47 +08:00
|
|
|
{
|
2019-09-09 04:23:28 +08:00
|
|
|
GimpPlugInProcedure *proc;
|
2019-09-08 22:35:47 +08:00
|
|
|
|
|
|
|
g_return_val_if_fail (GIMP_IS_PLUG_IN (plug_in), FALSE);
|
|
|
|
g_return_val_if_fail (proc_name != NULL, FALSE);
|
|
|
|
|
2019-09-09 04:23:28 +08:00
|
|
|
proc = gimp_plug_in_proc_find (plug_in, proc_name);
|
2019-09-08 22:35:47 +08:00
|
|
|
|
|
|
|
if (! proc)
|
|
|
|
{
|
2019-09-09 18:10:32 +08:00
|
|
|
g_set_error (error, GIMP_PDB_ERROR, GIMP_PDB_ERROR_PROCEDURE_NOT_FOUND,
|
|
|
|
"Plug-in \"%s\"\n(%s)\n"
|
|
|
|
"attempted to set the icon "
|
|
|
|
"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);
|
2019-09-08 22:35:47 +08:00
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2019-09-09 18:10:32 +08:00
|
|
|
return gimp_plug_in_procedure_set_icon (proc, type, data, data_length,
|
|
|
|
error);
|
2019-09-08 22:35:47 +08:00
|
|
|
}
|
2019-09-09 04:23:28 +08:00
|
|
|
|
2019-09-09 06:36:24 +08:00
|
|
|
gboolean
|
2019-09-09 18:10:32 +08:00
|
|
|
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)
|
2019-09-09 06:36:24 +08:00
|
|
|
{
|
|
|
|
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)
|
|
|
|
{
|
2019-09-09 18:10:32 +08:00
|
|
|
g_set_error (error, GIMP_PDB_ERROR, GIMP_PDB_ERROR_PROCEDURE_NOT_FOUND,
|
|
|
|
"Plug-in \"%s\"\n(%s)\n"
|
|
|
|
"attempted to register help "
|
|
|
|
"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);
|
2019-09-09 06:36:24 +08:00
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
gimp_procedure_set_help (GIMP_PROCEDURE (proc),
|
|
|
|
blurb, help, help_id);
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
gboolean
|
2019-09-09 18:10:32 +08:00
|
|
|
gimp_plug_in_set_proc_attribution (GimpPlugIn *plug_in,
|
|
|
|
const gchar *proc_name,
|
|
|
|
const gchar *authors,
|
|
|
|
const gchar *copyright,
|
|
|
|
const gchar *date,
|
|
|
|
GError **error)
|
2019-09-09 06:36:24 +08:00
|
|
|
{
|
|
|
|
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)
|
|
|
|
{
|
2019-09-09 18:10:32 +08:00
|
|
|
g_set_error (error, GIMP_PDB_ERROR, GIMP_PDB_ERROR_PROCEDURE_NOT_FOUND,
|
|
|
|
"Plug-in \"%s\"\n(%s)\n"
|
|
|
|
"attempted to register the attribution "
|
|
|
|
"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);
|
2019-09-09 06:36:24 +08:00
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
gimp_procedure_set_attribution (GIMP_PROCEDURE (proc),
|
|
|
|
authors, copyright, date);
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
2019-09-09 04:23:28 +08:00
|
|
|
|
2019-09-11 02:05:27 +08:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2019-09-12 03:48:34 +08:00
|
|
|
static inline gboolean
|
|
|
|
GIMP_IS_PARAM_SPEC_FILE (GParamSpec *pspec)
|
|
|
|
{
|
|
|
|
return (G_IS_PARAM_SPEC_OBJECT (pspec) &&
|
|
|
|
pspec->value_type == G_TYPE_FILE);
|
|
|
|
}
|
|
|
|
|
2019-09-11 02:05:27 +08:00
|
|
|
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);
|
|
|
|
|
2019-09-11 06:21:03 +08:00
|
|
|
if (((procedure->num_args < 2) ||
|
2019-09-11 02:05:27 +08:00
|
|
|
(procedure->num_values < 1) ||
|
|
|
|
! GIMP_IS_PARAM_SPEC_RUN_MODE (procedure->args[0]) ||
|
2019-09-12 03:48:34 +08:00
|
|
|
! GIMP_IS_PARAM_SPEC_FILE (procedure->args[1]) ||
|
2019-09-11 02:05:27 +08:00
|
|
|
(! proc->generic_file_proc &&
|
|
|
|
! GIMP_IS_PARAM_SPEC_IMAGE (procedure->values[0]))))
|
|
|
|
{
|
|
|
|
g_set_error (error, GIMP_PDB_ERROR, GIMP_PDB_ERROR_FAILED,
|
2019-09-11 06:21:03 +08:00
|
|
|
"Plug-in \"%s\"\n(%s)\n"
|
|
|
|
"attempted to register procedure \"%s\" "
|
|
|
|
"as load handler which does not take the standard "
|
|
|
|
"load procedure arguments: "
|
2019-09-12 03:48:34 +08:00
|
|
|
"(GimpRunMode, GFile) -> (GimpImage)",
|
2019-09-11 06:21:03 +08:00
|
|
|
gimp_object_get_name (plug_in),
|
|
|
|
gimp_file_get_utf8_name (plug_in->file),
|
|
|
|
proc_name);
|
|
|
|
|
2019-09-11 02:05:27 +08:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
gimp_plug_in_procedure_set_file_proc (proc, extensions, prefixes, magics);
|
|
|
|
|
2019-09-11 03:13:56 +08:00
|
|
|
gimp_plug_in_manager_add_load_procedure (plug_in->manager, proc);
|
2019-09-11 02:05:27 +08:00
|
|
|
|
|
|
|
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);
|
|
|
|
|
2024-05-07 02:38:12 +08:00
|
|
|
if ((procedure->num_args < 4) ||
|
|
|
|
! GIMP_IS_PARAM_SPEC_RUN_MODE (procedure->args[0]) ||
|
|
|
|
! GIMP_IS_PARAM_SPEC_IMAGE (procedure->args[1]) ||
|
app, libgimp*, pdb, plug-ins: review and enhance MR !1549.
- Fix annotations for gimp_export_options_get_image() to make it
actually introspectable with the GimpImage being both input and
output. Even though the logic doesn't change much (the input image may
be overriden or not), it doesn't matter for introspection because
images are handled centrally by libgimp and therefore must not be
freed. Actually deleting the image from the central list of images
though remains a manual action depending on code logic, not some
automatic action to be handled by binding engines.
- Add G_GNUC_WARN_UNUSED_RESULT to gimp_export_options_get_image()
because ignoring the returned value is rarely a good idea (as you
usually want to delete the image).
- Remove gimp_export_options_new(): we don't need this constructor
because at this point, the best is to tell plug-in developers to just
pass NULL everywhere. This leaves us free to create a more useful
default constructor if needed, in the future. Main description for
GimpExportOptions has also been updated to say this.
- Add a data_destroy callback for the user data passed in
gimp_export_procedure_set_capabilities().
- Fixing annotations of 'export_options' object from pdb/pdb.pl: input
args would actually be (nullable) and would not transfer ownership
(calling code must still free the object). Return value's ownership on
the other hand is fully transfered.
- Add C and Python unit testing for GimpExportOptions and
gimp_export_options_get_image() in particular.
- Fix or improve various details.
Note that I have also considered for a long time changing the signature
of gimp_export_options_get_image() to return a boolean indicating
whether `image` had been replaced (hence needed deletion) or not. This
also meant getting rid of the GimpExportReturn enum. Right now it would
work because there are no third case, but I was considering the future
possibility that for instance we got some impossible conversion for some
future capability. I'm not sure it would ever happen; and for sure, this
is not desirable because it implies an export failure a bit late in the
workflow. But just in case, let's keep the enum return value. It does
not even make the using code that much more complicated (well just a
value comparison instead of a simple boolean test).
2024-08-17 21:06:27 +08:00
|
|
|
! GIMP_IS_PARAM_SPEC_FILE (procedure->args[2]) ||
|
|
|
|
! GIMP_IS_PARAM_SPEC_EXPORT_OPTIONS (procedure->args[3]))
|
2019-09-11 02:05:27 +08:00
|
|
|
{
|
|
|
|
g_set_error (error, GIMP_PDB_ERROR, GIMP_PDB_ERROR_FAILED,
|
2019-09-11 06:21:03 +08:00
|
|
|
"Plug-in \"%s\"\n(%s)\n"
|
|
|
|
"attempted to register procedure \"%s\" "
|
|
|
|
"as save handler which does not take the standard "
|
2020-04-14 17:46:17 +08:00
|
|
|
"save procedure arguments:\n"
|
2024-05-07 02:38:12 +08:00
|
|
|
"(GimpRunMode, GimpImage, GFile, GimpExportOptions)",
|
2019-09-11 06:21:03 +08:00
|
|
|
gimp_object_get_name (plug_in),
|
|
|
|
gimp_file_get_utf8_name (plug_in->file),
|
|
|
|
proc_name);
|
|
|
|
|
2019-09-11 02:05:27 +08:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
gimp_plug_in_procedure_set_file_proc (proc, extensions, prefixes, NULL);
|
|
|
|
|
2019-09-11 03:13:56 +08:00
|
|
|
gimp_plug_in_manager_add_save_procedure (plug_in->manager, proc);
|
2019-09-11 02:05:27 +08:00
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
app, libgimp, pdb: new GimpVectorLoadProcedure class.
It's still basic but will help to share code for support of various vector-able
formats, such as the logic for dimensioning them, but also the generated GUI.
Not only this, but we are paving the way for the link layers (though it'll be
after GIMP 3, we want plug-in procedures' API to stay stable) by giving a way
for a plug-in procedure to advertize a vector format support. This way, the core
will know when a source file is vector and can be directly reloaded at any
target size (right now, in my MR for link layers, the list of "vector" formats
is hardcoded, which is not reliable).
2024-04-23 05:11:37 +08:00
|
|
|
if (proc->handles_vector)
|
|
|
|
{
|
|
|
|
g_set_error (error, GIMP_PDB_ERROR, GIMP_PDB_ERROR_FAILED,
|
|
|
|
"Plug-in \"%s\"\n(%s)\n"
|
|
|
|
"attempted to register 'handles raw' "
|
|
|
|
"for procedure \"%s\" which already 'handles vector'.\n"
|
|
|
|
"It cannot handle both.",
|
|
|
|
gimp_object_get_name (plug_in),
|
|
|
|
gimp_file_get_utf8_name (plug_in->file),
|
|
|
|
proc_name);
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
2019-09-11 02:05:27 +08:00
|
|
|
gimp_plug_in_procedure_set_handles_raw (proc);
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
app, libgimp, pdb: new GimpVectorLoadProcedure class.
It's still basic but will help to share code for support of various vector-able
formats, such as the logic for dimensioning them, but also the generated GUI.
Not only this, but we are paving the way for the link layers (though it'll be
after GIMP 3, we want plug-in procedures' API to stay stable) by giving a way
for a plug-in procedure to advertize a vector format support. This way, the core
will know when a source file is vector and can be directly reloaded at any
target size (right now, in my MR for link layers, the list of "vector" formats
is hardcoded, which is not reliable).
2024-04-23 05:11:37 +08:00
|
|
|
gboolean
|
|
|
|
gimp_plug_in_set_file_proc_handles_vector (GimpPlugIn *plug_in,
|
|
|
|
const gchar *proc_name,
|
|
|
|
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 'handles vector' "
|
|
|
|
"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;
|
|
|
|
}
|
|
|
|
|
|
|
|
procedure = GIMP_PROCEDURE (proc);
|
|
|
|
|
|
|
|
if (procedure->num_args < 4 ||
|
|
|
|
procedure->num_values < 1 ||
|
|
|
|
! GIMP_IS_PARAM_SPEC_RUN_MODE (procedure->args[0]) ||
|
|
|
|
! GIMP_IS_PARAM_SPEC_FILE (procedure->args[1]) ||
|
|
|
|
! G_IS_PARAM_SPEC_INT (procedure->args[2]) ||
|
|
|
|
! G_IS_PARAM_SPEC_INT (procedure->args[3]) ||
|
|
|
|
! GIMP_IS_PARAM_SPEC_IMAGE (procedure->values[0]))
|
|
|
|
{
|
|
|
|
|
|
|
|
g_set_error (error, GIMP_PDB_ERROR, GIMP_PDB_ERROR_FAILED,
|
|
|
|
"Plug-in \"%s\"\n(%s)\n"
|
|
|
|
"attempted to register procedure \"%s\" "
|
|
|
|
"as a vector load procedure which does not take the "
|
|
|
|
"standard load procedure procedure arguments: "
|
|
|
|
"(GimpRunMode, file, int, int) -> (image)",
|
|
|
|
gimp_object_get_name (plug_in),
|
|
|
|
gimp_file_get_utf8_name (plug_in->file),
|
|
|
|
proc_name);
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (proc->handles_raw)
|
|
|
|
{
|
|
|
|
g_set_error (error, GIMP_PDB_ERROR, GIMP_PDB_ERROR_FAILED,
|
|
|
|
"Plug-in \"%s\"\n(%s)\n"
|
|
|
|
"attempted to register 'handles vector' "
|
|
|
|
"for procedure \"%s\" which already 'handles raw'.\n"
|
|
|
|
"It cannot handle both.",
|
|
|
|
gimp_object_get_name (plug_in),
|
|
|
|
gimp_file_get_utf8_name (plug_in->file),
|
|
|
|
proc_name);
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
gimp_plug_in_procedure_set_handles_vector (proc);
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2019-09-11 02:05:27 +08:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2022-04-16 23:09:21 +08:00
|
|
|
gboolean
|
|
|
|
gimp_plug_in_set_batch_interpreter (GimpPlugIn *plug_in,
|
|
|
|
const gchar *proc_name,
|
2022-04-17 05:13:50 +08:00
|
|
|
const gchar *interpreter_name,
|
2022-04-16 23:09:21 +08:00
|
|
|
GError **error)
|
|
|
|
{
|
|
|
|
GimpPlugInProcedure *proc;
|
2022-04-17 05:13:50 +08:00
|
|
|
GimpProcedure *procedure;
|
2022-04-16 23:09:21 +08:00
|
|
|
|
|
|
|
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 a 'batch interpreter'.\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;
|
|
|
|
}
|
|
|
|
|
2022-04-17 05:13:50 +08:00
|
|
|
procedure = GIMP_PROCEDURE (proc);
|
|
|
|
|
|
|
|
if (procedure->num_args < 2 ||
|
|
|
|
! GIMP_IS_PARAM_SPEC_RUN_MODE (procedure->args[0]) ||
|
|
|
|
! G_IS_PARAM_SPEC_STRING (procedure->args[1]))
|
|
|
|
{
|
|
|
|
g_set_error (error, GIMP_PDB_ERROR, GIMP_PDB_ERROR_FAILED,
|
|
|
|
"Plug-in \"%s\"\n(%s)\n"
|
|
|
|
"attempted to register procedure \"%s\" "
|
|
|
|
"as a batch interpreter which does not take the standard "
|
|
|
|
"batch interpreter procedure arguments: "
|
|
|
|
"(GimpRunMode, gchar *) -> ()",
|
|
|
|
gimp_object_get_name (plug_in),
|
|
|
|
gimp_file_get_utf8_name (plug_in->file),
|
|
|
|
proc_name);
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
gimp_plug_in_procedure_set_batch_interpreter (proc, interpreter_name);
|
|
|
|
gimp_plug_in_manager_add_batch_procedure (plug_in->manager, proc);
|
2022-04-16 23:09:21 +08:00
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2019-09-11 02:05:27 +08:00
|
|
|
|
2019-09-09 04:23:28 +08:00
|
|
|
/* private functions */
|
|
|
|
|
|
|
|
static GimpPlugInProcedure *
|
|
|
|
gimp_plug_in_proc_find (GimpPlugIn *plug_in,
|
|
|
|
const gchar *proc_name)
|
|
|
|
{
|
|
|
|
GimpPlugInProcedure *proc = NULL;
|
|
|
|
|
|
|
|
if (plug_in->plug_in_def)
|
|
|
|
proc = gimp_plug_in_procedure_find (plug_in->plug_in_def->procedures,
|
|
|
|
proc_name);
|
|
|
|
|
|
|
|
if (! proc)
|
|
|
|
proc = gimp_plug_in_procedure_find (plug_in->temp_procedures, proc_name);
|
|
|
|
|
|
|
|
return proc;
|
|
|
|
}
|