Commit 97fe81b4 authored by Sven Neumann's avatar Sven Neumann Committed by Sven Neumann

added new PDB function gimp_register_file_handler_mime() that allows to

2004-05-14  Sven Neumann  <sven@gimp.org>

	* tools/pdbgen/pdb/fileops.pdb: added new PDB function
	gimp_register_file_handler_mime() that allows to associate a MIME
	type with a file procecdurre.

	* app/pdb/fileops_cmds.c
	* app/pdb/internal_procs.c
	* libgimp/gimpfileops_pdb.[ch]: regenerated.

	* app/plug-in/plug-in-proc.[ch]
	* app/plug-in/plug-in-rc.c
	* app/plug-in/plug-ins.[ch]: store a mimetype with file procedures.

	* app/actions/file-commands.c
	* app/core/gimpdocumentlist.[ch]
	* app/core/gimpimagefile.[ch]
	* app/file/file-open.[ch]
	* app/file/file-save.c: set the thumbnail's mimetype from the file
	procedure used to load/save the image.

	* app/xcf/xcf.c
	* plug-ins/bmp/bmp.c
	* plug-ins/common/csource.c
	* plug-ins/common/dicom.c
	* plug-ins/common/gif.c
	* plug-ins/common/gifload.c
	* plug-ins/common/jpeg.c
	* plug-ins/common/mng.c
	* plug-ins/common/png.c
	* plug-ins/common/postscript.c
	* plug-ins/common/psd.c
	* plug-ins/common/psd_save.c
	* plug-ins/common/sunras.c
	* plug-ins/common/svg.c
	* plug-ins/common/tga.c
	* plug-ins/common/tiff.c
	* plug-ins/common/wmf.c
	* plug-ins/common/xbm.c
	* plug-ins/common/xpm.c
	* plug-ins/common/xwd.c
	* plug-ins/faxg3/faxg3.c
	* plug-ins/winicon/main.c: register a mimetype, set a translatable
	action name (taken from shared-mime-info) and register to the <Load>
	and <Save> menus using gimp_plugin_menu_register().
parent 373db07d
2004-05-14 Sven Neumann <sven@gimp.org>
* tools/pdbgen/pdb/fileops.pdb: added new PDB function
gimp_register_file_handler_mime() that allows to associate a MIME
type with a file procecdurre.
* app/pdb/fileops_cmds.c
* app/pdb/internal_procs.c
* libgimp/gimpfileops_pdb.[ch]: regenerated.
* app/plug-in/plug-in-proc.[ch]
* app/plug-in/plug-in-rc.c
* app/plug-in/plug-ins.[ch]: store a mimetype with file procedures.
* app/actions/file-commands.c
* app/core/gimpdocumentlist.[ch]
* app/core/gimpimagefile.[ch]
* app/file/file-open.[ch]
* app/file/file-save.c: set the thumbnail's mimetype from the file
procedure used to load/save the image.
* app/xcf/xcf.c
* plug-ins/bmp/bmp.c
* plug-ins/common/csource.c
* plug-ins/common/dicom.c
* plug-ins/common/gif.c
* plug-ins/common/gifload.c
* plug-ins/common/jpeg.c
* plug-ins/common/mng.c
* plug-ins/common/png.c
* plug-ins/common/postscript.c
* plug-ins/common/psd.c
* plug-ins/common/psd_save.c
* plug-ins/common/sunras.c
* plug-ins/common/svg.c
* plug-ins/common/tga.c
* plug-ins/common/tiff.c
* plug-ins/common/wmf.c
* plug-ins/common/xbm.c
* plug-ins/common/xpm.c
* plug-ins/common/xwd.c
* plug-ins/faxg3/faxg3.c
* plug-ins/winicon/main.c: register a mimetype, set a translatable
action name (taken from shared-mime-info) and register to the <Load>
and <Save> menus using gimp_plugin_menu_register().
2004-05-13 Sven Neumann <sven@gimp.org>
* tools/pdbgen/lib.pl
......
......@@ -376,7 +376,7 @@ file_revert_confirm_callback (GtkWidget *widget,
new_gimage = file_open_image (gimp, gimp_get_user_context (gimp),
uri, uri, NULL,
GIMP_RUN_INTERACTIVE,
&status, &error);
&status, NULL, &error);
if (new_gimage)
{
......
......@@ -194,7 +194,8 @@ gimp_document_list_new (Gimp *gimp)
GimpImagefile *
gimp_document_list_add_uri (GimpDocumentList *document_list,
const gchar *uri)
const gchar *uri,
const gchar *mime_type)
{
GimpImagefile *imagefile;
GimpContainer *container;
......@@ -218,5 +219,9 @@ gimp_document_list_add_uri (GimpDocumentList *document_list,
g_object_unref (imagefile);
}
g_object_set (imagefile->thumbnail,
"image-mimetype", mime_type,
NULL);
return imagefile;
}
......@@ -44,11 +44,12 @@ struct _GimpDocumentListClass
};
GType gimp_document_list_get_type (void) G_GNUC_CONST;
GType gimp_document_list_get_type (void) G_GNUC_CONST;
GimpContainer * gimp_document_list_new (Gimp *gimp);
GimpImagefile * gimp_document_list_add_uri (GimpDocumentList *document_list,
const gchar *uri);
const gchar *uri,
const gchar *mime_type);
#endif /* __GIMP_DOCUMENT_LIST_H__ */
......@@ -256,7 +256,8 @@ gimp_imagefile_create_thumbnail (GimpImagefile *imagefile,
GimpImage *gimage;
GimpPDBStatusType dummy;
gboolean success;
GError *error = NULL;
const gchar *mime_type = NULL;
GError *error = NULL;
gimage = file_open_image (imagefile->gimp,
context,
......@@ -265,10 +266,16 @@ gimp_imagefile_create_thumbnail (GimpImagefile *imagefile,
NULL,
GIMP_RUN_NONINTERACTIVE,
&dummy,
&mime_type,
NULL);
if (gimage)
{
if (mime_type)
g_object_set (thumbnail,
"image-mimetype", mime_type,
NULL);
success = gimp_imagefile_save_thumb (imagefile,
gimage, size, &error);
......
......@@ -46,13 +46,14 @@ struct _GimpImagefile
Gimp *gimp;
GimpThumbnail *thumbnail;
gchar *mime_type;
gchar *description;
gboolean static_desc;
};
struct _GimpImagefileClass
{
GimpViewableClass parent_class;
GimpViewableClass parent_class;
void (* info_changed) (GimpImagefile *imagefile);
};
......
......@@ -68,6 +68,7 @@ file_open_image (Gimp *gimp,
PlugInProcDef *file_proc,
GimpRunMode run_mode,
GimpPDBStatusType *status,
const gchar **mime_type,
GError **error)
{
const ProcRecord *proc;
......@@ -80,6 +81,7 @@ file_open_image (Gimp *gimp,
g_return_val_if_fail (GIMP_IS_GIMP (gimp), NULL);
g_return_val_if_fail (GIMP_IS_CONTEXT (context), NULL);
g_return_val_if_fail (status != NULL, NULL);
g_return_val_if_fail (mime_type == NULL || *mime_type == NULL, NULL);
g_return_val_if_fail (error == NULL || *error == NULL, NULL);
*status = GIMP_PDB_EXECUTION_ERROR;
......@@ -161,6 +163,9 @@ file_open_image (Gimp *gimp,
gimp_image_invalidate_channel_previews (gimage);
gimp_viewable_invalidate_preview (GIMP_VIEWABLE (gimage));
if (mime_type)
*mime_type = file_proc->mime_type;
return gimage;
}
else
......@@ -200,7 +205,8 @@ file_open_with_proc_and_display (Gimp *gimp,
GimpPDBStatusType *status,
GError **error)
{
GimpImage *gimage;
GimpImage *gimage;
const gchar *mime_type = NULL;
g_return_val_if_fail (GIMP_IS_GIMP (gimp), NULL);
g_return_val_if_fail (GIMP_IS_CONTEXT (context), NULL);
......@@ -212,6 +218,7 @@ file_open_with_proc_and_display (Gimp *gimp,
file_proc,
GIMP_RUN_INTERACTIVE,
status,
&mime_type,
error);
if (gimage)
......@@ -222,7 +229,7 @@ file_open_with_proc_and_display (Gimp *gimp,
gimp_create_display (gimage->gimp, gimage, 1.0);
documents = GIMP_DOCUMENT_LIST (gimp->documents);
imagefile = gimp_document_list_add_uri (documents, uri);
imagefile = gimp_document_list_add_uri (documents, uri, mime_type);
/* can only create a thumbnail if the passed uri and the
* resulting image's uri match.
......
......@@ -27,6 +27,7 @@ GimpImage * file_open_image (Gimp *gimp,
PlugInProcDef *file_proc,
GimpRunMode run_mode,
GimpPDBStatusType *status,
const gchar **mime_type,
GError **error);
GimpImage * file_open_with_display (Gimp *gimp,
......
......@@ -184,7 +184,8 @@ file_save_as (GimpImage *gimage,
}
documents = GIMP_DOCUMENT_LIST (gimage->gimp->documents);
imagefile = gimp_document_list_add_uri (documents, uri);
imagefile = gimp_document_list_add_uri (documents,
uri, file_proc->mime_type);
if (set_uri_and_proc)
{
......
......@@ -35,16 +35,19 @@ void
file_menu_setup (GimpUIManager *manager,
const gchar *ui_path)
{
gint n_entries;
guint merge_id;
gint i;
GtkUIManager *ui_manager;
gint n_entries;
guint merge_id;
gint i;
g_return_if_fail (GIMP_IS_UI_MANAGER (manager));
g_return_if_fail (ui_path != NULL);
ui_manager = GTK_UI_MANAGER (manager);
n_entries = GIMP_GUI_CONFIG (manager->gimp->config)->last_opened_size;
merge_id = gtk_ui_manager_new_merge_id (GTK_UI_MANAGER (manager));
merge_id = gtk_ui_manager_new_merge_id (ui_manager);
for (i = 0; i < n_entries; i++)
{
......@@ -54,7 +57,7 @@ file_menu_setup (GimpUIManager *manager,
action_name = g_strdup_printf ("file-open-recent-%02d", i + 1);
action_path = g_strdup_printf ("%s/File/Open Recent/Files", ui_path);
gtk_ui_manager_add_ui (GTK_UI_MANAGER (manager), merge_id,
gtk_ui_manager_add_ui (ui_manager, merge_id,
action_path, action_name, action_name,
GTK_UI_MANAGER_MENUITEM,
FALSE);
......
......@@ -64,6 +64,7 @@ static ProcRecord temp_name_proc;
static ProcRecord register_magic_load_handler_proc;
static ProcRecord register_load_handler_proc;
static ProcRecord register_save_handler_proc;
static ProcRecord register_file_handler_mime_proc;
void
register_fileops_procs (Gimp *gimp)
......@@ -76,6 +77,7 @@ register_fileops_procs (Gimp *gimp)
procedural_db_register (gimp, &register_magic_load_handler_proc);
procedural_db_register (gimp, &register_load_handler_proc);
procedural_db_register (gimp, &register_save_handler_proc);
procedural_db_register (gimp, &register_file_handler_mime_proc);
}
static Argument *
......@@ -582,7 +584,8 @@ register_magic_load_handler_invoker (Gimp *gimp,
goto done;
}
file_proc = plug_ins_file_handler (gimp, name, extensions, prefixes, magics);
file_proc = plug_ins_file_register_magic (gimp, name,
extensions, prefixes, magics);
if (! file_proc)
{
......@@ -732,7 +735,8 @@ register_save_handler_invoker (Gimp *gimp,
goto done;
}
file_proc = plug_ins_file_handler (gimp, name, extensions, prefixes, NULL);
file_proc = plug_ins_file_register_magic (gimp, name,
extensions, prefixes, NULL);
if (! file_proc)
{
......@@ -786,3 +790,58 @@ static ProcRecord register_save_handler_proc =
NULL,
{ { register_save_handler_invoker } }
};
static Argument *
register_file_handler_mime_invoker (Gimp *gimp,
GimpContext *context,
Argument *args)
{
gboolean success = TRUE;
gchar *name;
gchar *mime_type;
name = (gchar *) args[0].value.pdb_pointer;
if (name == NULL || !g_utf8_validate (name, -1, NULL))
success = FALSE;
mime_type = (gchar *) args[1].value.pdb_pointer;
if (mime_type == NULL || !g_utf8_validate (mime_type, -1, NULL))
success = FALSE;
if (success)
{
success = (plug_ins_file_register_mime (gimp, name, mime_type) != NULL);
}
return procedural_db_return_args (&register_file_handler_mime_proc, success);
}
static ProcArg register_file_handler_mime_inargs[] =
{
{
GIMP_PDB_STRING,
"procedure_name",
"The name of the procedure to associate a MIME type with."
},
{
GIMP_PDB_STRING,
"mime_type",
"A single MIME type, like for example \"image/jpeg\"."
}
};
static ProcRecord register_file_handler_mime_proc =
{
"gimp_register_file_handler_mime",
"Associates a MIME type with a file handler procedure.",
"Registers a MIME type for a file handler procedure. This allows GIMP to determine the MIME type of the file opened, or saved using this procedure.",
"Sven Neumann",
"Sven Neumann",
"2004",
GIMP_INTERNAL,
2,
register_file_handler_mime_inargs,
0,
NULL,
{ { register_file_handler_mime_invoker } }
};
......@@ -36,11 +36,7 @@
PlugInProcDef *
plug_in_proc_def_new (void)
{
PlugInProcDef *proc_def;
proc_def = g_new0 (PlugInProcDef, 1);
return proc_def;
return g_new0 (PlugInProcDef, 1);
}
void
......@@ -81,6 +77,7 @@ plug_in_proc_def_free (PlugInProcDef *proc_def)
g_free (proc_def->extensions);
g_free (proc_def->prefixes);
g_free (proc_def->magics);
g_free (proc_def->mime_type);
g_free (proc_def->image_types);
g_free (proc_def);
......
......@@ -32,6 +32,7 @@ struct _PlugInProcDef
gchar *extensions;
gchar *prefixes;
gchar *magics;
gchar *mime_type;
gchar *image_types;
PlugInImageType image_types_val;
ProcRecord db_info;
......
......@@ -68,7 +68,7 @@ void register_transform_tools_procs (Gimp *gimp);
void register_undo_procs (Gimp *gimp);
void register_unit_procs (Gimp *gimp);
/* 348 procedures registered total */
/* 349 procedures registered total */
void
internal_procs_init (Gimp *gimp,
......@@ -95,76 +95,76 @@ internal_procs_init (Gimp *gimp,
(* status_callback) (NULL, _("Display procedures"), 0.112);
register_display_procs (gimp);
(* status_callback) (NULL, _("Drawable procedures"), 0.124);
(* status_callback) (NULL, _("Drawable procedures"), 0.123);
register_drawable_procs (gimp);
(* status_callback) (NULL, _("Edit procedures"), 0.216);
(* status_callback) (NULL, _("Edit procedures"), 0.215);
register_edit_procs (gimp);
(* status_callback) (NULL, _("File Operations"), 0.239);
(* status_callback) (NULL, _("File Operations"), 0.238);
register_fileops_procs (gimp);
(* status_callback) (NULL, _("Floating selections"), 0.261);
(* status_callback) (NULL, _("Floating selections"), 0.264);
register_floating_sel_procs (gimp);
(* status_callback) (NULL, _("Font UI"), 0.279);
(* status_callback) (NULL, _("Font UI"), 0.281);
register_font_select_procs (gimp);
(* status_callback) (NULL, _("Fonts"), 0.287);
(* status_callback) (NULL, _("Fonts"), 0.289);
register_fonts_procs (gimp);
(* status_callback) (NULL, _("Gimprc procedures"), 0.293);
(* status_callback) (NULL, _("Gimprc procedures"), 0.295);
register_gimprc_procs (gimp);
(* status_callback) (NULL, _("Gradient UI"), 0.31);
(* status_callback) (NULL, _("Gradient UI"), 0.312);
register_gradient_select_procs (gimp);
(* status_callback) (NULL, _("Gradients"), 0.319);
(* status_callback) (NULL, _("Gradients"), 0.321);
register_gradients_procs (gimp);
(* status_callback) (NULL, _("Guide procedures"), 0.339);
(* status_callback) (NULL, _("Guide procedures"), 0.341);
register_guides_procs (gimp);
(* status_callback) (NULL, _("Help procedures"), 0.356);
(* status_callback) (NULL, _("Help procedures"), 0.358);
register_help_procs (gimp);
(* status_callback) (NULL, _("Image"), 0.359);
(* status_callback) (NULL, _("Image"), 0.361);
register_image_procs (gimp);
(* status_callback) (NULL, _("Layer"), 0.534);
(* status_callback) (NULL, _("Layer"), 0.536);
register_layer_procs (gimp);
(* status_callback) (NULL, _("Message procedures"), 0.609);
(* status_callback) (NULL, _("Message procedures"), 0.61);
register_message_procs (gimp);
(* status_callback) (NULL, _("Miscellaneous"), 0.618);
(* status_callback) (NULL, _("Miscellaneous"), 0.619);
register_misc_procs (gimp);
(* status_callback) (NULL, _("Paint Tool procedures"), 0.624);
(* status_callback) (NULL, _("Paint Tool procedures"), 0.625);
register_paint_tools_procs (gimp);
(* status_callback) (NULL, _("Palette"), 0.667);
(* status_callback) (NULL, _("Palette"), 0.668);
register_palette_procs (gimp);
(* status_callback) (NULL, _("Palette UI"), 0.684);
(* status_callback) (NULL, _("Palette UI"), 0.685);
register_palette_select_procs (gimp);
(* status_callback) (NULL, _("Palettes"), 0.693);
register_palettes_procs (gimp);
(* status_callback) (NULL, _("Parasite procedures"), 0.707);
(* status_callback) (NULL, _("Parasite procedures"), 0.708);
register_parasite_procs (gimp);
(* status_callback) (NULL, _("Paths"), 0.741);
(* status_callback) (NULL, _("Paths"), 0.742);
register_paths_procs (gimp);
(* status_callback) (NULL, _("Pattern UI"), 0.784);
(* status_callback) (NULL, _("Pattern UI"), 0.785);
register_pattern_select_procs (gimp);
(* status_callback) (NULL, _("Patterns"), 0.793);
(* status_callback) (NULL, _("Patterns"), 0.794);
register_patterns_procs (gimp);
(* status_callback) (NULL, _("Plug-in"), 0.807);
(* status_callback) (NULL, _("Plug-in"), 0.808);
register_plug_in_procs (gimp);
(* status_callback) (NULL, _("Procedural database"), 0.825);
......@@ -173,7 +173,7 @@ internal_procs_init (Gimp *gimp,
(* status_callback) (NULL, _("Image mask"), 0.851);
register_selection_procs (gimp);
(* status_callback) (NULL, _("Selection Tool procedures"), 0.902);
(* status_callback) (NULL, _("Selection Tool procedures"), 0.903);
register_selection_tools_procs (gimp);
(* status_callback) (NULL, _("Text procedures"), 0.917);
......@@ -182,7 +182,7 @@ internal_procs_init (Gimp *gimp,
(* status_callback) (NULL, _("Transform Tool procedures"), 0.928);
register_transform_tools_procs (gimp);
(* status_callback) (NULL, _("Undo"), 0.945);
(* status_callback) (NULL, _("Undo"), 0.946);
register_undo_procs (gimp);
(* status_callback) (NULL, _("Units"), 0.966);
......
......@@ -49,7 +49,7 @@
#include "gimp-intl.h"
#define STD_PLUGINS_DOMAIN GETTEXT_PACKAGE "-std-plug-ins"
#define STD_PLUGINS_DOMAIN GETTEXT_PACKAGE "-std-plug-ins"
typedef struct _PlugInLocaleDomainDef PlugInLocaleDomainDef;
......@@ -88,7 +88,7 @@ plug_ins_init (Gimp *gimp,
gchar *filename;
gchar *basename;
gchar *path;
GSList *tmp;
GSList *list;
GList *extensions = NULL;
gdouble n_plugins;
gdouble n_extensions;
......@@ -149,11 +149,9 @@ plug_ins_init (Gimp *gimp,
(* status_callback) (_("Querying new Plug-ins"), "", 0);
n_plugins = g_slist_length (gimp->plug_in_defs);
for (tmp = gimp->plug_in_defs, nth = 0;
tmp;
tmp = g_slist_next (tmp), nth++)
for (list = gimp->plug_in_defs, nth = 0; list; list = list->next, nth++)
{
PlugInDef *plug_in_def = tmp->data;
PlugInDef *plug_in_def = list->data;
basename = g_path_get_basename (plug_in_def->prog);
(* status_callback) (NULL, gimp_filename_to_utf8 (basename),
......@@ -177,11 +175,9 @@ plug_ins_init (Gimp *gimp,
/* initialize the plug-ins */
(* status_callback) (_("Initializing Plug-ins"), "", 0);
for (tmp = gimp->plug_in_defs, nth = 0;
tmp;
tmp = g_slist_next (tmp), nth++)
for (list = gimp->plug_in_defs, nth = 0; list; list = list->next, nth++)
{
PlugInDef *plug_in_def = tmp->data;
PlugInDef *plug_in_def = list->data;
basename = g_path_get_basename (plug_in_def->prog);
(* status_callback) (NULL, gimp_filename_to_utf8 (basename),
......@@ -201,14 +197,14 @@ plug_ins_init (Gimp *gimp,
(* status_callback) (NULL, NULL, 1.0);
/* insert the proc defs */
for (tmp = gimp->plug_in_defs; tmp; tmp = g_slist_next (tmp))
for (list = gimp->plug_in_defs; list; list = list->next)
{
PlugInDef *plug_in_def = tmp->data;
GSList *tmp2;
PlugInDef *plug_in_def = list->data;
GSList *list2;
for (tmp2 = plug_in_def->proc_defs; tmp2; tmp2 = g_slist_next (tmp2))
for (list2 = plug_in_def->proc_defs; list2; list2 = list2->next)
{
PlugInProcDef *proc_def = tmp2->data;
PlugInProcDef *proc_def = list2->data;
PlugInProcDef *overridden_proc_def;
proc_def->mtime = plug_in_def->mtime;
......@@ -217,7 +213,7 @@ plug_ins_init (Gimp *gimp,
if (overridden_proc_def)
{
GSList *tmp3;
GSList *list3;
g_printerr ("removing duplicate PDB procedure \"%s\" "
"registered by '%s'\n",
......@@ -227,9 +223,9 @@ plug_ins_init (Gimp *gimp,
/* search the plugin list to see if any plugins had references to
* the overridden_proc_def.
*/
for (tmp3 = gimp->plug_in_defs; tmp3; tmp3 = g_slist_next (tmp3))
for (list3 = gimp->plug_in_defs; list3; list3 = list3->next)
{
PlugInDef *plug_in_def2 = tmp3->data;
PlugInDef *plug_in_def2 = list3->data;
plug_in_def2->proc_defs =
g_slist_remove (plug_in_def2->proc_defs,
......@@ -277,9 +273,9 @@ plug_ins_init (Gimp *gimp,
gimp);
/* create help_path and locale_domain lists */
for (tmp = gimp->plug_in_defs; tmp; tmp = g_slist_next (tmp))
for (list = gimp->plug_in_defs; list; list = list->next)
{
PlugInDef *plug_in_def = tmp->data;
PlugInDef *plug_in_def = list->data;
if (plug_in_def->locale_domain_name)
{
......@@ -327,11 +323,9 @@ plug_ins_init (Gimp *gimp,
gimp_menus_init (gimp, gimp->plug_in_defs, STD_PLUGINS_DOMAIN);
/* build list of automatically started extensions */
for (tmp = gimp->plug_in_proc_defs, nth = 0;
tmp;
tmp = g_slist_next (tmp), nth++)
for (list = gimp->plug_in_proc_defs, nth = 0; list; list = list->next, nth++)
{
PlugInProcDef *proc_def = tmp->data;