2006-12-10 05:33:38 +08:00
|
|
|
/* GIMP - The GNU Image Manipulation Program
|
1999-04-13 01:55:06 +08:00
|
|
|
* Copyright (C) 1995-1999 Spencer Kimball and Peter Mattis
|
|
|
|
*
|
|
|
|
* 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
|
|
|
|
1999-06-07 03:44:36 +08:00
|
|
|
#include "config.h"
|
2000-01-14 20:41:00 +08:00
|
|
|
|
2003-06-30 04:40:45 +08:00
|
|
|
#include <glib-object.h>
|
2000-12-17 05:37:03 +08:00
|
|
|
|
2003-02-09 07:56:16 +08:00
|
|
|
#include "libgimpbase/gimpbase.h"
|
2005-01-26 03:11:26 +08:00
|
|
|
#include "libgimpconfig/gimpconfig.h"
|
2003-02-09 07:56:16 +08:00
|
|
|
|
2003-06-30 04:40:45 +08:00
|
|
|
#include "core-types.h"
|
2000-12-17 05:37:03 +08:00
|
|
|
|
2005-11-07 06:01:25 +08:00
|
|
|
#include "gimp.h"
|
2003-06-30 04:40:45 +08:00
|
|
|
#include "gimptoolinfo.h"
|
|
|
|
#include "gimptooloptions.h"
|
1999-04-22 22:34:00 +08:00
|
|
|
|
|
|
|
|
2003-02-05 22:39:40 +08:00
|
|
|
enum
|
1999-04-13 01:55:06 +08:00
|
|
|
{
|
2003-02-05 22:39:40 +08:00
|
|
|
PROP_0,
|
|
|
|
PROP_TOOL_INFO
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
static void gimp_tool_options_set_property (GObject *object,
|
|
|
|
guint property_id,
|
|
|
|
const GValue *value,
|
|
|
|
GParamSpec *pspec);
|
|
|
|
static void gimp_tool_options_get_property (GObject *object,
|
|
|
|
guint property_id,
|
|
|
|
GValue *value,
|
|
|
|
GParamSpec *pspec);
|
|
|
|
|
|
|
|
static void gimp_tool_options_real_reset (GimpToolOptions *tool_options);
|
|
|
|
|
|
|
|
|
2006-05-15 17:46:31 +08:00
|
|
|
G_DEFINE_TYPE (GimpToolOptions, gimp_tool_options, GIMP_TYPE_CONTEXT)
|
2003-02-05 22:39:40 +08:00
|
|
|
|
|
|
|
|
2003-08-30 21:22:20 +08:00
|
|
|
static void
|
2003-02-05 22:39:40 +08:00
|
|
|
gimp_tool_options_class_init (GimpToolOptionsClass *klass)
|
|
|
|
{
|
2004-07-04 04:27:28 +08:00
|
|
|
GObjectClass *object_class = G_OBJECT_CLASS (klass);
|
2003-02-05 22:39:40 +08:00
|
|
|
|
|
|
|
object_class->set_property = gimp_tool_options_set_property;
|
|
|
|
object_class->get_property = gimp_tool_options_get_property;
|
|
|
|
|
|
|
|
klass->reset = gimp_tool_options_real_reset;
|
|
|
|
|
|
|
|
g_object_class_install_property (object_class, PROP_TOOL_INFO,
|
|
|
|
g_param_spec_object ("tool-info",
|
|
|
|
NULL, NULL,
|
|
|
|
GIMP_TYPE_TOOL_INFO,
|
2006-01-19 04:29:40 +08:00
|
|
|
GIMP_PARAM_READWRITE));
|
2003-02-05 22:39:40 +08:00
|
|
|
|
1999-04-13 01:55:06 +08:00
|
|
|
}
|
|
|
|
|
2003-02-05 22:39:40 +08:00
|
|
|
static void
|
|
|
|
gimp_tool_options_init (GimpToolOptions *options)
|
|
|
|
{
|
2003-02-08 01:12:21 +08:00
|
|
|
options->tool_info = NULL;
|
2003-02-05 22:39:40 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_tool_options_set_property (GObject *object,
|
|
|
|
guint property_id,
|
|
|
|
const GValue *value,
|
|
|
|
GParamSpec *pspec)
|
|
|
|
{
|
2004-07-04 04:27:28 +08:00
|
|
|
GimpToolOptions *options = GIMP_TOOL_OPTIONS (object);
|
2003-02-05 22:39:40 +08:00
|
|
|
|
|
|
|
switch (property_id)
|
|
|
|
{
|
|
|
|
case PROP_TOOL_INFO:
|
2003-09-30 04:26:09 +08:00
|
|
|
{
|
2006-11-25 22:57:26 +08:00
|
|
|
GimpToolInfo *tool_info = g_value_get_object (value);
|
2003-09-30 04:26:09 +08:00
|
|
|
|
|
|
|
g_return_if_fail (options->tool_info == NULL ||
|
|
|
|
options->tool_info == tool_info);
|
|
|
|
|
|
|
|
if (! options->tool_info)
|
|
|
|
options->tool_info = GIMP_TOOL_INFO (g_value_dup_object (value));
|
|
|
|
}
|
2003-02-05 22:39:40 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_tool_options_get_property (GObject *object,
|
|
|
|
guint property_id,
|
|
|
|
GValue *value,
|
|
|
|
GParamSpec *pspec)
|
1999-04-13 01:55:06 +08:00
|
|
|
{
|
2004-07-04 04:27:28 +08:00
|
|
|
GimpToolOptions *options = GIMP_TOOL_OPTIONS (object);
|
2003-02-05 22:39:40 +08:00
|
|
|
|
|
|
|
switch (property_id)
|
|
|
|
{
|
|
|
|
case PROP_TOOL_INFO:
|
|
|
|
g_value_set_object (value, options->tool_info);
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_tool_options_real_reset (GimpToolOptions *tool_options)
|
|
|
|
{
|
2003-10-11 22:30:18 +08:00
|
|
|
gimp_config_reset (GIMP_CONFIG (tool_options));
|
2003-02-05 22:39:40 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
gimp_tool_options_reset (GimpToolOptions *tool_options)
|
|
|
|
{
|
|
|
|
g_return_if_fail (GIMP_IS_TOOL_OPTIONS (tool_options));
|
|
|
|
|
|
|
|
GIMP_TOOL_OPTIONS_GET_CLASS (tool_options)->reset (tool_options);
|
|
|
|
}
|
|
|
|
|
2003-09-30 04:26:09 +08:00
|
|
|
gchar *
|
2003-02-10 19:46:10 +08:00
|
|
|
gimp_tool_options_build_filename (GimpToolOptions *tool_options,
|
|
|
|
const gchar *extension)
|
|
|
|
{
|
|
|
|
gchar *filename;
|
|
|
|
|
2003-09-30 04:26:09 +08:00
|
|
|
g_return_val_if_fail (GIMP_IS_TOOL_OPTIONS (tool_options), NULL);
|
|
|
|
|
2003-02-27 04:34:58 +08:00
|
|
|
if (extension)
|
|
|
|
{
|
2003-09-30 04:26:09 +08:00
|
|
|
gchar *basename;
|
|
|
|
|
2003-02-27 04:34:58 +08:00
|
|
|
basename = g_strconcat (GIMP_OBJECT (tool_options->tool_info)->name,
|
|
|
|
".", extension, NULL);
|
|
|
|
|
|
|
|
filename = g_build_filename (gimp_directory (),
|
|
|
|
"tool-options",
|
|
|
|
basename,
|
|
|
|
NULL);
|
|
|
|
g_free (basename);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
filename = g_build_filename (gimp_directory (),
|
|
|
|
"tool-options",
|
|
|
|
GIMP_OBJECT (tool_options->tool_info)->name,
|
2003-08-30 21:22:20 +08:00
|
|
|
NULL);
|
2003-02-27 04:34:58 +08:00
|
|
|
}
|
2003-02-10 19:46:10 +08:00
|
|
|
|
|
|
|
return filename;
|
|
|
|
}
|
|
|
|
|
2003-02-09 07:56:16 +08:00
|
|
|
gboolean
|
|
|
|
gimp_tool_options_serialize (GimpToolOptions *tool_options,
|
2003-02-10 19:46:10 +08:00
|
|
|
const gchar *extension,
|
2003-02-09 07:56:16 +08:00
|
|
|
GError **error)
|
|
|
|
{
|
|
|
|
gchar *filename;
|
2003-07-24 20:07:22 +08:00
|
|
|
gchar *header;
|
|
|
|
gchar *footer;
|
2003-02-09 07:56:16 +08:00
|
|
|
gboolean retval;
|
|
|
|
|
|
|
|
g_return_val_if_fail (GIMP_IS_TOOL_OPTIONS (tool_options), FALSE);
|
|
|
|
g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
|
|
|
|
|
2003-02-10 19:46:10 +08:00
|
|
|
filename = gimp_tool_options_build_filename (tool_options, extension);
|
2003-02-09 07:56:16 +08:00
|
|
|
|
2005-11-07 06:01:25 +08:00
|
|
|
if (tool_options->tool_info->gimp->be_verbose)
|
|
|
|
g_print ("Writing '%s'\n", gimp_filename_to_utf8 (filename));
|
|
|
|
|
2003-07-24 20:07:22 +08:00
|
|
|
header = g_strdup_printf ("GIMP %s options",
|
|
|
|
GIMP_OBJECT (tool_options->tool_info)->name);
|
|
|
|
footer = g_strdup_printf ("end of %s options",
|
|
|
|
GIMP_OBJECT (tool_options->tool_info)->name);
|
|
|
|
|
2003-10-11 22:30:18 +08:00
|
|
|
retval = gimp_config_serialize_to_file (GIMP_CONFIG (tool_options),
|
2004-07-04 04:27:28 +08:00
|
|
|
filename,
|
|
|
|
header, footer,
|
|
|
|
NULL,
|
|
|
|
error);
|
2003-02-09 07:56:16 +08:00
|
|
|
|
|
|
|
g_free (filename);
|
2003-07-24 20:07:22 +08:00
|
|
|
g_free (header);
|
|
|
|
g_free (footer);
|
2003-02-09 07:56:16 +08:00
|
|
|
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
|
|
|
gboolean
|
|
|
|
gimp_tool_options_deserialize (GimpToolOptions *tool_options,
|
2003-02-10 19:46:10 +08:00
|
|
|
const gchar *extension,
|
2003-02-09 07:56:16 +08:00
|
|
|
GError **error)
|
|
|
|
{
|
|
|
|
gchar *filename;
|
|
|
|
gboolean retval;
|
|
|
|
|
|
|
|
g_return_val_if_fail (GIMP_IS_TOOL_OPTIONS (tool_options), FALSE);
|
|
|
|
g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
|
|
|
|
|
2003-02-10 19:46:10 +08:00
|
|
|
filename = gimp_tool_options_build_filename (tool_options, extension);
|
2003-02-09 07:56:16 +08:00
|
|
|
|
2005-11-07 06:01:25 +08:00
|
|
|
if (tool_options->tool_info->gimp->be_verbose)
|
|
|
|
g_print ("Parsing '%s'\n", gimp_filename_to_utf8 (filename));
|
|
|
|
|
2003-10-11 22:30:18 +08:00
|
|
|
retval = gimp_config_deserialize_file (GIMP_CONFIG (tool_options),
|
2004-07-04 04:27:28 +08:00
|
|
|
filename,
|
|
|
|
NULL,
|
|
|
|
error);
|
2003-02-09 07:56:16 +08:00
|
|
|
|
|
|
|
g_free (filename);
|
|
|
|
|
|
|
|
return retval;
|
|
|
|
}
|