2006-01-12 08:50:44 +08:00
|
|
|
/* parasitelist.c: Copyright 1998 Jay Cox <jaycox@gimp.org>
|
1998-10-30 18:21:33 +08:00
|
|
|
*
|
2009-01-18 06:28:01 +08:00
|
|
|
* This program is free software: you can redistribute it and/or modify
|
1998-10-30 18:21:33 +08:00
|
|
|
* it under the terms of the GNU General Public License as published by
|
2009-01-18 06:28:01 +08:00
|
|
|
* the Free Software Foundation; either version 3 of the License, or
|
1998-10-30 18:21:33 +08:00
|
|
|
* (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
|
2009-01-18 06:28:01 +08:00
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
1998-10-30 18:21:33 +08:00
|
|
|
*/
|
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"
|
2005-01-26 03:11:26 +08:00
|
|
|
#include "libgimpconfig/gimpconfig.h"
|
2001-05-21 21:58:46 +08:00
|
|
|
|
2001-07-10 03:48:30 +08:00
|
|
|
#include "core-types.h"
|
2000-12-17 05:37:03 +08:00
|
|
|
|
2003-11-25 20:53:29 +08:00
|
|
|
#include "gimp-utils.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_finalize (GObject *object);
|
2003-11-17 01:51:36 +08:00
|
|
|
static gint64 gimp_parasite_list_get_memsize (GimpObject *object,
|
|
|
|
gint64 *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,
|
2004-11-23 22:28:43 +08:00
|
|
|
GimpConfigWriter *writer,
|
|
|
|
gpointer data);
|
2003-10-11 22:30:18 +08:00
|
|
|
static gboolean gimp_parasite_list_deserialize (GimpConfig *list,
|
2004-11-23 22:28:43 +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
|
|
|
|
|
|
|
|
2005-12-11 03:24:36 +08:00
|
|
|
G_DEFINE_TYPE_WITH_CODE (GimpParasiteList, gimp_parasite_list, GIMP_TYPE_OBJECT,
|
|
|
|
G_IMPLEMENT_INTERFACE (GIMP_TYPE_CONFIG,
|
2006-05-15 17:46:31 +08:00
|
|
|
gimp_parasite_list_config_iface_init))
|
1998-10-30 18:21:33 +08:00
|
|
|
|
2005-12-11 03:24:36 +08:00
|
|
|
#define parent_class gimp_parasite_list_parent_class
|
2001-08-11 22:39:19 +08:00
|
|
|
|
2005-12-11 03:24:36 +08:00
|
|
|
static guint parasite_list_signals[LAST_SIGNAL] = { 0 };
|
2006-04-18 18:08:10 +08:00
|
|
|
static const gchar parasite_symbol[] = "parasite";
|
2002-05-15 21:48:47 +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
|
|
|
{
|
2004-11-23 22:28:43 +08:00
|
|
|
GObjectClass *object_class = G_OBJECT_CLASS (klass);
|
|
|
|
GimpObjectClass *gimp_object_class = GIMP_OBJECT_CLASS (klass);
|
2001-08-11 22:39:19 +08:00
|
|
|
|
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",
|
2004-11-23 22:28:43 +08:00
|
|
|
G_TYPE_FROM_CLASS (klass),
|
|
|
|
G_SIGNAL_RUN_FIRST,
|
|
|
|
G_STRUCT_OFFSET (GimpParasiteListClass, add),
|
|
|
|
NULL, NULL,
|
|
|
|
gimp_marshal_VOID__POINTER,
|
|
|
|
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",
|
2004-11-23 22:28:43 +08:00
|
|
|
G_TYPE_FROM_CLASS (klass),
|
|
|
|
G_SIGNAL_RUN_FIRST,
|
|
|
|
G_STRUCT_OFFSET (GimpParasiteListClass, remove),
|
|
|
|
NULL, NULL,
|
|
|
|
gimp_marshal_VOID__POINTER,
|
|
|
|
G_TYPE_NONE, 1,
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2003-11-17 01:51:36 +08:00
|
|
|
static gint64
|
2003-08-25 18:49:33 +08:00
|
|
|
gimp_parasite_list_get_memsize (GimpObject *object,
|
2003-11-17 01:51:36 +08:00
|
|
|
gint64 *gui_size)
|
2002-01-31 00:14:26 +08:00
|
|
|
{
|
2004-11-23 22:28:43 +08:00
|
|
|
GimpParasiteList *list = GIMP_PARASITE_LIST (object);
|
2003-11-17 01:51:36 +08:00
|
|
|
gint64 memsize = 0;
|
2002-01-31 00:14:26 +08:00
|
|
|
|
2007-11-17 02:19:30 +08:00
|
|
|
memsize += gimp_g_hash_table_get_memsize_foreach (list->table,
|
|
|
|
(GimpMemsizeFunc)
|
|
|
|
gimp_parasite_get_memsize,
|
|
|
|
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
|
|
|
}
|
|
|
|
|
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,
|
2004-11-23 22:28:43 +08:00
|
|
|
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
|
|
|
{
|
2005-01-19 04:47:10 +08:00
|
|
|
gchar *parasite_name = NULL;
|
|
|
|
gint parasite_flags = 0;
|
|
|
|
guint8 *parasite_data = NULL;
|
|
|
|
gint parasite_data_size = 0;
|
2002-05-15 06:48:24 +08:00
|
|
|
GimpParasite *parasite;
|
|
|
|
|
|
|
|
token = G_TOKEN_STRING;
|
|
|
|
|
|
|
|
if (g_scanner_peek_next_token (scanner) != token)
|
|
|
|
break;
|
|
|
|
|
|
|
|
if (! gimp_scanner_parse_string (scanner, ¶site_name))
|
|
|
|
break;
|
|
|
|
|
2004-01-26 17:22:06 +08:00
|
|
|
token = G_TOKEN_INT;
|
2002-05-15 06:48:24 +08:00
|
|
|
|
|
|
|
if (g_scanner_peek_next_token (scanner) != token)
|
2004-01-26 17:22:06 +08:00
|
|
|
goto cleanup;
|
2002-05-15 06:48:24 +08:00
|
|
|
|
|
|
|
if (! gimp_scanner_parse_int (scanner, ¶site_flags))
|
2004-01-26 17:22:06 +08:00
|
|
|
goto cleanup;
|
2002-05-15 06:48:24 +08:00
|
|
|
|
2005-01-19 04:47:10 +08:00
|
|
|
token = G_TOKEN_INT;
|
2002-05-15 06:48:24 +08:00
|
|
|
|
|
|
|
if (g_scanner_peek_next_token (scanner) != token)
|
2005-01-19 04:47:10 +08:00
|
|
|
{
|
|
|
|
/* old format -- plain string */
|
2002-05-15 06:48:24 +08:00
|
|
|
|
2005-01-19 04:47:10 +08:00
|
|
|
gchar *str;
|
|
|
|
|
|
|
|
if (g_scanner_peek_next_token (scanner) != G_TOKEN_STRING)
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
if (! gimp_scanner_parse_string (scanner, &str))
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
parasite_data_size = strlen (str);
|
2006-04-02 22:44:32 +08:00
|
|
|
parasite_data = (guint8 *) str;
|
2005-01-19 04:47:10 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* new format -- properly encoded binary data */
|
|
|
|
|
|
|
|
if (! gimp_scanner_parse_int (scanner, ¶site_data_size))
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
token = G_TOKEN_STRING;
|
|
|
|
|
|
|
|
if (g_scanner_peek_next_token (scanner) != token)
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
if (! gimp_scanner_parse_data (scanner, parasite_data_size,
|
|
|
|
¶site_data))
|
|
|
|
goto cleanup;
|
|
|
|
}
|
2002-05-15 06:48:24 +08:00
|
|
|
|
|
|
|
parasite = gimp_parasite_new (parasite_name,
|
|
|
|
parasite_flags,
|
2005-01-19 04:47:10 +08:00
|
|
|
parasite_data_size,
|
2002-05-15 06:48:24 +08:00
|
|
|
parasite_data);
|
|
|
|
gimp_parasite_list_add (GIMP_PARASITE_LIST (list),
|
|
|
|
parasite); /* adds a copy */
|
|
|
|
gimp_parasite_free (parasite);
|
|
|
|
|
|
|
|
token = G_TOKEN_RIGHT_PAREN;
|
2004-01-26 17:22:06 +08:00
|
|
|
|
|
|
|
g_free (parasite_data);
|
2005-01-19 04:47:10 +08:00
|
|
|
cleanup:
|
2004-01-26 17:22:06 +08:00
|
|
|
g_free (parasite_name);
|
2002-05-15 06:48:24 +08:00
|
|
|
}
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2006-04-02 23:37:25 +08:00
|
|
|
void
|
2006-04-02 22:44:32 +08:00
|
|
|
gimp_parasite_list_add (GimpParasiteList *list,
|
|
|
|
const GimpParasite *parasite)
|
1998-10-30 18:21:33 +08:00
|
|
|
{
|
2006-04-02 22:44:32 +08:00
|
|
|
GimpParasite *copy;
|
|
|
|
|
2006-04-02 23:37:25 +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);
|
2006-04-02 22:44:32 +08:00
|
|
|
copy = gimp_parasite_copy (parasite);
|
|
|
|
g_hash_table_insert (list->table, copy->name, copy);
|
|
|
|
|
|
|
|
g_signal_emit (list, parasite_list_signals[ADD], 0, copy);
|
1998-10-30 18:21:33 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2003-08-25 18:49:33 +08:00
|
|
|
gimp_parasite_list_remove (GimpParasiteList *list,
|
2004-11-23 22:28:43 +08:00
|
|
|
const gchar *name)
|
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));
|
2000-01-11 07:27:25 +08:00
|
|
|
|
1998-10-30 18:21:33 +08:00
|
|
|
if (list->table)
|
|
|
|
{
|
2006-04-02 23:37:25 +08:00
|
|
|
GimpParasite *parasite;
|
|
|
|
|
|
|
|
parasite = (GimpParasite *) gimp_parasite_list_find (list, name);
|
2001-07-05 06:59:25 +08:00
|
|
|
|
|
|
|
if (parasite)
|
2004-11-23 22:28:43 +08:00
|
|
|
{
|
|
|
|
g_hash_table_remove (list->table, name);
|
2001-07-05 06:59:25 +08:00
|
|
|
|
2004-11-23 22:28:43 +08:00
|
|
|
g_signal_emit (list, parasite_list_signals[REMOVE], 0, parasite);
|
2001-07-05 06:59:25 +08:00
|
|
|
|
2004-11-23 22:28:43 +08:00
|
|
|
gimp_parasite_free (parasite);
|
|
|
|
}
|
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
|
|
|
|
2004-11-23 22:28:43 +08:00
|
|
|
if (! list->table)
|
1998-12-16 19:23:30 +08:00
|
|
|
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,
|
2004-11-23 22:28:43 +08:00
|
|
|
GHFunc function,
|
|
|
|
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
|
|
|
|
2004-11-23 22:28:43 +08:00
|
|
|
if (! list->table)
|
1998-12-16 19:23:30 +08:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2006-04-02 23:37:25 +08:00
|
|
|
const GimpParasite *
|
2003-08-25 18:49:33 +08:00
|
|
|
gimp_parasite_list_find (GimpParasiteList *list,
|
2004-11-23 22:28:43 +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);
|
2004-11-23 22:28:43 +08:00
|
|
|
|
|
|
|
return NULL;
|
1998-10-30 18:21:33 +08:00
|
|
|
}
|
|
|
|
|
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
|
|
|
{
|
|
|
|
if (! gimp_parasite_is_persistent (parasite))
|
|
|
|
return;
|
|
|
|
|
2003-03-06 04:21:50 +08:00
|
|
|
gimp_config_writer_open (writer, parasite_symbol);
|
|
|
|
|
2005-01-19 04:47:10 +08:00
|
|
|
gimp_config_writer_printf (writer, "\"%s\" %lu %lu",
|
|
|
|
gimp_parasite_name (parasite),
|
|
|
|
gimp_parasite_flags (parasite),
|
|
|
|
gimp_parasite_data_size (parasite));
|
2002-05-15 06:48:24 +08:00
|
|
|
|
2005-01-19 04:47:10 +08:00
|
|
|
gimp_config_writer_data (writer,
|
|
|
|
gimp_parasite_data_size (parasite),
|
|
|
|
gimp_parasite_data (parasite));
|
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;
|
|
|
|
}
|