[gnome-photos/wip/rishi/edit-mode: 10/12] application, preview-view: Add a desaturation / gray operation



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

    application, preview-view: Add a desaturation / gray operation

 src/photos-application.c  |    8 +++++++
 src/photos-preview-view.c |   52 +++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 60 insertions(+), 0 deletions(-)
---
diff --git a/src/photos-application.c b/src/photos-application.c
index 791024c..5c77cc5 100644
--- a/src/photos-application.c
+++ b/src/photos-application.c
@@ -68,6 +68,7 @@ struct _PhotosApplicationPrivate
   GSettings *ss_settings;
   GSimpleAction *fs_action;
   GSimpleAction *gear_action;
+  GSimpleAction *gray_action;
   GSimpleAction *open_action;
   GSimpleAction *print_action;
   GSimpleAction *properties_action;
@@ -691,6 +692,9 @@ 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->gray_action, enable);
+
   enable = (mode == PHOTOS_WINDOW_MODE_COLLECTIONS
             || mode == PHOTOS_WINDOW_MODE_FAVORITES
             || mode == PHOTOS_WINDOW_MODE_OVERVIEW
@@ -914,6 +918,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->gray_action = g_simple_action_new ("gray-current", NULL);
+  g_action_map_add_action (G_ACTION_MAP (self), G_ACTION (priv->gray_action));
+
   priv->open_action = g_simple_action_new ("open-current", NULL);
   g_signal_connect_swapped (priv->open_action, "activate", G_CALLBACK (photos_application_open_current), 
self);
   g_action_map_add_action (G_ACTION_MAP (self), G_ACTION (priv->open_action));
@@ -1049,6 +1056,7 @@ photos_application_dispose (GObject *object)
   g_clear_object (&priv->ss_settings);
   g_clear_object (&priv->fs_action);
   g_clear_object (&priv->gear_action);
+  g_clear_object (&priv->gray_action);
   g_clear_object (&priv->open_action);
   g_clear_object (&priv->print_action);
   g_clear_object (&priv->properties_action);
diff --git a/src/photos-preview-view.c b/src/photos-preview-view.c
index e978118..ed07045 100644
--- a/src/photos-preview-view.c
+++ b/src/photos-preview-view.c
@@ -30,9 +30,12 @@
 #include <glib/gi18n.h>
 
 #include "gegl-gtk-view.h"
+#include "photos-base-item.h"
+#include "photos-base-manager.h"
 #include "photos-mode-controller.h"
 #include "photos-preview-nav-buttons.h"
 #include "photos-preview-view.h"
+#include "photos-search-context.h"
 
 
 struct _PhotosPreviewViewPrivate
@@ -41,6 +44,7 @@ struct _PhotosPreviewViewPrivate
   GtkWidget *overlay;
   GtkWidget *stack;
   GtkWidget *view;
+  PhotosBaseManager *item_mngr;
   PhotosModeController *mode_cntrlr;
   PhotosPreviewNavButtons *nav_buttons;
 };
@@ -196,6 +200,42 @@ photos_preview_view_scale_and_align_image (PhotosPreviewView *self, GtkWidget *v
 
 
 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));
+  photos_preview_view_scale_and_align_image (self, view);
+  gtk_widget_queue_draw (view);
+}
+
+
+static void
+photos_preview_view_gray (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_add_operation (item, "gegl:gray");
+  photos_base_item_process_async (item, NULL, photos_preview_view_process, self);
+}
+
+
+static void
 photos_preview_view_size_allocate (PhotosPreviewView *self, GdkRectangle *allocation, gpointer user_data)
 {
   GtkWidget *view = GTK_WIDGET (user_data);
@@ -258,6 +298,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);
@@ -310,12 +351,20 @@ static void
 photos_preview_view_init (PhotosPreviewView *self)
 {
   PhotosPreviewViewPrivate *priv;
+  GAction *action;
+  GApplication *app;
   GtkStyleContext *context;
   GtkWidget *view;
+  PhotosSearchContextState *state;
 
   self->priv = photos_preview_view_get_instance_private (self);
   priv = self->priv;
 
+  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 = photos_mode_controller_dup_singleton ();
   g_signal_connect_object (priv->mode_cntrlr,
                            "window-mode-changed",
@@ -337,6 +386,9 @@ 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), "gray-current");
+  g_signal_connect_object (action, "activate", G_CALLBACK (photos_preview_view_gray), self, 
G_CONNECT_SWAPPED);
 }
 
 


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