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

app: fix adding file procedures from pluginrc

gimp_plug_in_manager_add_to_db() used to call the PDB in order
to properly register file procedures from pluginrc. This broke
when I moved code to gimpplugin-file.c.

Instead, add gimp_plug_in_manager_add_load_procedure() and
gimp_plug_in_manager_add_save_procedure() and call them from both
gimpplugin-file.c and gimp_plug_in_manager_add_to_db(), which also has
the nice side effect that more GimpFileProcedureGroup logic gets moved
to its place in gimppluginmanager-file.c and less magic is needed in
gimpplugin-file.c.
parent 56fee734
Pipeline #113789 passed with stages
in 14 minutes and 19 seconds
......@@ -34,17 +34,16 @@
#include "gimpplugin-proc.h"
#include "gimpplugindef.h"
#include "gimppluginmanager.h"
#include "gimptemporaryprocedure.h"
#include "gimppluginmanager-file.h"
#include "gimppluginprocedure.h"
#include "gimp-intl.h"
/* local function prototypes */
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);
static GimpPlugInProcedure * gimp_plug_in_proc_find (GimpPlugIn *plug_in,
const gchar *proc_name);
/* public functions */
......@@ -308,9 +307,7 @@ gimp_plug_in_set_file_proc_load_handler (GimpPlugIn *plug_in,
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);
gimp_plug_in_manager_add_load_procedure (plug_in->manager, proc);
return TRUE;
}
......@@ -362,19 +359,7 @@ gimp_plug_in_set_file_proc_save_handler (GimpPlugIn *plug_in,
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);
}
gimp_plug_in_manager_add_save_procedure (plug_in->manager, proc);
return TRUE;
}
......@@ -578,40 +563,3 @@ 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;
}
}
......@@ -54,7 +54,10 @@ typedef enum
/* local function prototypes */
static GimpPlugInProcedure * file_procedure_find (GSList *procs,
static gboolean file_proc_in_group (GimpPlugInProcedure *file_proc,
GimpFileProcedureGroup group);
static GimpPlugInProcedure * file_proc_find (GSList *procs,
GFile *file,
GError **error);
static GimpPlugInProcedure * file_proc_find_by_prefix (GSList *procs,
......@@ -89,6 +92,37 @@ static FileMatchType file_check_magic_list (GSList *magics_l
/* public functions */
void
gimp_plug_in_manager_add_load_procedure (GimpPlugInManager *manager,
GimpPlugInProcedure *proc)
{
g_return_if_fail (GIMP_IS_PLUG_IN_MANAGER (manager));
g_return_if_fail (GIMP_IS_PLUG_IN_PROCEDURE (proc));
if (! g_slist_find (manager->load_procs, proc))
manager->load_procs = g_slist_prepend (manager->load_procs, proc);
}
void
gimp_plug_in_manager_add_save_procedure (GimpPlugInManager *manager,
GimpPlugInProcedure *proc)
{
g_return_if_fail (GIMP_IS_PLUG_IN_MANAGER (manager));
g_return_if_fail (GIMP_IS_PLUG_IN_PROCEDURE (proc));
if (file_proc_in_group (proc, GIMP_FILE_PROCEDURE_GROUP_SAVE))
{
if (! g_slist_find (manager->save_procs, proc))
manager->save_procs = g_slist_prepend (manager->save_procs, proc);
}
if (file_proc_in_group (proc, GIMP_FILE_PROCEDURE_GROUP_EXPORT))
{
if (! g_slist_find (manager->export_procs, proc))
manager->export_procs = g_slist_prepend (manager->export_procs, proc);
}
}
GSList *
gimp_plug_in_manager_get_file_procedures (GimpPlugInManager *manager,
GimpFileProcedureGroup group)
......@@ -127,13 +161,13 @@ gimp_plug_in_manager_file_procedure_find (GimpPlugInManager *manager,
switch (group)
{
case GIMP_FILE_PROCEDURE_GROUP_OPEN:
return file_procedure_find (manager->load_procs, file, error);
return file_proc_find (manager->load_procs, file, error);
case GIMP_FILE_PROCEDURE_GROUP_SAVE:
return file_procedure_find (manager->save_procs, file, error);
return file_proc_find (manager->save_procs, file, error);
case GIMP_FILE_PROCEDURE_GROUP_EXPORT:
return file_procedure_find (manager->export_procs, file, error);
return file_proc_find (manager->export_procs, file, error);
default:
g_return_val_if_reached (NULL);
......@@ -215,10 +249,47 @@ gimp_plug_in_manager_file_procedure_find_by_mime_type (GimpPlugInManager *m
/* private functions */
static gboolean
file_proc_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;
}
}
static GimpPlugInProcedure *
file_procedure_find (GSList *procs,
GFile *file,
GError **error)
file_proc_find (GSList *procs,
GFile *file,
GError **error)
{
GimpPlugInProcedure *file_proc;
GimpPlugInProcedure *size_matched_proc = NULL;
......
......@@ -21,6 +21,11 @@
#define __GIMP_PLUG_IN_MANAGER_FILE_H__
void gimp_plug_in_manager_add_load_procedure (GimpPlugInManager *manager,
GimpPlugInProcedure *proc);
void gimp_plug_in_manager_add_save_procedure (GimpPlugInManager *manager,
GimpPlugInProcedure *proc);
GSList * gimp_plug_in_manager_get_file_procedures (GimpPlugInManager *manager,
GimpFileProcedureGroup group);
......
......@@ -42,6 +42,7 @@
#include "gimppluginmanager.h"
#define __YES_I_NEED_GIMP_PLUG_IN_MANAGER_CALL__
#include "gimppluginmanager-call.h"
#include "gimppluginmanager-file.h"
#include "gimppluginmanager-help-domain.h"
#include "gimppluginmanager-locale-domain.h"
#include "gimppluginmanager-restore.h"
......@@ -834,40 +835,23 @@ gimp_plug_in_manager_add_to_db (GimpPlugInManager *manager,
if (proc->file_proc)
{
GimpValueArray *return_vals;
GError *error = NULL;
if (proc->image_types)
{
return_vals =
gimp_pdb_execute_procedure_by_name (manager->gimp->pdb,
context, NULL, &error,
"gimp-register-save-handler",
G_TYPE_STRING, gimp_object_get_name (proc),
G_TYPE_STRING, proc->extensions,
G_TYPE_STRING, proc->prefixes,
G_TYPE_NONE);
gimp_plug_in_procedure_set_file_proc (proc,
proc->extensions,
proc->prefixes,
NULL);
gimp_plug_in_manager_add_save_procedure (manager, proc);
}
else
{
return_vals =
gimp_pdb_execute_procedure_by_name (manager->gimp->pdb,
context, NULL, &error,
"gimp-register-load-handler",
G_TYPE_STRING, gimp_object_get_name (proc),
G_TYPE_STRING, proc->extensions,
G_TYPE_STRING, proc->prefixes,
G_TYPE_STRING, proc->magics,
G_TYPE_NONE);
}
gimp_plug_in_procedure_set_file_proc (proc,
proc->extensions,
proc->prefixes,
proc->magics);
gimp_value_array_unref (return_vals);
if (error)
{
gimp_message_literal (manager->gimp, NULL, GIMP_MESSAGE_ERROR,
error->message);
g_error_free (error);
gimp_plug_in_manager_add_load_procedure (manager, proc);
}
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment