From a921d65df64a2aad14d498530a106fcfce6b5fb5 Mon Sep 17 00:00:00 2001 From: Michael Natterer Date: Tue, 20 May 2008 21:41:47 +0000 Subject: [PATCH] app/core/Makefile.am app/core/core-types.h new GimpViewable subclass which 2008-05-20 Michael Natterer * app/core/Makefile.am * app/core/core-types.h * app/core/gimpimagemapconfig.[ch]: new GimpViewable subclass which has a "time" property. Sets the object's name to a date string if a time != 0 gets set. Has a compare function which first sorts the objects with a timestamp in MRU order and then the objects without timestamp by name. * app/gegl/gimpbrightnesscontrastconfig.[ch] * app/gegl/gimpcolorbalanceconfig.[ch] * app/gegl/gimpcolorizeconfig.[ch] * app/gegl/gimpcurvesconfig.[ch] * app/gegl/gimphuesaturationconfig.[ch] * app/gegl/gimplevelsconfig.[ch] * app/gegl/gimpposterizeconfig.[ch] * app/gegl/gimpthresholdconfig.[ch]: derive from GimpImageMapConfig. * app/tools/gimpimagemaptool.c: sort the settings container with above compare function. * app/tools/gimpimagemaptool-settings.c: add utility functions for loading and saving the settings container. In the settings combo, add a separator between MRU items and favorites. * app/Makefile.am: make the thing link. svn path=/trunk/; revision=25724 --- ChangeLog | 28 ++++ app/Makefile.am | 13 +- app/core/Makefile.am | 2 + app/core/core-types.h | 1 + app/core/gimpimagemapconfig.c | 169 +++++++++++++++++++++ app/core/gimpimagemapconfig.h | 58 +++++++ app/gegl/gimpbrightnesscontrastconfig.c | 2 +- app/gegl/gimpbrightnesscontrastconfig.h | 10 +- app/gegl/gimpcolorbalanceconfig.c | 2 +- app/gegl/gimpcolorbalanceconfig.h | 16 +- app/gegl/gimpcolorizeconfig.c | 2 +- app/gegl/gimpcolorizeconfig.h | 12 +- app/gegl/gimpcurvesconfig.c | 2 +- app/gegl/gimpcurvesconfig.h | 6 +- app/gegl/gimphuesaturationconfig.c | 2 +- app/gegl/gimphuesaturationconfig.h | 16 +- app/gegl/gimplevelsconfig.c | 2 +- app/gegl/gimplevelsconfig.h | 6 +- app/gegl/gimpposterizeconfig.c | 2 +- app/gegl/gimpposterizeconfig.h | 8 +- app/gegl/gimpthresholdconfig.c | 2 +- app/gegl/gimpthresholdconfig.h | 10 +- app/tools/gimpimagemaptool-settings.c | 193 ++++++++++++++++-------- app/tools/gimpimagemaptool.c | 7 +- 24 files changed, 450 insertions(+), 121 deletions(-) create mode 100644 app/core/gimpimagemapconfig.c create mode 100644 app/core/gimpimagemapconfig.h diff --git a/ChangeLog b/ChangeLog index 0853d0c8aa..1ad8353928 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,31 @@ +2008-05-20 Michael Natterer + + * app/core/Makefile.am + * app/core/core-types.h + * app/core/gimpimagemapconfig.[ch]: new GimpViewable subclass + which has a "time" property. Sets the object's name to a date + string if a time != 0 gets set. Has a compare function which first + sorts the objects with a timestamp in MRU order and then the + objects without timestamp by name. + + * app/gegl/gimpbrightnesscontrastconfig.[ch] + * app/gegl/gimpcolorbalanceconfig.[ch] + * app/gegl/gimpcolorizeconfig.[ch] + * app/gegl/gimpcurvesconfig.[ch] + * app/gegl/gimphuesaturationconfig.[ch] + * app/gegl/gimplevelsconfig.[ch] + * app/gegl/gimpposterizeconfig.[ch] + * app/gegl/gimpthresholdconfig.[ch]: derive from GimpImageMapConfig. + + * app/tools/gimpimagemaptool.c: sort the settings container with + above compare function. + + * app/tools/gimpimagemaptool-settings.c: add utility functions + for loading and saving the settings container. In the settings + combo, add a separator between MRU items and favorites. + + * app/Makefile.am: make the thing link. + 2008-05-20 Michael Natterer * app/core/gimplist.c (gimp_list_uniquefy_name): don't crash if an diff --git a/app/Makefile.am b/app/Makefile.am index 580e74fd38..018ba7c2fe 100644 --- a/app/Makefile.am +++ b/app/Makefile.am @@ -91,12 +91,13 @@ INCLUDES = \ -I$(includedir) AM_LDFLAGS = \ - $(munix) \ - $(CARBON_LDFLAGS) \ - -u $(SYMPREFIX)xcf_init \ - -u $(SYMPREFIX)internal_procs_init \ - -u $(SYMPREFIX)gimp_coords_mix \ - -u $(SYMPREFIX)gimp_curve_map_pixels \ + $(munix) \ + $(CARBON_LDFLAGS) \ + -u $(SYMPREFIX)xcf_init \ + -u $(SYMPREFIX)internal_procs_init \ + -u $(SYMPREFIX)gimp_coords_mix \ + -u $(SYMPREFIX)gimp_curve_map_pixels \ + -u $(SYMPREFIX)gimp_image_map_config_get_type \ -u $(SYMPREFIX)gimp_plug_in_manager_restore gimp_2_5_LDFLAGS = $(AM_LDFLAGS) $(mwindows) diff --git a/app/core/Makefile.am b/app/core/Makefile.am index ef0b931a97..473c1b0cd1 100644 --- a/app/core/Makefile.am +++ b/app/core/Makefile.am @@ -227,6 +227,8 @@ libappcore_a_sources = \ gimpimagefile.h \ gimpimagemap.c \ gimpimagemap.h \ + gimpimagemapconfig.c \ + gimpimagemapconfig.h \ gimpitem.c \ gimpitem.h \ gimpitem-linked.c \ diff --git a/app/core/core-types.h b/app/core/core-types.h index 577f6348ae..5b322df825 100644 --- a/app/core/core-types.h +++ b/app/core/core-types.h @@ -137,6 +137,7 @@ typedef struct _GimpEnvironTable GimpEnvironTable; typedef struct _GimpGuide GimpGuide; typedef struct _GimpImagefile GimpImagefile; typedef struct _GimpImageMap GimpImageMap; +typedef struct _GimpImageMapConfig GimpImageMapConfig; typedef struct _GimpInterpreterDB GimpInterpreterDB; typedef struct _GimpParasiteList GimpParasiteList; typedef struct _GimpPdbProgress GimpPdbProgress; diff --git a/app/core/gimpimagemapconfig.c b/app/core/gimpimagemapconfig.c new file mode 100644 index 0000000000..74d02b9850 --- /dev/null +++ b/app/core/gimpimagemapconfig.c @@ -0,0 +1,169 @@ +/* GIMP - The GNU Image Manipulation Program + * Copyright (C) 1995 Spencer Kimball and Peter Mattis + * + * gimpimagemapconfig.c + * Copyright (C) 2008 Michael Natterer + * + * 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" + +#include + +#include + +#include "libgimpconfig/gimpconfig.h" + +#include "core-types.h" + +#include "gimpimagemapconfig.h" + + +enum +{ + PROP_0, + PROP_TIME +}; + + +static void gimp_image_map_config_get_property (GObject *object, + guint property_id, + GValue *value, + GParamSpec *pspec); +static void gimp_image_map_config_set_property (GObject *object, + guint property_id, + const GValue *value, + GParamSpec *pspec); + + +G_DEFINE_TYPE (GimpImageMapConfig, gimp_image_map_config, + GIMP_TYPE_VIEWABLE) + +#define parent_class gimp_image_map_config_parent_class + + +static void +gimp_image_map_config_class_init (GimpImageMapConfigClass *klass) +{ + GObjectClass *object_class = G_OBJECT_CLASS (klass); + + object_class->set_property = gimp_image_map_config_set_property; + object_class->get_property = gimp_image_map_config_get_property; + + GIMP_CONFIG_INSTALL_PROP_UINT (object_class, PROP_TIME, + "time", + "Time of settings creation", + 0, G_MAXUINT, 0, 0); +} + +static void +gimp_image_map_config_init (GimpImageMapConfig *config) +{ +} + +static void +gimp_image_map_config_get_property (GObject *object, + guint property_id, + GValue *value, + GParamSpec *pspec) +{ + GimpImageMapConfig *config = GIMP_IMAGE_MAP_CONFIG (object); + + switch (property_id) + { + case PROP_TIME: + g_value_set_uint (value, config->time); + break; + + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); + break; + } +} + +static void +gimp_image_map_config_set_property (GObject *object, + guint property_id, + const GValue *value, + GParamSpec *pspec) +{ + GimpImageMapConfig *config = GIMP_IMAGE_MAP_CONFIG (object); + + switch (property_id) + { + case PROP_TIME: + config->time = g_value_get_uint (value); + + if (config->time > 0) + { + time_t t; + struct tm tm; + gchar buf[64]; + gchar *name; + + t = config->time; + tm = *localtime (&t); + strftime (buf, sizeof (buf), "%Y-%m-%d %T", &tm); + + name = g_locale_to_utf8 (buf, -1, NULL, NULL, NULL); + gimp_object_set_name (GIMP_OBJECT (config), name); + g_free (name); + } + break; + + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); + break; + } +} + + +/* public functions */ + +gint +gimp_image_map_config_compare (GimpImageMapConfig *a, + GimpImageMapConfig *b) +{ + const gchar *name_a = gimp_object_get_name (GIMP_OBJECT (a)); + const gchar *name_b = gimp_object_get_name (GIMP_OBJECT (b)); + + if (a->time > 0 && b->time > 0) + { + return - strcmp (name_a, name_b); + } + else if (a->time > 0) + { + return -1; + } + else if (b->time) + { + return 1; + } + else if (name_a && name_b) + { + return strcmp (name_a, name_b); + } + else if (name_a) + { + return 1; + } + else if (name_b) + { + return -1; + } + + return 0; +} diff --git a/app/core/gimpimagemapconfig.h b/app/core/gimpimagemapconfig.h new file mode 100644 index 0000000000..cc9f66ce08 --- /dev/null +++ b/app/core/gimpimagemapconfig.h @@ -0,0 +1,58 @@ +/* GIMP - The GNU Image Manipulation Program + * Copyright (C) 1995 Spencer Kimball and Peter Mattis + * + * gimpimagemapconfig.h + * Copyright (C) 2008 Michael Natterer + * + * 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. + */ + +#ifndef __GIMP_IMAGE_MAP_CONFIG_H__ +#define __GIMP_IMAGE_MAP_CONFIG_H__ + + +#include "gimpviewable.h" + + +#define GIMP_TYPE_IMAGE_MAP_CONFIG (gimp_image_map_config_get_type ()) +#define GIMP_IMAGE_MAP_CONFIG(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GIMP_TYPE_IMAGE_MAP_CONFIG, GimpImageMapConfig)) +#define GIMP_IMAGE_MAP_CONFIG_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GIMP_TYPE_IMAGE_MAP_CONFIG, GimpImageMapConfigClass)) +#define GIMP_IS_IMAGE_MAP_CONFIG(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GIMP_TYPE_IMAGE_MAP_CONFIG)) +#define GIMP_IS_IMAGE_MAP_CONFIG_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GIMP_TYPE_IMAGE_MAP_CONFIG)) +#define GIMP_IMAGE_MAP_CONFIG_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GIMP_TYPE_IMAGE_MAP_CONFIG, GimpImageMapConfigClass)) + + +typedef struct _GimpImageMapConfigClass GimpImageMapConfigClass; + +struct _GimpImageMapConfig +{ + GimpViewable parent_instance; + + guint time; +}; + +struct _GimpImageMapConfigClass +{ + GimpViewableClass parent_class; +}; + + +GType gimp_image_map_config_get_type (void) G_GNUC_CONST; + +gint gimp_image_map_config_compare (GimpImageMapConfig *a, + GimpImageMapConfig *b); + + +#endif /* __GIMP_IMAGE_MAP_CONFIG_H__ */ diff --git a/app/gegl/gimpbrightnesscontrastconfig.c b/app/gegl/gimpbrightnesscontrastconfig.c index 1a9ed900ce..a637d18859 100644 --- a/app/gegl/gimpbrightnesscontrastconfig.c +++ b/app/gegl/gimpbrightnesscontrastconfig.c @@ -52,7 +52,7 @@ static void gimp_brightness_contrast_config_set_property (GObject *object G_DEFINE_TYPE_WITH_CODE (GimpBrightnessContrastConfig, gimp_brightness_contrast_config, - GIMP_TYPE_VIEWABLE, + GIMP_TYPE_IMAGE_MAP_CONFIG, G_IMPLEMENT_INTERFACE (GIMP_TYPE_CONFIG, NULL)) #define parent_class gimp_brightness_contrast_config_parent_class diff --git a/app/gegl/gimpbrightnesscontrastconfig.h b/app/gegl/gimpbrightnesscontrastconfig.h index d7473abd64..62569765b1 100644 --- a/app/gegl/gimpbrightnesscontrastconfig.h +++ b/app/gegl/gimpbrightnesscontrastconfig.h @@ -23,7 +23,7 @@ #define __GIMP_BRIGHTNESS_CONTRAST_CONFIG_H__ -#include "core/gimpviewable.h" +#include "core/gimpimagemapconfig.h" #define GIMP_TYPE_BRIGHTNESS_CONTRAST_CONFIG (gimp_brightness_contrast_config_get_type ()) @@ -38,15 +38,15 @@ typedef struct _GimpBrightnessContrastConfigClass GimpBrightnessContrastConfigCl struct _GimpBrightnessContrastConfig { - GimpViewable parent_instance; + GimpImageMapConfig parent_instance; - gdouble brightness; - gdouble contrast; + gdouble brightness; + gdouble contrast; }; struct _GimpBrightnessContrastConfigClass { - GimpViewableClass parent_class; + GimpImageMapConfigClass parent_class; }; diff --git a/app/gegl/gimpcolorbalanceconfig.c b/app/gegl/gimpcolorbalanceconfig.c index e5ca8bbfd8..42366e0ede 100644 --- a/app/gegl/gimpcolorbalanceconfig.c +++ b/app/gegl/gimpcolorbalanceconfig.c @@ -73,7 +73,7 @@ static gboolean gimp_color_balance_config_copy (GimpConfig *src, G_DEFINE_TYPE_WITH_CODE (GimpColorBalanceConfig, gimp_color_balance_config, - GIMP_TYPE_VIEWABLE, + GIMP_TYPE_IMAGE_MAP_CONFIG, G_IMPLEMENT_INTERFACE (GIMP_TYPE_CONFIG, gimp_color_balance_config_iface_init)) diff --git a/app/gegl/gimpcolorbalanceconfig.h b/app/gegl/gimpcolorbalanceconfig.h index dfb5dc6a5f..53d04220c5 100644 --- a/app/gegl/gimpcolorbalanceconfig.h +++ b/app/gegl/gimpcolorbalanceconfig.h @@ -23,7 +23,7 @@ #define __GIMP_COLOR_BALANCE_CONFIG_H__ -#include "core/gimpviewable.h" +#include "core/gimpimagemapconfig.h" #define GIMP_TYPE_COLOR_BALANCE_CONFIG (gimp_color_balance_config_get_type ()) @@ -38,20 +38,20 @@ typedef struct _GimpColorBalanceConfigClass GimpColorBalanceConfigClass; struct _GimpColorBalanceConfig { - GimpViewable parent_instance; + GimpImageMapConfig parent_instance; - GimpTransferMode range; + GimpTransferMode range; - gdouble cyan_red[3]; - gdouble magenta_green[3]; - gdouble yellow_blue[3]; + gdouble cyan_red[3]; + gdouble magenta_green[3]; + gdouble yellow_blue[3]; - gboolean preserve_luminosity; + gboolean preserve_luminosity; }; struct _GimpColorBalanceConfigClass { - GimpViewableClass parent_class; + GimpImageMapConfigClass parent_class; }; diff --git a/app/gegl/gimpcolorizeconfig.c b/app/gegl/gimpcolorizeconfig.c index 8a0e3bf8d0..381e8251bf 100644 --- a/app/gegl/gimpcolorizeconfig.c +++ b/app/gegl/gimpcolorizeconfig.c @@ -53,7 +53,7 @@ static void gimp_colorize_config_set_property (GObject *object, G_DEFINE_TYPE_WITH_CODE (GimpColorizeConfig, gimp_colorize_config, - GIMP_TYPE_VIEWABLE, + GIMP_TYPE_IMAGE_MAP_CONFIG, G_IMPLEMENT_INTERFACE (GIMP_TYPE_CONFIG, NULL)) #define parent_class gimp_colorize_config_parent_class diff --git a/app/gegl/gimpcolorizeconfig.h b/app/gegl/gimpcolorizeconfig.h index 197bd3ebf7..eaf7992681 100644 --- a/app/gegl/gimpcolorizeconfig.h +++ b/app/gegl/gimpcolorizeconfig.h @@ -23,7 +23,7 @@ #define __GIMP_COLORIZE_CONFIG_H__ -#include "core/gimpviewable.h" +#include "core/gimpimagemapconfig.h" #define GIMP_TYPE_COLORIZE_CONFIG (gimp_colorize_config_get_type ()) @@ -38,16 +38,16 @@ typedef struct _GimpColorizeConfigClass GimpColorizeConfigClass; struct _GimpColorizeConfig { - GimpViewable parent_instance; + GimpImageMapConfig parent_instance; - gdouble hue; - gdouble saturation; - gdouble lightness; + gdouble hue; + gdouble saturation; + gdouble lightness; }; struct _GimpColorizeConfigClass { - GimpViewableClass parent_class; + GimpImageMapConfigClass parent_class; }; diff --git a/app/gegl/gimpcurvesconfig.c b/app/gegl/gimpcurvesconfig.c index 99ee57a5b0..f851e44d50 100644 --- a/app/gegl/gimpcurvesconfig.c +++ b/app/gegl/gimpcurvesconfig.c @@ -83,7 +83,7 @@ static void gimp_curves_config_curve_dirty (GimpCurve *curve, G_DEFINE_TYPE_WITH_CODE (GimpCurvesConfig, gimp_curves_config, - GIMP_TYPE_VIEWABLE, + GIMP_TYPE_IMAGE_MAP_CONFIG, G_IMPLEMENT_INTERFACE (GIMP_TYPE_CONFIG, gimp_curves_config_iface_init)) diff --git a/app/gegl/gimpcurvesconfig.h b/app/gegl/gimpcurvesconfig.h index a3e68df16f..91b750ba57 100644 --- a/app/gegl/gimpcurvesconfig.h +++ b/app/gegl/gimpcurvesconfig.h @@ -23,7 +23,7 @@ #define __GIMP_CURVES_CONFIG_H__ -#include "core/gimpviewable.h" +#include "core/gimpimagemapconfig.h" #define GIMP_TYPE_CURVES_CONFIG (gimp_curves_config_get_type ()) @@ -38,7 +38,7 @@ typedef struct _GimpCurvesConfigClass GimpCurvesConfigClass; struct _GimpCurvesConfig { - GimpViewable parent_instance; + GimpImageMapConfig parent_instance; GimpHistogramChannel channel; @@ -47,7 +47,7 @@ struct _GimpCurvesConfig struct _GimpCurvesConfigClass { - GimpViewableClass parent_class; + GimpImageMapConfigClass parent_class; }; diff --git a/app/gegl/gimphuesaturationconfig.c b/app/gegl/gimphuesaturationconfig.c index 750f825129..c9bcec7963 100644 --- a/app/gegl/gimphuesaturationconfig.c +++ b/app/gegl/gimphuesaturationconfig.c @@ -71,7 +71,7 @@ static gboolean gimp_hue_saturation_config_copy (GimpConfig *src, G_DEFINE_TYPE_WITH_CODE (GimpHueSaturationConfig, gimp_hue_saturation_config, - GIMP_TYPE_VIEWABLE, + GIMP_TYPE_IMAGE_MAP_CONFIG, G_IMPLEMENT_INTERFACE (GIMP_TYPE_CONFIG, gimp_hue_saturation_config_iface_init)) diff --git a/app/gegl/gimphuesaturationconfig.h b/app/gegl/gimphuesaturationconfig.h index 65681693ce..dd3819fe67 100644 --- a/app/gegl/gimphuesaturationconfig.h +++ b/app/gegl/gimphuesaturationconfig.h @@ -23,7 +23,7 @@ #define __GIMP_HUE_SATURATION_CONFIG_H__ -#include "core/gimpviewable.h" +#include "core/gimpimagemapconfig.h" #define GIMP_TYPE_HUE_SATURATION_CONFIG (gimp_hue_saturation_config_get_type ()) @@ -38,20 +38,20 @@ typedef struct _GimpHueSaturationConfigClass GimpHueSaturationConfigClass; struct _GimpHueSaturationConfig { - GimpViewable parent_instance; + GimpImageMapConfig parent_instance; - GimpHueRange range; + GimpHueRange range; - gdouble hue[7]; - gdouble saturation[7]; - gdouble lightness[7]; + gdouble hue[7]; + gdouble saturation[7]; + gdouble lightness[7]; - gdouble overlap; + gdouble overlap; }; struct _GimpHueSaturationConfigClass { - GimpViewableClass parent_class; + GimpImageMapConfigClass parent_class; }; diff --git a/app/gegl/gimplevelsconfig.c b/app/gegl/gimplevelsconfig.c index de43fb19c5..37c0116d76 100644 --- a/app/gegl/gimplevelsconfig.c +++ b/app/gegl/gimplevelsconfig.c @@ -85,7 +85,7 @@ static gboolean gimp_levels_config_copy (GimpConfig *src, G_DEFINE_TYPE_WITH_CODE (GimpLevelsConfig, gimp_levels_config, - GIMP_TYPE_VIEWABLE, + GIMP_TYPE_IMAGE_MAP_CONFIG, G_IMPLEMENT_INTERFACE (GIMP_TYPE_CONFIG, gimp_levels_config_iface_init)) diff --git a/app/gegl/gimplevelsconfig.h b/app/gegl/gimplevelsconfig.h index 107b440335..3f5dbadffe 100644 --- a/app/gegl/gimplevelsconfig.h +++ b/app/gegl/gimplevelsconfig.h @@ -23,7 +23,7 @@ #define __GIMP_LEVELS_CONFIG_H__ -#include "core/gimpviewable.h" +#include "core/gimpimagemapconfig.h" #define GIMP_TYPE_LEVELS_CONFIG (gimp_levels_config_get_type ()) @@ -38,7 +38,7 @@ typedef struct _GimpLevelsConfigClass GimpLevelsConfigClass; struct _GimpLevelsConfig { - GimpViewable parent_instance; + GimpImageMapConfig parent_instance; GimpHistogramChannel channel; @@ -53,7 +53,7 @@ struct _GimpLevelsConfig struct _GimpLevelsConfigClass { - GimpViewableClass parent_class; + GimpImageMapConfigClass parent_class; }; diff --git a/app/gegl/gimpposterizeconfig.c b/app/gegl/gimpposterizeconfig.c index 06cc8f581a..611588ca81 100644 --- a/app/gegl/gimpposterizeconfig.c +++ b/app/gegl/gimpposterizeconfig.c @@ -48,7 +48,7 @@ static void gimp_posterize_config_set_property (GObject *object, G_DEFINE_TYPE_WITH_CODE (GimpPosterizeConfig, gimp_posterize_config, - GIMP_TYPE_VIEWABLE, + GIMP_TYPE_IMAGE_MAP_CONFIG, G_IMPLEMENT_INTERFACE (GIMP_TYPE_CONFIG, NULL)) #define parent_class gimp_posterize_config_parent_class diff --git a/app/gegl/gimpposterizeconfig.h b/app/gegl/gimpposterizeconfig.h index 58b57fadb9..a7bc6fe7da 100644 --- a/app/gegl/gimpposterizeconfig.h +++ b/app/gegl/gimpposterizeconfig.h @@ -23,7 +23,7 @@ #define __GIMP_POSTERIZE_CONFIG_H__ -#include "core/gimpviewable.h" +#include "core/gimpimagemapconfig.h" #define GIMP_TYPE_POSTERIZE_CONFIG (gimp_posterize_config_get_type ()) @@ -38,14 +38,14 @@ typedef struct _GimpPosterizeConfigClass GimpPosterizeConfigClass; struct _GimpPosterizeConfig { - GimpViewable parent_instance; + GimpImageMapConfig parent_instance; - gint levels; + gint levels; }; struct _GimpPosterizeConfigClass { - GimpViewableClass parent_class; + GimpImageMapConfigClass parent_class; }; diff --git a/app/gegl/gimpthresholdconfig.c b/app/gegl/gimpthresholdconfig.c index 68ea3d1f79..373f003df6 100644 --- a/app/gegl/gimpthresholdconfig.c +++ b/app/gegl/gimpthresholdconfig.c @@ -52,7 +52,7 @@ static void gimp_threshold_config_set_property (GObject *object, G_DEFINE_TYPE_WITH_CODE (GimpThresholdConfig, gimp_threshold_config, - GIMP_TYPE_VIEWABLE, + GIMP_TYPE_IMAGE_MAP_CONFIG, G_IMPLEMENT_INTERFACE (GIMP_TYPE_CONFIG, NULL)) #define parent_class gimp_threshold_config_parent_class diff --git a/app/gegl/gimpthresholdconfig.h b/app/gegl/gimpthresholdconfig.h index a0c1d4d97d..792330d765 100644 --- a/app/gegl/gimpthresholdconfig.h +++ b/app/gegl/gimpthresholdconfig.h @@ -23,7 +23,7 @@ #define __GIMP_THRESHOLD_CONFIG_H__ -#include "core/gimpviewable.h" +#include "core/gimpimagemapconfig.h" #define GIMP_TYPE_THRESHOLD_CONFIG (gimp_threshold_config_get_type ()) @@ -38,15 +38,15 @@ typedef struct _GimpThresholdConfigClass GimpThresholdConfigClass; struct _GimpThresholdConfig { - GimpViewable parent_instance; + GimpImageMapConfig parent_instance; - gdouble low; - gdouble high; + gdouble low; + gdouble high; }; struct _GimpThresholdConfigClass { - GimpViewableClass parent_class; + GimpImageMapConfigClass parent_class; }; diff --git a/app/tools/gimpimagemaptool-settings.c b/app/tools/gimpimagemaptool-settings.c index 1554237ecf..ed4872f4f3 100644 --- a/app/tools/gimpimagemaptool-settings.c +++ b/app/tools/gimpimagemaptool-settings.c @@ -34,6 +34,7 @@ #include "core/gimp.h" #include "core/gimpcontext.h" +#include "core/gimpimagemapconfig.h" #include "core/gimplist.h" #include "core/gimptoolinfo.h" @@ -49,6 +50,13 @@ /* local function prototypes */ +static void gimp_image_map_tool_recent_deserialize (GimpImageMapTool *im_tool); +static void gimp_image_map_tool_recent_serialize (GimpImageMapTool *im_tool); + +static gboolean + gimp_image_map_tool_row_separator_func (GtkTreeModel *model, + GtkTreeIter *iter, + gpointer data); static void gimp_image_map_tool_recent_selected (GimpContainerView *view, GimpViewable *object, gpointer insert_data, @@ -91,31 +99,7 @@ gimp_image_map_tool_add_settings_gui (GimpImageMapTool *image_map_tool) tool_info = GIMP_TOOL (image_map_tool)->tool_info; if (gimp_container_num_children (klass->recent_settings) == 0) - { - gchar *filename; - GError *error = NULL; - - filename = gimp_tool_info_build_options_filename (tool_info, - ".settings"); - - if (tool_info->gimp->be_verbose) - g_print ("Parsing '%s'\n", gimp_filename_to_utf8 (filename)); - - if (! gimp_config_deserialize_file (GIMP_CONFIG (klass->recent_settings), - filename, - NULL, &error)) - { - if (error->code != GIMP_CONFIG_ERROR_OPEN_ENOENT) - gimp_message (tool_info->gimp, NULL, GIMP_MESSAGE_ERROR, - "%s", error->message); - - g_clear_error (&error); - } - - gimp_list_reverse (GIMP_LIST (klass->recent_settings)); - - g_free (filename); - } + gimp_image_map_tool_recent_deserialize (image_map_tool); hbox = gtk_hbox_new (FALSE, 4); gtk_box_pack_start (GTK_BOX (image_map_tool->main_vbox), hbox, @@ -129,6 +113,9 @@ gimp_image_map_tool_add_settings_gui (GimpImageMapTool *image_map_tool) combo = gimp_container_combo_box_new (klass->recent_settings, GIMP_CONTEXT (tool_info->tool_options), 16, 0); + gtk_combo_box_set_row_separator_func (GTK_COMBO_BOX (combo), + gimp_image_map_tool_row_separator_func, + NULL, NULL); gtk_box_pack_start (GTK_BOX (hbox), combo, TRUE, TRUE, 0); gtk_widget_show (combo); @@ -195,17 +182,10 @@ gimp_image_map_tool_add_settings_gui (GimpImageMapTool *image_map_tool) void gimp_image_map_tool_add_recent_settings (GimpImageMapTool *image_map_tool) { - GimpTool *tool = GIMP_TOOL (image_map_tool); GimpContainer *recent; GimpConfig *current; GimpConfig *config = NULL; GList *list; - time_t now; - struct tm tm; - gchar buf[64]; - gchar *name; - gchar *filename; - GError *error = NULL; recent = GIMP_IMAGE_MAP_TOOL_GET_CLASS (image_map_tool)->recent_settings; current = GIMP_CONFIG (image_map_tool->config); @@ -214,48 +194,29 @@ gimp_image_map_tool_add_recent_settings (GimpImageMapTool *image_map_tool) { config = list->data; - if (gimp_config_is_equal_to (config, current)) + if (GIMP_IMAGE_MAP_CONFIG (config)->time > 0 && + gimp_config_is_equal_to (config, current)) { - gimp_container_reorder (recent, GIMP_OBJECT (config), 0); + g_object_set (current, + "time", (guint) time (NULL), + NULL); break; } - - config = NULL; } - if (! config) + if (! list) { config = gimp_config_duplicate (current); + g_object_set (config, + "time", (guint) time (NULL), + NULL); + gimp_container_insert (recent, GIMP_OBJECT (config), 0); g_object_unref (config); } - now = time (NULL); - tm = *localtime (&now); - strftime (buf, sizeof (buf), "%Y-%m-%d %T", &tm); - name = g_locale_to_utf8 (buf, -1, NULL, NULL, NULL); - gimp_object_set_name (GIMP_OBJECT (config), name); - g_free (name); - - filename = gimp_tool_info_build_options_filename (tool->tool_info, - ".settings"); - - if (tool->tool_info->gimp->be_verbose) - g_print ("Writing '%s'\n", gimp_filename_to_utf8 (filename)); - - if (! gimp_config_serialize_to_file (GIMP_CONFIG (recent), - filename, - "tool settings", - "end of tool settings", - NULL, &error)) - { - gimp_message (tool->tool_info->gimp, NULL, GIMP_MESSAGE_ERROR, - "%s", error->message); - g_clear_error (&error); - } - - g_free (filename); + gimp_image_map_tool_recent_serialize (image_map_tool); } gboolean @@ -305,6 +266,108 @@ gimp_image_map_tool_real_settings_save (GimpImageMapTool *tool, /* private functions */ +static void +gimp_image_map_tool_separator_add (GimpContainer *container) +{ + GimpObject *sep = g_object_new (GIMP_TYPE_IMAGE_MAP_CONFIG, NULL); + + gimp_container_add (container, sep); + g_object_unref (sep); + + g_object_set_data (G_OBJECT (container), "separator", sep); +} + +static void +gimp_image_map_tool_separator_remove (GimpContainer *container) +{ + GimpObject *sep = g_object_get_data (G_OBJECT (container), "separator"); + + gimp_container_remove (container, sep); + + g_object_set_data (G_OBJECT (container), "separator", NULL); +} + +static void +gimp_image_map_tool_recent_deserialize (GimpImageMapTool *im_tool) +{ + GimpImageMapToolClass *klass = GIMP_IMAGE_MAP_TOOL_GET_CLASS (im_tool); + GimpToolInfo *tool_info = GIMP_TOOL (im_tool)->tool_info; + gchar *filename; + GError *error = NULL; + + filename = gimp_tool_info_build_options_filename (tool_info, + ".settings"); + + if (tool_info->gimp->be_verbose) + g_print ("Parsing '%s'\n", gimp_filename_to_utf8 (filename)); + + if (! gimp_config_deserialize_file (GIMP_CONFIG (klass->recent_settings), + filename, + NULL, &error)) + { + if (error->code != GIMP_CONFIG_ERROR_OPEN_ENOENT) + gimp_message (tool_info->gimp, NULL, GIMP_MESSAGE_ERROR, + "%s", error->message); + + g_clear_error (&error); + } + + g_free (filename); + + gimp_image_map_tool_separator_add (klass->recent_settings); +} + +static void +gimp_image_map_tool_recent_serialize (GimpImageMapTool *im_tool) +{ + GimpImageMapToolClass *klass = GIMP_IMAGE_MAP_TOOL_GET_CLASS (im_tool); + GimpToolInfo *tool_info = GIMP_TOOL (im_tool)->tool_info; + gchar *filename; + GError *error = NULL; + + gimp_image_map_tool_separator_remove (klass->recent_settings); + + filename = gimp_tool_info_build_options_filename (tool_info, + ".settings"); + + if (tool_info->gimp->be_verbose) + g_print ("Writing '%s'\n", gimp_filename_to_utf8 (filename)); + + if (! gimp_config_serialize_to_file (GIMP_CONFIG (klass->recent_settings), + filename, + "tool settings", + "end of tool settings", + NULL, &error)) + { + gimp_message (tool_info->gimp, NULL, GIMP_MESSAGE_ERROR, + "%s", error->message); + g_clear_error (&error); + } + + g_free (filename); + + gimp_image_map_tool_separator_add (klass->recent_settings); +} + +static gboolean +gimp_image_map_tool_row_separator_func (GtkTreeModel *model, + GtkTreeIter *iter, + gpointer data) +{ + gchar *name = NULL; + +#ifdef __GNUC__ +#warning FIXME: dont use magic model column +#endif + gtk_tree_model_get (model, iter, + 1, &name, + -1); + + g_free (name); + + return name == NULL; +} + static void gimp_image_map_tool_recent_selected (GimpContainerView *view, GimpViewable *object, @@ -482,9 +545,11 @@ gimp_image_map_tool_favorite_callback (GtkWidget *query_box, config = gimp_config_duplicate (GIMP_CONFIG (tool->config)); gimp_object_set_name (GIMP_OBJECT (config), string); - gimp_container_insert (GIMP_IMAGE_MAP_TOOL_GET_CLASS (tool)->recent_settings, - GIMP_OBJECT (config), 0); + gimp_container_add (GIMP_IMAGE_MAP_TOOL_GET_CLASS (tool)->recent_settings, + GIMP_OBJECT (config)); g_object_unref (config); + + gimp_image_map_tool_recent_serialize (tool); } static gboolean diff --git a/app/tools/gimpimagemaptool.c b/app/tools/gimpimagemaptool.c index b5fd6d0dcb..f8d660a522 100644 --- a/app/tools/gimpimagemaptool.c +++ b/app/tools/gimpimagemaptool.c @@ -18,6 +18,8 @@ #include "config.h" +#include + #include #include #include @@ -33,6 +35,7 @@ #include "core/gimpimage.h" #include "core/gimpimage-pick-color.h" #include "core/gimpimagemap.h" +#include "core/gimpimagemapconfig.h" #include "core/gimplist.h" #include "core/gimppickable.h" #include "core/gimpprojection.h" @@ -170,7 +173,9 @@ gimp_image_map_tool_class_init (GimpImageMapToolClass *klass) static void gimp_image_map_tool_base_init (GimpImageMapToolClass *klass) { - klass->recent_settings = gimp_list_new (GIMP_TYPE_VIEWABLE, FALSE); + klass->recent_settings = gimp_list_new (GIMP_TYPE_VIEWABLE, TRUE); + gimp_list_set_sort_func (GIMP_LIST (klass->recent_settings), + (GCompareFunc) gimp_image_map_config_compare); } static void