app: move the plug-in procedure setters to gimpplugin-proc.[ch]

because there are going to be much more more.
This commit is contained in:
Michael Natterer 2019-09-08 16:35:47 +02:00
parent 303ccbedad
commit d75a25c565
7 changed files with 227 additions and 163 deletions

View File

@ -34,7 +34,7 @@
#include "core/gimpparamspecs.h"
#include "gimp-pdb-compat.h"
#include "gimppdb-query.h"
#include "plug-in/gimpplugin.h"
#include "plug-in/gimpplugin-proc.h"
#include "plug-in/gimppluginmanager-data.h"
#include "plug-in/gimppluginmanager.h"
#include "plug-in/gimppluginprocedure.h"

View File

@ -33,6 +33,8 @@ libappplug_in_a_SOURCES = \
gimpplugin-context.h \
gimpplugin-message.c \
gimpplugin-message.h \
gimpplugin-proc.c \
gimpplugin-proc.h \
gimpplugin-progress.c \
gimpplugin-progress.h \
gimpplugindef.c \

View File

@ -0,0 +1,162 @@
/* 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"
#include "core/gimp.h"
#include "gimpplugin.h"
#include "gimpplugin-proc.h"
#include "gimpplugindef.h"
#include "gimppluginmanager.h"
#include "gimptemporaryprocedure.h"
#include "gimp-intl.h"
gboolean
gimp_plug_in_add_proc_menu_path (GimpPlugIn *plug_in,
const gchar *proc_name,
const gchar *menu_path)
{
GimpPlugInProcedure *proc = NULL;
GError *error = NULL;
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);
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);
if (! proc)
{
gimp_message (plug_in->manager->gimp, NULL, GIMP_MESSAGE_ERROR,
"Plug-in \"%s\"\n(%s)\n"
"attempted to register the menu item \"%s\" "
"for the 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);
return FALSE;
}
switch (GIMP_PROCEDURE (proc)->proc_type)
{
case GIMP_PDB_PROC_TYPE_INTERNAL:
return FALSE;
case GIMP_PDB_PROC_TYPE_PLUGIN:
case GIMP_PDB_PROC_TYPE_EXTENSION:
if (plug_in->call_mode != GIMP_PLUG_IN_CALL_QUERY &&
plug_in->call_mode != GIMP_PLUG_IN_CALL_INIT)
return FALSE;
case GIMP_PDB_PROC_TYPE_TEMPORARY:
break;
}
if (! gimp_plug_in_procedure_add_menu_path (proc, menu_path, &error))
{
gimp_message_literal (plug_in->manager->gimp, NULL, GIMP_MESSAGE_ERROR,
error->message);
g_clear_error (&error);
return FALSE;
}
return TRUE;
}
gboolean
gimp_plug_in_set_proc_icon (GimpPlugIn *plug_in,
const gchar *proc_name,
GimpIconType type,
const guint8 *data,
gint data_length)
{
GimpPlugInProcedure *proc = NULL;
GError *error = NULL;
g_return_val_if_fail (GIMP_IS_PLUG_IN (plug_in), FALSE);
g_return_val_if_fail (proc_name != NULL, FALSE);
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);
if (! proc)
{
gimp_message (plug_in->manager->gimp, NULL, GIMP_MESSAGE_ERROR,
"Plug-in \"%s\"\n(%s)\n"
"attempted to set the icon "
"for the 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;
}
switch (GIMP_PROCEDURE (proc)->proc_type)
{
case GIMP_PDB_PROC_TYPE_INTERNAL:
return FALSE;
case GIMP_PDB_PROC_TYPE_PLUGIN:
case GIMP_PDB_PROC_TYPE_EXTENSION:
if (plug_in->call_mode != GIMP_PLUG_IN_CALL_QUERY &&
plug_in->call_mode != GIMP_PLUG_IN_CALL_INIT)
return FALSE;
case GIMP_PDB_PROC_TYPE_TEMPORARY:
break;
}
if (! gimp_plug_in_procedure_set_icon (proc, type, data, data_length,
&error))
{
gimp_message_literal (plug_in->manager->gimp, NULL, GIMP_MESSAGE_ERROR,
error->message);
g_clear_error (&error);
return FALSE;
}
return TRUE;
}

View File

@ -0,0 +1,34 @@
/* GIMP - The GNU Image Manipulation Program
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
*
* gimpplugin-proc.h
*
* 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/>.
*/
#ifndef __GIMP_PLUG_IN_PROC_H__
#define __GIMP_PLUG_IN_PROC_H__
gboolean gimp_plug_in_add_proc_menu_path (GimpPlugIn *plug_in,
const gchar *proc_name,
const gchar *menu_path);
gboolean gimp_plug_in_set_proc_icon (GimpPlugIn *plug_in,
const gchar *proc_name,
GimpIconType type,
const guint8 *data,
gint data_length);
#endif /* __GIMP_PLUG_IN_PROC_H__ */

View File

@ -874,131 +874,6 @@ gimp_plug_in_get_undo_desc (GimpPlugIn *plug_in)
return undo_desc ? undo_desc : gimp_object_get_name (plug_in);
}
/* called from the PDB (gimp_pdb_add_proc_menu_path) */
gboolean
gimp_plug_in_add_proc_menu_path (GimpPlugIn *plug_in,
const gchar *proc_name,
const gchar *menu_path)
{
GimpPlugInProcedure *proc = NULL;
GError *error = NULL;
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);
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);
if (! proc)
{
gimp_message (plug_in->manager->gimp, NULL, GIMP_MESSAGE_ERROR,
"Plug-in \"%s\"\n(%s)\n"
"attempted to register the menu item \"%s\" "
"for the 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);
return FALSE;
}
switch (GIMP_PROCEDURE (proc)->proc_type)
{
case GIMP_PDB_PROC_TYPE_INTERNAL:
return FALSE;
case GIMP_PDB_PROC_TYPE_PLUGIN:
case GIMP_PDB_PROC_TYPE_EXTENSION:
if (plug_in->call_mode != GIMP_PLUG_IN_CALL_QUERY &&
plug_in->call_mode != GIMP_PLUG_IN_CALL_INIT)
return FALSE;
case GIMP_PDB_PROC_TYPE_TEMPORARY:
break;
}
if (! gimp_plug_in_procedure_add_menu_path (proc, menu_path, &error))
{
gimp_message_literal (plug_in->manager->gimp, NULL, GIMP_MESSAGE_ERROR,
error->message);
g_clear_error (&error);
return FALSE;
}
return TRUE;
}
gboolean
gimp_plug_in_set_proc_icon (GimpPlugIn *plug_in,
const gchar *proc_name,
GimpIconType type,
const guint8 *data,
gint data_length)
{
GimpPlugInProcedure *proc = NULL;
GError *error = NULL;
g_return_val_if_fail (GIMP_IS_PLUG_IN (plug_in), FALSE);
g_return_val_if_fail (proc_name != NULL, FALSE);
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);
if (! proc)
{
gimp_message (plug_in->manager->gimp, NULL, GIMP_MESSAGE_ERROR,
"Plug-in \"%s\"\n(%s)\n"
"attempted to set the icon "
"for the 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;
}
switch (GIMP_PROCEDURE (proc)->proc_type)
{
case GIMP_PDB_PROC_TYPE_INTERNAL:
return FALSE;
case GIMP_PDB_PROC_TYPE_PLUGIN:
case GIMP_PDB_PROC_TYPE_EXTENSION:
if (plug_in->call_mode != GIMP_PLUG_IN_CALL_QUERY &&
plug_in->call_mode != GIMP_PLUG_IN_CALL_INIT)
return FALSE;
case GIMP_PDB_PROC_TYPE_TEMPORARY:
break;
}
if (! gimp_plug_in_procedure_set_icon (proc, type, data, data_length,
&error))
{
gimp_message_literal (plug_in->manager->gimp, NULL, GIMP_MESSAGE_ERROR,
error->message);
g_clear_error (&error);
return FALSE;
}
return TRUE;
}
void
gimp_plug_in_add_temp_proc (GimpPlugIn *plug_in,
GimpTemporaryProcedure *proc)

View File

@ -76,53 +76,44 @@ struct _GimpPlugInClass
};
GType gimp_plug_in_get_type (void) G_GNUC_CONST;
GType gimp_plug_in_get_type (void) G_GNUC_CONST;
GimpPlugIn * gimp_plug_in_new (GimpPlugInManager *manager,
GimpContext *context,
GimpProgress *progress,
GimpPlugInProcedure *procedure,
GFile *file);
GimpPlugIn * gimp_plug_in_new (GimpPlugInManager *manager,
GimpContext *context,
GimpProgress *progress,
GimpPlugInProcedure *procedure,
GFile *file);
gboolean gimp_plug_in_open (GimpPlugIn *plug_in,
GimpPlugInCallMode call_mode,
gboolean synchronous);
void gimp_plug_in_close (GimpPlugIn *plug_in,
gboolean kill_it);
gboolean gimp_plug_in_open (GimpPlugIn *plug_in,
GimpPlugInCallMode call_mode,
gboolean synchronous);
void gimp_plug_in_close (GimpPlugIn *plug_in,
gboolean kill_it);
GimpPlugInProcFrame *
gimp_plug_in_get_proc_frame (GimpPlugIn *plug_in);
gimp_plug_in_get_proc_frame (GimpPlugIn *plug_in);
GimpPlugInProcFrame *
gimp_plug_in_proc_frame_push (GimpPlugIn *plug_in,
GimpContext *context,
GimpProgress *progress,
GimpTemporaryProcedure *procedure);
void gimp_plug_in_proc_frame_pop (GimpPlugIn *plug_in);
gimp_plug_in_proc_frame_push (GimpPlugIn *plug_in,
GimpContext *context,
GimpProgress *progress,
GimpTemporaryProcedure *procedure);
void gimp_plug_in_proc_frame_pop (GimpPlugIn *plug_in);
void gimp_plug_in_main_loop (GimpPlugIn *plug_in);
void gimp_plug_in_main_loop_quit (GimpPlugIn *plug_in);
void gimp_plug_in_main_loop (GimpPlugIn *plug_in);
void gimp_plug_in_main_loop_quit (GimpPlugIn *plug_in);
const gchar * gimp_plug_in_get_undo_desc (GimpPlugIn *plug_in);
const gchar * gimp_plug_in_get_undo_desc (GimpPlugIn *plug_in);
gboolean gimp_plug_in_add_proc_menu_path (GimpPlugIn *plug_in,
const gchar *proc_name,
const gchar *menu_path);
gboolean gimp_plug_in_set_proc_icon (GimpPlugIn *plug_in,
const gchar *proc_name,
GimpIconType type,
const guint8 *data,
gint data_length);
void gimp_plug_in_add_temp_proc (GimpPlugIn *plug_in,
GimpTemporaryProcedure *procedure);
void gimp_plug_in_remove_temp_proc (GimpPlugIn *plug_in,
GimpTemporaryProcedure *procedure);
void gimp_plug_in_add_temp_proc (GimpPlugIn *plug_in,
GimpTemporaryProcedure *procedure);
void gimp_plug_in_remove_temp_proc (GimpPlugIn *plug_in,
GimpTemporaryProcedure *procedure);
void gimp_plug_in_set_error_handler (GimpPlugIn *plug_in,
GimpPDBErrorHandler handler);
void gimp_plug_in_set_error_handler (GimpPlugIn *plug_in,
GimpPDBErrorHandler handler);
GimpPDBErrorHandler
gimp_plug_in_get_error_handler (GimpPlugIn *plug_in);
gimp_plug_in_get_error_handler (GimpPlugIn *plug_in);
#endif /* __GIMP_PLUG_IN_H__ */

View File

@ -836,7 +836,7 @@ CODE
@headers = qw("libgimpbase/gimpbase.h"
"core/gimp.h"
"core/gimpparamspecs-desc.h"
"plug-in/gimpplugin.h"
"plug-in/gimpplugin-proc.h"
"plug-in/gimppluginmanager.h"
"plug-in/gimppluginmanager-data.h"
"plug-in/gimppluginprocedure.h"