[gnome-photos/wip/rishi/edit-mode: 11/32] application, preview-view: Hook up various edit operations to GActions



commit afd02c1b6a89bf3acebf904883e3db3a4c3aa297
Author: Debarshi Ray <debarshir gnome org>
Date:   Thu May 21 09:20:37 2015 +0200

    application, preview-view: Hook up various edit operations to GActions

 src/photos-application.c  |   42 ++++++++++
 src/photos-preview-view.c |  185 +++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 227 insertions(+), 0 deletions(-)
---
diff --git a/src/photos-application.c b/src/photos-application.c
index 3dc2d90..428b91b 100644
--- a/src/photos-application.c
+++ b/src/photos-application.c
@@ -65,8 +65,12 @@ struct _PhotosApplicationPrivate
   GResource *resource;
   GSettings *bg_settings;
   GSettings *ss_settings;
+  GSimpleAction *brightness_contrast_action;
+  GSimpleAction *crop_action;
+  GSimpleAction *denoise_action;
   GSimpleAction *fs_action;
   GSimpleAction *gear_action;
+  GSimpleAction *insta_action;
   GSimpleAction *load_next_action;
   GSimpleAction *load_previous_action;
   GSimpleAction *open_action;
@@ -80,6 +84,8 @@ struct _PhotosApplicationPrivate
   GSimpleAction *sel_none_action;
   GSimpleAction *set_bg_action;
   GSimpleAction *set_ss_action;
+  GSimpleAction *sharpen_action;
+  GSimpleAction *undo_action;
   GtkWidget *main_window;
   PhotosCameraCache *camera_cache;
   PhotosSearchContextState *state;
@@ -854,6 +860,14 @@ photos_application_window_mode_changed (PhotosApplication *self, PhotosWindowMod
   PhotosApplicationPrivate *priv = self->priv;
   gboolean enable;
 
+  enable = (mode == PHOTOS_WINDOW_MODE_EDIT);
+  g_simple_action_set_enabled (priv->brightness_contrast_action, enable);
+  g_simple_action_set_enabled (priv->crop_action, enable);
+  g_simple_action_set_enabled (priv->denoise_action, enable);
+  g_simple_action_set_enabled (priv->insta_action, enable);
+  g_simple_action_set_enabled (priv->sharpen_action, enable);
+  g_simple_action_set_enabled (priv->undo_action, enable);
+
   enable = (mode == PHOTOS_WINDOW_MODE_COLLECTIONS
             || mode == PHOTOS_WINDOW_MODE_FAVORITES
             || mode == PHOTOS_WINDOW_MODE_OVERVIEW
@@ -1015,10 +1029,23 @@ photos_application_startup (GApplication *application)
   g_action_map_add_action (G_ACTION_MAP (self), G_ACTION (action));
   g_object_unref (action);
 
+  parameter_type = g_variant_type_new ("a{sd}");
+  priv->brightness_contrast_action = g_simple_action_new ("brightness-contrast-current", parameter_type);
+  g_action_map_add_action (G_ACTION_MAP (self), G_ACTION (priv->brightness_contrast_action));
+  g_variant_type_free (parameter_type);
+
+  parameter_type = g_variant_type_new ("a{sd}");
+  priv->crop_action = g_simple_action_new ("crop-current", parameter_type);
+  g_action_map_add_action (G_ACTION_MAP (self), G_ACTION (priv->crop_action));
+  g_variant_type_free (parameter_type);
+
   action = g_simple_action_new ("delete", NULL);
   g_action_map_add_action (G_ACTION_MAP (self), G_ACTION (action));
   g_object_unref (action);
 
+  priv->denoise_action = g_simple_action_new ("denoise-current", G_VARIANT_TYPE_UINT16);
+  g_action_map_add_action (G_ACTION_MAP (self), G_ACTION (priv->denoise_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));
@@ -1038,6 +1065,9 @@ photos_application_startup (GApplication *application)
   g_signal_connect (priv->gear_action, "activate", G_CALLBACK (photos_application_action_toggle), self);
   g_action_map_add_action (G_ACTION_MAP (self), G_ACTION (priv->gear_action));
 
+  priv->insta_action = g_simple_action_new ("insta-current", G_VARIANT_TYPE_INT16);
+  g_action_map_add_action (G_ACTION_MAP (self), G_ACTION (priv->insta_action));
+
   priv->load_next_action = g_simple_action_new ("load-next", NULL);
   g_action_map_add_action (G_ACTION_MAP (self), G_ACTION (priv->load_next_action));
 
@@ -1111,6 +1141,12 @@ photos_application_startup (GApplication *application)
   g_signal_connect_swapped (priv->set_ss_action, "activate", G_CALLBACK (photos_application_set_bg_common), 
self);
   g_action_map_add_action (G_ACTION_MAP (self), G_ACTION (priv->set_ss_action));
 
+  priv->sharpen_action = g_simple_action_new ("sharpen-current", G_VARIANT_TYPE_DOUBLE);
+  g_action_map_add_action (G_ACTION_MAP (self), G_ACTION (priv->sharpen_action));
+
+  priv->undo_action = g_simple_action_new ("undo-current", NULL);
+  g_action_map_add_action (G_ACTION_MAP (self), G_ACTION (priv->undo_action));
+
   g_signal_connect_swapped (priv->state->mode_cntrlr,
                             "window-mode-changed",
                             G_CALLBACK (photos_application_window_mode_changed),
@@ -1177,8 +1213,12 @@ photos_application_dispose (GObject *object)
   g_clear_object (&priv->create_window_cancellable);
   g_clear_object (&priv->bg_settings);
   g_clear_object (&priv->ss_settings);
+  g_clear_object (&priv->brightness_contrast_action);
+  g_clear_object (&priv->crop_action);
+  g_clear_object (&priv->denoise_action);
   g_clear_object (&priv->fs_action);
   g_clear_object (&priv->gear_action);
+  g_clear_object (&priv->insta_action);
   g_clear_object (&priv->load_next_action);
   g_clear_object (&priv->load_previous_action);
   g_clear_object (&priv->open_action);
@@ -1192,6 +1232,8 @@ photos_application_dispose (GObject *object)
   g_clear_object (&priv->sel_none_action);
   g_clear_object (&priv->set_bg_action);
   g_clear_object (&priv->set_ss_action);
+  g_clear_object (&priv->sharpen_action);
+  g_clear_object (&priv->undo_action);
   g_clear_object (&priv->camera_cache);
   g_clear_object (&priv->extract_priority);
 
diff --git a/src/photos-preview-view.c b/src/photos-preview-view.c
index 27c51b1..55b84ff 100644
--- a/src/photos-preview-view.c
+++ b/src/photos-preview-view.c
@@ -30,7 +30,9 @@
 #include <glib/gi18n.h>
 
 #include "gegl-gtk-view.h"
+#include "photos-base-item.h"
 #include "photos-item-manager.h"
+#include "photos-operation-insta-common.h"
 #include "photos-preview-nav-buttons.h"
 #include "photos-preview-view.h"
 #include "photos-search-context.h"
@@ -42,6 +44,7 @@ struct _PhotosPreviewViewPrivate
   GtkWidget *overlay;
   GtkWidget *stack;
   GtkWidget *view;
+  PhotosBaseManager *item_mngr;
   PhotosModeController *mode_cntrlr;
   PhotosPreviewNavButtons *nav_buttons;
 };
@@ -158,6 +161,163 @@ photos_preview_view_create_view (PhotosPreviewView *self)
 
 
 static void
+photos_preview_view_process (GObject *source_object, GAsyncResult *res, gpointer user_data)
+{
+  PhotosPreviewView *self = PHOTOS_PREVIEW_VIEW (user_data);
+  PhotosPreviewViewPrivate *priv = self->priv;
+  GError *error = NULL;
+  GtkWidget *view;
+  PhotosBaseItem *item = PHOTOS_BASE_ITEM (source_object);
+
+  photos_base_item_process_finish (item, res, &error);
+  if (error != NULL)
+    {
+      g_warning ("Unable to process item: %s", error->message);
+      g_error_free (error);
+    }
+
+  view = gtk_stack_get_visible_child (GTK_STACK (priv->stack));
+  gtk_widget_queue_draw (view);
+}
+
+
+static void
+photos_preview_view_brightness_contrast (PhotosPreviewView *self, GVariant *parameter)
+{
+  GVariantIter iter;
+  PhotosBaseItem *item;
+  const gchar *key;
+  gdouble brightness = -G_MAXDOUBLE;
+  gdouble contrast = -G_MAXDOUBLE;
+  gdouble value;
+
+  item = PHOTOS_BASE_ITEM (photos_base_manager_get_active_object (self->priv->item_mngr));
+  if (item == NULL)
+    return;
+
+  g_variant_iter_init (&iter, parameter);
+  while (g_variant_iter_next (&iter, "{&sd}", &key, &value))
+    {
+      if (g_strcmp0 (key, "brightness") == 0)
+        brightness = value;
+      else if (g_strcmp0 (key, "contrast") == 0)
+        contrast = value;
+    }
+
+  g_return_if_fail (brightness > -G_MAXDOUBLE);
+  g_return_if_fail (contrast > -G_MAXDOUBLE);
+
+  photos_base_item_operation_add (item,
+                                  "gegl:brightness-contrast",
+                                  "brightness", brightness,
+                                  "contrast", contrast,
+                                  NULL);
+  photos_base_item_process_async (item, NULL, photos_preview_view_process, self);
+}
+
+
+static void
+photos_preview_view_crop (PhotosPreviewView *self, GVariant *parameter)
+{
+  GVariantIter iter;
+  PhotosBaseItem *item;
+  const gchar *key;
+  gdouble height = -1.0;
+  gdouble width = -1.0;
+  gdouble value;
+  gdouble x = -1.0;
+  gdouble y = -1.0;
+
+  item = PHOTOS_BASE_ITEM (photos_base_manager_get_active_object (self->priv->item_mngr));
+  if (item == NULL)
+    return;
+
+  g_variant_iter_init (&iter, parameter);
+  while (g_variant_iter_next (&iter, "{&sd}", &key, &value))
+    {
+      if (g_strcmp0 (key, "height") == 0)
+        height = value;
+      else if (g_strcmp0 (key, "width") == 0)
+        width = value;
+      else if (g_strcmp0 (key, "x") == 0)
+        x = value;
+      else if (g_strcmp0 (key, "y") == 0)
+        y = value;
+    }
+
+  g_return_if_fail (height >= 0.0);
+  g_return_if_fail (width >= 0.0);
+  g_return_if_fail (x >= 0.0);
+  g_return_if_fail (y >= 0.0);
+
+  photos_base_item_operation_add (item, "gegl:crop", "height", height, "width", width, "x", x, "y", y, NULL);
+  photos_base_item_process_async (item, NULL, photos_preview_view_process, self);
+}
+
+
+static void
+photos_preview_view_denoise (PhotosPreviewView *self, GVariant *parameter)
+{
+  PhotosBaseItem *item;
+  guint16 iterations;
+
+  item = PHOTOS_BASE_ITEM (photos_base_manager_get_active_object (self->priv->item_mngr));
+  if (item == NULL)
+    return;
+
+  iterations = g_variant_get_uint16 (parameter);
+  photos_base_item_operation_add (item, "gegl:noise-reduction", "iterations", (gint) iterations, NULL);
+  photos_base_item_process_async (item, NULL, photos_preview_view_process, self);
+}
+
+
+static void
+photos_preview_view_insta (PhotosPreviewView *self, GVariant *parameter)
+{
+  PhotosBaseItem *item;
+  PhotosOperationInstaPreset preset;
+
+  item = PHOTOS_BASE_ITEM (photos_base_manager_get_active_object (self->priv->item_mngr));
+  if (item == NULL)
+    return;
+
+  preset = (PhotosOperationInstaPreset) g_variant_get_int16 (parameter);
+  photos_base_item_operation_add (item, "photos:insta-filter", "preset", preset, NULL);
+  photos_base_item_process_async (item, NULL, photos_preview_view_process, self);
+}
+
+
+static void
+photos_preview_view_sharpen (PhotosPreviewView *self, GVariant *parameter)
+{
+  PhotosBaseItem *item;
+  gdouble scale;
+
+  item = PHOTOS_BASE_ITEM (photos_base_manager_get_active_object (self->priv->item_mngr));
+  if (item == NULL)
+    return;
+
+  scale = g_variant_get_double (parameter);
+  photos_base_item_operation_add (item, "gegl:unsharp-mask", "scale", scale, NULL);
+  photos_base_item_process_async (item, NULL, photos_preview_view_process, self);
+}
+
+
+static void
+photos_preview_view_undo (PhotosPreviewView *self)
+{
+  PhotosBaseItem *item;
+
+  item = PHOTOS_BASE_ITEM (photos_base_manager_get_active_object (self->priv->item_mngr));
+  if (item == NULL)
+    return;
+
+  photos_base_item_operation_undo (item);
+  photos_base_item_process_async (item, NULL, photos_preview_view_process, self);
+}
+
+
+static void
 photos_preview_view_window_mode_changed (PhotosPreviewView *self, PhotosWindowMode mode, PhotosWindowMode 
old_mode)
 {
   PhotosPreviewViewPrivate *priv = self->priv;
@@ -192,6 +352,7 @@ photos_preview_view_dispose (GObject *object)
   PhotosPreviewViewPrivate *priv = self->priv;
 
   g_clear_object (&priv->node);
+  g_clear_object (&priv->item_mngr);
   g_clear_object (&priv->mode_cntrlr);
 
   G_OBJECT_CLASS (photos_preview_view_parent_class)->dispose (object);
@@ -251,6 +412,8 @@ photos_preview_view_init (PhotosPreviewView *self)
   app = g_application_get_default ();
   state = photos_search_context_get_state (PHOTOS_SEARCH_CONTEXT (app));
 
+  priv->item_mngr = g_object_ref (state->item_mngr);
+
   priv->mode_cntrlr = g_object_ref (state->mode_cntrlr);
   g_signal_connect_object (priv->mode_cntrlr,
                            "window-mode-changed",
@@ -273,11 +436,33 @@ photos_preview_view_init (PhotosPreviewView *self)
   view = photos_preview_view_create_view (self);
   gtk_container_add (GTK_CONTAINER (priv->stack), view);
 
+  action = g_action_map_lookup_action (G_ACTION_MAP (app), "brightness-contrast-current");
+  g_signal_connect_object (action,
+                           "activate",
+                           G_CALLBACK (photos_preview_view_brightness_contrast),
+                           self,
+                           G_CONNECT_SWAPPED);
+
+  action = g_action_map_lookup_action (G_ACTION_MAP (app), "crop-current");
+  g_signal_connect_object (action, "activate", G_CALLBACK (photos_preview_view_crop), self, 
G_CONNECT_SWAPPED);
+
+  action = g_action_map_lookup_action (G_ACTION_MAP (app), "denoise-current");
+  g_signal_connect_object (action, "activate", G_CALLBACK (photos_preview_view_denoise), self, 
G_CONNECT_SWAPPED);
+
+  action = g_action_map_lookup_action (G_ACTION_MAP (app), "insta-current");
+  g_signal_connect_object (action, "activate", G_CALLBACK (photos_preview_view_insta), self, 
G_CONNECT_SWAPPED);
+
   action = g_action_map_lookup_action (G_ACTION_MAP (app), "load-next");
   g_signal_connect_swapped (action, "activate", G_CALLBACK (photos_preview_view_navigate_next), self);
 
   action = g_action_map_lookup_action (G_ACTION_MAP (app), "load-previous");
   g_signal_connect_swapped (action, "activate", G_CALLBACK (photos_preview_view_navigate_previous), self);
+
+  action = g_action_map_lookup_action (G_ACTION_MAP (app), "sharpen-current");
+  g_signal_connect_object (action, "activate", G_CALLBACK (photos_preview_view_sharpen), self, 
G_CONNECT_SWAPPED);
+
+  action = g_action_map_lookup_action (G_ACTION_MAP (app), "undo-current");
+  g_signal_connect_object (action, "activate", G_CALLBACK (photos_preview_view_undo), self, 
G_CONNECT_SWAPPED);
 }
 
 


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