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"
|
|
|
|
|
2002-12-02 21:39:09 +08:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
2001-08-14 22:53:55 +08:00
|
|
|
#include <glib-object.h>
|
2001-02-14 03:53:07 +08:00
|
|
|
|
2002-10-23 22:55:07 +08:00
|
|
|
#include "libgimpbase/gimpbase.h"
|
|
|
|
|
2001-05-10 06:34:59 +08:00
|
|
|
#include "core-types.h"
|
2001-02-14 03:53:07 +08:00
|
|
|
|
2002-12-01 00:31:39 +08:00
|
|
|
#include "config/gimpbaseconfig.h"
|
2002-12-30 02:58:24 +08:00
|
|
|
#include "config/gimpconfig-path.h"
|
2002-12-01 00:31:39 +08:00
|
|
|
|
|
|
|
#include "gimp.h"
|
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 "gimpdatalist.h"
|
2001-02-14 03:53:07 +08:00
|
|
|
|
2003-03-26 00:38:19 +08:00
|
|
|
#include "gimp-intl.h"
|
2001-02-14 09:42:12 +08:00
|
|
|
|
2001-02-14 03:53:07 +08:00
|
|
|
|
2004-01-29 05:53:50 +08:00
|
|
|
#define WRITABLE_PATH_KEY "gimp-data-factory-writable-path"
|
2001-08-11 22:39:19 +08:00
|
|
|
|
2001-02-14 03:53:07 +08:00
|
|
|
|
2004-01-29 05:53:50 +08:00
|
|
|
static void gimp_data_factory_class_init (GimpDataFactoryClass *klass);
|
|
|
|
static void gimp_data_factory_init (GimpDataFactory *factory);
|
2002-01-31 00:14:26 +08:00
|
|
|
|
2004-01-29 05:53:50 +08:00
|
|
|
static void gimp_data_factory_finalize (GObject *object);
|
|
|
|
|
|
|
|
static gint64 gimp_data_factory_get_memsize (GimpObject *object,
|
|
|
|
gint64 *gui_size);
|
|
|
|
|
|
|
|
static gchar * gimp_data_factory_get_save_dir (GimpDataFactory *factory);
|
|
|
|
static void gimp_data_factory_load_data (const GimpDatafileData *file_data,
|
|
|
|
gpointer user_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)
|
|
|
|
{
|
2002-12-01 00:31:39 +08:00
|
|
|
factory->gimp = NULL;
|
2001-02-14 03:53:07 +08:00
|
|
|
factory->container = NULL;
|
2002-12-02 21:39:09 +08:00
|
|
|
factory->path_property_name = NULL;
|
2004-01-29 05:53:50 +08:00
|
|
|
factory->writable_property_name = 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
|
|
|
{
|
2002-12-02 21:39:09 +08:00
|
|
|
g_object_unref (factory->container);
|
2001-07-05 03:31:35 +08:00
|
|
|
factory->container = NULL;
|
|
|
|
}
|
2001-02-14 03:53:07 +08:00
|
|
|
|
2002-12-02 21:39:09 +08:00
|
|
|
if (factory->path_property_name)
|
|
|
|
{
|
|
|
|
g_free (factory->path_property_name);
|
|
|
|
factory->path_property_name = NULL;
|
|
|
|
}
|
|
|
|
|
2004-01-29 05:53:50 +08:00
|
|
|
if (factory->writable_property_name)
|
|
|
|
{
|
|
|
|
g_free (factory->writable_property_name);
|
|
|
|
factory->writable_property_name = NULL;
|
|
|
|
}
|
|
|
|
|
2001-08-11 22:39:19 +08:00
|
|
|
G_OBJECT_CLASS (parent_class)->finalize (object);
|
2001-02-14 03:53:07 +08:00
|
|
|
}
|
|
|
|
|
2003-11-17 01:51:36 +08:00
|
|
|
static gint64
|
2003-08-25 18:49:33 +08:00
|
|
|
gimp_data_factory_get_memsize (GimpObject *object,
|
2003-11-17 01:51:36 +08:00
|
|
|
gint64 *gui_size)
|
2002-01-31 00:14:26 +08:00
|
|
|
{
|
|
|
|
GimpDataFactory *factory;
|
2003-11-17 01:51:36 +08:00
|
|
|
gint64 memsize = 0;
|
2002-01-31 00:14:26 +08:00
|
|
|
|
|
|
|
factory = GIMP_DATA_FACTORY (object);
|
|
|
|
|
2003-08-25 18:49:33 +08:00
|
|
|
memsize += gimp_object_get_memsize (GIMP_OBJECT (factory->container),
|
|
|
|
gui_size);
|
2002-01-31 00:14:26 +08:00
|
|
|
|
2003-08-25 18:49:33 +08:00
|
|
|
return memsize + GIMP_OBJECT_CLASS (parent_class)->get_memsize (object,
|
|
|
|
gui_size);
|
2002-01-31 00:14:26 +08:00
|
|
|
}
|
|
|
|
|
2001-02-14 03:53:07 +08:00
|
|
|
GimpDataFactory *
|
2002-12-02 21:39:09 +08:00
|
|
|
gimp_data_factory_new (Gimp *gimp,
|
|
|
|
GType data_type,
|
|
|
|
const gchar *path_property_name,
|
2004-01-29 05:53:50 +08:00
|
|
|
const gchar *writable_property_name,
|
2002-12-02 21:39:09 +08:00
|
|
|
const GimpDataFactoryLoaderEntry *loader_entries,
|
|
|
|
gint n_loader_entries,
|
|
|
|
GimpDataNewFunc new_func,
|
|
|
|
GimpDataGetStandardFunc standard_func)
|
2001-02-14 03:53:07 +08:00
|
|
|
{
|
|
|
|
GimpDataFactory *factory;
|
|
|
|
|
2002-12-01 00:31:39 +08:00
|
|
|
g_return_val_if_fail (GIMP_IS_GIMP (gimp), NULL);
|
2001-08-11 22:39:19 +08:00
|
|
|
g_return_val_if_fail (g_type_is_a (data_type, GIMP_TYPE_DATA), NULL);
|
2002-12-02 21:39:09 +08:00
|
|
|
g_return_val_if_fail (path_property_name != NULL, NULL);
|
2004-01-29 05:53:50 +08:00
|
|
|
g_return_val_if_fail (writable_property_name != 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-12-01 00:31:39 +08:00
|
|
|
factory->gimp = gimp;
|
2002-01-31 00:14:26 +08:00
|
|
|
factory->container = gimp_data_list_new (data_type);
|
2001-02-14 03:53:07 +08:00
|
|
|
|
2002-12-02 21:39:09 +08:00
|
|
|
factory->path_property_name = g_strdup (path_property_name);
|
2004-01-29 05:53:50 +08:00
|
|
|
factory->writable_property_name = g_strdup (writable_property_name);
|
2001-02-14 09:42:12 +08: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-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
|
|
|
{
|
2004-01-29 05:53:50 +08:00
|
|
|
gchar *path;
|
|
|
|
gchar *writable_path;
|
2002-12-02 21:39:09 +08:00
|
|
|
|
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
|
|
|
|
2003-01-06 06:07:10 +08:00
|
|
|
g_object_get (factory->gimp->config,
|
2004-01-29 05:53:50 +08:00
|
|
|
factory->path_property_name, &path,
|
|
|
|
factory->writable_property_name, &writable_path,
|
2002-12-02 21:39:09 +08:00
|
|
|
NULL);
|
|
|
|
|
|
|
|
if (path && strlen (path))
|
2001-02-14 09:42:12 +08:00
|
|
|
{
|
2004-01-29 05:53:50 +08:00
|
|
|
GList *writable_list = NULL;
|
2003-12-08 21:29:14 +08:00
|
|
|
gchar *tmp;
|
2002-12-30 02:58:24 +08:00
|
|
|
|
|
|
|
tmp = gimp_config_path_expand (path, TRUE, NULL);
|
|
|
|
g_free (path);
|
|
|
|
path = tmp;
|
|
|
|
|
2004-01-29 05:53:50 +08:00
|
|
|
if (writable_path)
|
|
|
|
{
|
|
|
|
tmp = gimp_config_path_expand (writable_path, TRUE, NULL);
|
|
|
|
g_free (writable_path);
|
|
|
|
writable_path = tmp;
|
|
|
|
|
|
|
|
writable_list = gimp_path_parse (writable_path, 16, TRUE, NULL);
|
|
|
|
|
|
|
|
g_object_set_data (G_OBJECT (factory), WRITABLE_PATH_KEY,
|
|
|
|
writable_list);
|
|
|
|
}
|
|
|
|
|
2002-12-02 21:39:09 +08:00
|
|
|
gimp_datafiles_read_directories (path,
|
2002-10-23 22:55:07 +08:00
|
|
|
G_FILE_TEST_EXISTS,
|
2003-07-03 01:11:00 +08:00
|
|
|
gimp_data_factory_load_data,
|
2001-05-10 06:34:59 +08:00
|
|
|
factory);
|
2004-01-29 05:53:50 +08:00
|
|
|
|
|
|
|
if (writable_path)
|
|
|
|
{
|
|
|
|
gimp_path_free (writable_list);
|
|
|
|
g_object_set_data (G_OBJECT (factory), WRITABLE_PATH_KEY, NULL);
|
|
|
|
}
|
2001-02-14 09:42:12 +08:00
|
|
|
}
|
|
|
|
|
2002-12-02 21:39:09 +08:00
|
|
|
g_free (path);
|
2004-01-29 05:53:50 +08:00
|
|
|
g_free (writable_path);
|
2002-12-02 21:39:09 +08:00
|
|
|
|
2003-12-08 21:29:14 +08:00
|
|
|
gimp_container_thaw (factory->container);
|
2001-02-14 09:42:12 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
gimp_data_factory_data_save (GimpDataFactory *factory)
|
2001-02-14 03:53:07 +08:00
|
|
|
{
|
2004-01-29 05:53:50 +08:00
|
|
|
GList *list;
|
|
|
|
gchar *writable_dir;
|
2001-02-18 05:20:10 +08:00
|
|
|
|
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;
|
|
|
|
|
2004-01-29 05:53:50 +08:00
|
|
|
writable_dir = gimp_data_factory_get_save_dir (factory);
|
2001-02-18 05:20:10 +08:00
|
|
|
|
2004-01-29 05:53:50 +08:00
|
|
|
if (! writable_dir)
|
|
|
|
return;
|
2002-12-30 02:58:24 +08:00
|
|
|
|
2004-01-29 05:53:50 +08:00
|
|
|
gimp_container_freeze (factory->container);
|
2001-02-18 05:20:10 +08:00
|
|
|
|
2004-01-29 05:53:50 +08:00
|
|
|
for (list = GIMP_LIST (factory->container)->list;
|
|
|
|
list;
|
|
|
|
list = g_list_next (list))
|
|
|
|
{
|
|
|
|
GimpData *data = list->data;
|
2001-02-18 05:20:10 +08:00
|
|
|
|
2004-01-29 05:53:50 +08:00
|
|
|
if (! data->filename)
|
|
|
|
gimp_data_create_filename (data, GIMP_OBJECT (data)->name, writable_dir);
|
2001-02-18 05:20:10 +08:00
|
|
|
|
2004-01-29 05:53:50 +08:00
|
|
|
if (data->dirty)
|
|
|
|
{
|
|
|
|
GError *error = NULL;
|
2002-12-02 21:39:09 +08:00
|
|
|
|
2004-01-29 05:53:50 +08:00
|
|
|
if (! gimp_data_save (data, &error))
|
2002-12-02 21:39:09 +08:00
|
|
|
{
|
2004-01-29 05:53:50 +08:00
|
|
|
/* check if there actually was an error (no error
|
|
|
|
* means the data class does not implement save)
|
|
|
|
*/
|
|
|
|
if (error)
|
2002-12-02 21:39:09 +08:00
|
|
|
{
|
2004-01-29 05:53:50 +08:00
|
|
|
g_message (_("Warning: Failed to save data:\n%s"),
|
|
|
|
error->message);
|
|
|
|
g_clear_error (&error);
|
2002-12-02 21:39:09 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2001-02-18 05:20:10 +08:00
|
|
|
}
|
|
|
|
|
2004-01-29 05:53:50 +08:00
|
|
|
gimp_container_thaw (factory->container);
|
|
|
|
|
|
|
|
g_free (writable_dir);
|
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)
|
|
|
|
{
|
2002-12-01 00:31:39 +08:00
|
|
|
GimpBaseConfig *base_config;
|
|
|
|
GimpData *data;
|
2001-02-14 09:42:12 +08:00
|
|
|
|
2002-12-01 00:31:39 +08:00
|
|
|
base_config = GIMP_BASE_CONFIG (factory->gimp->config);
|
|
|
|
|
|
|
|
data = factory->data_new_func (name, base_config->stingy_memory_use);
|
2001-02-14 09:42:12 +08:00
|
|
|
|
|
|
|
gimp_container_add (factory->container, GIMP_OBJECT (data));
|
2003-01-06 06:07:10 +08:00
|
|
|
g_object_unref (data);
|
2001-02-14 09:42:12 +08:00
|
|
|
|
|
|
|
return data;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2002-12-02 21:39:09 +08: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 09:42:12 +08: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;
|
|
|
|
}
|
|
|
|
|
2004-01-29 05:53:50 +08:00
|
|
|
gboolean
|
|
|
|
gimp_data_factory_data_save_single (GimpDataFactory *factory,
|
|
|
|
GimpData *data)
|
|
|
|
{
|
|
|
|
gchar *writable_dir;
|
|
|
|
GError *error = NULL;
|
|
|
|
|
|
|
|
g_return_val_if_fail (GIMP_IS_DATA_FACTORY (factory), FALSE);
|
|
|
|
g_return_val_if_fail (GIMP_IS_DATA (data), FALSE);
|
|
|
|
|
|
|
|
if (! data->dirty)
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
writable_dir = gimp_data_factory_get_save_dir (factory);
|
|
|
|
|
|
|
|
if (! writable_dir)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
if (! data->filename)
|
|
|
|
gimp_data_create_filename (data, GIMP_OBJECT (data)->name, writable_dir);
|
|
|
|
|
|
|
|
g_free (writable_dir);
|
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* private functions */
|
|
|
|
|
|
|
|
static gchar *
|
|
|
|
gimp_data_factory_get_save_dir (GimpDataFactory *factory)
|
|
|
|
{
|
|
|
|
gchar *path;
|
|
|
|
gchar *writable_path;
|
|
|
|
gchar *tmp;
|
|
|
|
GList *path_list;
|
|
|
|
GList *writable_list;
|
|
|
|
GList *list;
|
|
|
|
gchar *writable_dir = NULL;
|
|
|
|
|
|
|
|
g_object_get (factory->gimp->config,
|
|
|
|
factory->path_property_name, &path,
|
|
|
|
factory->writable_property_name, &writable_path,
|
|
|
|
NULL);
|
|
|
|
|
|
|
|
tmp = gimp_config_path_expand (path, TRUE, NULL);
|
|
|
|
g_free (path);
|
|
|
|
path = tmp;
|
|
|
|
|
|
|
|
tmp = gimp_config_path_expand (writable_path, TRUE, NULL);
|
|
|
|
g_free (writable_path);
|
|
|
|
writable_path = tmp;
|
|
|
|
|
|
|
|
path_list = gimp_path_parse (path, 16, TRUE, NULL);
|
|
|
|
writable_list = gimp_path_parse (writable_path, 16, TRUE, NULL);
|
|
|
|
|
|
|
|
g_free (path);
|
|
|
|
g_free (writable_path);
|
|
|
|
|
|
|
|
for (list = writable_list; list; list = g_list_next (list))
|
|
|
|
{
|
|
|
|
GList *found;
|
|
|
|
|
|
|
|
found = g_list_find_custom (path_list, list->data, (GCompareFunc) strcmp);
|
|
|
|
|
|
|
|
if (found)
|
|
|
|
{
|
|
|
|
writable_dir = g_strdup (found->data);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
gimp_path_free (path_list);
|
|
|
|
gimp_path_free (writable_list);
|
|
|
|
|
|
|
|
return writable_dir;
|
|
|
|
}
|
|
|
|
|
2001-02-14 09:42:12 +08:00
|
|
|
static void
|
2003-07-03 01:11:00 +08:00
|
|
|
gimp_data_factory_load_data (const GimpDatafileData *file_data,
|
|
|
|
gpointer user_data)
|
2001-02-14 09:42:12 +08:00
|
|
|
{
|
2004-01-29 05:53:50 +08:00
|
|
|
GimpDataFactory *factory = GIMP_DATA_FACTORY (user_data);
|
2001-12-03 21:44:59 +08:00
|
|
|
gint i;
|
2001-02-14 09:42:12 +08:00
|
|
|
|
|
|
|
for (i = 0; i < factory->n_loader_entries; i++)
|
|
|
|
{
|
|
|
|
if (factory->loader_entries[i].extension)
|
|
|
|
{
|
2002-10-23 22:55:07 +08:00
|
|
|
if (gimp_datafiles_check_extension (file_data->filename,
|
2001-05-10 06:34:59 +08:00
|
|
|
factory->loader_entries[i].extension))
|
2001-02-14 09:42:12 +08:00
|
|
|
{
|
|
|
|
goto insert;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2003-11-14 23:33:40 +08:00
|
|
|
g_message (_("Trying legacy loader on file '%s' "
|
2001-11-16 20:23:01 +08:00
|
|
|
"with unknown extension."),
|
2004-01-24 01:24:44 +08:00
|
|
|
gimp_filename_to_utf8 (file_data->filename));
|
2001-02-14 09:42:12 +08:00
|
|
|
goto insert;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
insert:
|
|
|
|
{
|
2002-12-01 00:31:39 +08:00
|
|
|
GimpBaseConfig *base_config;
|
|
|
|
GimpData *data;
|
2002-12-02 21:39:09 +08:00
|
|
|
GError *error = NULL;
|
2002-12-01 00:31:39 +08:00
|
|
|
|
|
|
|
base_config = GIMP_BASE_CONFIG (factory->gimp->config);
|
2001-02-14 09:42:12 +08:00
|
|
|
|
2002-12-01 00:31:39 +08:00
|
|
|
data = (GimpData *)
|
|
|
|
(* factory->loader_entries[i].load_func) (file_data->filename,
|
2002-12-02 21:39:09 +08:00
|
|
|
base_config->stingy_memory_use,
|
|
|
|
&error);
|
2001-02-14 09:42:12 +08:00
|
|
|
|
|
|
|
if (! data)
|
2001-08-12 23:39:23 +08:00
|
|
|
{
|
2002-12-02 21:39:09 +08:00
|
|
|
g_message (_("Warning: Failed to load data:\n%s"),
|
|
|
|
error->message);
|
|
|
|
g_clear_error (&error);
|
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
|
|
|
{
|
2004-01-29 05:53:50 +08:00
|
|
|
GList *writable_list;
|
|
|
|
gboolean writable = FALSE;
|
|
|
|
|
|
|
|
writable_list = g_object_get_data (G_OBJECT (factory),
|
|
|
|
WRITABLE_PATH_KEY);
|
|
|
|
|
|
|
|
writable = (g_list_find_custom (writable_list, file_data->dirname,
|
|
|
|
(GCompareFunc) strcmp) != NULL);
|
|
|
|
|
|
|
|
gimp_data_set_filename (data, file_data->filename, writable);
|
|
|
|
data->dirty = FALSE;
|
|
|
|
|
2001-08-12 23:39:23 +08:00
|
|
|
gimp_container_add (factory->container, GIMP_OBJECT (data));
|
2003-01-06 06:07:10 +08:00
|
|
|
g_object_unref (data);
|
2001-08-12 23:39:23 +08:00
|
|
|
}
|
2001-02-14 09:42:12 +08:00
|
|
|
}
|
|
|
|
}
|