2001-02-13 19:53:07 +00:00
|
|
|
/* The GIMP -- an image manipulation program
|
|
|
|
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
|
|
|
|
*
|
2001-04-22 00:38:56 +00:00
|
|
|
* gimpdatafactory.c
|
|
|
|
* Copyright (C) 2001 Michael Natterer <mitch@gimp.org>
|
|
|
|
*
|
2001-02-13 19:53:07 +00: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"
|
|
|
|
|
2002-12-02 13:39:09 +00:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
2001-08-14 14:53:55 +00:00
|
|
|
#include <glib-object.h>
|
2001-02-13 19:53:07 +00:00
|
|
|
|
2002-10-23 14:55:07 +00:00
|
|
|
#include "libgimpbase/gimpbase.h"
|
|
|
|
|
2001-05-09 22:34:59 +00:00
|
|
|
#include "core-types.h"
|
2001-02-13 19:53:07 +00:00
|
|
|
|
2002-11-30 16:31:39 +00:00
|
|
|
#include "config/gimpbaseconfig.h"
|
2002-12-29 18:58:24 +00:00
|
|
|
#include "config/gimpconfig-path.h"
|
2002-11-30 16:31:39 +00:00
|
|
|
|
|
|
|
#include "gimp.h"
|
2001-07-09 19:48:30 +00:00
|
|
|
#include "gimpcontext.h"
|
2001-02-13 19:53:07 +00:00
|
|
|
#include "gimpdata.h"
|
|
|
|
#include "gimpdatafactory.h"
|
2001-07-09 19:48:30 +00:00
|
|
|
#include "gimpdatalist.h"
|
2001-02-13 19:53:07 +00:00
|
|
|
|
2001-02-14 01:42:12 +00:00
|
|
|
#include "libgimp/gimpintl.h"
|
|
|
|
|
2001-02-13 19:53:07 +00:00
|
|
|
|
2002-12-02 13:39:09 +00:00
|
|
|
static void gimp_data_factory_class_init (GimpDataFactoryClass *klass);
|
|
|
|
static void gimp_data_factory_init (GimpDataFactory *factory);
|
2001-08-11 14:39:19 +00:00
|
|
|
|
2002-12-02 13:39:09 +00:00
|
|
|
static void gimp_data_factory_finalize (GObject *object);
|
2001-02-13 19:53:07 +00:00
|
|
|
|
2002-12-02 13:39:09 +00:00
|
|
|
static gsize gimp_data_factory_get_memsize (GimpObject *object);
|
2002-01-30 16:14:26 +00:00
|
|
|
|
2002-12-02 13:39:09 +00:00
|
|
|
static void gimp_data_factory_load_callback (GimpDatafileData *file_data);
|
2001-02-14 01:42:12 +00:00
|
|
|
|
2001-02-13 19:53:07 +00:00
|
|
|
|
|
|
|
static GimpObjectClass *parent_class = NULL;
|
|
|
|
|
|
|
|
|
2001-08-11 14:39:19 +00:00
|
|
|
GType
|
2001-02-13 19:53:07 +00:00
|
|
|
gimp_data_factory_get_type (void)
|
|
|
|
{
|
2001-08-11 14:39:19 +00:00
|
|
|
static GType factory_type = 0;
|
2001-02-13 19:53:07 +00:00
|
|
|
|
|
|
|
if (! factory_type)
|
|
|
|
{
|
2001-08-11 14:39:19 +00:00
|
|
|
static const GTypeInfo factory_info =
|
2001-02-13 19:53:07 +00:00
|
|
|
{
|
2001-08-11 14:39:19 +00:00
|
|
|
sizeof (GimpDataFactoryClass),
|
|
|
|
(GBaseInitFunc) NULL,
|
|
|
|
(GBaseFinalizeFunc) NULL,
|
|
|
|
(GClassInitFunc) gimp_data_factory_class_init,
|
|
|
|
NULL, /* class_finalize */
|
|
|
|
NULL, /* class_data */
|
2001-02-13 19:53:07 +00:00
|
|
|
sizeof (GimpDataFactory),
|
2001-08-11 14:39:19 +00:00
|
|
|
0, /* n_preallocs */
|
|
|
|
(GInstanceInitFunc) gimp_data_factory_init,
|
2001-02-13 19:53:07 +00:00
|
|
|
};
|
|
|
|
|
2001-08-11 14:39:19 +00:00
|
|
|
factory_type = g_type_register_static (GIMP_TYPE_OBJECT,
|
|
|
|
"GimpDataFactory",
|
|
|
|
&factory_info, 0);
|
2001-02-13 19:53:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return factory_type;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_data_factory_class_init (GimpDataFactoryClass *klass)
|
|
|
|
{
|
2002-01-30 16:14:26 +00:00
|
|
|
GObjectClass *object_class;
|
|
|
|
GimpObjectClass *gimp_object_class;
|
2001-02-13 19:53:07 +00:00
|
|
|
|
2002-01-30 16:14:26 +00:00
|
|
|
object_class = G_OBJECT_CLASS (klass);
|
|
|
|
gimp_object_class = GIMP_OBJECT_CLASS (klass);
|
2001-02-13 19:53:07 +00: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-24 21:27:11 +00:00
|
|
|
parent_class = g_type_class_peek_parent (klass);
|
2001-02-13 19:53:07 +00:00
|
|
|
|
2002-01-30 16:14:26 +00:00
|
|
|
object_class->finalize = gimp_data_factory_finalize;
|
|
|
|
|
|
|
|
gimp_object_class->get_memsize = gimp_data_factory_get_memsize;
|
2001-02-13 19:53:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_data_factory_init (GimpDataFactory *factory)
|
|
|
|
{
|
2002-11-30 16:31:39 +00:00
|
|
|
factory->gimp = NULL;
|
2001-02-13 19:53:07 +00:00
|
|
|
factory->container = NULL;
|
2002-12-02 13:39:09 +00:00
|
|
|
factory->path_property_name = NULL;
|
2001-02-14 01:42:12 +00:00
|
|
|
factory->loader_entries = NULL;
|
|
|
|
factory->n_loader_entries = 0;
|
|
|
|
factory->data_new_func = NULL;
|
|
|
|
factory->data_get_standard_func = NULL;
|
2001-02-13 19:53:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2001-08-11 14:39:19 +00:00
|
|
|
gimp_data_factory_finalize (GObject *object)
|
2001-02-13 19:53:07 +00:00
|
|
|
{
|
|
|
|
GimpDataFactory *factory;
|
|
|
|
|
|
|
|
factory = GIMP_DATA_FACTORY (object);
|
|
|
|
|
|
|
|
if (factory->container)
|
2001-07-04 19:31:35 +00:00
|
|
|
{
|
2002-12-02 13:39:09 +00:00
|
|
|
g_object_unref (factory->container);
|
2001-07-04 19:31:35 +00:00
|
|
|
factory->container = NULL;
|
|
|
|
}
|
2001-02-13 19:53:07 +00:00
|
|
|
|
2002-12-02 13:39:09 +00:00
|
|
|
if (factory->path_property_name)
|
|
|
|
{
|
|
|
|
g_free (factory->path_property_name);
|
|
|
|
factory->path_property_name = NULL;
|
|
|
|
}
|
|
|
|
|
2001-08-11 14:39:19 +00:00
|
|
|
G_OBJECT_CLASS (parent_class)->finalize (object);
|
2001-02-13 19:53:07 +00:00
|
|
|
}
|
|
|
|
|
2002-01-30 16:14:26 +00: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-13 19:53:07 +00:00
|
|
|
GimpDataFactory *
|
2002-12-02 13:39:09 +00:00
|
|
|
gimp_data_factory_new (Gimp *gimp,
|
|
|
|
GType data_type,
|
|
|
|
const gchar *path_property_name,
|
|
|
|
const GimpDataFactoryLoaderEntry *loader_entries,
|
|
|
|
gint n_loader_entries,
|
|
|
|
GimpDataNewFunc new_func,
|
|
|
|
GimpDataGetStandardFunc standard_func)
|
2001-02-13 19:53:07 +00:00
|
|
|
{
|
|
|
|
GimpDataFactory *factory;
|
|
|
|
|
2002-11-30 16:31:39 +00:00
|
|
|
g_return_val_if_fail (GIMP_IS_GIMP (gimp), NULL);
|
2001-08-11 14:39:19 +00:00
|
|
|
g_return_val_if_fail (g_type_is_a (data_type, GIMP_TYPE_DATA), NULL);
|
2002-12-02 13:39:09 +00:00
|
|
|
g_return_val_if_fail (path_property_name != NULL, NULL);
|
2001-02-14 01:42:12 +00:00
|
|
|
g_return_val_if_fail (loader_entries != NULL, NULL);
|
|
|
|
g_return_val_if_fail (n_loader_entries > 0, NULL);
|
2001-02-13 19:53:07 +00:00
|
|
|
|
2001-08-10 14:41:39 +00:00
|
|
|
factory = g_object_new (GIMP_TYPE_DATA_FACTORY, NULL);
|
2001-02-13 19:53:07 +00:00
|
|
|
|
2002-11-30 16:31:39 +00:00
|
|
|
factory->gimp = gimp;
|
2002-01-30 16:14:26 +00:00
|
|
|
factory->container = gimp_data_list_new (data_type);
|
2001-02-13 19:53:07 +00:00
|
|
|
|
2002-12-02 13:39:09 +00:00
|
|
|
factory->path_property_name = g_strdup (path_property_name);
|
2001-02-14 01:42:12 +00:00
|
|
|
|
|
|
|
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-13 19:53:07 +00:00
|
|
|
|
|
|
|
return factory;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2001-02-14 01:42:12 +00:00
|
|
|
gimp_data_factory_data_init (GimpDataFactory *factory,
|
2001-07-04 22:59:25 +00:00
|
|
|
gboolean no_data /* FIXME */)
|
2001-02-14 01:42:12 +00:00
|
|
|
{
|
2002-12-02 13:39:09 +00:00
|
|
|
gchar *path = NULL;
|
|
|
|
|
2001-02-14 01:42:12 +00:00
|
|
|
g_return_if_fail (GIMP_IS_DATA_FACTORY (factory));
|
|
|
|
|
|
|
|
gimp_container_freeze (factory->container);
|
|
|
|
|
2002-06-12 13:48:47 +00:00
|
|
|
gimp_data_factory_data_free (factory);
|
2001-02-14 01:42:12 +00:00
|
|
|
|
2003-01-05 22:07:10 +00:00
|
|
|
g_object_get (factory->gimp->config,
|
2002-12-02 13:39:09 +00:00
|
|
|
factory->path_property_name, &path,
|
|
|
|
NULL);
|
|
|
|
|
|
|
|
if (path && strlen (path))
|
2001-02-14 01:42:12 +00:00
|
|
|
{
|
2002-12-29 18:58:24 +00:00
|
|
|
gchar *tmp;
|
|
|
|
|
|
|
|
tmp = gimp_config_path_expand (path, TRUE, NULL);
|
|
|
|
g_free (path);
|
|
|
|
path = tmp;
|
|
|
|
|
2002-12-02 13:39:09 +00:00
|
|
|
gimp_datafiles_read_directories (path,
|
2002-10-23 14:55:07 +00:00
|
|
|
G_FILE_TEST_EXISTS,
|
2002-12-02 13:39:09 +00:00
|
|
|
gimp_data_factory_load_callback,
|
2001-05-09 22:34:59 +00:00
|
|
|
factory);
|
2001-02-14 01:42:12 +00:00
|
|
|
}
|
|
|
|
|
2002-12-02 13:39:09 +00:00
|
|
|
g_free (path);
|
|
|
|
|
2001-02-14 01:42:12 +00:00
|
|
|
gimp_container_thaw (factory->container);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
gimp_data_factory_data_save (GimpDataFactory *factory)
|
2001-02-13 19:53:07 +00:00
|
|
|
{
|
2002-12-02 13:39:09 +00:00
|
|
|
gchar *path = NULL;
|
2001-02-17 21:20:10 +00:00
|
|
|
|
2001-02-13 19:53:07 +00:00
|
|
|
g_return_if_fail (GIMP_IS_DATA_FACTORY (factory));
|
2001-02-17 21:20:10 +00:00
|
|
|
|
|
|
|
if (gimp_container_num_children (factory->container) == 0)
|
|
|
|
return;
|
|
|
|
|
2003-01-05 22:07:10 +00:00
|
|
|
g_object_get (factory->gimp->config,
|
2002-12-02 13:39:09 +00:00
|
|
|
factory->path_property_name, &path,
|
|
|
|
NULL);
|
2001-02-17 21:20:10 +00:00
|
|
|
|
2002-12-02 13:39:09 +00:00
|
|
|
if (path && strlen (path))
|
|
|
|
{
|
|
|
|
GimpList *gimp_list;
|
|
|
|
GList *list;
|
2002-12-29 18:58:24 +00:00
|
|
|
gchar *tmp;
|
|
|
|
|
|
|
|
tmp = gimp_config_path_expand (path, TRUE, NULL);
|
|
|
|
g_free (path);
|
|
|
|
path = tmp;
|
2001-02-17 21:20:10 +00:00
|
|
|
|
2002-12-02 13:39:09 +00:00
|
|
|
gimp_list = GIMP_LIST (factory->container);
|
2001-02-17 21:20:10 +00:00
|
|
|
|
2002-12-02 13:39:09 +00:00
|
|
|
gimp_container_freeze (factory->container);
|
2001-02-17 21:20:10 +00:00
|
|
|
|
2002-12-02 13:39:09 +00:00
|
|
|
for (list = gimp_list->list; list; list = g_list_next (list))
|
|
|
|
{
|
|
|
|
GimpData *data;
|
2001-02-17 21:20:10 +00:00
|
|
|
|
2002-12-02 13:39:09 +00:00
|
|
|
data = GIMP_DATA (list->data);
|
2001-02-17 21:20:10 +00:00
|
|
|
|
2002-12-02 13:39:09 +00:00
|
|
|
if (! data->filename)
|
|
|
|
gimp_data_create_filename (data, GIMP_OBJECT (data)->name, path);
|
|
|
|
|
|
|
|
if (data->dirty)
|
|
|
|
{
|
|
|
|
GError *error = NULL;
|
|
|
|
|
|
|
|
if (! gimp_data_save (data, &error))
|
|
|
|
{
|
|
|
|
/* check if there actually was an error (no error
|
|
|
|
* means the data class does not implement save)
|
|
|
|
*/
|
|
|
|
if (error)
|
|
|
|
{
|
|
|
|
g_message (_("Warning: Failed to save data:\n%s"),
|
|
|
|
error->message);
|
|
|
|
g_clear_error (&error);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
gimp_container_thaw (factory->container);
|
2001-02-17 21:20:10 +00:00
|
|
|
}
|
|
|
|
|
2002-12-02 13:39:09 +00:00
|
|
|
g_free (path);
|
2001-02-13 19:53:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
gimp_data_factory_data_free (GimpDataFactory *factory)
|
|
|
|
{
|
2001-02-17 21:20:10 +00:00
|
|
|
GimpList *list;
|
|
|
|
|
2001-02-13 19:53:07 +00:00
|
|
|
g_return_if_fail (GIMP_IS_DATA_FACTORY (factory));
|
|
|
|
|
|
|
|
if (gimp_container_num_children (factory->container) == 0)
|
|
|
|
return;
|
|
|
|
|
2001-02-17 21:20:10 +00:00
|
|
|
list = GIMP_LIST (factory->container);
|
|
|
|
|
|
|
|
gimp_container_freeze (factory->container);
|
|
|
|
|
2002-06-12 13:48:47 +00:00
|
|
|
if (list->list)
|
2001-02-17 21:20:10 +00:00
|
|
|
{
|
2002-06-12 13:48:47 +00: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-17 21:20:10 +00:00
|
|
|
}
|
2001-02-13 19:53:07 +00:00
|
|
|
|
2001-02-17 21:20:10 +00:00
|
|
|
gimp_container_thaw (factory->container);
|
2001-02-13 19:53:07 +00:00
|
|
|
}
|
2001-02-14 01:42:12 +00: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)
|
|
|
|
{
|
2002-11-30 16:31:39 +00:00
|
|
|
GimpBaseConfig *base_config;
|
|
|
|
GimpData *data;
|
2001-02-14 01:42:12 +00:00
|
|
|
|
2002-11-30 16:31:39 +00:00
|
|
|
base_config = GIMP_BASE_CONFIG (factory->gimp->config);
|
|
|
|
|
|
|
|
data = factory->data_new_func (name, base_config->stingy_memory_use);
|
2001-02-14 01:42:12 +00:00
|
|
|
|
|
|
|
gimp_container_add (factory->container, GIMP_OBJECT (data));
|
2003-01-05 22:07:10 +00:00
|
|
|
g_object_unref (data);
|
2001-02-14 01:42:12 +00:00
|
|
|
|
|
|
|
return data;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2002-12-02 13:39:09 +00:00
|
|
|
GimpData *
|
|
|
|
gimp_data_factory_data_duplicate (GimpDataFactory *factory,
|
|
|
|
GimpData *data)
|
|
|
|
{
|
|
|
|
GimpBaseConfig *base_config;
|
|
|
|
GimpData *new_data;
|
|
|
|
|
|
|
|
g_return_val_if_fail (GIMP_IS_DATA_FACTORY (factory), NULL);
|
|
|
|
g_return_val_if_fail (GIMP_IS_DATA (data), NULL);
|
|
|
|
|
|
|
|
base_config = GIMP_BASE_CONFIG (factory->gimp->config);
|
|
|
|
|
|
|
|
new_data = gimp_data_duplicate (data, base_config->stingy_memory_use);
|
|
|
|
|
|
|
|
if (new_data)
|
|
|
|
{
|
|
|
|
const gchar *name;
|
|
|
|
gchar *ext;
|
|
|
|
gint copy_len;
|
|
|
|
gint number;
|
|
|
|
gchar *new_name;
|
|
|
|
|
|
|
|
name = gimp_object_get_name (GIMP_OBJECT (data));
|
|
|
|
|
|
|
|
ext = strrchr (name, '#');
|
|
|
|
copy_len = strlen (_("copy"));
|
|
|
|
|
|
|
|
if ((strlen (name) >= copy_len &&
|
|
|
|
strcmp (&name[strlen (name) - copy_len], _("copy")) == 0) ||
|
|
|
|
(ext && (number = atoi (ext + 1)) > 0 &&
|
|
|
|
((gint) (log10 (number) + 1)) == strlen (ext + 1)))
|
|
|
|
{
|
|
|
|
/* don't have redundant "copy"s */
|
|
|
|
new_name = g_strdup (name);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
new_name = g_strdup_printf (_("%s copy"), name);
|
|
|
|
}
|
|
|
|
|
|
|
|
gimp_object_set_name (GIMP_OBJECT (new_data), new_name);
|
|
|
|
|
|
|
|
g_free (new_name);
|
|
|
|
|
|
|
|
gimp_container_add (factory->container, GIMP_OBJECT (new_data));
|
|
|
|
g_object_unref (new_data);
|
|
|
|
}
|
|
|
|
|
|
|
|
return new_data;
|
|
|
|
}
|
|
|
|
|
2001-02-14 01:42:12 +00:00
|
|
|
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
|
2002-12-02 13:39:09 +00:00
|
|
|
gimp_data_factory_load_callback (GimpDatafileData *file_data)
|
2001-02-14 01:42:12 +00:00
|
|
|
{
|
|
|
|
GimpDataFactory *factory;
|
2001-12-03 13:44:59 +00:00
|
|
|
gint i;
|
2001-02-14 01:42:12 +00:00
|
|
|
|
2002-10-23 14:55:07 +00:00
|
|
|
factory = (GimpDataFactory *) file_data->user_data;
|
2001-02-14 01:42:12 +00:00
|
|
|
|
|
|
|
for (i = 0; i < factory->n_loader_entries; i++)
|
|
|
|
{
|
|
|
|
if (factory->loader_entries[i].extension)
|
|
|
|
{
|
2002-10-23 14:55:07 +00:00
|
|
|
if (gimp_datafiles_check_extension (file_data->filename,
|
2001-05-09 22:34:59 +00:00
|
|
|
factory->loader_entries[i].extension))
|
2001-02-14 01:42:12 +00:00
|
|
|
{
|
|
|
|
goto insert;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2001-11-16 12:23:01 +00:00
|
|
|
g_message (_("Trying legacy loader on\n"
|
|
|
|
"file '%s'\n"
|
|
|
|
"with unknown extension."),
|
2002-10-23 14:55:07 +00:00
|
|
|
file_data->filename);
|
2001-02-14 01:42:12 +00:00
|
|
|
goto insert;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
insert:
|
|
|
|
{
|
2002-11-30 16:31:39 +00:00
|
|
|
GimpBaseConfig *base_config;
|
|
|
|
GimpData *data;
|
2002-12-02 13:39:09 +00:00
|
|
|
GError *error = NULL;
|
2002-11-30 16:31:39 +00:00
|
|
|
|
|
|
|
base_config = GIMP_BASE_CONFIG (factory->gimp->config);
|
2001-02-14 01:42:12 +00:00
|
|
|
|
2002-11-30 16:31:39 +00:00
|
|
|
data = (GimpData *)
|
|
|
|
(* factory->loader_entries[i].load_func) (file_data->filename,
|
2002-12-02 13:39:09 +00:00
|
|
|
base_config->stingy_memory_use,
|
|
|
|
&error);
|
2001-02-14 01:42:12 +00:00
|
|
|
|
|
|
|
if (! data)
|
2001-08-12 15:39:23 +00:00
|
|
|
{
|
2002-12-02 13:39:09 +00:00
|
|
|
g_message (_("Warning: Failed to load data:\n%s"),
|
|
|
|
error->message);
|
|
|
|
g_clear_error (&error);
|
2001-08-12 15:39:23 +00:00
|
|
|
}
|
2001-02-14 01:42:12 +00:00
|
|
|
else
|
2001-08-12 15:39:23 +00:00
|
|
|
{
|
|
|
|
gimp_container_add (factory->container, GIMP_OBJECT (data));
|
2003-01-05 22:07:10 +00:00
|
|
|
g_object_unref (data);
|
2001-08-12 15:39:23 +00:00
|
|
|
}
|
2001-02-14 01:42:12 +00:00
|
|
|
}
|
|
|
|
}
|