1998-10-30 18:21:33 +08:00
|
|
|
/* parasitelist.c: Copyright 1998 Jay Cox <jaycox@earthlink.net>
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*/
|
2000-12-17 05:37:03 +08:00
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
1999-02-21 07:20:54 +08:00
|
|
|
#include <string.h>
|
2002-05-15 06:48:24 +08:00
|
|
|
#ifdef HAVE_UNISTD_H
|
|
|
|
#include <unistd.h>
|
|
|
|
#endif
|
1999-02-21 07:20:54 +08:00
|
|
|
|
2001-08-14 22:53:55 +08:00
|
|
|
#include <glib-object.h>
|
2000-12-17 05:37:03 +08:00
|
|
|
|
2002-09-07 06:25:19 +08:00
|
|
|
#ifdef G_OS_WIN32
|
|
|
|
#include <io.h>
|
|
|
|
#endif
|
|
|
|
|
2001-05-21 21:58:46 +08:00
|
|
|
#include "libgimpbase/gimpbase.h"
|
|
|
|
|
2001-07-10 03:48:30 +08:00
|
|
|
#include "core-types.h"
|
2000-12-17 05:37:03 +08:00
|
|
|
|
2002-05-15 06:48:24 +08:00
|
|
|
#include "config/gimpconfig.h"
|
2003-03-06 04:21:50 +08:00
|
|
|
#include "config/gimpconfigwriter.h"
|
2002-05-15 06:48:24 +08:00
|
|
|
#include "config/gimpscanner.h"
|
|
|
|
|
2001-11-23 07:46:13 +08:00
|
|
|
#include "gimpmarshal.h"
|
2001-07-10 03:48:30 +08:00
|
|
|
#include "gimpparasitelist.h"
|
2000-05-27 06:28:40 +08:00
|
|
|
|
|
|
|
|
1998-10-30 18:21:33 +08:00
|
|
|
enum
|
|
|
|
{
|
|
|
|
ADD,
|
|
|
|
REMOVE,
|
|
|
|
LAST_SIGNAL
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2002-05-15 06:48:24 +08:00
|
|
|
static void gimp_parasite_list_class_init (GimpParasiteListClass *klass);
|
|
|
|
static void gimp_parasite_list_init (GimpParasiteList *list);
|
|
|
|
static void gimp_parasite_list_finalize (GObject *object);
|
2003-08-25 18:49:33 +08:00
|
|
|
static gsize gimp_parasite_list_get_memsize (GimpObject *object,
|
|
|
|
gsize *gui_size);
|
2002-05-15 06:48:24 +08:00
|
|
|
|
|
|
|
static void gimp_parasite_list_config_iface_init (gpointer iface,
|
|
|
|
gpointer iface_data);
|
2003-10-11 22:30:18 +08:00
|
|
|
static gboolean gimp_parasite_list_serialize (GimpConfig *list,
|
2003-03-06 04:21:50 +08:00
|
|
|
GimpConfigWriter *writer,
|
|
|
|
gpointer data);
|
2003-10-11 22:30:18 +08:00
|
|
|
static gboolean gimp_parasite_list_deserialize (GimpConfig *list,
|
2003-03-06 04:21:50 +08:00
|
|
|
GScanner *scanner,
|
|
|
|
gint nest_level,
|
|
|
|
gpointer data);
|
2002-05-15 06:48:24 +08:00
|
|
|
|
|
|
|
static void parasite_serialize (const gchar *key,
|
|
|
|
GimpParasite *parasite,
|
2003-03-06 04:21:50 +08:00
|
|
|
GimpConfigWriter *writer);
|
2002-05-15 06:48:24 +08:00
|
|
|
static void parasite_copy (const gchar *key,
|
|
|
|
GimpParasite *parasite,
|
|
|
|
GimpParasiteList *list);
|
|
|
|
static gboolean parasite_free (const gchar *key,
|
|
|
|
GimpParasite *parasite,
|
|
|
|
gpointer unused);
|
2003-08-25 18:49:33 +08:00
|
|
|
static void parasite_count_if_persistent (const gchar *key,
|
|
|
|
GimpParasite *parasite,
|
2002-05-15 06:48:24 +08:00
|
|
|
gint *count);
|
2001-01-10 08:36:54 +08:00
|
|
|
|
|
|
|
|
2001-07-05 06:59:25 +08:00
|
|
|
static guint parasite_list_signals[LAST_SIGNAL] = { 0 };
|
1998-10-30 18:21:33 +08:00
|
|
|
|
2001-08-11 22:39:19 +08:00
|
|
|
static GimpObjectClass *parent_class = NULL;
|
|
|
|
|
2002-05-15 21:48:47 +08:00
|
|
|
static const gchar *parasite_symbol = "parasite";
|
|
|
|
|
1998-10-30 18:21:33 +08:00
|
|
|
|
2001-07-25 23:22:55 +08:00
|
|
|
GType
|
|
|
|
gimp_parasite_list_get_type (void)
|
|
|
|
{
|
2001-08-11 22:39:19 +08:00
|
|
|
static GType list_type = 0;
|
2001-07-25 23:22:55 +08:00
|
|
|
|
2001-08-11 22:39:19 +08:00
|
|
|
if (! list_type)
|
2001-07-25 23:22:55 +08:00
|
|
|
{
|
2001-08-11 22:39:19 +08:00
|
|
|
static const GTypeInfo list_info =
|
2001-07-25 23:22:55 +08:00
|
|
|
{
|
2001-08-11 22:39:19 +08:00
|
|
|
sizeof (GimpParasiteListClass),
|
|
|
|
(GBaseInitFunc) NULL,
|
|
|
|
(GBaseFinalizeFunc) NULL,
|
|
|
|
(GClassInitFunc) gimp_parasite_list_class_init,
|
|
|
|
NULL, /* class_finalize */
|
|
|
|
NULL, /* class_data */
|
2001-07-25 23:22:55 +08:00
|
|
|
sizeof (GimpParasiteList),
|
2001-08-11 22:39:19 +08:00
|
|
|
0, /* n_preallocs */
|
|
|
|
(GInstanceInitFunc) gimp_parasite_list_init,
|
2001-07-25 23:22:55 +08:00
|
|
|
};
|
2003-08-25 18:49:33 +08:00
|
|
|
static const GInterfaceInfo list_iface_info =
|
|
|
|
{
|
2002-05-15 06:48:24 +08:00
|
|
|
gimp_parasite_list_config_iface_init,
|
2003-08-25 18:49:33 +08:00
|
|
|
NULL, /* iface_finalize */
|
2002-05-15 06:48:24 +08:00
|
|
|
NULL /* iface_data */
|
|
|
|
};
|
2001-07-25 23:22:55 +08:00
|
|
|
|
2001-08-11 22:39:19 +08:00
|
|
|
list_type = g_type_register_static (GIMP_TYPE_OBJECT,
|
2003-08-25 18:49:33 +08:00
|
|
|
"GimpParasiteList",
|
2001-08-11 22:39:19 +08:00
|
|
|
&list_info, 0);
|
2003-10-11 22:30:18 +08:00
|
|
|
g_type_add_interface_static (list_type, GIMP_TYPE_CONFIG,
|
2002-05-15 06:48:24 +08:00
|
|
|
&list_iface_info);
|
2001-07-25 23:22:55 +08:00
|
|
|
}
|
|
|
|
|
2001-08-11 22:39:19 +08:00
|
|
|
return list_type;
|
2001-07-25 23:22:55 +08:00
|
|
|
}
|
|
|
|
|
1998-10-30 18:21:33 +08:00
|
|
|
static void
|
2001-07-05 06:59:25 +08:00
|
|
|
gimp_parasite_list_class_init (GimpParasiteListClass *klass)
|
1998-10-30 18:21:33 +08:00
|
|
|
{
|
2002-01-31 00:14:26 +08:00
|
|
|
GObjectClass *object_class;
|
|
|
|
GimpObjectClass *gimp_object_class;
|
1998-10-30 18:21:33 +08:00
|
|
|
|
2002-01-31 00:14:26 +08:00
|
|
|
object_class = G_OBJECT_CLASS (klass);
|
|
|
|
gimp_object_class = GIMP_OBJECT_CLASS (klass);
|
2001-08-11 22:39:19 +08:00
|
|
|
|
|
|
|
parent_class = g_type_class_peek_parent (klass);
|
1998-10-30 18:21:33 +08:00
|
|
|
|
|
|
|
parasite_list_signals[ADD] =
|
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
|
|
|
g_signal_new ("add",
|
|
|
|
G_TYPE_FROM_CLASS (klass),
|
|
|
|
G_SIGNAL_RUN_FIRST,
|
|
|
|
G_STRUCT_OFFSET (GimpParasiteListClass, add),
|
|
|
|
NULL, NULL,
|
2001-11-23 07:46:13 +08:00
|
|
|
gimp_marshal_VOID__POINTER,
|
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
|
|
|
G_TYPE_NONE, 1,
|
|
|
|
G_TYPE_POINTER);
|
2000-05-27 06:28:40 +08:00
|
|
|
|
2003-08-25 18:49:33 +08:00
|
|
|
parasite_list_signals[REMOVE] =
|
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
|
|
|
g_signal_new ("remove",
|
|
|
|
G_TYPE_FROM_CLASS (klass),
|
|
|
|
G_SIGNAL_RUN_FIRST,
|
|
|
|
G_STRUCT_OFFSET (GimpParasiteListClass, remove),
|
|
|
|
NULL, NULL,
|
2001-11-23 07:46:13 +08:00
|
|
|
gimp_marshal_VOID__POINTER,
|
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
|
|
|
G_TYPE_NONE, 1,
|
2001-08-14 22:53:55 +08:00
|
|
|
G_TYPE_POINTER);
|
2001-01-10 08:36:54 +08:00
|
|
|
|
2002-01-31 00:14:26 +08:00
|
|
|
object_class->finalize = gimp_parasite_list_finalize;
|
|
|
|
|
|
|
|
gimp_object_class->get_memsize = gimp_parasite_list_get_memsize;
|
2001-01-10 08:36:54 +08:00
|
|
|
|
2002-01-31 00:14:26 +08:00
|
|
|
klass->add = NULL;
|
|
|
|
klass->remove = NULL;
|
1998-10-30 18:21:33 +08:00
|
|
|
}
|
|
|
|
|
2002-05-15 06:48:24 +08:00
|
|
|
static void
|
|
|
|
gimp_parasite_list_config_iface_init (gpointer iface,
|
|
|
|
gpointer iface_data)
|
|
|
|
{
|
|
|
|
GimpConfigInterface *config_iface = (GimpConfigInterface *) iface;
|
|
|
|
|
|
|
|
config_iface->serialize = gimp_parasite_list_serialize;
|
|
|
|
config_iface->deserialize = gimp_parasite_list_deserialize;
|
|
|
|
}
|
|
|
|
|
2001-07-05 06:59:25 +08:00
|
|
|
static void
|
|
|
|
gimp_parasite_list_init (GimpParasiteList *list)
|
|
|
|
{
|
|
|
|
list->table = NULL;
|
|
|
|
}
|
|
|
|
|
1998-10-30 18:21:33 +08:00
|
|
|
static void
|
2001-08-11 22:39:19 +08:00
|
|
|
gimp_parasite_list_finalize (GObject *object)
|
1998-10-30 18:21:33 +08:00
|
|
|
{
|
2003-09-02 21:43:26 +08:00
|
|
|
GimpParasiteList *list = GIMP_PARASITE_LIST (object);
|
1998-10-30 18:21:33 +08:00
|
|
|
|
|
|
|
if (list->table)
|
2000-01-11 07:27:25 +08:00
|
|
|
{
|
2002-05-15 06:48:24 +08:00
|
|
|
g_hash_table_foreach_remove (list->table, (GHRFunc) parasite_free, NULL);
|
2000-01-11 07:27:25 +08:00
|
|
|
g_hash_table_destroy (list->table);
|
2001-08-11 22:39:19 +08:00
|
|
|
list->table = NULL;
|
2000-01-11 07:27:25 +08:00
|
|
|
}
|
2001-08-11 22:39:19 +08:00
|
|
|
|
|
|
|
G_OBJECT_CLASS (parent_class)->finalize (object);
|
|
|
|
}
|
|
|
|
|
2002-01-31 00:14:26 +08:00
|
|
|
static void
|
|
|
|
gimp_parasite_list_get_memsize_foreach (gpointer key,
|
|
|
|
gpointer p,
|
|
|
|
gpointer m)
|
|
|
|
{
|
|
|
|
GimpParasite *parasite;
|
|
|
|
gsize *memsize;
|
|
|
|
|
|
|
|
parasite = (GimpParasite *) p;
|
|
|
|
memsize = (gsize *) m;
|
|
|
|
|
|
|
|
*memsize += (sizeof (GimpParasite) +
|
|
|
|
strlen (parasite->name) + 1 +
|
|
|
|
parasite->size);
|
|
|
|
}
|
|
|
|
|
|
|
|
static gsize
|
2003-08-25 18:49:33 +08:00
|
|
|
gimp_parasite_list_get_memsize (GimpObject *object,
|
|
|
|
gsize *gui_size)
|
2002-01-31 00:14:26 +08:00
|
|
|
{
|
|
|
|
GimpParasiteList *list;
|
|
|
|
gsize memsize = 0;
|
|
|
|
|
|
|
|
list = GIMP_PARASITE_LIST (object);
|
|
|
|
|
|
|
|
if (list->table)
|
|
|
|
{
|
2002-05-15 21:48:47 +08:00
|
|
|
/* FIXME */
|
|
|
|
memsize += (g_hash_table_size (list->table) * 3 * sizeof (gpointer));
|
2002-01-31 00:14:26 +08:00
|
|
|
|
|
|
|
g_hash_table_foreach (list->table,
|
|
|
|
gimp_parasite_list_get_memsize_foreach,
|
|
|
|
&memsize);
|
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2002-05-15 19:05:32 +08:00
|
|
|
static gboolean
|
2003-10-11 22:30:18 +08:00
|
|
|
gimp_parasite_list_serialize (GimpConfig *list,
|
2003-03-06 04:21:50 +08:00
|
|
|
GimpConfigWriter *writer,
|
|
|
|
gpointer data)
|
2002-01-31 00:14:26 +08:00
|
|
|
{
|
2002-05-15 06:48:24 +08:00
|
|
|
if (GIMP_PARASITE_LIST (list)->table)
|
|
|
|
g_hash_table_foreach (GIMP_PARASITE_LIST (list)->table,
|
2003-03-06 04:21:50 +08:00
|
|
|
(GHFunc) parasite_serialize,
|
|
|
|
writer);
|
2002-05-15 19:05:32 +08:00
|
|
|
|
2003-03-06 04:21:50 +08:00
|
|
|
return TRUE;
|
2002-01-31 00:14:26 +08:00
|
|
|
}
|
|
|
|
|
2002-05-15 06:48:24 +08:00
|
|
|
static gboolean
|
2003-10-11 22:30:18 +08:00
|
|
|
gimp_parasite_list_deserialize (GimpConfig *list,
|
|
|
|
GScanner *scanner,
|
|
|
|
gint nest_level,
|
|
|
|
gpointer data)
|
2001-08-11 22:39:19 +08:00
|
|
|
{
|
2002-05-15 06:48:24 +08:00
|
|
|
GTokenType token;
|
|
|
|
|
2002-05-15 21:48:47 +08:00
|
|
|
g_scanner_scope_add_symbol (scanner, 0,
|
|
|
|
parasite_symbol, (gpointer) parasite_symbol);
|
2002-05-15 06:48:24 +08:00
|
|
|
|
|
|
|
token = G_TOKEN_LEFT_PAREN;
|
|
|
|
|
2002-05-27 22:04:21 +08:00
|
|
|
while (g_scanner_peek_next_token (scanner) == token)
|
2002-05-15 06:48:24 +08:00
|
|
|
{
|
|
|
|
token = g_scanner_get_next_token (scanner);
|
|
|
|
|
|
|
|
switch (token)
|
|
|
|
{
|
|
|
|
case G_TOKEN_LEFT_PAREN:
|
|
|
|
token = G_TOKEN_SYMBOL;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case G_TOKEN_SYMBOL:
|
2002-05-15 21:48:47 +08:00
|
|
|
if (scanner->value.v_symbol == parasite_symbol)
|
2002-05-15 06:48:24 +08:00
|
|
|
{
|
|
|
|
gchar *parasite_name = NULL;
|
|
|
|
gint parasite_flags = 0;
|
|
|
|
gchar *parasite_data = NULL;
|
|
|
|
GimpParasite *parasite;
|
|
|
|
|
|
|
|
token = G_TOKEN_STRING;
|
|
|
|
|
|
|
|
if (g_scanner_peek_next_token (scanner) != token)
|
|
|
|
break;
|
|
|
|
|
|
|
|
if (! gimp_scanner_parse_string (scanner, ¶site_name))
|
|
|
|
break;
|
|
|
|
|
|
|
|
token = G_TOKEN_INT;
|
|
|
|
|
|
|
|
if (g_scanner_peek_next_token (scanner) != token)
|
|
|
|
break;
|
|
|
|
|
|
|
|
if (! gimp_scanner_parse_int (scanner, ¶site_flags))
|
|
|
|
break;
|
|
|
|
|
|
|
|
token = G_TOKEN_STRING;
|
|
|
|
|
|
|
|
if (g_scanner_peek_next_token (scanner) != token)
|
|
|
|
break;
|
|
|
|
|
|
|
|
if (! gimp_scanner_parse_string (scanner, ¶site_data))
|
|
|
|
break;
|
|
|
|
|
|
|
|
parasite = gimp_parasite_new (parasite_name,
|
|
|
|
parasite_flags,
|
|
|
|
strlen (parasite_data),
|
|
|
|
parasite_data);
|
|
|
|
gimp_parasite_list_add (GIMP_PARASITE_LIST (list),
|
|
|
|
parasite); /* adds a copy */
|
|
|
|
gimp_parasite_free (parasite);
|
|
|
|
|
|
|
|
token = G_TOKEN_RIGHT_PAREN;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case G_TOKEN_RIGHT_PAREN:
|
|
|
|
token = G_TOKEN_LEFT_PAREN;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default: /* do nothing */
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2001-08-11 22:39:19 +08:00
|
|
|
|
2002-06-18 03:36:33 +08:00
|
|
|
return gimp_config_deserialize_return (scanner, token, nest_level);
|
1998-10-30 18:21:33 +08:00
|
|
|
}
|
|
|
|
|
2002-05-15 06:48:24 +08:00
|
|
|
GimpParasiteList *
|
|
|
|
gimp_parasite_list_new (void)
|
1998-10-30 18:21:33 +08:00
|
|
|
{
|
2002-05-15 06:48:24 +08:00
|
|
|
GimpParasiteList *list;
|
|
|
|
|
|
|
|
list = g_object_new (GIMP_TYPE_PARASITE_LIST, NULL);
|
|
|
|
|
|
|
|
return list;
|
1998-10-30 18:21:33 +08:00
|
|
|
}
|
|
|
|
|
2001-07-05 06:59:25 +08:00
|
|
|
GimpParasiteList *
|
|
|
|
gimp_parasite_list_copy (const GimpParasiteList *list)
|
1998-10-30 18:21:33 +08:00
|
|
|
{
|
2001-07-05 06:59:25 +08:00
|
|
|
GimpParasiteList *newlist;
|
2000-01-11 07:27:25 +08:00
|
|
|
|
2001-07-25 23:22:55 +08:00
|
|
|
g_return_val_if_fail (GIMP_IS_PARASITE_LIST (list), NULL);
|
|
|
|
|
2001-07-05 06:59:25 +08:00
|
|
|
newlist = gimp_parasite_list_new ();
|
2001-07-25 23:22:55 +08:00
|
|
|
|
1998-10-30 18:21:33 +08:00
|
|
|
if (list->table)
|
2002-05-15 06:48:24 +08:00
|
|
|
g_hash_table_foreach (list->table, (GHFunc) parasite_copy, newlist);
|
2000-01-11 07:27:25 +08:00
|
|
|
|
1998-10-30 18:21:33 +08:00
|
|
|
return newlist;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2003-08-25 18:49:33 +08:00
|
|
|
gimp_parasite_list_add (GimpParasiteList *list,
|
2001-07-05 06:59:25 +08:00
|
|
|
GimpParasite *parasite)
|
1998-10-30 18:21:33 +08:00
|
|
|
{
|
2001-07-25 23:22:55 +08:00
|
|
|
g_return_if_fail (GIMP_IS_PARASITE_LIST (list));
|
|
|
|
g_return_if_fail (parasite != NULL);
|
|
|
|
g_return_if_fail (parasite->name != NULL);
|
2000-01-11 07:27:25 +08:00
|
|
|
|
1998-10-30 18:21:33 +08:00
|
|
|
if (list->table == NULL)
|
2000-01-11 07:27:25 +08:00
|
|
|
list->table = g_hash_table_new (g_str_hash, g_str_equal);
|
|
|
|
|
2001-07-05 06:59:25 +08:00
|
|
|
gimp_parasite_list_remove (list, parasite->name);
|
|
|
|
parasite = gimp_parasite_copy (parasite);
|
|
|
|
g_hash_table_insert (list->table, parasite->name, parasite);
|
|
|
|
|
2003-01-06 06:07:10 +08:00
|
|
|
g_signal_emit (list, parasite_list_signals[ADD], 0, parasite);
|
1998-10-30 18:21:33 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2003-08-25 18:49:33 +08:00
|
|
|
gimp_parasite_list_remove (GimpParasiteList *list,
|
2001-07-05 06:59:25 +08:00
|
|
|
const gchar *name)
|
1998-10-30 18:21:33 +08:00
|
|
|
{
|
2001-07-05 06:59:25 +08:00
|
|
|
GimpParasite *parasite;
|
2000-01-11 07:27:25 +08:00
|
|
|
|
2001-07-25 23:22:55 +08:00
|
|
|
g_return_if_fail (GIMP_IS_PARASITE_LIST (list));
|
2000-01-11 07:27:25 +08:00
|
|
|
|
1998-10-30 18:21:33 +08:00
|
|
|
if (list->table)
|
|
|
|
{
|
2001-07-05 06:59:25 +08:00
|
|
|
parasite = gimp_parasite_list_find (list, name);
|
|
|
|
|
|
|
|
if (parasite)
|
2000-01-11 07:27:25 +08:00
|
|
|
{
|
|
|
|
g_hash_table_remove (list->table, name);
|
2001-07-05 06:59:25 +08:00
|
|
|
|
2003-01-06 06:07:10 +08:00
|
|
|
g_signal_emit (list, parasite_list_signals[REMOVE], 0, parasite);
|
2001-07-05 06:59:25 +08:00
|
|
|
|
|
|
|
gimp_parasite_free (parasite);
|
2000-01-11 07:27:25 +08:00
|
|
|
}
|
1998-10-30 18:21:33 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1998-12-16 19:23:30 +08:00
|
|
|
gint
|
2001-07-05 06:59:25 +08:00
|
|
|
gimp_parasite_list_length (GimpParasiteList *list)
|
1998-12-16 19:23:30 +08:00
|
|
|
{
|
2001-07-25 23:22:55 +08:00
|
|
|
g_return_val_if_fail (GIMP_IS_PARASITE_LIST (list), 0);
|
2000-01-11 07:27:25 +08:00
|
|
|
|
2001-07-25 23:22:55 +08:00
|
|
|
if (! list->table)
|
1998-12-16 19:23:30 +08:00
|
|
|
return 0;
|
2001-07-05 06:59:25 +08:00
|
|
|
|
2000-01-11 07:27:25 +08:00
|
|
|
return g_hash_table_size (list->table);
|
1998-12-16 19:23:30 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
gint
|
2001-07-05 06:59:25 +08:00
|
|
|
gimp_parasite_list_persistent_length (GimpParasiteList *list)
|
1998-12-16 19:23:30 +08:00
|
|
|
{
|
2002-05-15 06:48:24 +08:00
|
|
|
gint len = 0;
|
2000-01-11 07:27:25 +08:00
|
|
|
|
2001-07-25 23:22:55 +08:00
|
|
|
g_return_val_if_fail (GIMP_IS_PARASITE_LIST (list), 0);
|
2000-01-11 07:27:25 +08:00
|
|
|
|
1998-12-16 19:23:30 +08:00
|
|
|
if (!list->table)
|
|
|
|
return 0;
|
2000-01-11 07:27:25 +08:00
|
|
|
|
2002-05-15 06:48:24 +08:00
|
|
|
gimp_parasite_list_foreach (list,
|
|
|
|
(GHFunc) parasite_count_if_persistent, &len);
|
2000-05-27 06:28:40 +08:00
|
|
|
|
2002-05-15 06:48:24 +08:00
|
|
|
return len;
|
1998-12-16 19:23:30 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2003-08-25 18:49:33 +08:00
|
|
|
gimp_parasite_list_foreach (GimpParasiteList *list,
|
|
|
|
GHFunc function,
|
2001-07-05 06:59:25 +08:00
|
|
|
gpointer user_data)
|
1998-12-16 19:23:30 +08:00
|
|
|
{
|
2001-07-25 23:22:55 +08:00
|
|
|
g_return_if_fail (GIMP_IS_PARASITE_LIST (list));
|
2000-01-11 07:27:25 +08:00
|
|
|
|
1998-12-16 19:23:30 +08:00
|
|
|
if (!list->table)
|
|
|
|
return;
|
2000-01-11 07:27:25 +08:00
|
|
|
|
|
|
|
g_hash_table_foreach (list->table, function, user_data);
|
1998-12-16 19:23:30 +08:00
|
|
|
}
|
|
|
|
|
2000-05-27 06:28:40 +08:00
|
|
|
GimpParasite *
|
2003-08-25 18:49:33 +08:00
|
|
|
gimp_parasite_list_find (GimpParasiteList *list,
|
2001-07-05 06:59:25 +08:00
|
|
|
const gchar *name)
|
1998-10-30 18:21:33 +08:00
|
|
|
{
|
2001-08-11 22:39:19 +08:00
|
|
|
g_return_val_if_fail (GIMP_IS_PARASITE_LIST (list), NULL);
|
2000-01-11 07:27:25 +08:00
|
|
|
|
1998-10-30 18:21:33 +08:00
|
|
|
if (list->table)
|
2000-05-27 06:28:40 +08:00
|
|
|
return (GimpParasite *) g_hash_table_lookup (list->table, name);
|
1998-10-30 18:21:33 +08:00
|
|
|
else
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2002-05-15 06:48:24 +08:00
|
|
|
|
|
|
|
static void
|
2003-03-06 04:21:50 +08:00
|
|
|
parasite_serialize (const gchar *key,
|
|
|
|
GimpParasite *parasite,
|
|
|
|
GimpConfigWriter *writer)
|
2002-05-15 06:48:24 +08:00
|
|
|
{
|
|
|
|
GString *str;
|
|
|
|
const gchar *data;
|
|
|
|
guint32 len;
|
|
|
|
|
|
|
|
if (! gimp_parasite_is_persistent (parasite))
|
|
|
|
return;
|
|
|
|
|
2003-03-06 04:21:50 +08:00
|
|
|
gimp_config_writer_open (writer, parasite_symbol);
|
|
|
|
|
2002-05-15 06:48:24 +08:00
|
|
|
str = g_string_sized_new (64);
|
2003-08-25 18:49:33 +08:00
|
|
|
|
2003-03-06 04:21:50 +08:00
|
|
|
g_string_printf (str, "\"%s\" %lu \"",
|
2002-05-15 06:48:24 +08:00
|
|
|
gimp_parasite_name (parasite),
|
|
|
|
gimp_parasite_flags (parasite));
|
|
|
|
|
|
|
|
/*
|
|
|
|
* the current methodology is: never move the parasiterc from one
|
|
|
|
* system to another. If you want to do this you should probably
|
|
|
|
* write out parasites which contain any non-alphanumeric(+some)
|
|
|
|
* characters as \xHH sequences altogether.
|
|
|
|
*/
|
|
|
|
|
|
|
|
data = (const gchar *) gimp_parasite_data (parasite);
|
|
|
|
|
|
|
|
for (len = gimp_parasite_data_size (parasite); len > 0; len--, data++)
|
|
|
|
{
|
|
|
|
switch (*data)
|
|
|
|
{
|
|
|
|
case '\\': g_string_append_len (str, "\\\\", 2); break;
|
|
|
|
case '\0': g_string_append_len (str, "\\0" , 2); break;
|
|
|
|
case '"' : g_string_append_len (str, "\\\"", 2); break;
|
|
|
|
/* disabled, not portable! */
|
|
|
|
/* case '\n': fputs ("\\n", fp); break;*/
|
|
|
|
/* case '\r': fputs ("\\r", fp); break;*/
|
|
|
|
case 26 : g_string_append_len (str, "\\z", 2); break;
|
|
|
|
|
|
|
|
default : g_string_append_c (str, *data);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2003-08-25 18:49:33 +08:00
|
|
|
|
2003-03-06 21:22:11 +08:00
|
|
|
g_string_append (str, "\"");
|
2002-05-15 06:48:24 +08:00
|
|
|
|
2003-03-06 04:21:50 +08:00
|
|
|
gimp_config_writer_print (writer, str->str, str->len);
|
2002-05-15 06:48:24 +08:00
|
|
|
|
|
|
|
g_string_free (str, TRUE);
|
2003-03-06 04:21:50 +08:00
|
|
|
|
|
|
|
gimp_config_writer_close (writer);
|
|
|
|
gimp_config_writer_linefeed (writer);
|
2002-05-15 06:48:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
parasite_copy (const gchar *key,
|
|
|
|
GimpParasite *parasite,
|
|
|
|
GimpParasiteList *list)
|
|
|
|
{
|
|
|
|
gimp_parasite_list_add (list, parasite);
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
parasite_free (const gchar *key,
|
|
|
|
GimpParasite *parasite,
|
|
|
|
gpointer unused)
|
|
|
|
{
|
|
|
|
gimp_parasite_free (parasite);
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2003-08-25 18:49:33 +08:00
|
|
|
static void
|
|
|
|
parasite_count_if_persistent (const gchar *key,
|
|
|
|
GimpParasite *parasite,
|
2002-05-15 06:48:24 +08:00
|
|
|
gint *count)
|
|
|
|
{
|
|
|
|
if (gimp_parasite_is_persistent (parasite))
|
|
|
|
*count = *count + 1;
|
|
|
|
}
|