[gnome-photos/wip/rishi/revert-to-original: 3/3] properties-dialog: Add options to revert all edits



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

    properties-dialog: Add options to revert all edits
    
    https://bugzilla.gnome.org/show_bug.cgi?id=763156

 src/photos-properties-dialog.c |  119 ++++++++++++++++++++++++++++++++++++++++
 1 files changed, 119 insertions(+), 0 deletions(-)
---
diff --git a/src/photos-properties-dialog.c b/src/photos-properties-dialog.c
index c987b1e..b4f4882 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_str;
+  GtkWidget *revert_button;
   PhotosBaseManager *item_mngr;
   PhotosCameraCache *camera_cache;
   gchar *urn;
@@ -152,6 +154,86 @@ photos_properties_dialog_title_entry_changed (GtkEditable *editable, gpointer us
 
 
 static void
+photos_properties_dialog_disable_revert (PhotosPropertiesDialog *self)
+{
+  gtk_label_set_text (GTK_LABEL (self->modified_str), _("Untouched"));
+  gtk_widget_set_sensitive (self->revert_button, FALSE);
+}
+
+
+static void
+photos_properties_dialog_revert_edits_save_done (GObject *source_object, GAsyncResult *res, gpointer 
user_data)
+{
+  PhotosPropertiesDialog *self = PHOTOS_PROPERTIES_DIALOG (user_data);
+  PhotosBaseItem *item = PHOTOS_BASE_ITEM (source_object);
+  GAction *action;
+  GApplication *app;
+  GError *error = NULL;
+
+  if (!photos_base_item_pipeline_save_finish (item, res, &error))
+    {
+      if (!g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED))
+        g_warning ("Unable to save pipeline: %s", error->message);
+      g_error_free (error);
+      goto out;
+    }
+
+  /* Update UI */
+  photos_properties_dialog_disable_revert (self);
+
+ out:
+  app = g_application_get_default ();
+  action = g_action_map_lookup_action (G_ACTION_MAP (app), "draw-current");
+  g_action_activate (action, NULL);
+  g_application_release (app);
+}
+
+
+static void
+photos_properties_dialog_revert_edits_done (GObject *source_object, GAsyncResult *res, gpointer user_data)
+{
+  PhotosPropertiesDialog *self = PHOTOS_PROPERTIES_DIALOG (user_data);
+  PhotosBaseItem *item = PHOTOS_BASE_ITEM (source_object);
+  GError *error = NULL;
+
+  if (!photos_base_item_process_finish (item, res, &error))
+    {
+      GApplication *app = g_application_get_default ();
+
+      if (!g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED))
+        g_warning ("Unable to process item: %s", error->message);
+      g_error_free (error);
+
+      g_application_release (app);
+    }
+
+  photos_base_item_pipeline_save_async (item,
+                                        self->cancellable,
+                                        photos_properties_dialog_revert_edits_save_done,
+                                        self);
+}
+
+
+static void
+photos_properties_dialog_revert_edits_clicked (PhotosPropertiesDialog *self)
+{
+  PhotosBaseItem *item;
+  GApplication *app;
+
+  app = g_application_get_default ();
+  g_application_hold (app);
+
+  item = PHOTOS_BASE_ITEM (photos_base_manager_get_object_by_id (self->item_mngr, self->urn));
+
+  photos_base_item_revert_to_original (item);
+  photos_base_item_process_async (item,
+                                  self->cancellable,
+                                  photos_properties_dialog_revert_edits_done,
+                                  self);
+}
+
+
+static void
 photos_properties_dialog_constructed (GObject *object)
 {
   PhotosPropertiesDialog *self = PHOTOS_PROPERTIES_DIALOG (object);
@@ -170,6 +252,7 @@ photos_properties_dialog_constructed (GObject *object)
   GtkWidget *iso_speed_w = NULL;
   GtkWidget *item_type;
   GtkWidget *item_type_data;
+  GtkWidget *modified_w = NULL;
   GtkWidget *source;
   GtkWidget *source_data;
   GtkWidget *title;
@@ -352,6 +435,12 @@ 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);
+  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))
@@ -490,6 +579,36 @@ photos_properties_dialog_constructed (GObject *object)
       g_free (flash_str);
     }
 
+  if (modified_w != NULL)
+    {
+      GtkWidget *box;
+
+      box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 12);
+      gtk_widget_set_halign (box, GTK_ALIGN_FILL);
+      gtk_widget_set_hexpand (box, TRUE);
+      gtk_box_set_homogeneous (GTK_BOX (box), TRUE);
+
+      self->modified_str = gtk_label_new (_("Edited in Photos"));
+      gtk_widget_set_halign (self->modified_str, GTK_ALIGN_START);
+      gtk_box_pack_start (GTK_BOX (box), self->modified_str, TRUE, TRUE, 1);
+
+      self->revert_button = gtk_button_new_with_label (_("Discard all Edits"));
+      gtk_widget_set_halign (self->revert_button, GTK_ALIGN_END);
+      context = gtk_widget_get_style_context (self->revert_button);
+      gtk_style_context_add_class (context, "destructive-action");
+      gtk_box_pack_end (GTK_BOX (box), self->revert_button, FALSE, TRUE, 0);
+
+      g_signal_connect_swapped (self->revert_button,
+                                "clicked",
+                                G_CALLBACK (photos_properties_dialog_revert_edits_clicked),
+                                self);
+
+      gtk_grid_attach_next_to (GTK_GRID (self->grid), box, modified_w, GTK_POS_RIGHT, 2, 1);
+
+      if (!photos_base_item_get_edited (item))
+        photos_properties_dialog_disable_revert (self);
+    }
+
   g_free (date_created_str);
   g_free (date_modified_str);
 }


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