[gnome-photos] Add PhotosSelectionToolbar



commit f1aab6f158c397e7c945198913ea1734bd2ad05f
Author: Debarshi Ray <debarshir gnome org>
Date:   Wed Apr 25 21:23:31 2012 +0200

    Add PhotosSelectionToolbar

 src/Makefile.am                |    2 +
 src/photos-selection-toolbar.c |  356 ++++++++++++++++++++++++++++++++++++++++
 src/photos-selection-toolbar.h |   73 ++++++++
 3 files changed, 431 insertions(+), 0 deletions(-)
---
diff --git a/src/Makefile.am b/src/Makefile.am
index 998a110..0faaa60 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -25,6 +25,8 @@ gnome_photos_SOURCES = \
 	photos-mode-controller.h \
 	photos-selection-controller.c \
 	photos-selection-controller.h \
+	photos-selection-toolbar.c \
+	photos-selection-toolbar.h \
 	photos-utils.c \
 	photos-utils.h \
 	photos-main.c \
diff --git a/src/photos-selection-toolbar.c b/src/photos-selection-toolbar.c
new file mode 100644
index 0000000..56a5b17
--- /dev/null
+++ b/src/photos-selection-toolbar.c
@@ -0,0 +1,356 @@
+/*
+ * Photos - access, organize and share your photos on GNOME
+ * Copyright  2012 Red Hat, Inc.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301, USA.
+ */
+
+
+#include "config.h"
+
+#include <clutter-gtk/clutter-gtk.h>
+#include <glib/gi18n.h>
+#include <gtk/gtk.h>
+
+#include "photos-selection-controller.h"
+#include "photos-selection-toolbar.h"
+#include "photos-utils.h"
+
+
+struct _PhotosSelectionToolbarPrivate
+{
+  ClutterActor *actor;
+  GtkToolItem *left_group;
+  GtkToolItem *right_group;
+  GtkToolItem *separator;
+  GtkWidget *left_box;
+  GtkWidget *right_box;
+  GtkWidget *toolbar_collection;
+  GtkWidget *toolbar_favourite;
+  GtkWidget *toolbar_open;
+  GtkWidget *toolbar_print;
+  GtkWidget *toolbar_trash;
+  GtkWidget *widget;
+  PhotosSelectionController *sel_cntrlr;
+  gboolean inside_refresh;
+};
+
+
+G_DEFINE_TYPE (PhotosSelectionToolbar, photos_selection_toolbar, G_TYPE_OBJECT);
+
+
+static void
+photos_selection_toolbar_fade_in (PhotosSelectionToolbar *self)
+{
+  PhotosSelectionToolbarPrivate *priv = self->priv;
+  guint8 opacity;
+
+  opacity = clutter_actor_get_opacity (priv->actor);
+  if (opacity != 0)
+    return;
+
+  clutter_actor_show (priv->actor);
+  clutter_actor_animate (priv->actor, CLUTTER_EASE_OUT_QUAD, 300, "opacity", 255, NULL);
+}
+
+
+static void
+photos_selection_toolbar_fade_out (PhotosSelectionToolbar *self)
+{
+  ClutterAnimation *animation;
+  PhotosSelectionToolbarPrivate *priv = self->priv;
+
+  animation = clutter_actor_animate (priv->actor, CLUTTER_EASE_OUT_QUAD, 300, "opacity", 0, NULL);
+  g_signal_connect_swapped (animation, "completed", G_CALLBACK (clutter_actor_hide), priv->actor);
+}
+
+
+static void
+photos_selection_toolbar_collection_clicked (GtkButton *button, gpointer user_data)
+{
+  PhotosSelectionToolbar *self = PHOTOS_SELECTION_TOOLBAR (user_data);
+  PhotosSelectionToolbarPrivate *priv = self->priv;
+  GtkWidget *toplevel;
+
+  toplevel = gtk_widget_get_toplevel (priv->widget);
+  if (!gtk_widget_is_toplevel (toplevel))
+    return;
+
+  photos_selection_toolbar_fade_out (self);
+  /* TODO: OrganizeCollectionDialog */
+}
+
+
+static void
+photos_selection_toolbar_favourite_clicked (GtkButton *button, gpointer user_data)
+{
+  PhotosSelectionToolbar *self = PHOTOS_SELECTION_TOOLBAR (user_data);
+  PhotosSelectionToolbarPrivate *priv = self->priv;
+  GList *selection;
+  GList *l;
+
+  if (priv->inside_refresh)
+    return;
+
+  selection = photos_selection_controller_get_selection (priv->sel_cntrlr);
+  for (l = selection; l != NULL; l = l->next)
+    {
+      /* TODO: fave the doc */
+    }
+}
+
+
+static void
+photos_selection_toolbar_open_clicked (GtkButton *button, gpointer user_data)
+{
+  PhotosSelectionToolbar *self = PHOTOS_SELECTION_TOOLBAR (user_data);
+  PhotosSelectionToolbarPrivate *priv = self->priv;
+  GList *selection;
+  GList *l;
+
+  selection = photos_selection_controller_get_selection (priv->sel_cntrlr);
+  for (l = selection; l != NULL; l = l->next)
+    {
+      /* TODO: trash the doc */
+    }
+}
+
+
+static void
+photos_selection_toolbar_print_clicked (GtkButton *button, gpointer user_data)
+{
+}
+
+
+static void
+photos_selection_toolbar_set_item_listeners (PhotosSelectionToolbar *self, GList *selection)
+{
+}
+
+
+static void
+photos_selection_toolbar_set_item_visibility (PhotosSelectionToolbar *self)
+{
+  PhotosSelectionToolbarPrivate *priv = self->priv;
+
+  priv->inside_refresh = TRUE;
+
+  /* TODO: ... */
+
+  priv->inside_refresh = FALSE;
+}
+
+
+static void
+photos_selection_toolbar_selection_changed (PhotosSelectionController *sel_cntrlr, gpointer user_data)
+{
+  PhotosSelectionToolbar *self = PHOTOS_SELECTION_TOOLBAR (user_data);
+  PhotosSelectionToolbarPrivate *priv = self->priv;
+  GList *selection;
+
+  if (!photos_selection_controller_get_selection_mode (priv->sel_cntrlr))
+    return;
+
+  selection = photos_selection_controller_get_selection (priv->sel_cntrlr);
+  photos_selection_toolbar_set_item_listeners (self, selection);
+
+  if (g_list_length (selection) > 0)
+    {
+      photos_selection_toolbar_set_item_visibility (self);
+      photos_selection_toolbar_fade_in (self);
+    }
+  else
+    photos_selection_toolbar_fade_out (self);
+}
+
+
+static void
+photos_selection_toolbar_selection_mode_changed (PhotosSelectionController *sel_cntrlr,
+                                                 gboolean mode,
+                                                 gpointer user_data)
+{
+  PhotosSelectionToolbar *self = PHOTOS_SELECTION_TOOLBAR (user_data);
+
+  if (mode)
+    photos_selection_toolbar_selection_changed (sel_cntrlr, self);
+  else
+    photos_selection_toolbar_fade_out (self);
+}
+
+
+static void
+photos_selection_toolbar_trash_clicked (GtkButton *button, gpointer user_data)
+{
+  PhotosSelectionToolbar *self = PHOTOS_SELECTION_TOOLBAR (user_data);
+  PhotosSelectionToolbarPrivate *priv = self->priv;
+  GList *selection;
+  GList *l;
+
+  selection = photos_selection_controller_get_selection (priv->sel_cntrlr);
+  for (l = selection; l != NULL; l = l->next)
+    {
+      /* TODO: trash the doc */
+    }
+}
+
+
+static void
+photos_selection_toolbar_dispose (GObject *object)
+{
+  PhotosSelectionToolbar *self = PHOTOS_SELECTION_TOOLBAR (object);
+  PhotosSelectionToolbarPrivate *priv = self->priv;
+
+  if (priv->sel_cntrlr != NULL)
+    {
+      g_object_unref (priv->sel_cntrlr);
+      priv->sel_cntrlr = NULL;
+    }
+
+  G_OBJECT_CLASS (photos_selection_toolbar_parent_class)->dispose (object);
+}
+
+
+static void
+photos_selection_toolbar_init (PhotosSelectionToolbar *self)
+{
+  PhotosSelectionToolbarPrivate *priv;
+  GtkWidget *bin;
+  GtkWidget *image;
+  GtkStyleContext *context;
+
+  self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self, PHOTOS_TYPE_SELECTION_TOOLBAR, PhotosSelectionToolbarPrivate);
+  priv = self->priv;
+
+  priv->widget = gtk_toolbar_new ();
+  gtk_toolbar_set_show_arrow (GTK_TOOLBAR (priv->widget), FALSE);
+  gtk_toolbar_set_icon_size (GTK_TOOLBAR (priv->widget), GTK_ICON_SIZE_LARGE_TOOLBAR);
+  context = gtk_widget_get_style_context (priv->widget);
+  gtk_style_context_add_class (context, "osd");
+
+  priv->actor = gtk_clutter_actor_new_with_contents (priv->widget);
+  clutter_actor_set_opacity (priv->actor, 0);
+  g_object_set (priv->actor, "show-on-set-parent", FALSE, NULL);
+
+  bin = gtk_clutter_actor_get_widget (GTK_CLUTTER_ACTOR (priv->actor));
+  photos_utils_alpha_gtk_widget (bin);
+
+  priv->left_box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0);
+  priv->left_group = gtk_tool_item_new ();
+  gtk_container_add (GTK_CONTAINER (priv->left_group), priv->left_box);
+  gtk_toolbar_insert (GTK_TOOLBAR (priv->widget), priv->left_group, -1);
+  gtk_widget_show_all (GTK_WIDGET (priv->left_group));
+
+  priv->toolbar_favourite = gtk_toggle_button_new ();
+  image = gtk_image_new_from_icon_name ("emblem-favorite-symbolic", GTK_ICON_SIZE_INVALID);
+  gtk_image_set_pixel_size (GTK_IMAGE (image), 32);
+  gtk_container_add (GTK_CONTAINER (priv->toolbar_favourite), image);
+  gtk_container_add (GTK_CONTAINER (priv->left_box), priv->toolbar_favourite);
+  g_signal_connect (priv->toolbar_favourite,
+                    "clicked",
+                    G_CALLBACK (photos_selection_toolbar_favourite_clicked),
+                    self);
+
+  priv->toolbar_print = gtk_button_new ();
+  image = gtk_image_new_from_icon_name ("printer-symbolic", GTK_ICON_SIZE_INVALID);
+  gtk_image_set_pixel_size (GTK_IMAGE (image), 32);
+  gtk_container_add (GTK_CONTAINER (priv->toolbar_print), image);
+  gtk_container_add (GTK_CONTAINER (priv->left_box), priv->toolbar_print);
+  g_signal_connect (priv->toolbar_print,
+                    "clicked",
+                    G_CALLBACK (photos_selection_toolbar_print_clicked),
+                    self);
+
+  priv->separator = gtk_separator_tool_item_new ();
+  gtk_separator_tool_item_set_draw (GTK_SEPARATOR_TOOL_ITEM (priv->separator), FALSE);
+  gtk_widget_set_visible (GTK_WIDGET (priv->separator), TRUE);
+  gtk_tool_item_set_expand (priv->separator, TRUE);
+  gtk_toolbar_insert (GTK_TOOLBAR (priv->widget), priv->separator, -1);
+
+  priv->right_box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0);
+  priv->right_group = gtk_tool_item_new ();
+  gtk_container_add (GTK_CONTAINER (priv->right_group), priv->right_box);
+  gtk_toolbar_insert (GTK_TOOLBAR (priv->widget), priv->right_group, -1);
+  gtk_widget_show_all (GTK_WIDGET (priv->right_group));
+
+  priv->toolbar_collection = gtk_button_new ();
+  image = gtk_image_new_from_icon_name ("list-add-symbolic", GTK_ICON_SIZE_INVALID);
+  gtk_image_set_pixel_size (GTK_IMAGE (image), 32);
+  gtk_container_add (GTK_CONTAINER (priv->toolbar_collection), image);
+  gtk_widget_set_tooltip_text (GTK_WIDGET (priv->toolbar_collection), _("Organize"));
+  gtk_container_add (GTK_CONTAINER (priv->right_box), priv->toolbar_collection);
+  g_signal_connect (priv->toolbar_collection,
+                    "clicked",
+                    G_CALLBACK (photos_selection_toolbar_collection_clicked),
+                    self);
+
+  priv->toolbar_trash = gtk_button_new ();
+  image = gtk_image_new_from_icon_name ("user-trash-symbolic", GTK_ICON_SIZE_INVALID);
+  gtk_image_set_pixel_size (GTK_IMAGE (image), 32);
+  gtk_container_add (GTK_CONTAINER (priv->toolbar_trash), image);
+  gtk_widget_set_tooltip_text (GTK_WIDGET (priv->toolbar_trash), _("Delete"));
+  gtk_container_add (GTK_CONTAINER (priv->right_box), priv->toolbar_trash);
+  g_signal_connect (priv->toolbar_trash,
+                    "clicked",
+                    G_CALLBACK (photos_selection_toolbar_trash_clicked),
+                    self);
+
+  priv->toolbar_open = gtk_button_new ();
+  image = gtk_image_new_from_icon_name ("document-open-symbolic", GTK_ICON_SIZE_INVALID);
+  gtk_image_set_pixel_size (GTK_IMAGE (image), 32);
+  gtk_container_add (GTK_CONTAINER (priv->toolbar_open), image);
+  gtk_container_add (GTK_CONTAINER (priv->right_box), priv->toolbar_open);
+  g_signal_connect (priv->toolbar_open,
+                    "clicked",
+                    G_CALLBACK (photos_selection_toolbar_open_clicked),
+                    self);
+
+  gtk_widget_show (priv->widget);
+
+  priv->sel_cntrlr = photos_selection_controller_new ();
+  g_signal_connect (priv->sel_cntrlr,
+                    "selection-changed",
+                    G_CALLBACK (photos_selection_toolbar_selection_changed),
+                    self);
+  g_signal_connect (priv->sel_cntrlr,
+                    "selection-mode-changed",
+                    G_CALLBACK (photos_selection_toolbar_selection_mode_changed),
+                    self);
+}
+
+
+static void
+photos_selection_toolbar_class_init (PhotosSelectionToolbarClass *class)
+{
+  GObjectClass *object_class = G_OBJECT_CLASS (class);
+
+  object_class->dispose = photos_selection_toolbar_dispose;
+
+  g_type_class_add_private (class, sizeof (PhotosSelectionToolbarPrivate));
+}
+
+
+PhotosSelectionToolbar *
+photos_selection_toolbar_new (void)
+{
+  return g_object_new (PHOTOS_TYPE_SELECTION_TOOLBAR, NULL);
+}
+
+
+ClutterActor *
+photos_selection_toolbar_get_actor (PhotosSelectionToolbar *self)
+{
+  return self->priv->actor;
+}
diff --git a/src/photos-selection-toolbar.h b/src/photos-selection-toolbar.h
new file mode 100644
index 0000000..d1955cf
--- /dev/null
+++ b/src/photos-selection-toolbar.h
@@ -0,0 +1,73 @@
+/*
+ * Photos - access, organize and share your photos on GNOME
+ * Copyright  2012 Red Hat, Inc.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301, USA.
+ */
+
+#ifndef PHOTOS_SELECTION_TOOLBAR_H
+#define PHOTOS_SELECTION_TOOLBAR_H
+
+#include <clutter/clutter.h>
+
+G_BEGIN_DECLS
+
+#define PHOTOS_TYPE_SELECTION_TOOLBAR (photos_selection_toolbar_get_type ())
+
+#define PHOTOS_SELECTION_TOOLBAR(obj) \
+  (G_TYPE_CHECK_INSTANCE_CAST ((obj), \
+   PHOTOS_TYPE_SELECTION_TOOLBAR, PhotosSelectionToolbar))
+
+#define PHOTOS_SELECTION_TOOLBAR_CLASS(klass) \
+  (G_TYPE_CHECK_CLASS_CAST ((klass), \
+   PHOTOS_TYPE_SELECTION_TOOLBAR, PhotosSelectionToolbarClass))
+
+#define PHOTOS_IS_SELECTION_TOOLBAR(obj) \
+  (G_TYPE_CHECK_INSTANCE_TYPE ((obj), \
+   PHOTOS_TYPE_SELECTION_TOOLBAR))
+
+#define PHOTOS_IS_SELECTION_TOOLBAR_CLASS(klass) \
+  (G_TYPE_CHECK_CLASS_TYPE ((klass), \
+   PHOTOS_TYPE_SELECTION_TOOLBAR))
+
+#define PHOTOS_SELECTION_TOOLBAR_GET_CLASS(obj) \
+  (G_TYPE_INSTANCE_GET_CLASS ((obj), \
+   PHOTOS_TYPE_SELECTION_TOOLBAR, PhotosSelectionToolbarClass))
+
+typedef struct _PhotosSelectionToolbar        PhotosSelectionToolbar;
+typedef struct _PhotosSelectionToolbarClass   PhotosSelectionToolbarClass;
+typedef struct _PhotosSelectionToolbarPrivate PhotosSelectionToolbarPrivate;
+
+struct _PhotosSelectionToolbar
+{
+  GObject parent_instance;
+  PhotosSelectionToolbarPrivate *priv;
+};
+
+struct _PhotosSelectionToolbarClass
+{
+  GObjectClass parent_class;
+};
+
+GType                     photos_selection_toolbar_get_type             (void) G_GNUC_CONST;
+
+PhotosSelectionToolbar   *photos_selection_toolbar_new                  (void);
+
+ClutterActor             *photos_selection_toolbar_get_actor            (PhotosSelectionToolbar *self);
+
+G_END_DECLS
+
+#endif /* PHOTOS_SELECTION_TOOLBAR_H */



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