Bug 780015 - Filter settings are not properly restored after Gimp restart

Filters settings used to be serialized and deserialized only
when a filter tool's GUI was shown, too late for the code that
re-runs/re-shows filters with previous values.

Move the entire loading/saving code to gimp-operation-config.c, even
adding/removing the dummy separator item between timestamped automatic
history and manually saved settings. Load the settings automatically
when a settings container is requested, but still trigger saving from
the few places the container is changed in the GUI; could also
automate that later.

This commit also moves all settings of filters that have their own
tools from gimpdir/tool-options/ to gimpdir/filters/. Add compat code
to try the old filename if the new doesn't exist, so files are
migrated automatically.

WIP, but this step already fixes the bug.
This commit is contained in:
Michael Natterer 2017-03-24 01:29:50 +01:00
parent 8cf53b40b7
commit ee6c7ec7b7
14 changed files with 300 additions and 187 deletions

View File

@ -251,11 +251,15 @@ gimp_gegl_procedure_execute_async (GimpProcedure *procedure,
GimpContainer *container; GimpContainer *container;
GimpTool *active_tool; GimpTool *active_tool;
settings = gimp_operation_config_new (procedure->original_name, settings = gimp_operation_config_new (gimp,
procedure->original_name,
gimp_viewable_get_icon_name (GIMP_VIEWABLE (procedure)), gimp_viewable_get_icon_name (GIMP_VIEWABLE (procedure)),
GIMP_TYPE_SETTINGS); GIMP_TYPE_SETTINGS);
container = gimp_operation_config_get_container (G_TYPE_FROM_INSTANCE (settings)); container =
gimp_operation_config_get_container (gimp,
G_TYPE_FROM_INSTANCE (settings),
(GCompareFunc) gimp_settings_compare);
g_object_unref (settings); g_object_unref (settings);
@ -263,10 +267,15 @@ gimp_gegl_procedure_execute_async (GimpProcedure *procedure,
settings = gimp_container_get_child_by_index (container, 0); settings = gimp_container_get_child_by_index (container, 0);
/* only use the settings if they are automatically created "last used" /* only use the settings if they are automatically created "last used"
* values, not if they were saved explicitly and have a zero timestamp * values, not if they were saved explicitly and have a zero timestamp;
* and if they are not a separator.
*/ */
if (settings && GIMP_SETTINGS (settings)->time == 0) if (settings &&
(GIMP_SETTINGS (settings)->time == 0 ||
! gimp_object_get_name (settings)))
{
settings = NULL; settings = NULL;
}
if (run_mode == GIMP_RUN_WITH_LAST_VALS) if (run_mode == GIMP_RUN_WITH_LAST_VALS)
{ {

View File

@ -73,7 +73,7 @@ gimp_gegl_init (Gimp *gimp)
gimp_babl_init (); gimp_babl_init ();
gimp_operations_init (); gimp_operations_init (gimp);
} }
static void static void

View File

@ -23,11 +23,14 @@
#include <gegl.h> #include <gegl.h>
#include <gdk-pixbuf/gdk-pixbuf.h> #include <gdk-pixbuf/gdk-pixbuf.h>
#include "libgimpbase/gimpbase.h"
#include "libgimpcolor/gimpcolor.h" #include "libgimpcolor/gimpcolor.h"
#include "libgimpconfig/gimpconfig.h" #include "libgimpconfig/gimpconfig.h"
#include "operations-types.h" #include "operations-types.h"
#include "core/gimp.h"
#include "core/gimplist.h" #include "core/gimplist.h"
#include "core/gimpparamspecs-duplicate.h" #include "core/gimpparamspecs-duplicate.h"
#include "core/gimpviewable.h" #include "core/gimpviewable.h"
@ -49,11 +52,14 @@ static void gimp_operation_config_node_notify (GeglNode *node,
const GParamSpec *gegl_pspec, const GParamSpec *gegl_pspec,
GObject *config); GObject *config);
static void gimp_operation_config_add_sep (GimpContainer *container);
static void gimp_operation_config_remove_sep (GimpContainer *container);
/* public functions */ /* public functions */
static GHashTable * static GHashTable *
gimp_operation_config_get_type_table (void) gimp_operation_config_get_type_table (Gimp *gimp)
{ {
static GHashTable *config_types = NULL; static GHashTable *config_types = NULL;
@ -67,7 +73,7 @@ gimp_operation_config_get_type_table (void)
} }
static GHashTable * static GHashTable *
gimp_operation_config_get_container_table (void) gimp_operation_config_get_container_table (Gimp *gimp)
{ {
static GHashTable *config_containers = NULL; static GHashTable *config_containers = NULL;
@ -235,15 +241,17 @@ gimp_operation_config_config_iface_init (GimpConfigInterface *iface)
/* public functions */ /* public functions */
void void
gimp_operation_config_register (const gchar *operation, gimp_operation_config_register (Gimp *gimp,
const gchar *operation,
GType config_type) GType config_type)
{ {
GHashTable *config_types; GHashTable *config_types;
g_return_if_fail (GIMP_IS_GIMP (gimp));
g_return_if_fail (operation != NULL); g_return_if_fail (operation != NULL);
g_return_if_fail (g_type_is_a (config_type, GIMP_TYPE_OBJECT)); g_return_if_fail (g_type_is_a (config_type, GIMP_TYPE_OBJECT));
config_types = gimp_operation_config_get_type_table (); config_types = gimp_operation_config_get_type_table (gimp);
g_hash_table_insert (config_types, g_hash_table_insert (config_types,
g_strdup (operation), g_strdup (operation),
@ -251,17 +259,19 @@ gimp_operation_config_register (const gchar *operation,
} }
GimpObject * GimpObject *
gimp_operation_config_new (const gchar *operation, gimp_operation_config_new (Gimp *gimp,
const gchar *operation,
const gchar *icon_name, const gchar *icon_name,
GType parent_type) GType parent_type)
{ {
GHashTable *config_types; GHashTable *config_types;
GType config_type; GType config_type;
g_return_val_if_fail (GIMP_IS_GIMP (gimp), NULL);
g_return_val_if_fail (operation != NULL, NULL); g_return_val_if_fail (operation != NULL, NULL);
g_return_val_if_fail (g_type_is_a (parent_type, GIMP_TYPE_OBJECT), NULL); g_return_val_if_fail (g_type_is_a (parent_type, GIMP_TYPE_OBJECT), NULL);
config_types = gimp_operation_config_get_type_table (); config_types = gimp_operation_config_get_type_table (gimp);
config_type = (GType) g_hash_table_lookup (config_types, operation); config_type = (GType) g_hash_table_lookup (config_types, operation);
@ -315,7 +325,7 @@ gimp_operation_config_new (const gchar *operation,
g_type_class_unref (viewable_class); g_type_class_unref (viewable_class);
} }
gimp_operation_config_register (operation, config_type); gimp_operation_config_register (gimp, operation, config_type);
} }
} }
@ -323,28 +333,144 @@ gimp_operation_config_new (const gchar *operation,
} }
GimpContainer * GimpContainer *
gimp_operation_config_get_container (GType config_type) gimp_operation_config_get_container (Gimp *gimp,
GType config_type,
GCompareFunc sort_func)
{ {
GHashTable *config_containers; GHashTable *config_containers;
GimpContainer *container; GimpContainer *container;
g_return_val_if_fail (GIMP_IS_GIMP (gimp), NULL);
g_return_val_if_fail (g_type_is_a (config_type, GIMP_TYPE_OBJECT), NULL); g_return_val_if_fail (g_type_is_a (config_type, GIMP_TYPE_OBJECT), NULL);
config_containers = gimp_operation_config_get_container_table (); config_containers = gimp_operation_config_get_container_table (gimp);
container = g_hash_table_lookup (config_containers, (gpointer) config_type); container = g_hash_table_lookup (config_containers, (gpointer) config_type);
if (! container) if (! container)
{ {
container = gimp_list_new (config_type, TRUE); container = gimp_list_new (config_type, TRUE);
gimp_list_set_sort_func (GIMP_LIST (container), sort_func);
g_hash_table_insert (config_containers, g_hash_table_insert (config_containers,
(gpointer) config_type, container); (gpointer) config_type, container);
gimp_operation_config_deserialize (gimp, container, NULL);
if (gimp_container_get_n_children (container) == 0)
{
gchar *basename;
GFile *file;
basename = g_strconcat (g_type_name (config_type), ".settings", NULL);
file = gimp_directory_file ("filters", basename, NULL);
g_free (basename);
if (! g_file_query_exists (file, NULL))
{
GQuark quark = g_quark_from_static_string ("compat-file");
g_object_unref (file);
file = g_type_get_qdata (config_type, quark);
if (file)
{
g_object_ref (file);
gimp_operation_config_deserialize (gimp, container, file);
}
}
g_object_unref (file);
}
gimp_operation_config_add_sep (container);
} }
return container; return container;
} }
void
gimp_operation_config_serialize (Gimp *gimp,
GimpContainer *container,
GFile *file)
{
GError *error = NULL;
g_return_if_fail (GIMP_IS_GIMP (gimp));
g_return_if_fail (GIMP_IS_CONTAINER (container));
g_return_if_fail (file == NULL || G_IS_FILE (file));
if (! file)
{
GType config_type = gimp_container_get_children_type (container);
gchar *basename;
basename = g_strconcat (g_type_name (config_type), ".settings", NULL);
file = gimp_directory_file ("filters", basename, NULL);
g_free (basename);
}
if (gimp->be_verbose)
g_print ("Writing '%s'\n", gimp_file_get_utf8_name (file));
gimp_operation_config_remove_sep (container);
if (! gimp_config_serialize_to_gfile (GIMP_CONFIG (container),
file,
"settings",
"end of settings",
NULL, &error))
{
gimp_message_literal (gimp, NULL, GIMP_MESSAGE_ERROR,
error->message);
g_clear_error (&error);
}
gimp_operation_config_add_sep (container);
g_object_unref (file);
}
void
gimp_operation_config_deserialize (Gimp *gimp,
GimpContainer *container,
GFile *file)
{
GError *error = NULL;
g_return_if_fail (GIMP_IS_GIMP (gimp));
g_return_if_fail (GIMP_IS_CONTAINER (container));
g_return_if_fail (file == NULL || G_IS_FILE (file));
if (! file)
{
GType config_type = gimp_container_get_children_type (container);
gchar *basename;
basename = g_strconcat (g_type_name (config_type), ".settings", NULL);
file = gimp_directory_file ("filters", basename, NULL);
g_free (basename);
}
if (gimp->be_verbose)
g_print ("Parsing '%s'\n", gimp_file_get_utf8_name (file));
if (! gimp_config_deserialize_gfile (GIMP_CONFIG (container),
file,
NULL, &error))
{
if (error->code != GIMP_CONFIG_ERROR_OPEN_ENOENT)
gimp_message_literal (gimp, NULL, GIMP_MESSAGE_ERROR,
error->message);
g_clear_error (&error);
}
g_object_unref (file);
}
void void
gimp_operation_config_sync_node (GimpObject *config, gimp_operation_config_sync_node (GimpObject *config,
GeglNode *node) GeglNode *node)
@ -611,3 +737,33 @@ gimp_operation_config_node_notify (GeglNode *node,
g_signal_handler_unblock (config, handler); g_signal_handler_unblock (config, handler);
} }
} }
static void
gimp_operation_config_add_sep (GimpContainer *container)
{
GimpObject *sep = g_object_get_data (G_OBJECT (container), "separator");
if (! sep)
{
sep = g_object_new (gimp_container_get_children_type (container),
NULL);
gimp_container_add (container, sep);
g_object_unref (sep);
g_object_set_data (G_OBJECT (container), "separator", sep);
}
}
static void
gimp_operation_config_remove_sep (GimpContainer *container)
{
GimpObject *sep = g_object_get_data (G_OBJECT (container), "separator");
if (sep)
{
gimp_container_remove (container, sep);
g_object_set_data (G_OBJECT (container), "separator", NULL);
}
}

View File

@ -19,13 +19,25 @@
#define __GIMP_OPERATION_CONFIG_H__ #define __GIMP_OPERATION_CONFIG_H__
void gimp_operation_config_register (const gchar *operation, void gimp_operation_config_register (Gimp *gimp,
const gchar *operation,
GType config_type); GType config_type);
GimpObject * gimp_operation_config_new (const gchar *operation, GimpObject * gimp_operation_config_new (Gimp *gimp,
const gchar *operation,
const gchar *icon_name, const gchar *icon_name,
GType parent_type); GType parent_type);
GimpContainer * gimp_operation_config_get_container (GType config_type);
GimpContainer * gimp_operation_config_get_container (Gimp *gimp,
GType config_type,
GCompareFunc sort_func);
void gimp_operation_config_serialize (Gimp *gimp,
GimpContainer *container,
GFile *file);
void gimp_operation_config_deserialize (Gimp *gimp,
GimpContainer *container,
GFile *file);
void gimp_operation_config_sync_node (GimpObject *config, void gimp_operation_config_sync_node (GimpObject *config,
GeglNode *node); GeglNode *node);

View File

@ -22,6 +22,8 @@
#include <gdk-pixbuf/gdk-pixbuf.h> #include <gdk-pixbuf/gdk-pixbuf.h>
#include <gegl.h> #include <gegl.h>
#include "libgimpbase/gimpbase.h"
#include "operations-types.h" #include "operations-types.h"
#include "core/gimp.h" #include "core/gimp.h"
@ -94,9 +96,21 @@
#include "layer-modes/gimpoperationsplit.h" #include "layer-modes/gimpoperationsplit.h"
void static void
gimp_operations_init (void) set_compat_file (GType type,
const gchar *basename)
{ {
GFile *file = gimp_directory_file ("tool-options", basename, NULL);
GQuark quark = g_quark_from_static_string ("compat-file");
g_type_set_qdata (type, quark, file);
}
void
gimp_operations_init (Gimp *gimp)
{
g_return_if_fail (GIMP_IS_GIMP (gimp));
gimp_layer_modes_init (); gimp_layer_modes_init ();
g_type_class_ref (GIMP_TYPE_OPERATION_BLEND); g_type_class_ref (GIMP_TYPE_OPERATION_BLEND);
@ -154,16 +168,39 @@ gimp_operations_init (void)
g_type_class_ref (GIMP_TYPE_OPERATION_REPLACE); g_type_class_ref (GIMP_TYPE_OPERATION_REPLACE);
g_type_class_ref (GIMP_TYPE_OPERATION_ANTI_ERASE); g_type_class_ref (GIMP_TYPE_OPERATION_ANTI_ERASE);
gimp_operation_config_register ("gimp:brightness-contrast", gimp_operation_config_register (gimp,
"gimp:brightness-contrast",
GIMP_TYPE_BRIGHTNESS_CONTRAST_CONFIG); GIMP_TYPE_BRIGHTNESS_CONTRAST_CONFIG);
gimp_operation_config_register ("gimp:color-balance", set_compat_file (GIMP_TYPE_BRIGHTNESS_CONTRAST_CONFIG,
"gimp-brightness-contrast-tool.settings");
gimp_operation_config_register (gimp,
"gimp:color-balance",
GIMP_TYPE_COLOR_BALANCE_CONFIG); GIMP_TYPE_COLOR_BALANCE_CONFIG);
gimp_operation_config_register ("gimp:colorize", set_compat_file (GIMP_TYPE_COLOR_BALANCE_CONFIG,
"gimp-color-balance-tool.settings");
gimp_operation_config_register (gimp,
"gimp:colorize",
GIMP_TYPE_COLORIZE_CONFIG); GIMP_TYPE_COLORIZE_CONFIG);
gimp_operation_config_register ("gimp:curves", set_compat_file (GIMP_TYPE_COLORIZE_CONFIG,
"gimp-colorize-tool.settings");
gimp_operation_config_register (gimp,
"gimp:curves",
GIMP_TYPE_CURVES_CONFIG); GIMP_TYPE_CURVES_CONFIG);
gimp_operation_config_register ("gimp:hue-saturation", set_compat_file (GIMP_TYPE_CURVES_CONFIG,
"gimp-curves-tool.settings");
gimp_operation_config_register (gimp,
"gimp:hue-saturation",
GIMP_TYPE_HUE_SATURATION_CONFIG); GIMP_TYPE_HUE_SATURATION_CONFIG);
gimp_operation_config_register ("gimp:levels", set_compat_file (GIMP_TYPE_HUE_SATURATION_CONFIG,
"gimp-hue-saturation-tool.settings");
gimp_operation_config_register (gimp,
"gimp:levels",
GIMP_TYPE_LEVELS_CONFIG); GIMP_TYPE_LEVELS_CONFIG);
set_compat_file (GIMP_TYPE_LEVELS_CONFIG,
"gimp-levels-tool.settings");
} }

View File

@ -21,7 +21,7 @@
#define __GIMP_OPERATIONS_H__ #define __GIMP_OPERATIONS_H__
void gimp_operations_init (void); void gimp_operations_init (Gimp *gimp);
#endif /* __GIMP_OPERATIONS_H__ */ #endif /* __GIMP_OPERATIONS_H__ */

View File

@ -62,7 +62,6 @@ static gboolean gimp_filter_tool_settings_export (GimpSettingsBox *box,
GtkWidget * GtkWidget *
gimp_filter_tool_real_get_settings_ui (GimpFilterTool *filter_tool, gimp_filter_tool_real_get_settings_ui (GimpFilterTool *filter_tool,
GimpContainer *settings, GimpContainer *settings,
GFile *settings_file,
const gchar *import_dialog_title, const gchar *import_dialog_title,
const gchar *export_dialog_title, const gchar *export_dialog_title,
const gchar *file_dialog_help_id, const gchar *file_dialog_help_id,
@ -85,7 +84,6 @@ gimp_filter_tool_real_get_settings_ui (GimpFilterTool *filter_tool,
*settings_box = gimp_settings_box_new (tool_info->gimp, *settings_box = gimp_settings_box_new (tool_info->gimp,
filter_tool->config, filter_tool->config,
settings, settings,
settings_file,
import_dialog_title, import_dialog_title,
export_dialog_title, export_dialog_title,
file_dialog_help_id, file_dialog_help_id,

View File

@ -23,7 +23,6 @@
GtkWidget * gimp_filter_tool_real_get_settings_ui (GimpFilterTool *filter_tool, GtkWidget * gimp_filter_tool_real_get_settings_ui (GimpFilterTool *filter_tool,
GimpContainer *settings, GimpContainer *settings,
GFile *settings_file,
const gchar *import_dialog_title, const gchar *import_dialog_title,
const gchar *export_dialog_title, const gchar *export_dialog_title,
const gchar *file_dialog_help_id, const gchar *file_dialog_help_id,

View File

@ -133,6 +133,9 @@ static void gimp_filter_tool_dialog (GimpFilterTool *filter_to
static void gimp_filter_tool_dialog_unmap (GtkWidget *dialog, static void gimp_filter_tool_dialog_unmap (GtkWidget *dialog,
GimpFilterTool *filter_tool); GimpFilterTool *filter_tool);
static void gimp_filter_tool_reset (GimpFilterTool *filter_tool); static void gimp_filter_tool_reset (GimpFilterTool *filter_tool);
static GtkWidget * gimp_filter_tool_get_settings_ui
(GimpFilterTool *filter_tool);
static void gimp_filter_tool_create_filter (GimpFilterTool *filter_tool); static void gimp_filter_tool_create_filter (GimpFilterTool *filter_tool);
static void gimp_filter_tool_flush (GimpDrawableFilter *filter, static void gimp_filter_tool_flush (GimpDrawableFilter *filter,
@ -374,33 +377,9 @@ gimp_filter_tool_initialize (GimpTool *tool,
if (filter_tool->config && klass->settings_name) if (filter_tool->config && klass->settings_name)
{ {
GType type = G_TYPE_FROM_INSTANCE (filter_tool->config);
GimpContainer *settings;
GFile *settings_file;
GFile *default_folder;
GtkWidget *settings_ui; GtkWidget *settings_ui;
settings = gimp_operation_config_get_container (type); settings_ui = gimp_filter_tool_get_settings_ui (filter_tool);
if (! gimp_list_get_sort_func (GIMP_LIST (settings)))
gimp_list_set_sort_func (GIMP_LIST (settings),
(GCompareFunc) gimp_settings_compare);
settings_file = gimp_tool_info_get_options_file (tool_info,
".settings");
default_folder = gimp_directory_file (klass->settings_name, NULL);
settings_ui = klass->get_settings_ui (filter_tool,
settings,
settings_file,
klass->import_dialog_title,
klass->export_dialog_title,
filter_tool->help_id,
default_folder,
&filter_tool->settings_box);
g_object_unref (default_folder);
g_object_unref (settings_file);
gtk_box_pack_start (GTK_BOX (vbox), settings_ui, FALSE, FALSE, 0); gtk_box_pack_start (GTK_BOX (vbox), settings_ui, FALSE, FALSE, 0);
gtk_widget_show (settings_ui); gtk_widget_show (settings_ui);
} }
@ -977,6 +956,36 @@ gimp_filter_tool_reset (GimpFilterTool *filter_tool)
g_object_thaw_notify (filter_tool->config); g_object_thaw_notify (filter_tool->config);
} }
static GtkWidget *
gimp_filter_tool_get_settings_ui (GimpFilterTool *filter_tool)
{
GimpTool *tool = GIMP_TOOL (filter_tool);
GimpFilterToolClass *klass = GIMP_FILTER_TOOL_GET_CLASS (filter_tool);
GType type = G_TYPE_FROM_INSTANCE (filter_tool->config);
GimpContainer *settings;
GFile *default_folder;
GtkWidget *settings_ui;
settings =
gimp_operation_config_get_container (tool->tool_info->gimp,
type,
(GCompareFunc) gimp_settings_compare);
default_folder = gimp_directory_file (klass->settings_name, NULL);
settings_ui = klass->get_settings_ui (filter_tool,
settings,
klass->import_dialog_title,
klass->export_dialog_title,
filter_tool->help_id,
default_folder,
&filter_tool->settings_box);
g_object_unref (default_folder);
return settings_ui;
}
static void static void
gimp_filter_tool_create_filter (GimpFilterTool *filter_tool) gimp_filter_tool_create_filter (GimpFilterTool *filter_tool)
{ {
@ -1313,7 +1322,8 @@ gimp_filter_tool_get_operation (GimpFilterTool *filter_tool)
"operation", operation_name, "operation", operation_name,
NULL); NULL);
filter_tool->config = filter_tool->config =
G_OBJECT (gimp_operation_config_new (operation_name, G_OBJECT (gimp_operation_config_new (tool_info->gimp,
operation_name,
filter_tool->icon_name, filter_tool->icon_name,
GIMP_TYPE_SETTINGS)); GIMP_TYPE_SETTINGS));

View File

@ -82,7 +82,6 @@ struct _GimpFilterToolClass
GtkWidget * (* get_settings_ui) (GimpFilterTool *filter_tool, GtkWidget * (* get_settings_ui) (GimpFilterTool *filter_tool,
GimpContainer *settings, GimpContainer *settings,
GFile *settings_file,
const gchar *import_dialog_title, const gchar *import_dialog_title,
const gchar *export_dialog_title, const gchar *export_dialog_title,
const gchar *file_dialog_help_id, const gchar *file_dialog_help_id,

View File

@ -88,7 +88,6 @@ static void gimp_operation_tool_dialog (GimpFilterTool *filte
static void gimp_operation_tool_reset (GimpFilterTool *filter_tool); static void gimp_operation_tool_reset (GimpFilterTool *filter_tool);
static GtkWidget * gimp_operation_tool_get_settings_ui (GimpFilterTool *filter_tool, static GtkWidget * gimp_operation_tool_get_settings_ui (GimpFilterTool *filter_tool,
GimpContainer *settings, GimpContainer *settings,
GFile *settings_file,
const gchar *import_dialog_title, const gchar *import_dialog_title,
const gchar *export_dialog_title, const gchar *export_dialog_title,
const gchar *file_dialog_help_id, const gchar *file_dialog_help_id,
@ -320,7 +319,6 @@ gimp_operation_tool_reset (GimpFilterTool *filter_tool)
static GtkWidget * static GtkWidget *
gimp_operation_tool_get_settings_ui (GimpFilterTool *filter_tool, gimp_operation_tool_get_settings_ui (GimpFilterTool *filter_tool,
GimpContainer *settings, GimpContainer *settings,
GFile *settings_file,
const gchar *import_dialog_title, const gchar *import_dialog_title,
const gchar *export_dialog_title, const gchar *export_dialog_title,
const gchar *file_dialog_help_id, const gchar *file_dialog_help_id,
@ -329,23 +327,15 @@ gimp_operation_tool_get_settings_ui (GimpFilterTool *filter_tool,
{ {
GimpOperationTool *tool = GIMP_OPERATION_TOOL (filter_tool); GimpOperationTool *tool = GIMP_OPERATION_TOOL (filter_tool);
GtkWidget *widget; GtkWidget *widget;
gchar *basename;
GFile *file;
gchar *import_title; gchar *import_title;
gchar *export_title; gchar *export_title;
basename = g_strconcat (G_OBJECT_TYPE_NAME (filter_tool->config),
".settings", NULL);
file = gimp_directory_file ("filters", basename, NULL);
g_free (basename);
import_title = g_strdup_printf (_("Import '%s' Settings"), tool->title); import_title = g_strdup_printf (_("Import '%s' Settings"), tool->title);
export_title = g_strdup_printf (_("Export '%s' Settings"), tool->title); export_title = g_strdup_printf (_("Export '%s' Settings"), tool->title);
widget = widget =
GIMP_FILTER_TOOL_CLASS (parent_class)->get_settings_ui (filter_tool, GIMP_FILTER_TOOL_CLASS (parent_class)->get_settings_ui (filter_tool,
settings, settings,
file,
import_title, import_title,
export_title, export_title,
file_dialog_help_id, file_dialog_help_id,
@ -355,8 +345,6 @@ gimp_operation_tool_get_settings_ui (GimpFilterTool *filter_tool,
g_free (import_title); g_free (import_title);
g_free (export_title); g_free (export_title);
g_object_unref (file);
return widget; return widget;
} }

View File

@ -2,7 +2,7 @@
* Copyright (C) 1995 Spencer Kimball and Peter Mattis * Copyright (C) 1995 Spencer Kimball and Peter Mattis
* *
* gimpsettingsbox.c * gimpsettingsbox.c
* Copyright (C) 2008 Michael Natterer <mitch@gimp.org> * Copyright (C) 2008-2017 Michael Natterer <mitch@gimp.org>
* *
* This program is free software: you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
@ -23,12 +23,13 @@
#include <gegl.h> #include <gegl.h>
#include <gtk/gtk.h> #include <gtk/gtk.h>
#include "libgimpbase/gimpbase.h"
#include "libgimpconfig/gimpconfig.h" #include "libgimpconfig/gimpconfig.h"
#include "libgimpwidgets/gimpwidgets.h" #include "libgimpwidgets/gimpwidgets.h"
#include "widgets-types.h" #include "widgets-types.h"
#include "operations/gimp-operation-config.h"
#include "core/gimp.h" #include "core/gimp.h"
#include "core/gimplist.h" #include "core/gimplist.h"
#include "core/gimpmarshal.h" #include "core/gimpmarshal.h"
@ -56,8 +57,7 @@ enum
PROP_0, PROP_0,
PROP_GIMP, PROP_GIMP,
PROP_CONFIG, PROP_CONFIG,
PROP_CONTAINER, PROP_CONTAINER
PROP_FILE
}; };
@ -75,7 +75,6 @@ struct _GimpSettingsBoxPrivate
Gimp *gimp; Gimp *gimp;
GObject *config; GObject *config;
GimpContainer *container; GimpContainer *container;
GFile *file;
gchar *import_dialog_title; gchar *import_dialog_title;
gchar *export_dialog_title; gchar *export_dialog_title;
@ -100,8 +99,6 @@ static void gimp_settings_box_get_property (GObject *object,
GValue *value, GValue *value,
GParamSpec *pspec); GParamSpec *pspec);
static void gimp_settings_box_deserialize (GimpSettingsBox *box);
static void gimp_settings_box_serialize (GimpSettingsBox *box);
static GtkWidget * static GtkWidget *
gimp_settings_box_menu_item_add (GimpSettingsBox *box, gimp_settings_box_menu_item_add (GimpSettingsBox *box,
const gchar *icon_name, const gchar *icon_name,
@ -218,13 +215,6 @@ gimp_settings_box_class_init (GimpSettingsBoxClass *klass)
GIMP_PARAM_READWRITE | GIMP_PARAM_READWRITE |
G_PARAM_CONSTRUCT_ONLY)); G_PARAM_CONSTRUCT_ONLY));
g_object_class_install_property (object_class, PROP_FILE,
g_param_spec_object ("file",
NULL, NULL,
G_TYPE_FILE,
GIMP_PARAM_READWRITE |
G_PARAM_CONSTRUCT_ONLY));
g_type_class_add_private (klass, sizeof (GimpSettingsBoxPrivate)); g_type_class_add_private (klass, sizeof (GimpSettingsBoxPrivate));
} }
@ -252,10 +242,6 @@ gimp_settings_box_constructed (GObject *object)
g_assert (GIMP_IS_GIMP (private->gimp)); g_assert (GIMP_IS_GIMP (private->gimp));
g_assert (GIMP_IS_CONFIG (private->config)); g_assert (GIMP_IS_CONFIG (private->config));
g_assert (GIMP_IS_CONTAINER (private->container)); g_assert (GIMP_IS_CONTAINER (private->container));
g_assert (G_IS_FILE (private->file));
if (gimp_container_get_n_children (private->container) == 0)
gimp_settings_box_deserialize (box);
private->combo = gimp_container_combo_box_new (private->container, private->combo = gimp_container_combo_box_new (private->container,
gimp_get_user_context (private->gimp), gimp_get_user_context (private->gimp),
@ -352,12 +338,6 @@ gimp_settings_box_finalize (GObject *object)
private->container = NULL; private->container = NULL;
} }
if (private->file)
{
g_object_unref (private->file);
private->file = NULL;
}
if (private->last_file) if (private->last_file)
{ {
g_object_unref (private->last_file); g_object_unref (private->last_file);
@ -423,10 +403,6 @@ gimp_settings_box_set_property (GObject *object,
private->container = g_value_dup_object (value); private->container = g_value_dup_object (value);
break; break;
case PROP_FILE:
private->file = g_value_dup_object (value);
break;
default: default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
break; break;
@ -455,86 +431,12 @@ gimp_settings_box_get_property (GObject *object,
g_value_set_object (value, private->container); g_value_set_object (value, private->container);
break; break;
case PROP_FILE:
g_value_set_object (value, private->file);
break;
default: default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
break; break;
} }
} }
static void
gimp_settings_box_separator_add (GimpContainer *container)
{
GimpObject *sep = g_object_new (gimp_container_get_children_type (container),
NULL);
gimp_container_add (container, sep);
g_object_unref (sep);
g_object_set_data (G_OBJECT (container), "separator", sep);
}
static void
gimp_settings_box_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_settings_box_deserialize (GimpSettingsBox *box)
{
GimpSettingsBoxPrivate *private = GET_PRIVATE (box);
GError *error = NULL;
if (private->gimp->be_verbose)
g_print ("Parsing '%s'\n", gimp_file_get_utf8_name (private->file));
if (! gimp_config_deserialize_gfile (GIMP_CONFIG (private->container),
private->file,
NULL, &error))
{
if (error->code != GIMP_CONFIG_ERROR_OPEN_ENOENT)
gimp_message_literal (private->gimp, NULL, GIMP_MESSAGE_ERROR,
error->message);
g_clear_error (&error);
}
gimp_settings_box_separator_add (private->container);
}
static void
gimp_settings_box_serialize (GimpSettingsBox *box)
{
GimpSettingsBoxPrivate *private = GET_PRIVATE (box);
GError *error = NULL;
gimp_settings_box_separator_remove (private->container);
if (private->gimp->be_verbose)
g_print ("Writing '%s'\n", gimp_file_get_utf8_name (private->file));
if (! gimp_config_serialize_to_gfile (GIMP_CONFIG (private->container),
private->file,
"settings",
"end of settings",
NULL, &error))
{
gimp_message_literal (private->gimp, NULL, GIMP_MESSAGE_ERROR,
error->message);
g_clear_error (&error);
}
gimp_settings_box_separator_add (private->container);
}
static GtkWidget * static GtkWidget *
gimp_settings_box_menu_item_add (GimpSettingsBox *box, gimp_settings_box_menu_item_add (GimpSettingsBox *box,
const gchar *icon_name, const gchar *icon_name,
@ -735,7 +637,7 @@ gimp_settings_box_favorite_callback (GtkWidget *query_box,
gimp_container_add (private->container, GIMP_OBJECT (config)); gimp_container_add (private->container, GIMP_OBJECT (config));
g_object_unref (config); g_object_unref (config);
gimp_settings_box_serialize (box); gimp_operation_config_serialize (private->gimp, private->container, NULL);
} }
static void static void
@ -950,7 +852,6 @@ GtkWidget *
gimp_settings_box_new (Gimp *gimp, gimp_settings_box_new (Gimp *gimp,
GObject *config, GObject *config,
GimpContainer *container, GimpContainer *container,
GFile *file,
const gchar *import_dialog_title, const gchar *import_dialog_title,
const gchar *export_dialog_title, const gchar *export_dialog_title,
const gchar *file_dialog_help_id, const gchar *file_dialog_help_id,
@ -963,7 +864,6 @@ gimp_settings_box_new (Gimp *gimp,
g_return_val_if_fail (GIMP_IS_GIMP (gimp), NULL); g_return_val_if_fail (GIMP_IS_GIMP (gimp), NULL);
g_return_val_if_fail (GIMP_IS_CONFIG (config), NULL); g_return_val_if_fail (GIMP_IS_CONFIG (config), NULL);
g_return_val_if_fail (GIMP_IS_CONTAINER (container), NULL); g_return_val_if_fail (GIMP_IS_CONTAINER (container), NULL);
g_return_val_if_fail (G_IS_FILE (file), NULL);
g_return_val_if_fail (default_folder == NULL || G_IS_FILE (default_folder), g_return_val_if_fail (default_folder == NULL || G_IS_FILE (default_folder),
NULL); NULL);
g_return_val_if_fail (last_file == NULL || G_IS_FILE (last_file), NULL); g_return_val_if_fail (last_file == NULL || G_IS_FILE (last_file), NULL);
@ -972,7 +872,6 @@ gimp_settings_box_new (Gimp *gimp,
"gimp", gimp, "gimp", gimp,
"config", config, "config", config,
"container", container, "container", container,
"file", file,
NULL); NULL);
private = GET_PRIVATE (box); private = GET_PRIVATE (box);
@ -1037,7 +936,7 @@ gimp_settings_box_add_current (GimpSettingsBox *box,
gimp_settings_box_truncate_list (box, max_recent); gimp_settings_box_truncate_list (box, max_recent);
gimp_settings_box_serialize (box); gimp_operation_config_serialize (private->gimp, private->container, NULL);
} }
GtkWidget * GtkWidget *

View File

@ -57,7 +57,6 @@ GType gimp_settings_box_get_type (void) G_GNUC_CONST;
GtkWidget * gimp_settings_box_new (Gimp *gimp, GtkWidget * gimp_settings_box_new (Gimp *gimp,
GObject *config, GObject *config,
GimpContainer *container, GimpContainer *container,
GFile *file,
const gchar *import_dialog_title, const gchar *import_dialog_title,
const gchar *export_dialog_title, const gchar *export_dialog_title,
const gchar *file_dialog_help_id, const gchar *file_dialog_help_id,

View File

@ -2,7 +2,7 @@
* Copyright (C) 1995 Spencer Kimball and Peter Mattis * Copyright (C) 1995 Spencer Kimball and Peter Mattis
* *
* gimpsettingseditor.c * gimpsettingseditor.c
* Copyright (C) 2008-2011 Michael Natterer <mitch@gimp.org> * Copyright (C) 2008-2017 Michael Natterer <mitch@gimp.org>
* *
* This program is free software: you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
@ -31,8 +31,10 @@
#include "widgets-types.h" #include "widgets-types.h"
#include "operations/gimp-operation-config.h"
#include "core/gimp.h" #include "core/gimp.h"
#include "core/gimplist.h" #include "core/gimpcontainer.h"
#include "core/gimpviewable.h" #include "core/gimpviewable.h"
#include "gimpcontainertreestore.h" #include "gimpcontainertreestore.h"
@ -360,6 +362,8 @@ gimp_settings_editor_delete_clicked (GtkWidget *widget,
gimp_container_view_select_item (GIMP_CONTAINER_VIEW (private->view), gimp_container_view_select_item (GIMP_CONTAINER_VIEW (private->view),
GIMP_VIEWABLE (new)); GIMP_VIEWABLE (new));
gimp_operation_config_serialize (private->gimp, private->container, NULL);
} }
} }
@ -409,6 +413,9 @@ gimp_settings_editor_name_edited (GtkCellRendererText *cell,
/* set name after time so the object is reordered correctly */ /* set name after time so the object is reordered correctly */
gimp_object_take_name (object, name); gimp_object_take_name (object, name);
gimp_operation_config_serialize (private->gimp, private->container,
NULL);
} }
else else
{ {