[gnome-photos/wip/uajain/issue68: 79/79] pipeline: Enable the "Done" button only if current edit pipeline changes



commit 6a2725bcf8965c730f8f9f6ac166d99c3a09fa5e
Author: Umang Jain <mailumangjain gmail com>
Date:   Thu Feb 8 19:48:16 2018 +0530

    pipeline: Enable the "Done" button only if current edit pipeline changes
    
    The activation of "Done" button indicates the edit graph has changed
    with respect to its previous state.
    
    https://gitlab.gnome.org/GNOME/gnome-photos/issues/68

 src/photos-application.c |  2 +-
 src/photos-base-item.c   | 14 ++++++++++++++
 src/photos-pipeline.c    | 39 +++++++++++++++++++++++++++++++++++++++
 3 files changed, 54 insertions(+), 1 deletion(-)
---
diff --git a/src/photos-application.c b/src/photos-application.c
index 7621158f..d2cba990 100644
--- a/src/photos-application.c
+++ b/src/photos-application.c
@@ -483,7 +483,6 @@ photos_application_actions_update (PhotosApplication *self)
   g_simple_action_set_enabled (self->crop_action, enable);
   g_simple_action_set_enabled (self->denoise_action, enable);
   g_simple_action_set_enabled (self->edit_cancel_action, enable);
-  g_simple_action_set_enabled (self->edit_done_action, enable);
   g_simple_action_set_enabled (self->insta_action, enable);
   g_simple_action_set_enabled (self->saturation_action, enable);
   g_simple_action_set_enabled (self->shadows_highlights_action, enable);
@@ -2709,6 +2708,7 @@ photos_application_startup (GApplication *application)
   g_action_map_add_action (G_ACTION_MAP (self), G_ACTION (self->edit_action));
 
   self->edit_done_action = g_simple_action_new ("edit-done", NULL);
+  g_simple_action_set_enabled (self->edit_done_action, FALSE);
   g_action_map_add_action (G_ACTION_MAP (self), G_ACTION (self->edit_done_action));
 
   self->edit_revert_action = g_simple_action_new ("edit-revert", G_VARIANT_TYPE_STRING);
diff --git a/src/photos-base-item.c b/src/photos-base-item.c
index 854e4cf7..adc3c5da 100644
--- a/src/photos-base-item.c
+++ b/src/photos-base-item.c
@@ -1542,6 +1542,19 @@ photos_base_item_load_buffer_finish (PhotosBaseItem *self, GAsyncResult *res, GE
 }
 
 
+static void
+photos_base_item_pipeline_changed (PhotosPipeline *pipeline, gboolean result)
+{
+
+  GAction *action;
+  GApplication *app;
+
+  app = g_application_get_default ();
+  action = g_action_map_lookup_action (G_ACTION_MAP (app), "edit-done");
+  g_simple_action_set_enabled (G_SIMPLE_ACTION (action), result);
+}
+
+
 static void
 photos_base_item_load_pipeline_task_cache_populate_new (GObject *source_object,
                                                         GAsyncResult *res,
@@ -1559,6 +1572,7 @@ photos_base_item_load_pipeline_task_cache_populate_new (GObject *source_object,
       goto out;
     }
 
+  g_signal_connect (pipeline, "changed", G_CALLBACK (photos_base_item_pipeline_changed), NULL);
   g_task_return_pointer (task, g_object_ref (pipeline), g_object_unref);
 
  out:
diff --git a/src/photos-pipeline.c b/src/photos-pipeline.c
index 0e0a5088..bdf6a2f8 100644
--- a/src/photos-pipeline.c
+++ b/src/photos-pipeline.c
@@ -36,6 +36,7 @@ struct _PhotosPipeline
   GObject parent_instance;
   GHashTable *hash;
   GeglNode *graph;
+  gboolean pipeline_changed;
   gchar *snapshot;
   gchar *uri;
 };
@@ -47,6 +48,14 @@ enum
   PROP_URI
 };
 
+enum
+{
+  CHANGED,
+  LAST_SIGNAL
+};
+
+static guint signals[LAST_SIGNAL] = { 0 };
+
 static void photos_pipeline_async_initable_iface_init (GAsyncInitableIface *iface);
 
 
@@ -202,6 +211,19 @@ photos_pipeline_save_replace_contents (GObject *source_object, GAsyncResult *res
 }
 
 
+static void
+photos_pipeline_changed (PhotosPipeline *self, gboolean changed)
+{
+  g_return_if_fail (PHOTOS_PIPELINE (self));
+
+  if (self->pipeline_changed == changed)
+    return;
+
+  self->pipeline_changed = changed;
+  g_signal_emit (self, signals[CHANGED], 0, self->pipeline_changed);
+}
+
+
 static void
 photos_pipeline_constructed (GObject *object)
 {
@@ -285,6 +307,7 @@ photos_pipeline_init (PhotosPipeline *self)
 
   self->hash = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_object_unref);
   self->graph = gegl_node_new ();
+  self->pipeline_changed = FALSE;
 }
 
 
@@ -313,6 +336,17 @@ photos_pipeline_class_init (PhotosPipelineClass *class)
                                                         "The location to save this pipeline",
                                                         NULL,
                                                         G_PARAM_CONSTRUCT_ONLY | G_PARAM_WRITABLE));
+
+  signals[CHANGED] = g_signal_new ("changed",
+                                    G_TYPE_FROM_CLASS (class),
+                                    G_SIGNAL_RUN_LAST,
+                                    0,
+                                    NULL, /* accumulator */
+                                    NULL, /* accu_data */
+                                    NULL,
+                                    G_TYPE_NONE,
+                                    1,
+                                    G_TYPE_BOOLEAN);
 }
 
 
@@ -490,6 +524,8 @@ photos_pipeline_add_valist (PhotosPipeline *self,
   xml = gegl_node_to_xml_full (self->graph, self->graph, "/");
   photos_debug (PHOTOS_DEBUG_GEGL, "Pipeline: %s", xml);
 
+  photos_pipeline_changed (self, TRUE);
+
   g_free (xml);
 }
 
@@ -768,4 +804,7 @@ 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);
+
+  /* Reset Done Button after saving snapshot */
+  photos_pipeline_changed (self, FALSE);
 }


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