[gnome-photos/wip/rishi/misc-fixes: 13/15] application, base-item: Conditionally enable editing



commit 1453b90312d6aac9fed147f78a84a9ab7f338de4
Author: Debarshi Ray <debarshir gnome org>
Date:   Wed Dec 23 10:06:41 2015 +0100

    application, base-item: Conditionally enable editing
    
    Only local items can be edited. We require that the item has finished
    loading and we are in the preview.
    
    There are some high level challenges and questions involved in editing
    remote items - do we upload the edited version; do we replace the
    remote source with the edited version; etc.. So, let's keep it simple
    for the time being.

 src/photos-application.c |   16 ++++++++++++----
 src/photos-base-item.c   |   14 ++++++++++++++
 src/photos-base-item.h   |    2 ++
 3 files changed, 28 insertions(+), 4 deletions(-)
---
diff --git a/src/photos-application.c b/src/photos-application.c
index 90a8a79..2fc5389 100644
--- a/src/photos-application.c
+++ b/src/photos-application.c
@@ -72,6 +72,7 @@ struct _PhotosApplicationPrivate
   GSimpleAction *brightness_contrast_action;
   GSimpleAction *crop_action;
   GSimpleAction *denoise_action;
+  GSimpleAction *edit_action;
   GSimpleAction *edit_cancel_action;
   GSimpleAction *edit_done_action;
   GSimpleAction *fs_action;
@@ -242,10 +243,12 @@ static void
 photos_application_actions_update (PhotosApplication *self)
 {
   PhotosApplicationPrivate *priv = self->priv;
+  PhotosBaseItem *item;
   PhotosLoadState load_state;
   PhotosWindowMode mode;
   gboolean enable;
 
+  item = PHOTOS_BASE_ITEM (photos_base_manager_get_active_object (priv->state->item_mngr));
   load_state = photos_item_manager_get_load_state (priv->state->item_mngr);
   mode = photos_mode_controller_get_window_mode (priv->state->mode_cntrlr);
 
@@ -285,6 +288,11 @@ photos_application_actions_update (PhotosApplication *self)
   g_simple_action_set_enabled (priv->save_action, enable);
   g_simple_action_set_enabled (priv->set_bg_action, enable);
   g_simple_action_set_enabled (priv->set_ss_action, enable);
+
+  enable = (load_state == PHOTOS_LOAD_STATE_FINISHED
+            && mode == PHOTOS_WINDOW_MODE_PREVIEW
+            && photos_base_item_can_edit (item));
+  g_simple_action_set_enabled (priv->edit_action, enable);
 }
 
 
@@ -1315,10 +1323,9 @@ photos_application_startup (GApplication *application)
                             self);
   g_action_map_add_action (G_ACTION_MAP (self), G_ACTION (priv->edit_cancel_action));
 
-  action = g_simple_action_new ("edit-current", NULL);
-  g_signal_connect_swapped (action, "activate", G_CALLBACK (photos_application_edit_current), self);
-  g_action_map_add_action (G_ACTION_MAP (self), G_ACTION (action));
-  g_object_unref (action);
+  priv->edit_action = g_simple_action_new ("edit-current", NULL);
+  g_signal_connect_swapped (priv->edit_action, "activate", G_CALLBACK (photos_application_edit_current), 
self);
+  g_action_map_add_action (G_ACTION_MAP (self), G_ACTION (priv->edit_action));
 
   priv->edit_done_action = g_simple_action_new ("edit-done", NULL);
   g_signal_connect_swapped (priv->edit_done_action,
@@ -1504,6 +1511,7 @@ photos_application_dispose (GObject *object)
   g_clear_object (&priv->brightness_contrast_action);
   g_clear_object (&priv->crop_action);
   g_clear_object (&priv->denoise_action);
+  g_clear_object (&priv->edit_action);
   g_clear_object (&priv->edit_cancel_action);
   g_clear_object (&priv->edit_done_action);
   g_clear_object (&priv->fs_action);
diff --git a/src/photos-base-item.c b/src/photos-base-item.c
index 5ba8baf..11ee90f 100644
--- a/src/photos-base-item.c
+++ b/src/photos-base-item.c
@@ -1449,6 +1449,20 @@ photos_base_item_filterable_iface_init (PhotosFilterableInterface *iface)
 
 
 gboolean
+photos_base_item_can_edit (PhotosBaseItem *self)
+{
+  PhotosBaseItemPrivate *priv;
+
+  g_return_val_if_fail (PHOTOS_IS_BASE_ITEM (self), FALSE);
+  priv = self->priv;
+
+  return PHOTOS_BASE_ITEM_GET_CLASS (self)->create_pipeline_path != NULL
+    && priv->filename != NULL
+    && priv->filename[0] != '\0';
+}
+
+
+gboolean
 photos_base_item_can_trash (PhotosBaseItem *self)
 {
   return PHOTOS_BASE_ITEM_GET_CLASS (self)->trash != NULL;
diff --git a/src/photos-base-item.h b/src/photos-base-item.h
index 0cd8bc2..792f60f 100644
--- a/src/photos-base-item.h
+++ b/src/photos-base-item.h
@@ -90,6 +90,8 @@ struct _PhotosBaseItemClass
 
 GType               photos_base_item_get_type                (void) G_GNUC_CONST;
 
+gboolean            photos_base_item_can_edit                (PhotosBaseItem *self);
+
 gboolean            photos_base_item_can_trash               (PhotosBaseItem *self);
 
 cairo_surface_t    *photos_base_item_create_preview          (PhotosBaseItem *self,


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