[gnome-photos] Cancel should revert to the state prior to entering edit mode



commit 52598201d930a41ea70886ec105b3dadc58851f2
Author: Umang Jain <mailumangjain gmail com>
Date:   Tue Feb 23 20:53:03 2016 +0530

    Cancel should revert to the state prior to entering edit mode
    
    Instead of blowing away all the edits, cancel should revert back to the
    state before the current editing session was initiated. To do this, we
    snapshot the pipeline by serializing it to XML every time we enter
    edit mode.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=762046

 src/photos-application.c |    1 +
 src/photos-base-item.c   |    7 +++++++
 src/photos-base-item.h   |    2 ++
 src/photos-pipeline.c    |   21 +++++++++++++++++++--
 src/photos-pipeline.h    |    2 ++
 5 files changed, 31 insertions(+), 2 deletions(-)
---
diff --git a/src/photos-application.c b/src/photos-application.c
index 45e7bbf..ed261d5 100644
--- a/src/photos-application.c
+++ b/src/photos-application.c
@@ -738,6 +738,7 @@ photos_application_edit_current (PhotosApplication *self)
   item = PHOTOS_BASE_ITEM (photos_base_manager_get_active_object (priv->state->item_mngr));
   g_return_if_fail (item != NULL);
 
+  photos_base_item_pipeline_snapshot (item);
   photos_mode_controller_set_window_mode (priv->state->mode_cntrlr, PHOTOS_WINDOW_MODE_EDIT);
 }
 
diff --git a/src/photos-base-item.c b/src/photos-base-item.c
index 2f6fd38..789e3ee 100644
--- a/src/photos-base-item.c
+++ b/src/photos-base-item.c
@@ -2225,6 +2225,13 @@ photos_base_item_pipeline_save_finish (PhotosBaseItem *self, GAsyncResult *res,
 
 
 void
+photos_base_item_pipeline_snapshot (PhotosBaseItem *self)
+{
+  return photos_pipeline_snapshot (self->priv->pipeline);
+}
+
+
+void
 photos_base_item_print (PhotosBaseItem *self, GtkWidget *toplevel)
 {
   photos_base_item_load_async (self, NULL, photos_base_item_print_load, g_object_ref (toplevel));
diff --git a/src/photos-base-item.h b/src/photos-base-item.h
index 5207ce2..87cd93e 100644
--- a/src/photos-base-item.h
+++ b/src/photos-base-item.h
@@ -208,6 +208,8 @@ gboolean            photos_base_item_pipeline_save_finish    (PhotosBaseItem *se
                                                               GAsyncResult *res,
                                                               GError **error);
 
+void                photos_base_item_pipeline_snapshot       (PhotosBaseItem *self);
+
 void                photos_base_item_print                   (PhotosBaseItem *self, GtkWidget *toplevel);
 
 void                photos_base_item_process_async           (PhotosBaseItem *self,
diff --git a/src/photos-pipeline.c b/src/photos-pipeline.c
index e9e38d9..1d82342 100644
--- a/src/photos-pipeline.c
+++ b/src/photos-pipeline.c
@@ -1,6 +1,7 @@
 /*
  * Photos - access, organize and share your photos on GNOME
  * Copyright © 2015 – 2016 Red Hat, Inc.
+ * Copyright © 2016 Umang Jain
  *
  * This program is free software; you can redistribute it and/or
  * modify it under the terms of the GNU General Public License
@@ -37,6 +38,7 @@ struct _PhotosPipeline
   GeglNode *parent;
   GHashTable *hash;
   GeglNode *graph;
+  gchar *snapshot;
   gchar *uri;
 };
 
@@ -103,6 +105,7 @@ photos_pipeline_create_graph_from_xml (PhotosPipeline *self, gchar *contents)
   if (graph == NULL)
     goto out;
 
+  g_hash_table_remove_all (self->hash);
   photos_utils_remove_children_from_node (self->graph);
 
   input = gegl_node_get_input_proxy (self->graph, "input");
@@ -219,6 +222,7 @@ photos_pipeline_finalize (GObject *object)
 {
   PhotosPipeline *self = PHOTOS_PIPELINE (object);
 
+  g_free (self->snapshot);
   g_free (self->uri);
 
   G_OBJECT_CLASS (photos_pipeline_parent_class)->finalize (object);
@@ -583,11 +587,24 @@ photos_pipeline_revert (PhotosPipeline *self)
 {
   gchar *xml;
 
-  g_hash_table_remove_all (self->hash);
-  photos_utils_remove_children_from_node (self->graph);
+  g_return_if_fail (self->snapshot != NULL);
+
+  if (!photos_pipeline_create_graph_from_xml (self, self->snapshot))
+    g_warning ("Unable to revert to: %s", self->snapshot);
+
+  g_clear_pointer (&self->snapshot, g_free);
 
   xml = gegl_node_to_xml_full (self->graph, self->graph, "/");
   photos_debug (PHOTOS_DEBUG_GEGL, "Pipeline: %s", xml);
 
   g_free (xml);
 }
+
+
+void
+photos_pipeline_snapshot (PhotosPipeline *self)
+{
+  g_free (self->snapshot);
+  self->snapshot = gegl_node_to_xml_full (self->graph, self->graph, "/");
+  photos_debug (PHOTOS_DEBUG_GEGL, "Snapshot: %s", self->snapshot);
+}
diff --git a/src/photos-pipeline.h b/src/photos-pipeline.h
index 3def045..377ebf9 100644
--- a/src/photos-pipeline.h
+++ b/src/photos-pipeline.h
@@ -91,6 +91,8 @@ gboolean               photos_pipeline_remove            (PhotosPipeline *self,
 
 void                   photos_pipeline_revert            (PhotosPipeline *self);
 
+void                   photos_pipeline_snapshot          (PhotosPipeline *self);
+
 G_END_DECLS
 
 #endif /* PHOTOS_PIPELINE_H */


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