[gnome-photos/wip/rishi/edit-preview: 5/6] tool-filters: create preview



commit 44cc593c2509d0a0f9f597ca3aaf7c3fb006802c
Author: Debarshi Ray <debarshir gnome org>
Date:   Tue Nov 24 03:15:11 2015 +0100

    tool-filters: create preview

 src/photos-tool-filters.c |   84 +++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 84 insertions(+), 0 deletions(-)
---
diff --git a/src/photos-tool-filters.c b/src/photos-tool-filters.c
index 93eae9a..6308dd8 100644
--- a/src/photos-tool-filters.c
+++ b/src/photos-tool-filters.c
@@ -25,6 +25,7 @@
 #include <glib/gi18n.h>
 #include <gtk/gtk.h>
 
+#include "photos-application.h"
 #include "photos-icons.h"
 #include "photos-operation-insta-common.h"
 #include "photos-tool.h"
@@ -35,6 +36,7 @@
 struct _PhotosToolFilters
 {
   PhotosTool parent_instance;
+  GList *buttons;
   GtkWidget *grid;
 };
 
@@ -55,6 +57,36 @@ G_DEFINE_TYPE_WITH_CODE (PhotosToolFilters, photos_tool_filters, PHOTOS_TYPE_TOO
 static void
 photos_tool_filters_activate (PhotosTool *tool, PhotosBaseItem *item, GeglGtkView *view)
 {
+  PhotosToolFilters *self = PHOTOS_TOOL_FILTERS (tool);
+  GApplication *app;
+  GList *l;
+  gint scale;
+
+  app = g_application_get_default ();
+  scale = photos_application_get_scale_factor (PHOTOS_APPLICATION (app));
+
+  for (l = self->buttons; l != NULL; l = l->next)
+    {
+      PhotosOperationInstaPreset preset;
+      GtkWidget *button = GTK_WIDGET (l->data);
+      GtkWidget *image;
+      GVariant *target_value;
+      cairo_surface_t *surface;
+
+      target_value = gtk_actionable_get_action_target_value (GTK_ACTIONABLE (button));
+      preset = (PhotosOperationInstaPreset) g_variant_get_int16 (target_value);
+      surface = photos_base_item_create_preview (item,
+                                                 96,
+                                                 scale,
+                                                 "photos:insta-filter",
+                                                 "preset", preset,
+                                                 NULL);
+      image = gtk_image_new_from_surface (surface);
+      gtk_button_set_image (GTK_BUTTON (button), image);
+      cairo_surface_destroy (surface);
+
+      gtk_widget_show (image);
+    }
 }
 
 
@@ -78,51 +110,102 @@ photos_tool_filters_dispose (GObject *object)
 
 
 static void
+photos_tool_filters_finalize (GObject *object)
+{
+  PhotosToolFilters *self = PHOTOS_TOOL_FILTERS (object);
+
+  g_list_free (self->buttons);
+
+  G_OBJECT_CLASS (photos_tool_filters_parent_class)->finalize (object);
+}
+
+
+static void
 photos_tool_filters_init (PhotosToolFilters *self)
 {
+  GApplication *app;
+  GdkPixbuf *preview_icon = NULL;
   GtkWidget *button;
+  GtkWidget *image;
+  gint scale;
   guint row = 0;
 
+  app = g_application_get_default ();
+  scale = photos_application_get_scale_factor (PHOTOS_APPLICATION (app));
+  preview_icon = photos_utils_create_placeholder_icon_for_scale (PHOTOS_ICON_CONTENT_LOADING_SYMBOLIC, 48, 
scale);
+
   self->grid = g_object_ref_sink (gtk_grid_new ());
 
+  image = gtk_image_new_from_pixbuf (preview_icon);
   button = gtk_button_new_with_label (_("None"));
   gtk_actionable_set_action_name (GTK_ACTIONABLE (button), "app.insta-current");
   gtk_actionable_set_action_target (GTK_ACTIONABLE (button), "n", (gint16) 
PHOTOS_OPERATION_INSTA_PRESET_NONE);
+  gtk_button_set_always_show_image (GTK_BUTTON (button), TRUE);
+  gtk_button_set_image (GTK_BUTTON (button), image);
+  gtk_button_set_image_position (GTK_BUTTON (button), GTK_POS_TOP);
   gtk_button_set_relief (GTK_BUTTON (button), GTK_RELIEF_NONE);
   gtk_grid_attach (GTK_GRID (self->grid), button, 0, row, 1, 1);
+  self->buttons = g_list_prepend (self->buttons, button);
 
+  image = gtk_image_new_from_pixbuf (preview_icon);
   button = gtk_button_new_with_label (_("1977"));
   gtk_actionable_set_action_name (GTK_ACTIONABLE (button), "app.insta-current");
   gtk_actionable_set_action_target (GTK_ACTIONABLE (button), "n", (gint16) 
PHOTOS_OPERATION_INSTA_PRESET_1977);
+  gtk_button_set_always_show_image (GTK_BUTTON (button), TRUE);
+  gtk_button_set_image (GTK_BUTTON (button), image);
+  gtk_button_set_image_position (GTK_BUTTON (button), GTK_POS_TOP);
   gtk_button_set_relief (GTK_BUTTON (button), GTK_RELIEF_NONE);
   gtk_grid_attach (GTK_GRID (self->grid), button, 1, row, 1, 1);
+  self->buttons = g_list_prepend (self->buttons, button);
   row++;
 
+  image = gtk_image_new_from_pixbuf (preview_icon);
   button = gtk_button_new_with_label (_("Brannan"));
   gtk_actionable_set_action_name (GTK_ACTIONABLE (button), "app.insta-current");
   gtk_actionable_set_action_target (GTK_ACTIONABLE (button), "n", (gint16) 
PHOTOS_OPERATION_INSTA_PRESET_BRANNAN);
+  gtk_button_set_always_show_image (GTK_BUTTON (button), TRUE);
+  gtk_button_set_image (GTK_BUTTON (button), image);
+  gtk_button_set_image_position (GTK_BUTTON (button), GTK_POS_TOP);
   gtk_button_set_relief (GTK_BUTTON (button), GTK_RELIEF_NONE);
   gtk_grid_attach (GTK_GRID (self->grid), button, 0, row, 1, 1);
+  self->buttons = g_list_prepend (self->buttons, button);
 
+  image = gtk_image_new_from_pixbuf (preview_icon);
   button = gtk_button_new_with_label (_("Gotham"));
   gtk_actionable_set_action_name (GTK_ACTIONABLE (button), "app.insta-current");
   gtk_actionable_set_action_target (GTK_ACTIONABLE (button), "n", (gint16) 
PHOTOS_OPERATION_INSTA_PRESET_GOTHAM);
+  gtk_button_set_always_show_image (GTK_BUTTON (button), TRUE);
+  gtk_button_set_image (GTK_BUTTON (button), image);
+  gtk_button_set_image_position (GTK_BUTTON (button), GTK_POS_TOP);
   gtk_button_set_relief (GTK_BUTTON (button), GTK_RELIEF_NONE);
   gtk_grid_attach (GTK_GRID (self->grid), button, 1, row, 1, 1);
+  self->buttons = g_list_prepend (self->buttons, button);
   row++;
 
+  image = gtk_image_new_from_pixbuf (preview_icon);
   button = gtk_button_new_with_label (_("Gray"));
   gtk_actionable_set_action_name (GTK_ACTIONABLE (button), "app.insta-current");
   gtk_actionable_set_action_target (GTK_ACTIONABLE (button), "n", (gint16) 
PHOTOS_OPERATION_INSTA_PRESET_GRAY);
+  gtk_button_set_always_show_image (GTK_BUTTON (button), TRUE);
+  gtk_button_set_image (GTK_BUTTON (button), image);
+  gtk_button_set_image_position (GTK_BUTTON (button), GTK_POS_TOP);
   gtk_button_set_relief (GTK_BUTTON (button), GTK_RELIEF_NONE);
   gtk_grid_attach (GTK_GRID (self->grid), button, 0, row, 1, 1);
+  self->buttons = g_list_prepend (self->buttons, button);
 
+  image = gtk_image_new_from_pixbuf (preview_icon);
   button = gtk_button_new_with_label (_("Nashville"));
   gtk_actionable_set_action_name (GTK_ACTIONABLE (button), "app.insta-current");
   gtk_actionable_set_action_target (GTK_ACTIONABLE (button), "n", (gint16) 
PHOTOS_OPERATION_INSTA_PRESET_NASHVILLE);
+  gtk_button_set_always_show_image (GTK_BUTTON (button), TRUE);
+  gtk_button_set_image (GTK_BUTTON (button), image);
+  gtk_button_set_image_position (GTK_BUTTON (button), GTK_POS_TOP);
   gtk_button_set_relief (GTK_BUTTON (button), GTK_RELIEF_NONE);
   gtk_grid_attach (GTK_GRID (self->grid), button, 1, row, 1, 1);
+  self->buttons = g_list_prepend (self->buttons, button);
   row++;
+
+  g_clear_object (&preview_icon);
 }
 
 
@@ -136,6 +219,7 @@ photos_tool_filters_class_init (PhotosToolFiltersClass *class)
   tool_class->name = _("Filters");
 
   object_class->dispose = photos_tool_filters_dispose;
+  object_class->finalize = photos_tool_filters_finalize;
   tool_class->activate = photos_tool_filters_activate;
   tool_class->get_widget = photos_tool_filters_get_widget;
 }


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