2001-02-14 03:53:07 +08:00
|
|
|
/* The GIMP -- an image manipulation program
|
|
|
|
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
|
|
|
|
*
|
2001-04-22 08:38:56 +08:00
|
|
|
* gimpdatafactory.c
|
|
|
|
* Copyright (C) 2001 Michael Natterer <mitch@gimp.org>
|
|
|
|
*
|
2001-02-14 03:53:07 +08:00
|
|
|
* 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 2 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, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
2001-08-14 22:53:55 +08:00
|
|
|
#include <glib-object.h>
|
2001-02-14 03:53:07 +08:00
|
|
|
|
2001-05-10 06:34:59 +08:00
|
|
|
#include "core-types.h"
|
2001-02-14 03:53:07 +08:00
|
|
|
|
2001-07-10 03:48:30 +08:00
|
|
|
#include "gimpcontext.h"
|
2001-02-14 03:53:07 +08:00
|
|
|
#include "gimpdata.h"
|
|
|
|
#include "gimpdatafactory.h"
|
2001-07-10 03:48:30 +08:00
|
|
|
#include "gimpdatafiles.h"
|
|
|
|
#include "gimpdatalist.h"
|
2001-02-14 03:53:07 +08:00
|
|
|
|
2001-02-14 09:42:12 +08:00
|
|
|
#include "libgimp/gimpintl.h"
|
|
|
|
|
2001-02-14 03:53:07 +08:00
|
|
|
|
2002-01-31 00:14:26 +08:00
|
|
|
static void gimp_data_factory_class_init (GimpDataFactoryClass *klass);
|
|
|
|
static void gimp_data_factory_init (GimpDataFactory *factory);
|
2001-08-11 22:39:19 +08:00
|
|
|
|
2002-01-31 00:14:26 +08:00
|
|
|
static void gimp_data_factory_finalize (GObject *object);
|
2001-02-14 03:53:07 +08:00
|
|
|
|
2002-01-31 00:14:26 +08:00
|
|
|
static gsize gimp_data_factory_get_memsize (GimpObject *object);
|
|
|
|
|
|
|
|
static void gimp_data_factory_data_load_callback (const gchar *filename,
|
|
|
|
gpointer callback_data);
|
2001-02-14 09:42:12 +08:00
|
|
|
|
2001-02-14 03:53:07 +08:00
|
|
|
|
|
|
|
static GimpObjectClass *parent_class = NULL;
|
|
|
|
|
|
|
|
|
2001-08-11 22:39:19 +08:00
|
|
|
GType
|
2001-02-14 03:53:07 +08:00
|
|
|
gimp_data_factory_get_type (void)
|
|
|
|
{
|
2001-08-11 22:39:19 +08:00
|
|
|
static GType factory_type = 0;
|
2001-02-14 03:53:07 +08:00
|
|
|
|
|
|
|
if (! factory_type)
|
|
|
|
{
|
2001-08-11 22:39:19 +08:00
|
|
|
static const GTypeInfo factory_info =
|
2001-02-14 03:53:07 +08:00
|
|
|
{
|
2001-08-11 22:39:19 +08:00
|
|
|
sizeof (GimpDataFactoryClass),
|
|
|
|
(GBaseInitFunc) NULL,
|
|
|
|
(GBaseFinalizeFunc) NULL,
|
|
|
|
(GClassInitFunc) gimp_data_factory_class_init,
|
|
|
|
NULL, /* class_finalize */
|
|
|
|
NULL, /* class_data */
|
2001-02-14 03:53:07 +08:00
|
|
|
sizeof (GimpDataFactory),
|
2001-08-11 22:39:19 +08:00
|
|
|
0, /* n_preallocs */
|
|
|
|
(GInstanceInitFunc) gimp_data_factory_init,
|
2001-02-14 03:53:07 +08:00
|
|
|
};
|
|
|
|
|
2001-08-11 22:39:19 +08:00
|
|
|
factory_type = g_type_register_static (GIMP_TYPE_OBJECT,
|
|
|
|
"GimpDataFactory",
|
|
|
|
&factory_info, 0);
|
2001-02-14 03:53:07 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return factory_type;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_data_factory_class_init (GimpDataFactoryClass *klass)
|
|
|
|
{
|
2002-01-31 00:14:26 +08:00
|
|
|
GObjectClass *object_class;
|
|
|
|
GimpObjectClass *gimp_object_class;
|
2001-02-14 03:53:07 +08:00
|
|
|
|
2002-01-31 00:14:26 +08:00
|
|
|
object_class = G_OBJECT_CLASS (klass);
|
|
|
|
gimp_object_class = GIMP_OBJECT_CLASS (klass);
|
2001-02-14 03:53:07 +08:00
|
|
|
|
Port to glib/gtk+ 2.0 episode I (every segfault has it's beginning)
2001-07-24 Michael Natterer <mitch@gimp.org>
Port to glib/gtk+ 2.0 episode I (every segfault has it's beginning)
* configure.in: require glib/gtk+ >= 1.3.7, commented out the
gtkxmhtml stuff.
From now on, you will need glib, pango, atk and gtk+ HEAD from CVS
to hack or use GIMP HEAD.
Beware, it crashes randomly :)
* app/core/Makefile.am
* app/core/gimpmarshal.list: new file plus rules to generate
gimpmarshal.[ch] from it.
* app/core/*
* app/tools/*
* app/widgets/*
* libgimpwidgets/*: started to use the glib object system. All
core/ objects are still gtk objects however. All signals are
created using g_signal_new(). There are many gtk+ artefacts left.
Finally, we will _not_ use the gtk_signal_foo() wrappers and
friends any more.
* app/colormaps.c
* app/devices.[ch]
* app/disp_callbacks.c
* app/errorconsole.c
* app/file-save.[ch]
* app/interface.c
* app/module_db.c
* app/nav_window.c
* app/ops_buttons.c
* app/scroll.c
* app/user_install.c
* app/gui/about-dialog.c
* app/gui/brush-editor.c
* app/gui/brushes-commands.c
* app/gui/color-notebook.c
* app/gui/colormap-dialog.c
* app/gui/dialogs-commands.c
* app/gui/dialogs-constructors.c
* app/gui/file-commands.c
* app/gui/file-dialog-utils.c
* app/gui/file-new-dialog.c
* app/gui/file-open-dialog.[ch]
* app/gui/file-save-dialog.c
* app/gui/gradient-editor.c
* app/gui/gradients-commands.c
* app/gui/image-commands.c
* app/gui/info-dialog.[ch]
* app/gui/layer-select.c
* app/gui/layers-commands.c
* app/gui/menus.c
* app/gui/offset-dialog.c
* app/gui/palette-editor.c
* app/gui/palettes-commands.c
* app/gui/patterns-commands.c
* app/gui/preferences-dialog.c
* app/gui/resize-dialog.[ch]
* app/gui/splash.c
* app/gui/tips-dialog.c
* app/gui/tool-options-dialog.c
* app/gui/toolbox.c
* app/gui/tools-commands.c
* libgimp/gimpbrushmenu.c
* libgimp/gimpmenu.c
* libgimp/gimppatternmenu.c
* libgimp/gimpui.c
* libgimpbase/gimpenv.c: tons and tons of changes like "const
gchar*", switch from GdkDeviceInfo to GdkDevice (very incomplete
and currently disables), lots of s/gtk_signal/g_signal/,
removal/replacement of deprecated stuff,
s/GtkSignalFunc/GCallback/ and lots of small changes and fixes
while I was on it, zillions of warnings left...
* modules/Makefile.am: disabled the water color selector
temporarily (XInput issues).
* plug-ins/Makefile.am
* plug-ins/common/.cvsignore
* plug-ins/common/Makefile.am
* plug-ins/common/plugin-defs.pl: simply excluded all plug-ins
which did not build (including Script-Fu). They are trivial to
fix.
2001-07-25 05:27:11 +08:00
|
|
|
parent_class = g_type_class_peek_parent (klass);
|
2001-02-14 03:53:07 +08:00
|
|
|
|
2002-01-31 00:14:26 +08:00
|
|
|
object_class->finalize = gimp_data_factory_finalize;
|
|
|
|
|
|
|
|
gimp_object_class->get_memsize = gimp_data_factory_get_memsize;
|
2001-02-14 03:53:07 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_data_factory_init (GimpDataFactory *factory)
|
|
|
|
{
|
|
|
|
factory->container = NULL;
|
|
|
|
factory->data_path = NULL;
|
2001-02-14 09:42:12 +08:00
|
|
|
factory->loader_entries = NULL;
|
|
|
|
factory->n_loader_entries = 0;
|
|
|
|
factory->data_new_func = NULL;
|
|
|
|
factory->data_get_standard_func = NULL;
|
2001-02-14 03:53:07 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2001-08-11 22:39:19 +08:00
|
|
|
gimp_data_factory_finalize (GObject *object)
|
2001-02-14 03:53:07 +08:00
|
|
|
{
|
|
|
|
GimpDataFactory *factory;
|
|
|
|
|
|
|
|
factory = GIMP_DATA_FACTORY (object);
|
|
|
|
|
|
|
|
if (factory->container)
|
2001-07-05 03:31:35 +08:00
|
|
|
{
|
2001-07-28 03:41:54 +08:00
|
|
|
g_object_unref (G_OBJECT (factory->container));
|
2001-07-05 03:31:35 +08:00
|
|
|
factory->container = NULL;
|
|
|
|
}
|
2001-02-14 03:53:07 +08:00
|
|
|
|
2001-08-11 22:39:19 +08:00
|
|
|
G_OBJECT_CLASS (parent_class)->finalize (object);
|
2001-02-14 03:53:07 +08:00
|
|
|
}
|
|
|
|
|
2002-01-31 00:14:26 +08:00
|
|
|
static gsize
|
|
|
|
gimp_data_factory_get_memsize (GimpObject *object)
|
|
|
|
{
|
|
|
|
GimpDataFactory *factory;
|
|
|
|
gsize memsize = 0;
|
|
|
|
|
|
|
|
factory = GIMP_DATA_FACTORY (object);
|
|
|
|
|
|
|
|
memsize += gimp_object_get_memsize (GIMP_OBJECT (factory->container));
|
|
|
|
|
|
|
|
return memsize + GIMP_OBJECT_CLASS (parent_class)->get_memsize (object);
|
|
|
|
}
|
|
|
|
|
2001-02-14 03:53:07 +08:00
|
|
|
GimpDataFactory *
|
2001-08-11 22:39:19 +08:00
|
|
|
gimp_data_factory_new (GType data_type,
|
2001-02-14 22:57:14 +08:00
|
|
|
const gchar **data_path,
|
|
|
|
const GimpDataFactoryLoaderEntry *loader_entries,
|
2001-12-03 21:44:59 +08:00
|
|
|
gint n_loader_entries,
|
2001-02-14 22:57:14 +08:00
|
|
|
GimpDataNewFunc new_func,
|
|
|
|
GimpDataGetStandardFunc standard_func)
|
2001-02-14 03:53:07 +08:00
|
|
|
{
|
|
|
|
GimpDataFactory *factory;
|
|
|
|
|
2001-08-11 22:39:19 +08:00
|
|
|
g_return_val_if_fail (g_type_is_a (data_type, GIMP_TYPE_DATA), NULL);
|
2001-02-14 03:53:07 +08:00
|
|
|
g_return_val_if_fail (data_path != NULL, NULL);
|
2001-02-14 09:42:12 +08:00
|
|
|
g_return_val_if_fail (loader_entries != NULL, NULL);
|
|
|
|
g_return_val_if_fail (n_loader_entries > 0, NULL);
|
2001-02-14 03:53:07 +08:00
|
|
|
|
2001-08-10 22:41:39 +08:00
|
|
|
factory = g_object_new (GIMP_TYPE_DATA_FACTORY, NULL);
|
2001-02-14 03:53:07 +08:00
|
|
|
|
2002-01-31 00:14:26 +08:00
|
|
|
factory->container = gimp_data_list_new (data_type);
|
2001-02-14 03:53:07 +08:00
|
|
|
|
2001-02-14 09:42:12 +08:00
|
|
|
factory->data_path = data_path;
|
|
|
|
|
|
|
|
factory->loader_entries = loader_entries;
|
|
|
|
factory->n_loader_entries = n_loader_entries;
|
|
|
|
|
|
|
|
factory->data_new_func = new_func;
|
|
|
|
factory->data_get_standard_func = standard_func;
|
2001-02-14 03:53:07 +08:00
|
|
|
|
|
|
|
return factory;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2001-02-14 09:42:12 +08:00
|
|
|
gimp_data_factory_data_init (GimpDataFactory *factory,
|
2001-07-05 06:59:25 +08:00
|
|
|
gboolean no_data /* FIXME */)
|
2001-02-14 09:42:12 +08:00
|
|
|
{
|
|
|
|
g_return_if_fail (GIMP_IS_DATA_FACTORY (factory));
|
|
|
|
|
|
|
|
gimp_container_freeze (factory->container);
|
|
|
|
|
2002-06-12 21:48:47 +08:00
|
|
|
gimp_data_factory_data_free (factory);
|
2001-02-14 09:42:12 +08:00
|
|
|
|
|
|
|
if (factory->data_path && *factory->data_path)
|
|
|
|
{
|
2001-05-10 06:34:59 +08:00
|
|
|
gimp_datafiles_read_directories (*factory->data_path, 0,
|
|
|
|
gimp_data_factory_data_load_callback,
|
|
|
|
factory);
|
2001-02-14 09:42:12 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
gimp_container_thaw (factory->container);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
gimp_data_factory_data_save (GimpDataFactory *factory)
|
2001-02-14 03:53:07 +08:00
|
|
|
{
|
2001-02-18 05:20:10 +08:00
|
|
|
GimpList *gimp_list;
|
|
|
|
GList *list;
|
|
|
|
|
2001-02-14 03:53:07 +08:00
|
|
|
g_return_if_fail (GIMP_IS_DATA_FACTORY (factory));
|
2001-02-18 05:20:10 +08:00
|
|
|
|
|
|
|
if (gimp_container_num_children (factory->container) == 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (! (factory->data_path && *factory->data_path))
|
|
|
|
return;
|
|
|
|
|
|
|
|
gimp_list = GIMP_LIST (factory->container);
|
|
|
|
|
|
|
|
gimp_container_freeze (factory->container);
|
|
|
|
|
|
|
|
for (list = gimp_list->list; list; list = g_list_next (list))
|
|
|
|
{
|
|
|
|
GimpData *data;
|
|
|
|
|
|
|
|
data = GIMP_DATA (list->data);
|
|
|
|
|
|
|
|
if (! data->filename)
|
|
|
|
gimp_data_create_filename (data,
|
|
|
|
GIMP_OBJECT (data)->name,
|
|
|
|
*factory->data_path);
|
|
|
|
|
|
|
|
if (data->dirty)
|
|
|
|
gimp_data_save (data);
|
|
|
|
}
|
|
|
|
|
|
|
|
gimp_container_thaw (factory->container);
|
2001-02-14 03:53:07 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
gimp_data_factory_data_free (GimpDataFactory *factory)
|
|
|
|
{
|
2001-02-18 05:20:10 +08:00
|
|
|
GimpList *list;
|
|
|
|
|
2001-02-14 03:53:07 +08:00
|
|
|
g_return_if_fail (GIMP_IS_DATA_FACTORY (factory));
|
|
|
|
|
|
|
|
if (gimp_container_num_children (factory->container) == 0)
|
|
|
|
return;
|
|
|
|
|
2001-02-18 05:20:10 +08:00
|
|
|
list = GIMP_LIST (factory->container);
|
|
|
|
|
|
|
|
gimp_container_freeze (factory->container);
|
|
|
|
|
2002-06-12 21:48:47 +08:00
|
|
|
if (list->list)
|
2001-02-18 05:20:10 +08:00
|
|
|
{
|
2002-06-12 21:48:47 +08:00
|
|
|
if (GIMP_DATA (list->list->data)->internal)
|
|
|
|
{
|
|
|
|
/* if there are internal objects in the list, skip them */
|
|
|
|
|
|
|
|
GList *glist;
|
|
|
|
|
|
|
|
for (glist = list->list; glist; glist = g_list_next (glist))
|
|
|
|
{
|
|
|
|
if (glist->next && ! GIMP_DATA (glist->next->data)->internal)
|
|
|
|
{
|
|
|
|
while (glist->next)
|
|
|
|
{
|
|
|
|
gimp_container_remove (factory->container,
|
|
|
|
GIMP_OBJECT (glist->next->data));
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* otherwise delete everything */
|
|
|
|
|
|
|
|
while (list->list)
|
|
|
|
{
|
|
|
|
gimp_container_remove (factory->container,
|
|
|
|
GIMP_OBJECT (list->list->data));
|
|
|
|
}
|
|
|
|
}
|
2001-02-18 05:20:10 +08:00
|
|
|
}
|
2001-02-14 03:53:07 +08:00
|
|
|
|
2001-02-18 05:20:10 +08:00
|
|
|
gimp_container_thaw (factory->container);
|
2001-02-14 03:53:07 +08:00
|
|
|
}
|
2001-02-14 09:42:12 +08:00
|
|
|
|
|
|
|
GimpData *
|
|
|
|
gimp_data_factory_data_new (GimpDataFactory *factory,
|
|
|
|
const gchar *name)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail (GIMP_IS_DATA_FACTORY (factory), NULL);
|
|
|
|
g_return_val_if_fail (name != NULL, NULL);
|
|
|
|
|
|
|
|
if (factory->data_new_func)
|
|
|
|
{
|
|
|
|
GimpData *data;
|
|
|
|
|
|
|
|
data = factory->data_new_func (name);
|
|
|
|
|
|
|
|
gimp_container_add (factory->container, GIMP_OBJECT (data));
|
2001-08-12 23:39:23 +08:00
|
|
|
g_object_unref (G_OBJECT (data));
|
2001-02-14 09:42:12 +08:00
|
|
|
|
|
|
|
return data;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
GimpData *
|
|
|
|
gimp_data_factory_data_get_standard (GimpDataFactory *factory)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail (GIMP_IS_DATA_FACTORY (factory), NULL);
|
|
|
|
|
|
|
|
if (factory->data_get_standard_func)
|
|
|
|
return factory->data_get_standard_func ();
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_data_factory_data_load_callback (const gchar *filename,
|
|
|
|
gpointer callback_data)
|
|
|
|
{
|
|
|
|
GimpDataFactory *factory;
|
2001-12-03 21:44:59 +08:00
|
|
|
gint i;
|
2001-02-14 09:42:12 +08:00
|
|
|
|
|
|
|
factory = (GimpDataFactory *) callback_data;
|
|
|
|
|
|
|
|
for (i = 0; i < factory->n_loader_entries; i++)
|
|
|
|
{
|
|
|
|
if (factory->loader_entries[i].extension)
|
|
|
|
{
|
2001-05-10 06:34:59 +08:00
|
|
|
if (gimp_datafiles_check_extension (filename,
|
|
|
|
factory->loader_entries[i].extension))
|
2001-02-14 09:42:12 +08:00
|
|
|
{
|
|
|
|
goto insert;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2001-11-16 20:23:01 +08:00
|
|
|
g_message (_("Trying legacy loader on\n"
|
|
|
|
"file '%s'\n"
|
|
|
|
"with unknown extension."),
|
|
|
|
filename);
|
2001-02-14 09:42:12 +08:00
|
|
|
goto insert;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
insert:
|
|
|
|
{
|
|
|
|
GimpData *data;
|
|
|
|
|
|
|
|
data = (GimpData *) (* factory->loader_entries[i].load_func) (filename);
|
|
|
|
|
|
|
|
if (! data)
|
2001-08-12 23:39:23 +08:00
|
|
|
{
|
2001-11-16 20:23:01 +08:00
|
|
|
g_message (_("Warning: Failed to load data from\n'%s'"), filename);
|
2001-08-12 23:39:23 +08:00
|
|
|
}
|
2001-02-14 09:42:12 +08:00
|
|
|
else
|
2001-08-12 23:39:23 +08:00
|
|
|
{
|
|
|
|
gimp_container_add (factory->container, GIMP_OBJECT (data));
|
|
|
|
g_object_unref (G_OBJECT (data));
|
|
|
|
}
|
2001-02-14 09:42:12 +08:00
|
|
|
}
|
|
|
|
}
|