Commit 74710fcc authored by Michael Natterer's avatar Michael Natterer 😴 Committed by Michael Natterer
Browse files

changed GimpDatafileLoaderFunc to take a separate "gpointer user_data"

2003-07-02  Michael Natterer  <mitch@gimp.org>

	* libgimpbase/gimpbasetypes.h: changed GimpDatafileLoaderFunc to
	take a separate "gpointer user_data" parameter (passing user_data
	in a struct was a quite nonstandard API design). Made the
	GimpDatafileData pointer const.

	* libgimpbase/gimpdatafiles.[ch]: removed user_data from the
	GimpDatafileData struct and added "const gchar *basename" so we
	don't need to g_path_get_basename() in many callbacks.

	* libgimp/gimpmiscui.[ch]: changed gimp_plug_in_parse_path() to
	gimp_plug_in_get_path() and return the unparsed path.

	* app/core/gimpdatafactory.c
	* app/core/gimpenvirontable.c
	* app/gui/gui.c
	* app/plug-in/plug-ins.c
	* libgimpmodule/gimpmoduledb.c
	* plug-ins/script-fu/script-fu-scripts.c: changed accordingly.

	* plug-ins/FractalExplorer/Dialogs.c
	* plug-ins/FractalExplorer/FractalExplorer.[ch]
	* plug-ins/FractalExplorer/Globals.c
	* plug-ins/gfig/gfig.c
	* plug-ins/gflare/gflare.c: use gimp_datafiles_read_directories()
	instead of fiddling with g_dir_open() manually. Random cleanups.
parent 5143aa7c
2003-07-02 Michael Natterer <mitch@gimp.org>
* libgimpbase/gimpbasetypes.h: changed GimpDatafileLoaderFunc to
take a separate "gpointer user_data" parameter (passing user_data
in a struct was a quite nonstandard API design). Made the
GimpDatafileData pointer const.
* libgimpbase/gimpdatafiles.[ch]: removed user_data from the
GimpDatafileData struct and added "const gchar *basename" so we
don't need to g_path_get_basename() in many callbacks.
* libgimp/gimpmiscui.[ch]: changed gimp_plug_in_parse_path() to
gimp_plug_in_get_path() and return the unparsed path.
* app/core/gimpdatafactory.c
* app/core/gimpenvirontable.c
* app/gui/gui.c
* app/plug-in/plug-ins.c
* libgimpmodule/gimpmoduledb.c
* plug-ins/script-fu/script-fu-scripts.c: changed accordingly.
* plug-ins/FractalExplorer/Dialogs.c
* plug-ins/FractalExplorer/FractalExplorer.[ch]
* plug-ins/FractalExplorer/Globals.c
* plug-ins/gfig/gfig.c
* plug-ins/gflare/gflare.c: use gimp_datafiles_read_directories()
instead of fiddling with g_dir_open() manually. Random cleanups.
2003-07-02 Sven Neumann <sven@gimp.org>
 
* plug-ins: last bunch of plug-ins adapted to libgimp changes.
......@@ -49,7 +49,8 @@ static void gimp_data_factory_finalize (GObject *object);
static gsize gimp_data_factory_get_memsize (GimpObject *object);
static void gimp_data_factory_load_callback (GimpDatafileData *file_data);
static void gimp_data_factory_load_data (const GimpDatafileData *file_data,
gpointer user_data);
static GimpObjectClass *parent_class = NULL;
......@@ -205,7 +206,7 @@ gimp_data_factory_data_init (GimpDataFactory *factory,
gimp_datafiles_read_directories (path,
G_FILE_TEST_EXISTS,
gimp_data_factory_load_callback,
gimp_data_factory_load_data,
factory);
}
......@@ -415,12 +416,13 @@ gimp_data_factory_data_get_standard (GimpDataFactory *factory)
}
static void
gimp_data_factory_load_callback (GimpDatafileData *file_data)
gimp_data_factory_load_data (const GimpDatafileData *file_data,
gpointer user_data)
{
GimpDataFactory *factory;
gint i;
factory = (GimpDataFactory *) file_data->user_data;
factory = GIMP_DATA_FACTORY (user_data);
for (i = 0; i < factory->n_loader_entries; i++)
{
......
......@@ -54,7 +54,8 @@ static void gimp_environ_table_init (GimpEnvironTable *enviro
static void gimp_environ_table_finalize (GObject *object);
static void gimp_environ_table_load_env_file (GimpDatafileData *file_data);
static void gimp_environ_table_load_env_file (const GimpDatafileData *file_data,
gpointer user_data);
static gboolean gimp_environ_table_legal_name (gchar *name);
static void gimp_environ_table_populate (GimpEnvironTable *environ_table);
......@@ -240,7 +241,8 @@ gimp_environ_table_get_envp (GimpEnvironTable *environ_table)
/* private */
static void
gimp_environ_table_load_env_file (GimpDatafileData *file_data)
gimp_environ_table_load_env_file (const GimpDatafileData *file_data,
gpointer user_data)
{
GimpEnvironTable *environ_table;
FILE *env;
......@@ -249,7 +251,7 @@ gimp_environ_table_load_env_file (GimpDatafileData *file_data)
gchar *name, *value, *separator, *p, *q;
GimpEnvironValue *val;
environ_table = GIMP_ENVIRON_TABLE (file_data->user_data);
environ_table = GIMP_ENVIRON_TABLE (user_data);
env = fopen (file_data->filename, "r");
if (! env)
......
......@@ -79,7 +79,8 @@ static void gui_message (Gimp *gimp,
static GimpObject * gui_display_new (GimpImage *gimage,
guint scale);
static void gui_themes_dir_foreach_func (GimpDatafileData *file_data);
static void gui_themes_dir_foreach_func (const GimpDatafileData *file_data,
gpointer user_data);
static gboolean gui_exit_callback (Gimp *gimp,
gboolean kill_it);
static gboolean gui_exit_finish_callback (Gimp *gimp,
......@@ -456,20 +457,19 @@ gui_display_new (GimpImage *gimage,
}
static void
gui_themes_dir_foreach_func (GimpDatafileData *file_data)
gui_themes_dir_foreach_func (const GimpDatafileData *file_data,
gpointer user_data)
{
Gimp *gimp;
gchar *basename;
gimp = (Gimp *) file_data->user_data;
Gimp *gimp;
basename = g_path_get_basename (file_data->filename);
gimp = GIMP (user_data);
if (gimp->be_verbose)
g_print (_("Adding theme '%s' (%s)\n"), basename, file_data->filename);
g_print (_("Adding theme '%s' (%s)\n"),
file_data->basename, file_data->filename);
g_hash_table_insert (themes_hash,
basename,
g_strdup (file_data->basename),
g_strdup (file_data->filename));
}
......
......@@ -54,7 +54,8 @@ static void gimp_environ_table_init (GimpEnvironTable *enviro
static void gimp_environ_table_finalize (GObject *object);
static void gimp_environ_table_load_env_file (GimpDatafileData *file_data);
static void gimp_environ_table_load_env_file (const GimpDatafileData *file_data,
gpointer user_data);
static gboolean gimp_environ_table_legal_name (gchar *name);
static void gimp_environ_table_populate (GimpEnvironTable *environ_table);
......@@ -240,7 +241,8 @@ gimp_environ_table_get_envp (GimpEnvironTable *environ_table)
/* private */
static void
gimp_environ_table_load_env_file (GimpDatafileData *file_data)
gimp_environ_table_load_env_file (const GimpDatafileData *file_data,
gpointer user_data)
{
GimpEnvironTable *environ_table;
FILE *env;
......@@ -249,7 +251,7 @@ gimp_environ_table_load_env_file (GimpDatafileData *file_data)
gchar *name, *value, *separator, *p, *q;
GimpEnvironValue *val;
environ_table = GIMP_ENVIRON_TABLE (file_data->user_data);
environ_table = GIMP_ENVIRON_TABLE (user_data);
env = fopen (file_data->filename, "r");
if (! env)
......
......@@ -75,7 +75,8 @@ struct _PlugInHelpPathDef
};
static void plug_ins_init_file (GimpDatafileData *file_data);
static void plug_ins_init_file (const GimpDatafileData *file_data,
gpointer user_data);
static void plug_ins_add_to_db (Gimp *gimp);
static PlugInProcDef * plug_ins_proc_def_insert (Gimp *gimp,
PlugInProcDef *proc_def);
......@@ -796,16 +797,14 @@ plug_ins_image_types_parse (gchar *image_types)
/* private functions */
static void
plug_ins_init_file (GimpDatafileData *file_data)
plug_ins_init_file (const GimpDatafileData *file_data,
gpointer user_data)
{
PlugInDef *plug_in_def;
GSList **plug_in_defs;
GSList *list;
gchar *basename;
plug_in_defs = file_data->user_data;
basename = g_path_get_basename (file_data->filename);
plug_in_defs = (GSList **) user_data;
for (list = *plug_in_defs; list; list = g_slist_next (list))
{
......@@ -815,13 +814,12 @@ plug_ins_init_file (GimpDatafileData *file_data)
plug_in_name = g_path_get_basename (plug_in_def->prog);
if (g_ascii_strcasecmp (basename, plug_in_name) == 0)
if (g_ascii_strcasecmp (file_data->basename, plug_in_name) == 0)
{
g_print ("skipping duplicate plug-in: \"%s\"\n",
file_data->filename);
g_free (plug_in_name);
g_free (basename);
return;
}
......@@ -829,8 +827,6 @@ plug_ins_init_file (GimpDatafileData *file_data)
g_free (plug_in_name);
}
g_free (basename);
plug_in_def = plug_in_def_new (file_data->filename);
plug_in_def_set_mtime (plug_in_def, file_data->mtime);
......
......@@ -75,7 +75,8 @@ struct _PlugInHelpPathDef
};
static void plug_ins_init_file (GimpDatafileData *file_data);
static void plug_ins_init_file (const GimpDatafileData *file_data,
gpointer user_data);
static void plug_ins_add_to_db (Gimp *gimp);
static PlugInProcDef * plug_ins_proc_def_insert (Gimp *gimp,
PlugInProcDef *proc_def);
......@@ -796,16 +797,14 @@ plug_ins_image_types_parse (gchar *image_types)
/* private functions */
static void
plug_ins_init_file (GimpDatafileData *file_data)
plug_ins_init_file (const GimpDatafileData *file_data,
gpointer user_data)
{
PlugInDef *plug_in_def;
GSList **plug_in_defs;
GSList *list;
gchar *basename;
plug_in_defs = file_data->user_data;
basename = g_path_get_basename (file_data->filename);
plug_in_defs = (GSList **) user_data;
for (list = *plug_in_defs; list; list = g_slist_next (list))
{
......@@ -815,13 +814,12 @@ plug_ins_init_file (GimpDatafileData *file_data)
plug_in_name = g_path_get_basename (plug_in_def->prog);
if (g_ascii_strcasecmp (basename, plug_in_name) == 0)
if (g_ascii_strcasecmp (file_data->basename, plug_in_name) == 0)
{
g_print ("skipping duplicate plug-in: \"%s\"\n",
file_data->filename);
g_free (plug_in_name);
g_free (basename);
return;
}
......@@ -829,8 +827,6 @@ plug_ins_init_file (GimpDatafileData *file_data)
g_free (plug_in_name);
}
g_free (basename);
plug_in_def = plug_in_def_new (file_data->filename);
plug_in_def_set_mtime (plug_in_def, file_data->mtime);
......
......@@ -509,45 +509,41 @@ gimp_fixme_preview_fill_scaled (GimpFixMePreview *preview,
preview->height = GTK_PREVIEW (preview->widget)->buffer_height;
}
GList *
gimp_plug_in_parse_path (const gchar *path_name,
const gchar *dir_name)
gchar *
gimp_plug_in_get_path (const gchar *path_name,
const gchar *dir_name)
{
GList *path_list = NULL;
gchar *path;
g_return_val_if_fail (path_name != NULL, NULL);
g_return_val_if_fail (dir_name != NULL, NULL);
path = gimp_gimprc_query (path_name);
if (!path)
if (! path)
{
gchar *gimprc = gimp_personal_rc_file ("gimprc");
gchar *full_path;
gchar *esc_path;
full_path = g_strconcat
("${gimp_dir}", G_DIR_SEPARATOR_S, dir_name,
G_SEARCHPATH_SEPARATOR_S,
"${gimp_data_dir}", G_DIR_SEPARATOR_S, dir_name,
NULL);
full_path =
g_strconcat ("${gimp_dir}", G_DIR_SEPARATOR_S, dir_name,
G_SEARCHPATH_SEPARATOR_S,
"${gimp_data_dir}", G_DIR_SEPARATOR_S, dir_name,
NULL);
esc_path = g_strescape (full_path, NULL);
g_free (full_path);
g_message (_("No %s in gimprc:\n"
"You need to add an entry like\n"
"(%s \"%s\")\n"
"to your %s file."), path_name, path_name, esc_path,
gimprc);
"to your %s file."),
path_name, path_name, esc_path, gimprc);
g_free (gimprc);
g_free (full_path);
g_free (esc_path);
return NULL;
}
path_list = gimp_path_parse (path, 16, TRUE, NULL);
g_free (path);
return path_list;
return path;
}
......@@ -94,7 +94,7 @@ void gimp_fixme_preview_get_pixel (GimpFixMePreview *preview,
gint y,
guchar *pixel);
GList * gimp_plug_in_parse_path (const gchar *path_name,
gchar * gimp_plug_in_get_path (const gchar *path_name,
const gchar *dir_name);
......
......@@ -33,7 +33,8 @@ typedef struct _GimpParasite GimpParasite;
typedef struct _GimpDatafileData GimpDatafileData;
typedef void (* GimpDatafileLoaderFunc) (GimpDatafileData *file_data);
typedef void (* GimpDatafileLoaderFunc) (const GimpDatafileData *file_data,
gpointer user_data);
typedef enum
......
......@@ -131,24 +131,22 @@ gimp_datafiles_read_directories (const gchar *path_str,
g_return_if_fail (path_str != NULL);
g_return_if_fail (loader_func != NULL);
file_data.user_data = user_data;
local_path = g_strdup (path_str);
#ifdef __EMX__
/*
* Change drive so opendir works.
*/
if (local_path[1] == ':')
{
_chdrive (local_path[0]);
}
#endif
path = gimp_path_parse (local_path, 16, TRUE, NULL);
for (list = path; list; list = g_list_next (list))
{
#ifdef __EMX__
/*
* Change drive so opendir works.
*/
if (((gchar *) list->data)[1] == ':')
{
_chdrive (((gchar *) list->data)[0]);
}
#endif
dir = g_dir_open ((gchar *) list->data, 0, NULL);
if (dir)
......@@ -158,10 +156,10 @@ gimp_datafiles_read_directories (const gchar *path_str,
filename = g_build_filename ((gchar *) list->data,
dir_ent, NULL);
/* Check the file and see that it is not a sub-directory */
err = stat (filename, &filestat);
file_data.filename = filename;
file_data.basename = dir_ent;
file_data.atime = filestat.st_atime;
file_data.mtime = filestat.st_mtime;
file_data.ctime = filestat.st_ctime;
......@@ -170,23 +168,23 @@ gimp_datafiles_read_directories (const gchar *path_str,
{
if (flags & G_FILE_TEST_EXISTS)
{
(* loader_func) (&file_data);
(* loader_func) (&file_data, user_data);
}
else if ((flags & G_FILE_TEST_IS_REGULAR) &&
S_ISREG (filestat.st_mode))
{
(* loader_func) (&file_data);
(* loader_func) (&file_data, user_data);
}
else if ((flags & G_FILE_TEST_IS_DIR) &&
S_ISDIR (filestat.st_mode))
{
(* loader_func) (&file_data);
(* loader_func) (&file_data, user_data);
}
#ifndef G_OS_WIN32
else if ((flags & G_FILE_TEST_IS_SYMLINK) &&
S_ISLNK (filestat.st_mode))
{
(* loader_func) (&file_data);
(* loader_func) (&file_data, user_data);
}
#endif
else if ((flags & G_FILE_TEST_IS_EXECUTABLE) &&
......@@ -195,7 +193,7 @@ gimp_datafiles_read_directories (const gchar *path_str,
(S_ISREG (filestat.st_mode) &&
is_script (filename))))
{
(* loader_func) (&file_data);
(* loader_func) (&file_data, user_data);
}
}
......
......@@ -28,12 +28,11 @@
struct _GimpDatafileData
{
const gchar *filename;
const gchar *basename;
time_t atime;
time_t mtime;
time_t ctime;
gpointer user_data;
};
......
......@@ -56,7 +56,8 @@ static void gimp_module_db_init (GimpModuleDB *db);
static void gimp_module_db_finalize (GObject *object);
static void gimp_module_db_module_initialize (GimpDatafileData *file_data);
static void gimp_module_db_module_initialize (const GimpDatafileData *file_data,
gpointer user_data);
static GimpModule * gimp_module_db_module_find_by_path (GimpModuleDB *db,
const char *fullpath);
......@@ -389,13 +390,14 @@ valid_module_name (const gchar *filename)
}
static void
gimp_module_db_module_initialize (GimpDatafileData *file_data)
gimp_module_db_module_initialize (const GimpDatafileData *file_data,
gpointer user_data)
{
GimpModuleDB *db;
GimpModule *module;
gboolean load_inhibit;
db = GIMP_MODULE_DB (file_data->user_data);
db = GIMP_MODULE_DB (user_data);
if (! valid_module_name (file_data->filename))
return;
......
......@@ -276,7 +276,8 @@ explorer_dialog (void)
gimp_ui_init ("fractalexplorer", TRUE);
plug_in_parse_fractalexplorer_path ();
fractalexplorer_path = gimp_plug_in_get_path ("fractalexplorer-path",
"fractalexplorer");
wint.wimage = g_new (guchar, preview_width * preview_height * 3);
elements = g_new (DialogElements, 1);
......@@ -1743,11 +1744,14 @@ create_file_selection (void)
{
gtk_file_selection_set_filename (GTK_FILE_SELECTION (window), tpath);
}
else if (fractalexplorer_path_list)
else if (fractalexplorer_path)
{
GList *path_list;
gchar *dir;
dir = gimp_path_get_user_writable_dir (fractalexplorer_path_list);
path_list = gimp_path_parse (fractalexplorer_path, 16, FALSE, NULL);
dir = gimp_path_get_user_writable_dir (path_list);
if (!dir)
dir = g_strdup (gimp_directory ());
......@@ -1755,6 +1759,7 @@ create_file_selection (void)
gtk_file_selection_set_filename (GTK_FILE_SELECTION (window), dir);
g_free (dir);
gimp_path_free (path_list);
}
else
{
......
......@@ -151,7 +151,7 @@ static void fractalexplorer_list_free_all (void);
static fractalexplorerOBJ * fractalexplorer_load (const gchar *filename,
const gchar *name);
static void fractalexplorer_list_load_all (GList *plist);
static void fractalexplorer_list_load_all (const gchar *path);
static void fractalexplorer_rescan_ok_callback (GtkWidget *widget,
gpointer data);
static void fractalexplorer_rescan_list (void);
......@@ -1113,13 +1113,6 @@ list_button_press (GtkWidget *widget,
return FALSE;
}
void
plug_in_parse_fractalexplorer_path (void)
{
fractalexplorer_path_list =
gimp_plug_in_parse_path ("fractalexplorer-path", "fractalexplorer");
}
static void
fractalexplorer_free (fractalexplorerOBJ *fractalexplorer)
{
......@@ -1208,59 +1201,39 @@ fractalexplorer_load (const gchar *filename,
}
static void
fractalexplorer_list_load_all (GList *plist)
fractalexplorer_list_load_one (const GimpDatafileData *file_data,
gpointer user_data)
{
fractalexplorerOBJ *fractalexplorer;
GList *list;
gchar *path;
gchar *filename;
GDir *dir;
const gchar *dir_ent;
/* Make sure to clear any existing fractalexplorers */
current_obj = pic_obj = NULL;
fractalexplorer_list_free_all ();
list = plist;
while (list)
{
path = list->data;
list = list->next;
fractalexplorer = fractalexplorer_load (file_data->filename,
file_data->basename);
/* Open directory */
dir = g_dir_open (path, 0, NULL);
if (fractalexplorer)
{
/* Read only ?*/
if (access (filename, W_OK))
fractalexplorer->obj_status |= fractalexplorer_READONLY;
if (!dir)
{
g_warning ("error reading fractalexplorer folder \"%s\"", path);
}
else
{
while ((dir_ent = g_dir_read_name (dir)))
{
filename = g_build_filename (path, dir_ent, NULL);
fractalexplorer_list_insert (fractalexplorer);
}
}
if (g_file_test (filename, G_FILE_TEST_IS_REGULAR))
{
fractalexplorer = fractalexplorer_load (filename, dir_ent);
if (fractalexplorer)
{
/* Read only ?*/
if (access (filename, W_OK))
fractalexplorer->obj_status |= fractalexplorer_READONLY;
fractalexplorer_list_insert (fractalexplorer);
}
}
static void
fractalexplorer_list_load_all (const gchar *path)
{
/* Make sure to clear any existing fractalexplorers */
current_obj = pic_obj = NULL;
fractalexplorer_list_free_all ();
g_free (filename);
}
g_dir_close (dir);
}
}
gimp_datafiles_read_directories (path, G_FILE_TEST_IS_REGULAR,
fractalexplorer_list_load_one,
NULL);
if (!fractalexplorer_list)
if (! fractalexplorer_list)
{
fractalexplorerOBJ *fractalexplorer;
/* lets have at least one! */
fractalexplorer = fractalexplorer_new ();
fractalexplorer->draw_name = g_strdup (_("My first fractal"));
......@@ -1306,7 +1279,7 @@ add_objects_list (void)
list);
gtk_widget_show (list);