2010-04-03 23:25:31 +08:00
|
|
|
/* GIMP - The GNU Image Manipulation Program
|
|
|
|
* 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 3 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, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
|
|
|
#include <gegl.h>
|
|
|
|
|
|
|
|
#include "libgimpmath/gimpmath.h"
|
|
|
|
#include "libgimpconfig/gimpconfig.h"
|
|
|
|
|
|
|
|
#include "core-types.h"
|
|
|
|
|
2010-04-05 19:24:54 +08:00
|
|
|
#include "gimptoolinfo.h"
|
2010-04-03 23:25:31 +08:00
|
|
|
#include "gimptooloptions.h"
|
|
|
|
#include "gimptoolpreset.h"
|
|
|
|
#include "gimptoolpreset-load.h"
|
|
|
|
#include "gimptoolpreset-save.h"
|
|
|
|
|
|
|
|
#include "gimp-intl.h"
|
|
|
|
|
2010-04-04 19:58:55 +08:00
|
|
|
|
2010-04-03 23:25:31 +08:00
|
|
|
enum
|
|
|
|
{
|
|
|
|
PROP_0,
|
|
|
|
PROP_NAME,
|
|
|
|
PROP_TOOL_OPTIONS
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
static void gimp_tool_preset_finalize (GObject *object);
|
|
|
|
static void gimp_tool_preset_set_property (GObject *object,
|
|
|
|
guint property_id,
|
|
|
|
const GValue *value,
|
|
|
|
GParamSpec *pspec);
|
|
|
|
static void gimp_tool_preset_get_property (GObject *object,
|
|
|
|
guint property_id,
|
|
|
|
GValue *value,
|
|
|
|
GParamSpec *pspec);
|
|
|
|
static void
|
|
|
|
gimp_tool_preset_dispatch_properties_changed (GObject *object,
|
|
|
|
guint n_pspecs,
|
|
|
|
GParamSpec **pspecs);
|
|
|
|
|
|
|
|
static const gchar * gimp_tool_preset_get_extension (GimpData *data);
|
|
|
|
|
|
|
|
|
|
|
|
G_DEFINE_TYPE (GimpToolPreset, gimp_tool_preset,
|
|
|
|
GIMP_TYPE_DATA)
|
|
|
|
|
|
|
|
#define parent_class gimp_tool_preset_parent_class
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_tool_preset_class_init (GimpToolPresetClass *klass)
|
|
|
|
{
|
|
|
|
GObjectClass *object_class = G_OBJECT_CLASS (klass);
|
|
|
|
GimpDataClass *data_class = GIMP_DATA_CLASS (klass);
|
|
|
|
|
|
|
|
object_class->finalize = gimp_tool_preset_finalize;
|
|
|
|
object_class->set_property = gimp_tool_preset_set_property;
|
|
|
|
object_class->get_property = gimp_tool_preset_get_property;
|
|
|
|
object_class->dispatch_properties_changed = gimp_tool_preset_dispatch_properties_changed;
|
|
|
|
|
|
|
|
data_class->save = gimp_tool_preset_save;
|
|
|
|
data_class->get_extension = gimp_tool_preset_get_extension;
|
|
|
|
|
|
|
|
GIMP_CONFIG_INSTALL_PROP_STRING (object_class, PROP_NAME,
|
|
|
|
"name", NULL,
|
|
|
|
"Unnamed",
|
|
|
|
GIMP_PARAM_STATIC_STRINGS);
|
|
|
|
|
|
|
|
GIMP_CONFIG_INSTALL_PROP_OBJECT (object_class, PROP_TOOL_OPTIONS,
|
|
|
|
"tool-options", NULL,
|
2010-04-05 19:24:54 +08:00
|
|
|
GIMP_TYPE_TOOL_OPTIONS,
|
|
|
|
GIMP_PARAM_STATIC_STRINGS);
|
2010-04-03 23:25:31 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_tool_preset_init (GimpToolPreset *tool_preset)
|
|
|
|
{
|
|
|
|
tool_preset->tool_options = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_tool_preset_finalize (GObject *object)
|
|
|
|
{
|
|
|
|
GimpToolPreset *tool_preset = GIMP_TOOL_PRESET (object);
|
|
|
|
|
2010-04-04 19:58:55 +08:00
|
|
|
if (tool_preset->tool_options)
|
|
|
|
{
|
|
|
|
g_object_unref (tool_preset->tool_options);
|
|
|
|
tool_preset->tool_options = NULL;
|
|
|
|
}
|
2010-04-03 23:25:31 +08:00
|
|
|
|
|
|
|
G_OBJECT_CLASS (parent_class)->finalize (object);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_tool_preset_set_property (GObject *object,
|
|
|
|
guint property_id,
|
|
|
|
const GValue *value,
|
|
|
|
GParamSpec *pspec)
|
|
|
|
{
|
2010-04-04 19:58:55 +08:00
|
|
|
GimpToolPreset *tool_preset = GIMP_TOOL_PRESET (object);
|
2010-04-03 23:25:31 +08:00
|
|
|
|
|
|
|
switch (property_id)
|
|
|
|
{
|
|
|
|
case PROP_NAME:
|
2010-04-04 19:58:55 +08:00
|
|
|
gimp_object_set_name (GIMP_OBJECT (tool_preset),
|
|
|
|
g_value_get_string (value));
|
2010-04-03 23:25:31 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
case PROP_TOOL_OPTIONS:
|
2010-04-04 19:58:55 +08:00
|
|
|
if (tool_preset->tool_options)
|
|
|
|
g_object_unref (tool_preset->tool_options);
|
|
|
|
tool_preset->tool_options =
|
|
|
|
gimp_config_duplicate (g_value_get_object (value));
|
2010-04-03 23:25:31 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_tool_preset_get_property (GObject *object,
|
2010-04-04 19:58:55 +08:00
|
|
|
guint property_id,
|
|
|
|
GValue *value,
|
|
|
|
GParamSpec *pspec)
|
2010-04-03 23:25:31 +08:00
|
|
|
{
|
|
|
|
GimpToolPreset *tool_preset = GIMP_TOOL_PRESET (object);
|
|
|
|
|
|
|
|
switch (property_id)
|
|
|
|
{
|
|
|
|
case PROP_NAME:
|
|
|
|
g_value_set_string (value, gimp_object_get_name (tool_preset));
|
|
|
|
break;
|
|
|
|
|
|
|
|
case PROP_TOOL_OPTIONS:
|
|
|
|
g_value_set_object (value, tool_preset->tool_options);
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_tool_preset_dispatch_properties_changed (GObject *object,
|
|
|
|
guint n_pspecs,
|
|
|
|
GParamSpec **pspecs)
|
|
|
|
{
|
|
|
|
gint i;
|
|
|
|
|
|
|
|
G_OBJECT_CLASS (parent_class)->dispatch_properties_changed (object,
|
|
|
|
n_pspecs, pspecs);
|
|
|
|
|
|
|
|
for (i = 0; i < n_pspecs; i++)
|
|
|
|
{
|
|
|
|
if (pspecs[i]->flags & GIMP_CONFIG_PARAM_SERIALIZE)
|
|
|
|
{
|
|
|
|
gimp_data_dirty (GIMP_DATA (object));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static const gchar *
|
|
|
|
gimp_tool_preset_get_extension (GimpData *data)
|
|
|
|
{
|
|
|
|
return GIMP_TOOL_PRESET_FILE_EXTENSION;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* public functions */
|
|
|
|
|
|
|
|
GimpData *
|
2010-04-11 01:55:42 +08:00
|
|
|
gimp_tool_preset_new (GimpContext *context,
|
|
|
|
const gchar *name)
|
2010-04-03 23:25:31 +08:00
|
|
|
{
|
2010-04-05 19:24:54 +08:00
|
|
|
GimpToolInfo *tool_info;
|
|
|
|
const gchar *stock_id;
|
|
|
|
|
|
|
|
g_return_val_if_fail (GIMP_IS_CONTEXT (context), NULL);
|
2010-04-11 01:55:42 +08:00
|
|
|
g_return_val_if_fail (name != NULL, NULL);
|
|
|
|
g_return_val_if_fail (name[0] != '\0', NULL);
|
2010-04-05 19:24:54 +08:00
|
|
|
|
|
|
|
tool_info = gimp_context_get_tool (context);
|
|
|
|
|
|
|
|
stock_id = gimp_viewable_get_stock_id (GIMP_VIEWABLE (tool_info));
|
|
|
|
|
2010-04-03 23:25:31 +08:00
|
|
|
return g_object_new (GIMP_TYPE_TOOL_PRESET,
|
2010-04-05 19:24:54 +08:00
|
|
|
"name", name,
|
|
|
|
"stock-id", stock_id,
|
|
|
|
"tool-options", tool_info->tool_options,
|
2010-04-03 23:25:31 +08:00
|
|
|
NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
GimpData *
|
2010-04-05 19:24:54 +08:00
|
|
|
gimp_tool_preset_get_standard (GimpContext *context)
|
2010-04-03 23:25:31 +08:00
|
|
|
{
|
|
|
|
static GimpData *standard_tool_preset = NULL;
|
|
|
|
|
2010-04-05 19:24:54 +08:00
|
|
|
g_return_val_if_fail (GIMP_IS_CONTEXT (context), NULL);
|
|
|
|
|
2010-04-03 23:25:31 +08:00
|
|
|
if (! standard_tool_preset)
|
|
|
|
{
|
2010-04-11 01:55:42 +08:00
|
|
|
standard_tool_preset = gimp_tool_preset_new (context,
|
|
|
|
"Standard tool preset");
|
2010-04-03 23:25:31 +08:00
|
|
|
|
|
|
|
gimp_data_clean (standard_tool_preset);
|
|
|
|
gimp_data_make_internal (standard_tool_preset, "gimp-tool-preset-standard");
|
|
|
|
|
|
|
|
g_object_ref (standard_tool_preset);
|
|
|
|
}
|
|
|
|
|
|
|
|
return standard_tool_preset;
|
|
|
|
}
|