[gnome-photos] application, properties-dialog: Add UI to revert all edits



commit 688c72cabe492996b5fb46d7a9dea0bd356b8352
Author: Rafael Fonseca <r4f4rfs gmail com>
Date:   Mon Apr 4 14:31:55 2016 +0200

    application, properties-dialog: Add UI to revert all edits
    
    Some changes by Debarshi Ray.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=763156

 src/photos-application.c       |   61 ++++++++++++++++++
 src/photos-properties-dialog.c |  133 ++++++++++++++++++++++++++++++++++++++++
 2 files changed, 194 insertions(+), 0 deletions(-)
---
diff --git a/src/photos-application.c b/src/photos-application.c
index 9d6e3c1..d59d813 100644
--- a/src/photos-application.c
+++ b/src/photos-application.c
@@ -945,6 +945,63 @@ photos_application_print_current (PhotosApplication *self)
 
 
 static void
+photos_application_properties_pipeline_save (GObject *source_object, GAsyncResult *res, gpointer user_data)
+{
+  PhotosApplication *self = PHOTOS_APPLICATION (user_data);
+  GError *error;
+  PhotosBaseItem *item = PHOTOS_BASE_ITEM (source_object);
+
+  error = NULL;
+  if (!photos_base_item_pipeline_save_finish (item, res, &error))
+    {
+      g_warning ("Unable to save pipeline: %s", error->message);
+      g_error_free (error);
+    }
+
+  g_application_release (G_APPLICATION (self));
+}
+
+
+static void
+photos_application_properties_revert_to_original (GObject *source_object, GAsyncResult *res, gpointer 
user_data)
+{
+  PhotosApplication *self = PHOTOS_APPLICATION (user_data);
+  GError *error = NULL;
+  PhotosBaseItem *item = PHOTOS_BASE_ITEM (source_object);
+
+  if (!photos_base_item_pipeline_revert_to_original_finish (item, res, &error))
+    {
+      g_warning ("Unable to revert to original: %s", error->message);
+      g_error_free (error);
+      goto out;
+    }
+
+  g_application_hold (G_APPLICATION (self));
+  photos_base_item_pipeline_save_async (item, NULL, photos_application_properties_pipeline_save, self);
+
+ out:
+  g_action_activate (G_ACTION (self->draw_action), NULL);
+  g_application_release (G_APPLICATION (self));
+}
+
+
+static void
+photos_application_properties_discard_all_edits (PhotosApplication *self)
+{
+  PhotosBaseItem *item;
+
+  item = photos_application_get_selection_or_active_item (self);
+  g_return_if_fail (item != NULL);
+
+  g_application_hold (G_APPLICATION (self));
+  photos_base_item_pipeline_revert_to_original_async (item,
+                                                      NULL,
+                                                      photos_application_properties_revert_to_original,
+                                                      self);
+}
+
+
+static void
 photos_application_properties_response (GtkDialog *dialog, gint response_id, gpointer user_data)
 {
   PhotosApplication *self = PHOTOS_APPLICATION (user_data);
@@ -967,6 +1024,10 @@ photos_application_properties (PhotosApplication *self)
   id = photos_filterable_get_id (PHOTOS_FILTERABLE (item));
   dialog = photos_properties_dialog_new (GTK_WINDOW (self->main_window), id);
   gtk_widget_show_all (dialog);
+  g_signal_connect_swapped (dialog,
+                            "discard-all-edits",
+                            G_CALLBACK (photos_application_properties_discard_all_edits),
+                            self);
   g_signal_connect (dialog, "response", G_CALLBACK (photos_application_properties_response), self);
 }
 
diff --git a/src/photos-properties-dialog.c b/src/photos-properties-dialog.c
index 7a602e2..969e43b 100644
--- a/src/photos-properties-dialog.c
+++ b/src/photos-properties-dialog.c
@@ -44,6 +44,8 @@ struct _PhotosPropertiesDialog
   GtkWidget *camera_w;
   GtkWidget *grid;
   GtkWidget *title_entry;
+  GtkWidget *modified_data;
+  GtkWidget *revert_button;
   PhotosBaseManager *item_mngr;
   PhotosCameraCache *camera_cache;
   gchar *urn;
@@ -53,6 +55,9 @@ struct _PhotosPropertiesDialog
 struct _PhotosPropertiesDialogClass
 {
   GtkDialogClass parent_class;
+
+  /* signals */
+  void (*discard_all_edits) (PhotosPropertiesDialog *self);
 };
 
 enum
@@ -61,6 +66,14 @@ enum
   PROP_URN
 };
 
+enum
+{
+  DISCARD_ALL_EDITS,
+  LAST_SIGNAL
+};
+
+static guint signals[LAST_SIGNAL] = { 0 };
+
 
 G_DEFINE_TYPE (PhotosPropertiesDialog, photos_properties_dialog, GTK_TYPE_DIALOG);
 
@@ -106,6 +119,39 @@ photos_properties_dialog_get_camera (GObject *source_object, GAsyncResult *res,
 
 
 static void
+photos_properties_dialog_modified_updated (PhotosPropertiesDialog *self, gboolean is_edited)
+{
+  GtkStyleContext *context;
+
+  if (is_edited)
+    {
+      gtk_label_set_text (GTK_LABEL (self->modified_data), _("Edited in Photos"));
+      context = gtk_widget_get_style_context (self->modified_data);
+      gtk_style_context_remove_class (context, "photos-fade-out");
+      gtk_style_context_add_class (context, "photos-fade-in");
+      gtk_widget_show (self->modified_data);
+
+      context = gtk_widget_get_style_context (self->revert_button);
+      gtk_style_context_remove_class (context, "photos-fade-out");
+      gtk_style_context_add_class (context, "photos-fade-in");
+      gtk_widget_show (self->revert_button);
+    }
+  else
+    {
+      gtk_label_set_text (GTK_LABEL (self->modified_data), _("Untouched"));
+      context = gtk_widget_get_style_context (self->modified_data);
+      gtk_style_context_remove_class (context, "photos-fade-out");
+      gtk_style_context_add_class (context, "photos-fade-in");
+      gtk_widget_show (self->modified_data);
+
+      context = gtk_widget_get_style_context (self->revert_button);
+      gtk_style_context_remove_class (context, "photos-fade-in");
+      gtk_style_context_add_class (context, "photos-fade-out");
+    }
+}
+
+
+static void
 photos_properties_dialog_name_update (PhotosPropertiesDialog *self)
 {
   const gchar *new_title;
@@ -116,6 +162,30 @@ photos_properties_dialog_name_update (PhotosPropertiesDialog *self)
 
 
 static void
+photos_properties_dialog_pipeline_is_edited (GObject *source_object, GAsyncResult *res, gpointer user_data)
+{
+  PhotosPropertiesDialog *self;
+  GError *error;
+  PhotosBaseItem *item = PHOTOS_BASE_ITEM (source_object);
+  gboolean is_edited;
+
+  error = NULL;
+  is_edited = photos_base_item_pipeline_is_edited_finish (item, res, &error);
+  if (error != NULL)
+    {
+      if (!g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED))
+        g_warning ("Unable to check if item has been edited or not: %s", error->message);
+      g_error_free (error);
+      return;
+    }
+
+  self = PHOTOS_PROPERTIES_DIALOG (user_data);
+
+  photos_properties_dialog_modified_updated (self, is_edited);
+}
+
+
+static void
 photos_properties_dialog_remove_timeout (PhotosPropertiesDialog *self)
 {
   if (self->title_entry_timeout != 0)
@@ -152,6 +222,14 @@ photos_properties_dialog_title_entry_changed (GtkEditable *editable, gpointer us
 
 
 static void
+photos_properties_dialog_revert_clicked (PhotosPropertiesDialog *self)
+{
+  g_signal_emit (self, signals[DISCARD_ALL_EDITS], 0);
+  photos_properties_dialog_modified_updated (self, FALSE);
+}
+
+
+static void
 photos_properties_dialog_constructed (GObject *object)
 {
   PhotosPropertiesDialog *self = PHOTOS_PROPERTIES_DIALOG (object);
@@ -170,6 +248,8 @@ photos_properties_dialog_constructed (GObject *object)
   GtkWidget *iso_speed_w = NULL;
   GtkWidget *item_type;
   GtkWidget *item_type_data;
+  GtkWidget *modified_w;
+  GtkWidget *modified_grid;
   GtkWidget *source;
   GtkWidget *source_data;
   GtkWidget *title;
@@ -352,6 +432,14 @@ photos_properties_dialog_constructed (GObject *object)
       gtk_container_add (GTK_CONTAINER (self->grid), flash_w);
     }
 
+  modified_w = gtk_label_new (_("Modifications"));
+  gtk_widget_set_halign (modified_w, GTK_ALIGN_END);
+  gtk_widget_set_valign (modified_w, GTK_ALIGN_BASELINE);
+  gtk_widget_set_vexpand (modified_w, TRUE);
+  context = gtk_widget_get_style_context (modified_w);
+  gtk_style_context_add_class (context, "dim-label");
+  gtk_container_add (GTK_CONTAINER (self->grid), modified_w);
+
   name = photos_base_item_get_name (item);
 
   if (PHOTOS_IS_LOCAL_ITEM (item))
@@ -492,6 +580,41 @@ photos_properties_dialog_constructed (GObject *object)
       g_free (flash_str);
     }
 
+  photos_base_item_pipeline_is_edited_async (item,
+                                             self->cancellable,
+                                             photos_properties_dialog_pipeline_is_edited,
+                                             self);
+
+  modified_grid = gtk_grid_new ();
+  gtk_widget_set_hexpand (modified_grid, TRUE);
+  gtk_orientable_set_orientation (GTK_ORIENTABLE (modified_grid), GTK_ORIENTATION_HORIZONTAL);
+
+  self->modified_data = gtk_label_new (NULL);
+  gtk_widget_set_halign (self->modified_data, GTK_ALIGN_START);
+  gtk_widget_set_hexpand (self->modified_data, TRUE);
+  gtk_widget_set_no_show_all (self->modified_data, TRUE);
+  gtk_widget_set_valign (self->modified_data, GTK_ALIGN_BASELINE);
+  gtk_widget_set_vexpand (self->modified_data, TRUE);
+  context = gtk_widget_get_style_context (self->modified_data);
+  gtk_style_context_add_class (context, "photos-fade-out");
+  gtk_container_add (GTK_CONTAINER (modified_grid), self->modified_data);
+
+  self->revert_button = gtk_button_new_with_label (_("Discard all Edits"));
+  gtk_widget_set_halign (self->revert_button, GTK_ALIGN_END);
+  gtk_widget_set_hexpand (self->revert_button, TRUE);
+  gtk_widget_set_no_show_all (self->revert_button, TRUE);
+  context = gtk_widget_get_style_context (self->revert_button);
+  gtk_style_context_add_class (context, "destructive-action");
+  gtk_style_context_add_class (context, "photos-fade-out");
+  gtk_container_add (GTK_CONTAINER (modified_grid), self->revert_button);
+
+  g_signal_connect_swapped (self->revert_button,
+                            "clicked",
+                            G_CALLBACK (photos_properties_dialog_revert_clicked),
+                            self);
+
+  gtk_grid_attach_next_to (GTK_GRID (self->grid), modified_grid, modified_w, GTK_POS_RIGHT, 2, 1);
+
   g_free (date_created_str);
   g_free (date_modified_str);
 }
@@ -582,6 +705,16 @@ photos_properties_dialog_class_init (PhotosPropertiesDialogClass *class)
                                                         "An unique ID associated with this item",
                                                         NULL,
                                                         G_PARAM_CONSTRUCT_ONLY | G_PARAM_WRITABLE));
+
+  signals[DISCARD_ALL_EDITS] = g_signal_new ("discard-all-edits",
+                                             G_TYPE_FROM_CLASS (class),
+                                             G_SIGNAL_RUN_LAST,
+                                             G_STRUCT_OFFSET (PhotosPropertiesDialogClass, 
discard_all_edits),
+                                             NULL, /* accumulator */
+                                             NULL, /* accu_data */
+                                             g_cclosure_marshal_VOID__VOID,
+                                             G_TYPE_NONE,
+                                             0);
 }
 
 


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