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



commit e3145d8ffb0bbc3aff439a205d8a66e85c1408d5
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

 src/photos-application.c |  2 +-
 src/photos-base-item.c   | 14 ++++++++++++++
 src/photos-pipeline.c    | 38 ++++++++++++++++++++++++++++++++++++++
 3 files changed, 53 insertions(+), 1 deletion(-)
---
diff --git a/src/photos-application.c b/src/photos-application.c
index c9f868ad..5fb42ae0 100644
--- a/src/photos-application.c
+++ b/src/photos-application.c
@@ -401,6 +401,7 @@ photos_application_actions_update (PhotosApplication *self)
       n_items = g_list_model_get_n_items (G_LIST_MODEL (item_mngr_chld));
     }
 
+  g_simple_action_set_enabled (self->edit_done_action, FALSE);
   g_simple_action_set_enabled (self->zoom_best_fit_action, FALSE);
   g_simple_action_set_enabled (self->zoom_end_action, FALSE);
   g_simple_action_set_enabled (self->zoom_out_action, FALSE);
@@ -411,7 +412,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);
diff --git a/src/photos-base-item.c b/src/photos-base-item.c
index 0f39805e..aab7f001 100644
--- a/src/photos-base-item.c
+++ b/src/photos-base-item.c
@@ -1457,6 +1457,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,
@@ -1474,6 +1487,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..737a6448 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);
 
 
@@ -285,6 +294,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 +323,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);
 }
 
 
@@ -450,6 +471,19 @@ photos_pipeline_new_finish (GAsyncResult *res, GError **error)
 }
 
 
+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);
+}
+
+
 void
 photos_pipeline_add_valist (PhotosPipeline *self,
                             const gchar *operation,
@@ -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,6 @@ 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);
+
+  self->pipeline_changed = FALSE;
 }


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