[gimp/metadata-wip-rebased] app: make metadata changes undoable



commit f4f8c41438a864f897bc83c80c10499b55b7a29f
Author: Michael Natterer <mitch gimp org>
Date:   Thu Oct 24 23:12:28 2013 +0200

    app: make metadata changes undoable

 app/core/core-enums.c          |    2 ++
 app/core/core-enums.h          |    1 +
 app/core/gimpimage-metadata.c  |    7 ++++++-
 app/core/gimpimage-metadata.h  |    3 ++-
 app/core/gimpimage-undo-push.c |   12 ++++++++++++
 app/core/gimpimage-undo-push.h |    2 ++
 app/core/gimpimage.c           |    5 +----
 app/core/gimpimageundo.c       |   29 +++++++++++++++++++++++++++++
 app/core/gimpimageundo.h       |    1 +
 app/pdb/image-cmds.c           |    2 +-
 app/xcf/xcf-load.c             |    6 +++---
 tools/pdbgen/pdb/image.pdb     |    2 +-
 12 files changed, 61 insertions(+), 11 deletions(-)
---
diff --git a/app/core/core-enums.c b/app/core/core-enums.c
index 4dadaa5..b47176b 100644
--- a/app/core/core-enums.c
+++ b/app/core/core-enums.c
@@ -1115,6 +1115,7 @@ gimp_undo_type_get_type (void)
     { GIMP_UNDO_IMAGE_SIZE, "GIMP_UNDO_IMAGE_SIZE", "image-size" },
     { GIMP_UNDO_IMAGE_RESOLUTION, "GIMP_UNDO_IMAGE_RESOLUTION", "image-resolution" },
     { GIMP_UNDO_IMAGE_GRID, "GIMP_UNDO_IMAGE_GRID", "image-grid" },
+    { GIMP_UNDO_IMAGE_METADATA, "GIMP_UNDO_IMAGE_METADATA", "image-metadata" },
     { GIMP_UNDO_IMAGE_COLORMAP, "GIMP_UNDO_IMAGE_COLORMAP", "image-colormap" },
     { GIMP_UNDO_GUIDE, "GIMP_UNDO_GUIDE", "guide" },
     { GIMP_UNDO_SAMPLE_POINT, "GIMP_UNDO_SAMPLE_POINT", "sample-point" },
@@ -1205,6 +1206,7 @@ gimp_undo_type_get_type (void)
     { GIMP_UNDO_IMAGE_SIZE, NC_("undo-type", "Image size"), NULL },
     { GIMP_UNDO_IMAGE_RESOLUTION, NC_("undo-type", "Image resolution change"), NULL },
     { GIMP_UNDO_IMAGE_GRID, NC_("undo-type", "Grid"), NULL },
+    { GIMP_UNDO_IMAGE_METADATA, NC_("undo-type", "Change metadata"), NULL },
     { GIMP_UNDO_IMAGE_COLORMAP, NC_("undo-type", "Change indexed palette"), NULL },
     { GIMP_UNDO_GUIDE, NC_("undo-type", "Guide"), NULL },
     { GIMP_UNDO_SAMPLE_POINT, NC_("undo-type", "Sample Point"), NULL },
diff --git a/app/core/core-enums.h b/app/core/core-enums.h
index 4ee7713..b8339df 100644
--- a/app/core/core-enums.h
+++ b/app/core/core-enums.h
@@ -530,6 +530,7 @@ typedef enum /*< pdb-skip >*/
   GIMP_UNDO_IMAGE_SIZE,               /*< desc="Image size"                  >*/
   GIMP_UNDO_IMAGE_RESOLUTION,         /*< desc="Image resolution change"     >*/
   GIMP_UNDO_IMAGE_GRID,               /*< desc="Grid"                        >*/
+  GIMP_UNDO_IMAGE_METADATA,           /*< desc="Change metadata"             >*/
   GIMP_UNDO_IMAGE_COLORMAP,           /*< desc="Change indexed palette"      >*/
   GIMP_UNDO_GUIDE,                    /*< desc="Guide"                       >*/
   GIMP_UNDO_SAMPLE_POINT,             /*< desc="Sample Point"                >*/
diff --git a/app/core/gimpimage-metadata.c b/app/core/gimpimage-metadata.c
index 9c8cc5e..fb947ec 100644
--- a/app/core/gimpimage-metadata.c
+++ b/app/core/gimpimage-metadata.c
@@ -27,6 +27,7 @@
 #include "gimpimage.h"
 #include "gimpimage-metadata.h"
 #include "gimpimage-private.h"
+#include "gimpimage-undo-push.h"
 
 
 /* public functions */
@@ -46,7 +47,8 @@ gimp_image_get_metadata (GimpImage *image)
 
 void
 gimp_image_set_metadata (GimpImage    *image,
-                         GimpMetadata *metadata)
+                         GimpMetadata *metadata,
+                         gboolean      push_undo)
 {
   GimpImagePrivate *private;
 
@@ -56,6 +58,9 @@ gimp_image_set_metadata (GimpImage    *image,
 
   if (metadata != private->metadata)
     {
+      if (push_undo)
+        gimp_image_undo_push_image_metadata (image, NULL);
+
       if (private->metadata)
         g_object_unref (private->metadata);
 
diff --git a/app/core/gimpimage-metadata.h b/app/core/gimpimage-metadata.h
index feccd95..1f90d34 100644
--- a/app/core/gimpimage-metadata.h
+++ b/app/core/gimpimage-metadata.h
@@ -21,7 +21,8 @@
 
 GimpMetadata * gimp_image_get_metadata (GimpImage    *image);
 void           gimp_image_set_metadata (GimpImage    *image,
-                                        GimpMetadata *metadata);
+                                        GimpMetadata *metadata,
+                                        gboolean      push_undo);
 
 
 #endif /* __GIMP_IMAGE_METADATA_H__ */
diff --git a/app/core/gimpimage-undo-push.c b/app/core/gimpimage-undo-push.c
index 31970d2..066f35a 100644
--- a/app/core/gimpimage-undo-push.c
+++ b/app/core/gimpimage-undo-push.c
@@ -149,6 +149,18 @@ gimp_image_undo_push_image_colormap (GimpImage   *image,
 }
 
 GimpUndo *
+gimp_image_undo_push_image_metadata (GimpImage   *image,
+                                     const gchar *undo_desc)
+{
+  g_return_val_if_fail (GIMP_IS_IMAGE (image), NULL);
+
+  return gimp_image_undo_push (image, GIMP_TYPE_IMAGE_UNDO,
+                               GIMP_UNDO_IMAGE_METADATA, undo_desc,
+                               GIMP_DIRTY_IMAGE_META,
+                               NULL);
+}
+
+GimpUndo *
 gimp_image_undo_push_image_parasite (GimpImage          *image,
                                      const gchar        *undo_desc,
                                      const GimpParasite *parasite)
diff --git a/app/core/gimpimage-undo-push.h b/app/core/gimpimage-undo-push.h
index 6680c68..28d463d 100644
--- a/app/core/gimpimage-undo-push.h
+++ b/app/core/gimpimage-undo-push.h
@@ -38,6 +38,8 @@ GimpUndo * gimp_image_undo_push_image_grid          (GimpImage     *image,
                                                      GimpGrid      *grid);
 GimpUndo * gimp_image_undo_push_image_colormap      (GimpImage     *image,
                                                      const gchar   *undo_desc);
+GimpUndo * gimp_image_undo_push_image_metadata      (GimpImage     *image,
+                                                     const gchar   *undo_desc);
 GimpUndo * gimp_image_undo_push_image_parasite      (GimpImage     *image,
                                                      const gchar   *undo_desc,
                                                      const GimpParasite *parasite);
diff --git a/app/core/gimpimage.c b/app/core/gimpimage.c
index 62f37f7..226b872 100644
--- a/app/core/gimpimage.c
+++ b/app/core/gimpimage.c
@@ -618,8 +618,7 @@ gimp_image_class_init (GimpImageClass *klass)
   g_object_class_install_property (object_class, PROP_METADATA,
                                    g_param_spec_object ("metadata", NULL, NULL,
                                                         GEXIV2_TYPE_METADATA,
-                                                        GIMP_PARAM_READWRITE |
-                                                        G_PARAM_CONSTRUCT));
+                                                        GIMP_PARAM_READABLE));
 
   g_object_class_override_property (object_class, PROP_BUFFER, "buffer");
 
@@ -851,8 +850,6 @@ gimp_image_set_property (GObject      *object,
       private->precision = g_value_get_enum (value);
       break;
     case PROP_METADATA:
-      gimp_image_set_metadata (image, g_value_get_object (value));
-      break;
     case PROP_BUFFER:
     default:
       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
diff --git a/app/core/gimpimageundo.c b/app/core/gimpimageundo.c
index a6f0877..2faafa6 100644
--- a/app/core/gimpimageundo.c
+++ b/app/core/gimpimageundo.c
@@ -35,6 +35,7 @@
 #include "gimpimage.h"
 #include "gimpimage-colormap.h"
 #include "gimpimage-grid.h"
+#include "gimpimage-metadata.h"
 #include "gimpimage-private.h"
 #include "gimpimageundo.h"
 #include "gimpparasitelist.h"
@@ -186,6 +187,11 @@ gimp_image_undo_constructed (GObject *object)
                                          GIMP_IMAGE_COLORMAP_SIZE);
       break;
 
+    case GIMP_UNDO_IMAGE_METADATA:
+      image_undo->metadata =
+        gimp_metadata_duplicate (gimp_image_get_metadata (image));
+      break;
+
     case GIMP_UNDO_PARASITE_ATTACH:
     case GIMP_UNDO_PARASITE_REMOVE:
       g_assert (image_undo->parasite_name != NULL);
@@ -284,6 +290,9 @@ gimp_image_undo_get_memsize (GimpObject *object,
   if (image_undo->colormap)
     memsize += GIMP_IMAGE_COLORMAP_SIZE;
 
+  if (image_undo->metadata)
+    memsize += gimp_g_object_get_memsize (G_OBJECT (image_undo->metadata));
+
   memsize += gimp_object_get_memsize (GIMP_OBJECT (image_undo->grid),
                                       gui_size);
   memsize += gimp_string_get_memsize (image_undo->parasite_name);
@@ -447,6 +456,20 @@ gimp_image_undo_pop (GimpUndo            *undo,
       }
       break;
 
+    case GIMP_UNDO_IMAGE_METADATA:
+      {
+        GimpMetadata *metadata;
+
+        metadata = gimp_metadata_duplicate (gimp_image_get_metadata (image));
+
+        gimp_image_set_metadata (image, image_undo->metadata, FALSE);
+
+        if (image_undo->metadata)
+          g_object_unref (image_undo->metadata);
+        image_undo->metadata = metadata;
+      }
+      break;
+
     case GIMP_UNDO_PARASITE_ATTACH:
     case GIMP_UNDO_PARASITE_REMOVE:
       {
@@ -495,6 +518,12 @@ gimp_image_undo_free (GimpUndo     *undo,
       image_undo->colormap = NULL;
     }
 
+  if (image_undo->metadata)
+    {
+      g_free (image_undo->metadata);
+      image_undo->metadata = NULL;
+    }
+
   if (image_undo->parasite_name)
     {
       g_free (image_undo->parasite_name);
diff --git a/app/core/gimpimageundo.h b/app/core/gimpimageundo.h
index 33b2c5e..b6a9b01 100644
--- a/app/core/gimpimageundo.h
+++ b/app/core/gimpimageundo.h
@@ -50,6 +50,7 @@ struct _GimpImageUndo
   GimpGrid          *grid;
   gint               num_colors;
   guchar            *colormap;
+  GimpMetadata      *metadata;
   gchar             *parasite_name;
   GimpParasite      *parasite;
 };
diff --git a/app/pdb/image-cmds.c b/app/pdb/image-cmds.c
index f2e822e..f171fce 100644
--- a/app/pdb/image-cmds.c
+++ b/app/pdb/image-cmds.c
@@ -1758,7 +1758,7 @@ image_set_metadata_invoker (GimpProcedure         *procedure,
     {
       GimpMetadata *metadata = gimp_metadata_deserialize (metadata_string);
 
-      gimp_image_set_metadata (image, metadata);
+      gimp_image_set_metadata (image, metadata, TRUE);
 
       if (metadata)
         g_object_unref (metadata);
diff --git a/app/xcf/xcf-load.c b/app/xcf/xcf-load.c
index 517e3e8..28617c3 100644
--- a/app/xcf/xcf-load.c
+++ b/app/xcf/xcf-load.c
@@ -226,7 +226,7 @@ xcf_load_image (Gimp     *gimp,
         {
           has_metadata = TRUE;
 
-          gimp_image_set_metadata (image, metadata);
+          gimp_image_set_metadata (image, metadata, FALSE);
           g_object_unref (metadata);
         }
 
@@ -260,7 +260,7 @@ xcf_load_image (Gimp     *gimp,
                                        gimp_parasite_data (parasite),
                                        gimp_parasite_data_size (parasite));
 
-          gimp_image_set_metadata (image, metadata);
+          gimp_image_set_metadata (image, metadata, FALSE);
           g_object_unref (metadata);
         }
 
@@ -294,7 +294,7 @@ xcf_load_image (Gimp     *gimp,
                                       gimp_parasite_data (parasite),
                                       gimp_parasite_data_size (parasite));
 
-          gimp_image_set_metadata (image, metadata);
+          gimp_image_set_metadata (image, metadata, FALSE);
           g_object_unref (metadata);
         }
 
diff --git a/tools/pdbgen/pdb/image.pdb b/tools/pdbgen/pdb/image.pdb
index 94d6ebc..a34b484 100644
--- a/tools/pdbgen/pdb/image.pdb
+++ b/tools/pdbgen/pdb/image.pdb
@@ -1671,7 +1671,7 @@ sub image_set_metadata {
 {
   GimpMetadata *metadata = gimp_metadata_deserialize (metadata_string);
 
-  gimp_image_set_metadata (image, metadata);
+  gimp_image_set_metadata (image, metadata, TRUE);
 
   if (metadata)
     g_object_unref (metadata);


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]