From 22767ca7b8e47aaec023400197c94605f0e5c515 Mon Sep 17 00:00:00 2001 From: Michael Natterer Date: Sat, 31 Oct 2009 18:48:38 +0100 Subject: [PATCH] Seal GimpData completely and add the missing accessors --- app/actions/brushes-actions.c | 2 +- app/actions/context-commands.c | 20 +- app/actions/data-commands.c | 4 +- app/actions/dynamics-actions.c | 2 +- app/actions/gradient-editor-commands.c | 10 +- app/actions/gradients-actions.c | 2 +- app/actions/palettes-actions.c | 2 +- app/actions/patterns-actions.c | 2 +- app/core/gimpbrush.c | 6 +- app/core/gimpcurve.c | 4 +- app/core/gimpdata.c | 304 ++++++++++++++++++------- app/core/gimpdata.h | 27 +-- app/core/gimpdatafactory.c | 17 +- app/core/gimpdynamics.c | 5 +- app/core/gimpgradient.c | 5 +- app/core/gimppalette.c | 5 +- app/core/gimppattern.c | 6 +- app/pdb/brush-cmds.c | 4 +- app/pdb/gimppdb-utils.c | 6 +- app/pdb/gradient-cmds.c | 6 +- app/pdb/palette-cmds.c | 4 +- app/widgets/gimpdataeditor.c | 9 +- app/widgets/gimpdatafactoryview.c | 2 +- tools/pdbgen/pdb/brush.pdb | 4 +- tools/pdbgen/pdb/gradient.pdb | 6 +- tools/pdbgen/pdb/palette.pdb | 4 +- 26 files changed, 301 insertions(+), 167 deletions(-) diff --git a/app/actions/brushes-actions.c b/app/actions/brushes-actions.c index 0f53a11a28..d5b9c394fa 100644 --- a/app/actions/brushes-actions.c +++ b/app/actions/brushes-actions.c @@ -130,7 +130,7 @@ brushes_actions_update (GimpActionGroup *group, SET_SENSITIVE ("brushes-open-as-image", brush && filename && ! GIMP_IS_BRUSH_GENERATED (brush)); SET_SENSITIVE ("brushes-duplicate", brush && GIMP_DATA_GET_CLASS (data)->duplicate); SET_SENSITIVE ("brushes-copy-location", brush && filename); - SET_SENSITIVE ("brushes-delete", brush && data->deletable); + SET_SENSITIVE ("brushes-delete", brush && gimp_data_is_deletable (data)); #undef SET_SENSITIVE } diff --git a/app/actions/context-commands.c b/app/actions/context-commands.c index 068cd8c29f..ac6f004641 100644 --- a/app/actions/context-commands.c +++ b/app/actions/context-commands.c @@ -511,7 +511,7 @@ context_brush_spacing_cmd_callback (GtkAction *action, brush = gimp_context_get_brush (context); - if (GIMP_IS_BRUSH (brush) && GIMP_DATA (brush)->writable) + if (GIMP_IS_BRUSH (brush) && gimp_data_is_writable (GIMP_DATA (brush))) { action_select_property ((GimpActionSelectType) value, action_data_get_display (data), @@ -532,7 +532,8 @@ context_brush_shape_cmd_callback (GtkAction *action, brush = gimp_context_get_brush (context); - if (GIMP_IS_BRUSH_GENERATED (brush) && GIMP_DATA (brush)->writable) + if (GIMP_IS_BRUSH_GENERATED (brush) && + gimp_data_is_writable (GIMP_DATA (brush))) { GimpBrushGenerated *generated = GIMP_BRUSH_GENERATED (brush); GimpDisplay *display; @@ -564,7 +565,8 @@ context_brush_radius_cmd_callback (GtkAction *action, brush = gimp_context_get_brush (context); - if (GIMP_IS_BRUSH_GENERATED (brush) && GIMP_DATA (brush)->writable) + if (GIMP_IS_BRUSH_GENERATED (brush) && + gimp_data_is_writable (GIMP_DATA (brush))) { GimpBrushGenerated *generated = GIMP_BRUSH_GENERATED (brush); GimpDisplay *display; @@ -623,7 +625,8 @@ context_brush_spikes_cmd_callback (GtkAction *action, brush = gimp_context_get_brush (context); - if (GIMP_IS_BRUSH_GENERATED (brush) && GIMP_DATA (brush)->writable) + if (GIMP_IS_BRUSH_GENERATED (brush) && + gimp_data_is_writable (GIMP_DATA (brush))) { action_select_property ((GimpActionSelectType) value, action_data_get_display (data), @@ -644,7 +647,8 @@ context_brush_hardness_cmd_callback (GtkAction *action, brush = gimp_context_get_brush (context); - if (GIMP_IS_BRUSH_GENERATED (brush) && GIMP_DATA (brush)->writable) + if (GIMP_IS_BRUSH_GENERATED (brush) && + gimp_data_is_writable (GIMP_DATA (brush))) { action_select_property ((GimpActionSelectType) value, action_data_get_display (data), @@ -665,7 +669,8 @@ context_brush_aspect_cmd_callback (GtkAction *action, brush = gimp_context_get_brush (context); - if (GIMP_IS_BRUSH_GENERATED (brush) && GIMP_DATA (brush)->writable) + if (GIMP_IS_BRUSH_GENERATED (brush) && + gimp_data_is_writable (GIMP_DATA (brush))) { action_select_property ((GimpActionSelectType) value, action_data_get_display (data), @@ -686,7 +691,8 @@ context_brush_angle_cmd_callback (GtkAction *action, brush = gimp_context_get_brush (context); - if (GIMP_IS_BRUSH_GENERATED (brush) && GIMP_DATA (brush)->writable) + if (GIMP_IS_BRUSH_GENERATED (brush) && + gimp_data_is_writable (GIMP_DATA (brush))) { GimpBrushGenerated *generated = GIMP_BRUSH_GENERATED (brush); GimpDisplay *display; diff --git a/app/actions/data-commands.c b/app/actions/data-commands.c index d663bbd991..753b854214 100644 --- a/app/actions/data-commands.c +++ b/app/actions/data-commands.c @@ -220,8 +220,8 @@ data_delete_cmd_callback (GtkAction *action, gimp_context_get_by_type (context, gimp_data_factory_view_get_children_type (view)); - if (data && - data->deletable && + if (data && + gimp_data_is_deletable (data) && gimp_data_factory_view_have (view, GIMP_OBJECT (data))) { diff --git a/app/actions/dynamics-actions.c b/app/actions/dynamics-actions.c index e2043eeac9..7c33c87df0 100644 --- a/app/actions/dynamics-actions.c +++ b/app/actions/dynamics-actions.c @@ -123,7 +123,7 @@ dynamics_actions_update (GimpActionGroup *group, SET_SENSITIVE ("dynamics-edit", dynamics); SET_SENSITIVE ("dynamics-duplicate", dynamics && GIMP_DATA_GET_CLASS (data)->duplicate); SET_SENSITIVE ("dynamics-copy-location", dynamics && filename); - SET_SENSITIVE ("dynamics-delete", dynamics && data->deletable); + SET_SENSITIVE ("dynamics-delete", dynamics && gimp_data_is_deletable (data)); #undef SET_SENSITIVE } diff --git a/app/actions/gradient-editor-commands.c b/app/actions/gradient-editor-commands.c index 5aed984f29..1e2aee1d39 100644 --- a/app/actions/gradient-editor-commands.c +++ b/app/actions/gradient-editor-commands.c @@ -76,7 +76,7 @@ gradient_editor_left_color_cmd_callback (GtkAction *action, gradient = GIMP_GRADIENT (GIMP_DATA_EDITOR (editor)->data); - editor->left_saved_dirty = GIMP_DATA (gradient)->dirty; + editor->left_saved_dirty = gimp_data_is_dirty (GIMP_DATA (gradient)); editor->left_saved_segments = gradient_editor_save_selection (editor); editor->color_dialog = @@ -227,7 +227,7 @@ gradient_editor_right_color_cmd_callback (GtkAction *action, gradient = GIMP_GRADIENT (GIMP_DATA_EDITOR (editor)->data); - editor->right_saved_dirty = GIMP_DATA (gradient)->dirty; + editor->right_saved_dirty = gimp_data_is_dirty (GIMP_DATA (gradient)); editor->right_saved_segments = gradient_editor_save_selection (editor); editor->color_dialog = @@ -749,7 +749,8 @@ gradient_editor_left_color_update (GimpColorDialog *dialog, case GIMP_COLOR_DIALOG_CANCEL: gradient_editor_replace_selection (editor, editor->left_saved_segments); - GIMP_DATA (gradient)->dirty = editor->left_saved_dirty; + if (! editor->left_saved_dirty) + gimp_data_clean (GIMP_DATA (gradient)); gimp_viewable_invalidate_preview (GIMP_VIEWABLE (gradient)); gtk_widget_destroy (editor->color_dialog); editor->color_dialog = NULL; @@ -796,7 +797,8 @@ gradient_editor_right_color_update (GimpColorDialog *dialog, case GIMP_COLOR_DIALOG_CANCEL: gradient_editor_replace_selection (editor, editor->right_saved_segments); - GIMP_DATA (gradient)->dirty = editor->right_saved_dirty; + if (! editor->right_saved_dirty) + gimp_data_clean (GIMP_DATA (gradient)); gimp_viewable_invalidate_preview (GIMP_VIEWABLE (gradient)); gtk_widget_destroy (editor->color_dialog); editor->color_dialog = NULL; diff --git a/app/actions/gradients-actions.c b/app/actions/gradients-actions.c index f13a497317..a990190c82 100644 --- a/app/actions/gradients-actions.c +++ b/app/actions/gradients-actions.c @@ -131,7 +131,7 @@ gradients_actions_update (GimpActionGroup *group, SET_SENSITIVE ("gradients-duplicate", gradient); SET_SENSITIVE ("gradients-save-as-pov", gradient); SET_SENSITIVE ("gradients-copy-location", gradient && filename); - SET_SENSITIVE ("gradients-delete", gradient && data->deletable); + SET_SENSITIVE ("gradients-delete", gradient && gimp_data_is_deletable (data)); #undef SET_SENSITIVE } diff --git a/app/actions/palettes-actions.c b/app/actions/palettes-actions.c index bf5dc52d77..4a46acbf7c 100644 --- a/app/actions/palettes-actions.c +++ b/app/actions/palettes-actions.c @@ -137,7 +137,7 @@ palettes_actions_update (GimpActionGroup *group, SET_SENSITIVE ("palettes-duplicate", palette && GIMP_DATA_GET_CLASS (data)->duplicate); SET_SENSITIVE ("palettes-merge", FALSE); /* FIXME palette && GIMP_IS_CONTAINER_LIST_VIEW (editor->view)); */ SET_SENSITIVE ("palettes-copy-location", palette && filename); - SET_SENSITIVE ("palettes-delete", palette && data->deletable); + SET_SENSITIVE ("palettes-delete", palette && gimp_data_is_deletable (data)); #undef SET_SENSITIVE } diff --git a/app/actions/patterns-actions.c b/app/actions/patterns-actions.c index 49cb848937..87ed3362fc 100644 --- a/app/actions/patterns-actions.c +++ b/app/actions/patterns-actions.c @@ -130,7 +130,7 @@ patterns_actions_update (GimpActionGroup *group, SET_SENSITIVE ("patterns-open-as-image", pattern && filename); SET_SENSITIVE ("patterns-duplicate", pattern && GIMP_DATA_GET_CLASS (data)->duplicate); SET_SENSITIVE ("patterns-copy-location", pattern && filename); - SET_SENSITIVE ("patterns-delete", pattern && data->deletable); + SET_SENSITIVE ("patterns-delete", pattern && gimp_data_is_deletable (data)); #undef SET_SENSITIVE } diff --git a/app/core/gimpbrush.c b/app/core/gimpbrush.c index 90fa78d966..804052efa9 100644 --- a/app/core/gimpbrush.c +++ b/app/core/gimpbrush.c @@ -417,11 +417,9 @@ gimp_brush_get_standard (void) { standard_brush = gimp_brush_new ("Standard"); - standard_brush->dirty = FALSE; - gimp_data_make_internal (standard_brush, - "gimp-brush-standard"); + gimp_data_clean (standard_brush); + gimp_data_make_internal (standard_brush, "gimp-brush-standard"); - /* set ref_count to 2 --> never swap the standard brush */ g_object_ref (standard_brush); } diff --git a/app/core/gimpcurve.c b/app/core/gimpcurve.c index faeb7cfd9b..b19513a278 100644 --- a/app/core/gimpcurve.c +++ b/app/core/gimpcurve.c @@ -532,7 +532,7 @@ gimp_curve_get_standard (void) { standard_curve = gimp_curve_new ("Standard"); - standard_curve->dirty = FALSE; + gimp_data_clean (standard_curve); gimp_data_make_internal (standard_curve, "gimp-curve-standard"); @@ -887,7 +887,7 @@ gimp_curve_calculate (GimpCurve *curve) gint num_pts; gint p1, p2, p3, p4; - if (GIMP_DATA (curve)->freeze_count > 0) + if (gimp_data_is_frozen (GIMP_DATA (curve))) return; points = g_newa (gint, curve->n_points); diff --git a/app/core/gimpdata.c b/app/core/gimpdata.c index 2957d1e8ff..ce34751fd2 100644 --- a/app/core/gimpdata.c +++ b/app/core/gimpdata.c @@ -67,7 +67,21 @@ typedef struct _GimpDataPrivate GimpDataPrivate; struct _GimpDataPrivate { - gchar *filename; + gchar *filename; + GQuark mime_type; + guint writable : 1; + guint deletable : 1; + guint dirty : 1; + guint internal : 1; + gint freeze_count; + time_t mtime; + + /* Identifies the GimpData object across sessions. Used when there + * is not a filename associated with the object. + */ + gchar *identifier; + + GList *tags; }; #define GIMP_DATA_GET_PRIVATE(data) \ @@ -217,21 +231,17 @@ static void gimp_data_init (GimpData *data, GimpDataClass *data_class) { - data->mime_type = 0; - data->writable = TRUE; - data->deletable = TRUE; - data->dirty = TRUE; - data->internal = FALSE; - data->freeze_count = 0; - data->mtime = 0; - data->tags = NULL; - data->identifier = NULL; + GimpDataPrivate *private = GIMP_DATA_GET_PRIVATE (data); + + private->writable = TRUE; + private->deletable = TRUE; + private->dirty = TRUE; /* look at the passed class pointer, not at GIMP_DATA_GET_CLASS(data) * here, because the latter is always GimpDataClass itself */ if (! data_class->save) - data->writable = FALSE; + private->writable = FALSE; /* freeze the data object during construction */ gimp_data_freeze (data); @@ -254,8 +264,7 @@ gimp_data_constructor (GType type, static void gimp_data_finalize (GObject *object) { - GimpData *data = GIMP_DATA (object); - GimpDataPrivate *private = GIMP_DATA_GET_PRIVATE (data); + GimpDataPrivate *private = GIMP_DATA_GET_PRIVATE (object); if (private->filename) { @@ -263,16 +272,16 @@ gimp_data_finalize (GObject *object) private->filename = NULL; } - if (data->tags) + if (private->tags) { - g_list_free (data->tags); - data->tags = NULL; + g_list_free (private->tags); + private->tags = NULL; } - if (data->identifier) + if (private->identifier) { - g_free (data->identifier); - data->identifier = NULL; + g_free (private->identifier); + private->identifier = NULL; } G_OBJECT_CLASS (parent_class)->finalize (object); @@ -284,30 +293,31 @@ gimp_data_set_property (GObject *object, const GValue *value, GParamSpec *pspec) { - GimpData *data = GIMP_DATA (object); + GimpData *data = GIMP_DATA (object); + GimpDataPrivate *private = GIMP_DATA_GET_PRIVATE (data); switch (property_id) { case PROP_FILENAME: gimp_data_set_filename (data, g_value_get_string (value), - data->writable, - data->deletable); + private->writable, + private->deletable); break; case PROP_WRITABLE: - data->writable = g_value_get_boolean (value); + private->writable = g_value_get_boolean (value); break; case PROP_DELETABLE: - data->deletable = g_value_get_boolean (value); + private->deletable = g_value_get_boolean (value); break; case PROP_MIME_TYPE: if (g_value_get_string (value)) - data->mime_type = g_quark_from_string (g_value_get_string (value)); + private->mime_type = g_quark_from_string (g_value_get_string (value)); else - data->mime_type = 0; + private->mime_type = 0; break; default: @@ -322,8 +332,7 @@ gimp_data_get_property (GObject *object, GValue *value, GParamSpec *pspec) { - GimpData *data = GIMP_DATA (object); - GimpDataPrivate *private = GIMP_DATA_GET_PRIVATE (data); + GimpDataPrivate *private = GIMP_DATA_GET_PRIVATE (object); switch (property_id) { @@ -332,15 +341,15 @@ gimp_data_get_property (GObject *object, break; case PROP_WRITABLE: - g_value_set_boolean (value, data->writable); + g_value_set_boolean (value, private->writable); break; case PROP_DELETABLE: - g_value_set_boolean (value, data->deletable); + g_value_set_boolean (value, private->deletable); break; case PROP_MIME_TYPE: - g_value_set_string (value, g_quark_to_string (data->mime_type)); + g_value_set_string (value, g_quark_to_string (private->mime_type)); break; default: @@ -353,8 +362,7 @@ static gint64 gimp_data_get_memsize (GimpObject *object, gint64 *gui_size) { - GimpData *data = GIMP_DATA (object); - GimpDataPrivate *private = GIMP_DATA_GET_PRIVATE (data); + GimpDataPrivate *private = GIMP_DATA_GET_PRIVATE (object); gint64 memsize = 0; memsize += gimp_string_get_memsize (private->filename); @@ -366,7 +374,9 @@ gimp_data_get_memsize (GimpObject *object, static void gimp_data_real_dirty (GimpData *data) { - data->dirty = TRUE; + GimpDataPrivate *private = GIMP_DATA_GET_PRIVATE (data); + + private->dirty = TRUE; gimp_viewable_invalidate_preview (GIMP_VIEWABLE (data)); @@ -378,10 +388,10 @@ static gboolean gimp_data_add_tag (GimpTagged *tagged, GimpTag *tag) { - GimpData *data = GIMP_DATA (tagged); - GList *list; + GimpDataPrivate *private = GIMP_DATA_GET_PRIVATE (tagged); + GList *list; - for (list = data->tags; list; list = list->next) + for (list = private->tags; list; list = g_list_next (list)) { GimpTag *this = GIMP_TAG (list->data); @@ -389,8 +399,7 @@ gimp_data_add_tag (GimpTagged *tagged, return FALSE; } - g_object_ref (tag); - data->tags = g_list_prepend (data->tags, tag); + private->tags = g_list_prepend (private->tags, g_object_ref (tag)); return TRUE; } @@ -399,16 +408,16 @@ static gboolean gimp_data_remove_tag (GimpTagged *tagged, GimpTag *tag) { - GimpData *data = GIMP_DATA (tagged); - GList *list; + GimpDataPrivate *private = GIMP_DATA_GET_PRIVATE (tagged); + GList *list; - for (list = data->tags; list; list = list->next) + for (list = private->tags; list; list = g_list_next (list)) { GimpTag *this = GIMP_TAG (list->data); if (gimp_tag_equals (tag, this)) { - data->tags = g_list_delete_link (data->tags, list); + private->tags = g_list_delete_link (private->tags, list); g_object_unref (tag); return TRUE; } @@ -420,14 +429,15 @@ gimp_data_remove_tag (GimpTagged *tagged, static GList * gimp_data_get_tags (GimpTagged *tagged) { - return GIMP_DATA (tagged)->tags; + GimpDataPrivate *private = GIMP_DATA_GET_PRIVATE (tagged); + + return private->tags; } static gchar * gimp_data_get_identifier (GimpTagged *tagged) { - GimpData *data = GIMP_DATA (tagged); - GimpDataPrivate *private = GIMP_DATA_GET_PRIVATE (data); + GimpDataPrivate *private = GIMP_DATA_GET_PRIVATE (tagged); gchar *identifier = NULL; if (private->filename) @@ -440,9 +450,9 @@ gimp_data_get_identifier (GimpTagged *tagged) identifier = g_strdup (private->filename); } } - else if (data->internal) + else if (private->internal) { - identifier = g_strdup (data->identifier); + identifier = g_strdup (private->identifier); } return identifier; @@ -475,14 +485,15 @@ gimp_data_save (GimpData *data, gboolean success = FALSE; g_return_val_if_fail (GIMP_IS_DATA (data), FALSE); - g_return_val_if_fail (data->writable == TRUE, FALSE); g_return_val_if_fail (error == NULL || *error == NULL, FALSE); private = GIMP_DATA_GET_PRIVATE (data); - if (data->internal) + g_return_val_if_fail (private->writable == TRUE, FALSE); + + if (private->internal) { - data->dirty = FALSE; + private->dirty = FALSE; return TRUE; } @@ -497,8 +508,8 @@ gimp_data_save (GimpData *data, g_stat (private->filename, &filestat); - data->mtime = filestat.st_mtime; - data->dirty = FALSE; + private->mtime = filestat.st_mtime; + private->dirty = FALSE; } return success; @@ -515,12 +526,40 @@ gimp_data_save (GimpData *data, void gimp_data_dirty (GimpData *data) { + GimpDataPrivate *private; + g_return_if_fail (GIMP_IS_DATA (data)); - if (data->freeze_count == 0) + private = GIMP_DATA_GET_PRIVATE (data); + + if (private->freeze_count == 0) g_signal_emit (data, data_signals[DIRTY], 0); } +void +gimp_data_clean (GimpData *data) +{ + GimpDataPrivate *private; + + g_return_if_fail (GIMP_IS_DATA (data)); + + private = GIMP_DATA_GET_PRIVATE (data); + + private->dirty = FALSE; +} + +gboolean +gimp_data_is_dirty (GimpData *data) +{ + GimpDataPrivate *private; + + g_return_val_if_fail (GIMP_IS_DATA (data), FALSE); + + private = GIMP_DATA_GET_PRIVATE (data); + + return private->dirty; +} + /** * gimp_data_freeze: * @data: a #GimpData object. @@ -532,9 +571,13 @@ gimp_data_dirty (GimpData *data) void gimp_data_freeze (GimpData *data) { + GimpDataPrivate *private; + g_return_if_fail (GIMP_IS_DATA (data)); - data->freeze_count++; + private = GIMP_DATA_GET_PRIVATE (data); + + private->freeze_count++; } /** @@ -549,15 +592,32 @@ gimp_data_freeze (GimpData *data) void gimp_data_thaw (GimpData *data) { + GimpDataPrivate *private; + g_return_if_fail (GIMP_IS_DATA (data)); - g_return_if_fail (data->freeze_count > 0); - data->freeze_count--; + private = GIMP_DATA_GET_PRIVATE (data); - if (data->freeze_count == 0) + g_return_if_fail (private->freeze_count > 0); + + private->freeze_count--; + + if (private->freeze_count == 0) gimp_data_dirty (data); } +gboolean +gimp_data_is_frozen (GimpData *data) +{ + GimpDataPrivate *private; + + g_return_val_if_fail (GIMP_IS_DATA (data), FALSE); + + private = GIMP_DATA_GET_PRIVATE (data); + + return private->freeze_count > 0; +} + /** * gimp_data_delete_from_disk: * @data: a #GimpData object. @@ -578,14 +638,14 @@ gimp_data_delete_from_disk (GimpData *data, GimpDataPrivate *private; g_return_val_if_fail (GIMP_IS_DATA (data), FALSE); - g_return_val_if_fail (data->deletable == TRUE, FALSE); g_return_val_if_fail (error == NULL || *error == NULL, FALSE); private = GIMP_DATA_GET_PRIVATE (data); g_return_val_if_fail (private->filename != NULL, FALSE); + g_return_val_if_fail (private->deletable == TRUE, FALSE); - if (data->internal) + if (private->internal) return TRUE; if (g_unlink (private->filename) == -1) @@ -638,15 +698,15 @@ gimp_data_set_filename (GimpData *data, private = GIMP_DATA_GET_PRIVATE (data); - if (data->internal) + if (private->internal) return; if (private->filename) g_free (private->filename); - private->filename = g_strdup (filename); - data->writable = FALSE; - data->deletable = FALSE; + private->filename = g_strdup (filename); + private->writable = FALSE; + private->deletable = FALSE; /* if the data is supposed to be writable or deletable, * still check if it really is @@ -660,15 +720,15 @@ gimp_data_set_filename (GimpData *data, (g_access (filename, F_OK) != 0 && /* OR doesn't exist */ g_access (dirname, W_OK) == 0)) /* and we can write to its dir */ { - data->writable = writable ? TRUE : FALSE; - data->deletable = deletable ? TRUE : FALSE; + private->writable = writable ? TRUE : FALSE; + private->deletable = deletable ? TRUE : FALSE; } g_free (dirname); /* if we can't save, we are not writable */ if (! GIMP_DATA_GET_CLASS (data)->save) - data->writable = FALSE; + private->writable = FALSE; } } @@ -687,18 +747,21 @@ void gimp_data_create_filename (GimpData *data, const gchar *dest_dir) { - gchar *safename; - gchar *filename; - gchar *fullpath; - gint i; - gint unum = 1; - GError *error = NULL; + GimpDataPrivate *private; + gchar *safename; + gchar *filename; + gchar *fullpath; + gint i; + gint unum = 1; + GError *error = NULL; g_return_if_fail (GIMP_IS_DATA (data)); g_return_if_fail (dest_dir != NULL); g_return_if_fail (g_path_is_absolute (dest_dir)); - if (data->internal) + private = GIMP_DATA_GET_PRIVATE (data); + + if (private->internal) return; safename = g_filename_from_utf8 (gimp_object_get_name (data), @@ -761,9 +824,62 @@ gimp_data_get_filename (GimpData *data) const gchar * gimp_data_get_mime_type (GimpData *data) { + GimpDataPrivate *private; + g_return_val_if_fail (GIMP_IS_DATA (data), NULL); - return g_quark_to_string (data->mime_type); + private = GIMP_DATA_GET_PRIVATE (data); + + return g_quark_to_string (private->mime_type); +} + +gboolean +gimp_data_is_writable (GimpData *data) +{ + GimpDataPrivate *private; + + g_return_val_if_fail (GIMP_IS_DATA (data), FALSE); + + private = GIMP_DATA_GET_PRIVATE (data); + + return private->writable; +} + +gboolean +gimp_data_is_deletable (GimpData *data) +{ + GimpDataPrivate *private; + + g_return_val_if_fail (GIMP_IS_DATA (data), FALSE); + + private = GIMP_DATA_GET_PRIVATE (data); + + return private->deletable; +} + +void +gimp_data_set_mtime (GimpData *data, + time_t mtime) +{ + GimpDataPrivate *private; + + g_return_if_fail (GIMP_IS_DATA (data)); + + private = GIMP_DATA_GET_PRIVATE (data); + + private->mtime = mtime; +} + +time_t +gimp_data_get_mtime (GimpData *data) +{ + GimpDataPrivate *private; + + g_return_val_if_fail (GIMP_IS_DATA (data), 0); + + private = GIMP_DATA_GET_PRIVATE (data); + + return private->mtime; } /** @@ -800,8 +916,8 @@ gimp_data_duplicate (GimpData *data) * that identifies the internal object across sessions. **/ void -gimp_data_make_internal (GimpData *data, - const gchar *identifier) +gimp_data_make_internal (GimpData *data, + const gchar *identifier) { GimpDataPrivate *private; @@ -815,11 +931,22 @@ gimp_data_make_internal (GimpData *data, private->filename = NULL; } - data->identifier = g_strdup (identifier); + private->identifier = g_strdup (identifier); + private->writable = FALSE; + private->deletable = FALSE; + private->internal = TRUE; +} - data->internal = TRUE; - data->writable = FALSE; - data->deletable = FALSE; +gboolean +gimp_data_is_internal (GimpData *data) +{ + GimpDataPrivate *private; + + g_return_val_if_fail (GIMP_IS_DATA (data), FALSE); + + private = GIMP_DATA_GET_PRIVATE (data); + + return private->internal; } /** @@ -840,13 +967,16 @@ gint gimp_data_compare (GimpData *data1, GimpData *data2) { - /* move the internal objects (like the FG -> BG) gradient) to the top */ - if (data1->internal != data2->internal) - return data1->internal ? -1 : 1; + GimpDataPrivate *private1 = GIMP_DATA_GET_PRIVATE (data1); + GimpDataPrivate *private2 = GIMP_DATA_GET_PRIVATE (data2); - /* keep user-writable objects about system resource files */ - if (data1->writable != data2->writable) - return data1->writable ? -1 : 1; + /* move the internal objects (like the FG -> BG) gradient) to the top */ + if (private1->internal != private2->internal) + return private1->internal ? -1 : 1; + + /* keep user-writable objects above system resource files */ + if (private1->writable != private2->writable) + return private1->writable ? -1 : 1; return gimp_object_name_collate ((GimpObject *) data1, (GimpObject *) data2); diff --git a/app/core/gimpdata.h b/app/core/gimpdata.h index 6986ff959f..d042c3e35b 100644 --- a/app/core/gimpdata.h +++ b/app/core/gimpdata.h @@ -48,21 +48,6 @@ typedef struct _GimpDataClass GimpDataClass; struct _GimpData { GimpViewable parent_instance; - - GQuark mime_type; - guint writable : 1; - guint deletable : 1; - guint dirty : 1; - guint internal : 1; - gint freeze_count; - time_t mtime; - - /* Identifies the GimpData object across sessions. Used when there - * is not a filename associated with the object. - */ - gchar *identifier; - - GList *tags; }; struct _GimpDataClass @@ -86,8 +71,12 @@ gboolean gimp_data_save (GimpData *data, GError **error); void gimp_data_dirty (GimpData *data); +void gimp_data_clean (GimpData *data); +gboolean gimp_data_is_dirty (GimpData *data); + void gimp_data_freeze (GimpData *data); void gimp_data_thaw (GimpData *data); +gboolean gimp_data_is_frozen (GimpData *data); gboolean gimp_data_delete_from_disk (GimpData *data, GError **error); @@ -104,10 +93,18 @@ const gchar * gimp_data_get_filename (GimpData *data); const gchar * gimp_data_get_mime_type (GimpData *data); +gboolean gimp_data_is_writable (GimpData *data); +gboolean gimp_data_is_deletable (GimpData *data); + +void gimp_data_set_mtime (GimpData *data, + time_t mtime); +time_t gimp_data_get_mtime (GimpData *data); + GimpData * gimp_data_duplicate (GimpData *data); void gimp_data_make_internal (GimpData *data, const gchar *identifier); +gboolean gimp_data_is_internal (GimpData *data); gint gimp_data_compare (GimpData *data1, GimpData *data2); diff --git a/app/core/gimpdatafactory.c b/app/core/gimpdatafactory.c index b96e4c6ab0..4291b8d186 100644 --- a/app/core/gimpdatafactory.c +++ b/app/core/gimpdatafactory.c @@ -287,7 +287,7 @@ gimp_data_factory_data_foreach (GimpDataFactory *factory, if (skip_internal) { - while (list && GIMP_DATA (list->data)->internal) + while (list && gimp_data_is_internal (GIMP_DATA (list->data))) list = g_list_next (list); } @@ -431,7 +431,8 @@ gimp_data_factory_data_save (GimpDataFactory *factory) if (! gimp_data_get_filename (data)) gimp_data_create_filename (data, writable_dir); - if (data->dirty && data->writable) + if (gimp_data_is_dirty (data) && + gimp_data_is_writable (data)) { GError *error = NULL; @@ -592,7 +593,7 @@ gimp_data_factory_data_save_single (GimpDataFactory *factory, g_return_val_if_fail (GIMP_IS_DATA (data), FALSE); g_return_val_if_fail (error == NULL || *error == NULL, FALSE); - if (! data->dirty) + if (! gimp_data_is_dirty (data)) return TRUE; if (! gimp_data_get_filename (data)) @@ -617,7 +618,7 @@ gimp_data_factory_data_save_single (GimpDataFactory *factory, g_free (writable_dir); } - if (! data->writable) + if (! gimp_data_is_writable (data)) return FALSE; if (! gimp_data_save (data, error)) @@ -810,7 +811,8 @@ gimp_data_factory_load_data (const GimpDatafileData *file_data, { GimpData *data = cached_data->data; - load_from_disk = (data->mtime == 0 || data->mtime != file_data->mtime); + load_from_disk = (gimp_data_get_mtime (data) == 0 || + gimp_data_get_mtime (data) != file_data->mtime); if (! load_from_disk) { @@ -850,8 +852,9 @@ gimp_data_factory_load_data (const GimpDatafileData *file_data, gimp_data_set_filename (data, file_data->filename, writable, deletable); - data->mtime = file_data->mtime; - data->dirty = FALSE; + gimp_data_set_mtime (data, file_data->mtime); + + gimp_data_clean (data); if (strstr (file_data->dirname, GIMP_OBSOLETE_DATA_DIR_NAME)) gimp_container_add (factory->priv->container_obsolete, diff --git a/app/core/gimpdynamics.c b/app/core/gimpdynamics.c index 64a7765c6f..9dabdb5018 100644 --- a/app/core/gimpdynamics.c +++ b/app/core/gimpdynamics.c @@ -347,9 +347,8 @@ gimp_dynamics_get_standard (void) { standard_dynamics = gimp_dynamics_new ("Standard dynamics"); - standard_dynamics->dirty = FALSE; - gimp_data_make_internal (standard_dynamics, - "gimp-dynamics-standard"); + gimp_data_clean (standard_dynamics); + gimp_data_make_internal (standard_dynamics, "gimp-dynamics-standard"); g_object_ref (standard_dynamics); } diff --git a/app/core/gimpgradient.c b/app/core/gimpgradient.c index 54e94e2a86..365d818ff5 100644 --- a/app/core/gimpgradient.c +++ b/app/core/gimpgradient.c @@ -328,9 +328,8 @@ gimp_gradient_get_standard (void) { standard_gradient = gimp_gradient_new ("Standard"); - standard_gradient->dirty = FALSE; - gimp_data_make_internal (standard_gradient, - "gimp-gradient-standard"); + gimp_data_clean (standard_gradient); + gimp_data_make_internal (standard_gradient, "gimp-gradient-standard"); g_object_ref (standard_gradient); } diff --git a/app/core/gimppalette.c b/app/core/gimppalette.c index 26a020062e..c6993ebee5 100644 --- a/app/core/gimppalette.c +++ b/app/core/gimppalette.c @@ -291,9 +291,8 @@ gimp_palette_get_standard (void) { standard_palette = gimp_palette_new ("Standard"); - standard_palette->dirty = FALSE; - gimp_data_make_internal (standard_palette, - "gimp-palette-standard"); + gimp_data_clean (standard_palette); + gimp_data_make_internal (standard_palette, "gimp-palette-standard"); g_object_ref (standard_palette); } diff --git a/app/core/gimppattern.c b/app/core/gimppattern.c index a5da6f1d54..d0502b2eef 100644 --- a/app/core/gimppattern.c +++ b/app/core/gimppattern.c @@ -244,11 +244,9 @@ gimp_pattern_get_standard (void) { standard_pattern = gimp_pattern_new ("Standard"); - standard_pattern->dirty = FALSE; - gimp_data_make_internal (standard_pattern, - "gimp-pattern-standard"); + gimp_data_clean (standard_pattern); + gimp_data_make_internal (standard_pattern, "gimp-pattern-standard"); - /* set ref_count to 2 --> never swap the standard pattern */ g_object_ref (standard_pattern); } diff --git a/app/pdb/brush-cmds.c b/app/pdb/brush-cmds.c index cab427f461..f15300e211 100644 --- a/app/pdb/brush-cmds.c +++ b/app/pdb/brush-cmds.c @@ -206,7 +206,7 @@ brush_delete_invoker (GimpProcedure *procedure, { GimpBrush *brush = gimp_pdb_get_brush (gimp, name, FALSE, error); - if (brush && GIMP_DATA (brush)->deletable) + if (brush && gimp_data_is_deletable (GIMP_DATA (brush))) success = gimp_data_factory_data_delete (gimp->brush_factory, GIMP_DATA (brush), TRUE, error); @@ -238,7 +238,7 @@ brush_is_editable_invoker (GimpProcedure *procedure, GimpBrush *brush = gimp_pdb_get_brush (gimp, name, FALSE, error); if (brush) - editable = GIMP_DATA (brush)->writable; + editable = gimp_data_is_writable (GIMP_DATA (brush)); else success = FALSE; } diff --git a/app/pdb/gimppdb-utils.c b/app/pdb/gimppdb-utils.c index d398948dcb..523a000a34 100644 --- a/app/pdb/gimppdb-utils.c +++ b/app/pdb/gimppdb-utils.c @@ -81,7 +81,7 @@ gimp_pdb_get_brush (Gimp *gimp, g_set_error (error, GIMP_PDB_ERROR, GIMP_PDB_INVALID_ARGUMENT, _("Brush '%s' not found"), name); } - else if (writable && ! GIMP_DATA (brush)->writable) + else if (writable && ! gimp_data_is_writable (GIMP_DATA (brush))) { g_set_error (error, GIMP_PDB_ERROR, GIMP_PDB_INVALID_ARGUMENT, _("Brush '%s' is not editable"), name); @@ -170,7 +170,7 @@ gimp_pdb_get_gradient (Gimp *gimp, g_set_error (error, GIMP_PDB_ERROR, GIMP_PDB_INVALID_ARGUMENT, _("Gradient '%s' not found"), name); } - else if (writable && ! GIMP_DATA (gradient)->writable) + else if (writable && ! gimp_data_is_writable (GIMP_DATA (gradient))) { g_set_error (error, GIMP_PDB_ERROR, GIMP_PDB_INVALID_ARGUMENT, _("Gradient '%s' is not editable"), name); @@ -205,7 +205,7 @@ gimp_pdb_get_palette (Gimp *gimp, g_set_error (error, GIMP_PDB_ERROR, GIMP_PDB_INVALID_ARGUMENT, _("Palette '%s' not found"), name); } - else if (writable && ! GIMP_DATA (palette)->writable) + else if (writable && ! gimp_data_is_writable (GIMP_DATA (palette))) { g_set_error (error, GIMP_PDB_ERROR, GIMP_PDB_INVALID_ARGUMENT, _("Palette '%s' is not editable"), name); diff --git a/app/pdb/gradient-cmds.c b/app/pdb/gradient-cmds.c index adcb75af1f..2c1c68ea0e 100644 --- a/app/pdb/gradient-cmds.c +++ b/app/pdb/gradient-cmds.c @@ -185,7 +185,7 @@ gradient_is_editable_invoker (GimpProcedure *procedure, GimpGradient *gradient = gimp_pdb_get_gradient (gimp, name, FALSE, error); if (gradient) - editable = GIMP_DATA (gradient)->writable; + editable = gimp_data_is_writable (GIMP_DATA (gradient)); else success = FALSE; } @@ -255,7 +255,7 @@ gradient_delete_invoker (GimpProcedure *procedure, { GimpGradient *gradient = gimp_pdb_get_gradient (gimp, name, FALSE, error); - if (gradient && GIMP_DATA (gradient)->deletable) + if (gradient && gimp_data_is_deletable (GIMP_DATA (gradient))) success = gimp_data_factory_data_delete (gimp->gradient_factory, GIMP_DATA (gradient), TRUE, error); @@ -1098,7 +1098,7 @@ gradient_segment_range_replicate_invoker (GimpProcedure *procedure, gradient = gradient_get_range (gimp, name, start_segment, end_segment, &start_seg, &end_seg, error); - if (start_seg && GIMP_DATA (gradient)->writable) + if (start_seg && gimp_data_is_writable (GIMP_DATA (gradient))) { gimp_gradient_segment_range_replicate (gradient, start_seg, end_seg, diff --git a/app/pdb/palette-cmds.c b/app/pdb/palette-cmds.c index de60eeffcd..b6197d2638 100644 --- a/app/pdb/palette-cmds.c +++ b/app/pdb/palette-cmds.c @@ -172,7 +172,7 @@ palette_delete_invoker (GimpProcedure *procedure, { GimpPalette *palette = gimp_pdb_get_palette (gimp, name, FALSE, error); - if (palette && GIMP_DATA (palette)->deletable) + if (palette && gimp_data_is_deletable (GIMP_DATA (palette))) success = gimp_data_factory_data_delete (gimp->palette_factory, GIMP_DATA (palette), TRUE, error); @@ -204,7 +204,7 @@ palette_is_editable_invoker (GimpProcedure *procedure, GimpPalette *palette = gimp_pdb_get_palette (gimp, name, FALSE, error); if (palette) - editable = GIMP_DATA (palette)->writable; + editable = gimp_data_is_writable (GIMP_DATA (palette)); else success = FALSE; } diff --git a/app/widgets/gimpdataeditor.c b/app/widgets/gimpdataeditor.c index 80b5352e31..1bec49dfc1 100644 --- a/app/widgets/gimpdataeditor.c +++ b/app/widgets/gimpdataeditor.c @@ -476,7 +476,7 @@ gimp_data_editor_real_set_data (GimpDataEditor *editor, gtk_entry_set_text (GTK_ENTRY (editor->name_entry), ""); } - editable = (editor->data && editor->data->writable); + editable = (editor->data && gimp_data_is_writable (editor->data)); if (editor->data_editable != editable) { @@ -637,14 +637,17 @@ gimp_data_editor_save_dirty (GimpDataEditor *editor) { GimpData *data = editor->data; - if (data && data->dirty && data->writable) + if (data && + gimp_data_is_dirty (data) && + gimp_data_is_writable (data)) { GError *error = NULL; if (! gimp_data_factory_data_save_single (editor->data_factory, data, &error)) { - gimp_message_literal (gimp_data_factory_get_gimp (editor->data_factory), G_OBJECT (editor), + gimp_message_literal (gimp_data_factory_get_gimp (editor->data_factory), + G_OBJECT (editor), GIMP_MESSAGE_ERROR, error->message); g_clear_error (&error); diff --git a/app/widgets/gimpdatafactoryview.c b/app/widgets/gimpdatafactoryview.c index 5d2bc417c2..30c4af8e90 100644 --- a/app/widgets/gimpdatafactoryview.c +++ b/app/widgets/gimpdatafactoryview.c @@ -402,7 +402,7 @@ gimp_data_factory_view_tree_name_edited (GtkCellRendererText *cell, name = g_strstrip (g_strdup (new_name)); - if (data->writable && strlen (name)) + if (gimp_data_is_writable (data) && strlen (name)) { gimp_object_take_name (GIMP_OBJECT (data), name); } diff --git a/tools/pdbgen/pdb/brush.pdb b/tools/pdbgen/pdb/brush.pdb index 3062710ab6..1cd575be0c 100644 --- a/tools/pdbgen/pdb/brush.pdb +++ b/tools/pdbgen/pdb/brush.pdb @@ -137,7 +137,7 @@ sub brush_is_editable { GimpBrush *brush = gimp_pdb_get_brush (gimp, name, FALSE, error); if (brush) - editable = GIMP_DATA (brush)->writable; + editable = gimp_data_is_writable (GIMP_DATA (brush)); else success = FALSE; } @@ -196,7 +196,7 @@ sub brush_delete { { GimpBrush *brush = gimp_pdb_get_brush (gimp, name, FALSE, error); - if (brush && GIMP_DATA (brush)->deletable) + if (brush && gimp_data_is_deletable (GIMP_DATA (brush))) success = gimp_data_factory_data_delete (gimp->brush_factory, GIMP_DATA (brush), TRUE, error); diff --git a/tools/pdbgen/pdb/gradient.pdb b/tools/pdbgen/pdb/gradient.pdb index 81183b4278..16956041a3 100644 --- a/tools/pdbgen/pdb/gradient.pdb +++ b/tools/pdbgen/pdb/gradient.pdb @@ -105,7 +105,7 @@ sub gradient_is_editable { GimpGradient *gradient = gimp_pdb_get_gradient (gimp, name, FALSE, error); if (gradient) - editable = GIMP_DATA (gradient)->writable; + editable = gimp_data_is_writable (GIMP_DATA (gradient)); else success = FALSE; } @@ -164,7 +164,7 @@ sub gradient_delete { { GimpGradient *gradient = gimp_pdb_get_gradient (gimp, name, FALSE, error); - if (gradient && GIMP_DATA (gradient)->deletable) + if (gradient && gimp_data_is_deletable (GIMP_DATA (gradient))) success = gimp_data_factory_data_delete (gimp->gradient_factory, GIMP_DATA (gradient), TRUE, error); @@ -1035,7 +1035,7 @@ HELP gradient = gradient_get_range (gimp, name, start_segment, end_segment, &start_seg, &end_seg, error); - if (start_seg && GIMP_DATA (gradient)->writable) + if (start_seg && gimp_data_is_writable (GIMP_DATA (gradient))) { gimp_gradient_segment_range_replicate (gradient, start_seg, end_seg, diff --git a/tools/pdbgen/pdb/palette.pdb b/tools/pdbgen/pdb/palette.pdb index cff2ca4244..daea659cc5 100644 --- a/tools/pdbgen/pdb/palette.pdb +++ b/tools/pdbgen/pdb/palette.pdb @@ -68,7 +68,7 @@ sub palette_is_editable { GimpPalette *palette = gimp_pdb_get_palette (gimp, name, FALSE, error); if (palette) - editable = GIMP_DATA (palette)->writable; + editable = gimp_data_is_writable (GIMP_DATA (palette)); else success = FALSE; } @@ -166,7 +166,7 @@ sub palette_delete { { GimpPalette *palette = gimp_pdb_get_palette (gimp, name, FALSE, error); - if (palette && GIMP_DATA (palette)->deletable) + if (palette && gimp_data_is_deletable (GIMP_DATA (palette))) success = gimp_data_factory_data_delete (gimp->palette_factory, GIMP_DATA (palette), TRUE, error);