[gnome-photos] Add a PhotosOrganizeCollectionView



commit 06a67ec771701f5b0745ab646e03a5c329792e0a
Author: Debarshi Ray <debarshir gnome org>
Date:   Fri Apr 27 16:49:30 2012 +0200

    Add a PhotosOrganizeCollectionView

 src/Makefile.am                       |    4 +
 src/gd-styled-text-renderer.c         |  124 +++++++++++++++++++++
 src/gd-styled-text-renderer.h         |   79 +++++++++++++
 src/photos-organize-collection-view.c |  195 +++++++++++++++++++++++++++++++++
 src/photos-organize-collection-view.h |   71 ++++++++++++
 5 files changed, 473 insertions(+), 0 deletions(-)
---
diff --git a/src/Makefile.am b/src/Makefile.am
index 65a8318..91f2ade 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -11,6 +11,8 @@ gnome_photos_SOURCES = \
 	$(gnome_photos_built_sources) \
 	gd-main-toolbar.c \
 	gd-main-toolbar.h \
+	gd-styled-text-renderer.c \
+	gd-styled-text-renderer.h \
 	photos-application.c \
 	photos-application.h \
 	photos-base-manager.c \
@@ -29,6 +31,8 @@ gnome_photos_SOURCES = \
 	photos-organize-collection-dialog.h \
 	photos-organize-collection-model.c \
 	photos-organize-collection-model.h \
+	photos-organize-collection-view.c \
+	photos-organize-collection-view.h \
 	photos-selection-controller.c \
 	photos-selection-controller.h \
 	photos-selection-toolbar.c \
diff --git a/src/gd-styled-text-renderer.c b/src/gd-styled-text-renderer.c
new file mode 100644
index 0000000..50a315e
--- /dev/null
+++ b/src/gd-styled-text-renderer.c
@@ -0,0 +1,124 @@
+/*
+ * Copyright (c) 2011 Red Hat, Inc.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser 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 Lesser General Public 
+ * License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License 
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+ *
+ * Author: Cosimo Cecchi <cosimoc redhat com>
+ *
+ */
+
+#include "gd-styled-text-renderer.h"
+
+G_DEFINE_TYPE (GdStyledTextRenderer, gd_styled_text_renderer, GTK_TYPE_CELL_RENDERER_TEXT);
+
+struct _GdStyledTextRendererPrivate {
+  GList *style_classes;
+};
+
+static void
+gd_styled_text_renderer_render (GtkCellRenderer      *cell,
+                                cairo_t              *cr,
+                                GtkWidget            *widget,
+                                const GdkRectangle   *background_area,
+                                const GdkRectangle   *cell_area,
+                                GtkCellRendererState  flags)
+{
+  GdStyledTextRenderer *self = GD_STYLED_TEXT_RENDERER (cell);
+  GtkStyleContext *context;
+  const gchar *style_class;
+  GList *l;
+
+  context = gtk_widget_get_style_context (widget);
+  gtk_style_context_save (context);
+
+  for (l = self->priv->style_classes; l != NULL; l = l->next)
+    {
+      style_class = l->data;
+      gtk_style_context_add_class (context, style_class);
+    }
+
+  GTK_CELL_RENDERER_CLASS (gd_styled_text_renderer_parent_class)->render 
+    (cell, cr, widget,
+     background_area, cell_area, flags);
+
+  gtk_style_context_restore (context);
+}
+
+static void
+gd_styled_text_renderer_finalize (GObject *obj)
+{
+  GdStyledTextRenderer *self = GD_STYLED_TEXT_RENDERER (obj);
+
+  if (self->priv->style_classes != NULL)
+    {
+      g_list_free_full (self->priv->style_classes, g_free);
+      self->priv->style_classes = NULL;
+    }
+
+  G_OBJECT_CLASS (gd_styled_text_renderer_parent_class)->finalize (obj);
+}
+
+static void
+gd_styled_text_renderer_class_init (GdStyledTextRendererClass *klass)
+{
+  GtkCellRendererClass *crclass = GTK_CELL_RENDERER_CLASS (klass);
+  GObjectClass *oclass = G_OBJECT_CLASS (klass);
+
+  oclass->finalize = gd_styled_text_renderer_finalize;
+  crclass->render = gd_styled_text_renderer_render;
+
+  g_type_class_add_private (klass, sizeof (GdStyledTextRendererPrivate));
+}
+
+static void
+gd_styled_text_renderer_init (GdStyledTextRenderer *self)
+{
+  self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self, GD_TYPE_STYLED_TEXT_RENDERER,
+                                            GdStyledTextRendererPrivate);
+}
+
+GtkCellRenderer *
+gd_styled_text_renderer_new (void)
+{
+  return g_object_new (GD_TYPE_STYLED_TEXT_RENDERER,
+                       NULL);
+}
+
+void
+gd_styled_text_renderer_add_class (GdStyledTextRenderer *self,
+                                   const gchar *class)
+{
+  if (g_list_find_custom (self->priv->style_classes, class, (GCompareFunc) g_strcmp0))
+    return;
+
+  self->priv->style_classes = g_list_append (self->priv->style_classes, g_strdup (class));
+}
+
+void
+gd_styled_text_renderer_remove_class (GdStyledTextRenderer *self,
+                                      const gchar *class)
+{
+  GList *class_element;
+
+  class_element = g_list_find_custom (self->priv->style_classes, class, (GCompareFunc) g_strcmp0);
+
+  if (class_element == NULL)
+    return;
+
+  self->priv->style_classes = g_list_remove_link (self->priv->style_classes,
+                                                  class_element);
+  g_free (class_element->data);
+  g_list_free_1 (class_element);
+}
diff --git a/src/gd-styled-text-renderer.h b/src/gd-styled-text-renderer.h
new file mode 100644
index 0000000..fc1995b
--- /dev/null
+++ b/src/gd-styled-text-renderer.h
@@ -0,0 +1,79 @@
+/*
+ * Copyright (c) 2011 Red Hat, Inc.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser 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 Lesser General Public 
+ * License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License 
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+ *
+ * Author: Cosimo Cecchi <cosimoc redhat com>
+ *
+ */
+
+#ifndef _GD_STYLED_TEXT_RENDERER_H
+#define _GD_STYLED_TEXT_RENDERER_H
+
+#include <glib-object.h>
+
+#include <gtk/gtk.h>
+
+G_BEGIN_DECLS
+
+#define GD_TYPE_STYLED_TEXT_RENDERER gd_styled_text_renderer_get_type()
+
+#define GD_STYLED_TEXT_RENDERER(obj) \
+  (G_TYPE_CHECK_INSTANCE_CAST ((obj), \
+   GD_TYPE_STYLED_TEXT_RENDERER, GdStyledTextRenderer))
+
+#define GD_STYLED_TEXT_RENDERER_CLASS(klass) \
+  (G_TYPE_CHECK_CLASS_CAST ((klass), \
+   GD_TYPE_STYLED_TEXT_RENDERER, GdStyledTextRendererClass))
+
+#define GD_IS_STYLED_TEXT_RENDERER(obj) \
+  (G_TYPE_CHECK_INSTANCE_TYPE ((obj), \
+   GD_TYPE_STYLED_TEXT_RENDERER))
+
+#define GD_IS_STYLED_TEXT_RENDERER_CLASS(klass) \
+  (G_TYPE_CHECK_CLASS_TYPE ((klass), \
+   GD_TYPE_STYLED_TEXT_RENDERER))
+
+#define GD_STYLED_TEXT_RENDERER_GET_CLASS(obj) \
+  (G_TYPE_INSTANCE_GET_CLASS ((obj), \
+   GD_TYPE_STYLED_TEXT_RENDERER, GdStyledTextRendererClass))
+
+typedef struct _GdStyledTextRenderer GdStyledTextRenderer;
+typedef struct _GdStyledTextRendererClass GdStyledTextRendererClass;
+typedef struct _GdStyledTextRendererPrivate GdStyledTextRendererPrivate;
+
+struct _GdStyledTextRenderer
+{
+  GtkCellRendererText parent;
+
+  GdStyledTextRendererPrivate *priv;
+};
+
+struct _GdStyledTextRendererClass
+{
+  GtkCellRendererTextClass parent_class;
+};
+
+GType gd_styled_text_renderer_get_type (void) G_GNUC_CONST;
+
+GtkCellRenderer *gd_styled_text_renderer_new (void);
+void gd_styled_text_renderer_add_class (GdStyledTextRenderer *self,
+                                        const gchar *class);
+void gd_styled_text_renderer_remove_class (GdStyledTextRenderer *self,
+                                           const gchar *class);
+
+G_END_DECLS
+
+#endif /* _GD_STYLED_TEXT_RENDERER_H */
diff --git a/src/photos-organize-collection-view.c b/src/photos-organize-collection-view.c
new file mode 100644
index 0000000..c6af946
--- /dev/null
+++ b/src/photos-organize-collection-view.c
@@ -0,0 +1,195 @@
+/*
+ * 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 <glib.h>
+
+#include "gd-styled-text-renderer.h"
+#include "photos-organize-collection-model.h"
+#include "photos-organize-collection-view.h"
+
+
+struct _PhotosOrganizeCollectionViewPrivate
+{
+  GtkCellRenderer *renderer_check;
+  GtkCellRenderer *renderer_detail;
+  GtkCellRenderer *renderer_text;
+  GtkListStore *model;
+  GtkTreeViewColumn *view_col;
+};
+
+
+G_DEFINE_TYPE (PhotosOrganizeCollectionView, photos_organize_collection_view, GTK_TYPE_TREE_VIEW);
+
+
+static void
+photos_organize_collection_view_check_cell (GtkTreeViewColumn *tree_column,
+                                            GtkCellRenderer *cell_renderer,
+                                            GtkTreeModel *tree_model,
+                                            GtkTreeIter *iter,
+                                            gpointer user_data)
+{
+  gchar *id;
+  gint state;
+
+  gtk_tree_model_get (tree_model, iter, PHOTOS_ORGANIZE_MODEL_ID, &id, PHOTOS_ORGANIZE_MODEL_STATE, &state, -1);
+
+  gtk_cell_renderer_toggle_set_active (GTK_CELL_RENDERER_TOGGLE (cell_renderer),
+                                       state & PHOTOS_ORGANIZE_COLLECTION_STATE_ACTIVE);
+  g_object_set (cell_renderer, "inconsistent", state & PHOTOS_ORGANIZE_COLLECTION_STATE_INCONSISTENT, NULL);
+  gtk_cell_renderer_set_visible (cell_renderer, g_strcmp0 (id, PHOTOS_COLLECTION_PLACEHOLDER_ID));
+}
+
+
+static void
+photos_organize_collection_view_check_toggled (GtkCellRendererToggle *cell_renderer,
+                                               gchar *path,
+                                               gpointer user_data)
+{
+}
+
+
+static void
+photos_organize_collection_view_detail_cell (GtkTreeViewColumn *tree_column,
+                                             GtkCellRenderer *cell_renderer,
+                                             GtkTreeModel *tree_model,
+                                             GtkTreeIter *iter,
+                                             gpointer user_data)
+{
+}
+
+
+static void
+photos_organize_collection_view_text_edited (GtkCellRendererText *cell_renderer,
+                                             gchar *path,
+                                             gchar *new_text,
+                                             gpointer user_data)
+{
+}
+
+
+static void
+photos_organize_collection_view_text_editing_canceled (GObject *object, GParamSpec *pspec, gpointer user_data)
+{
+}
+
+
+static void
+photos_organize_collection_view_destroy (GtkWidget *widget)
+{
+  PhotosOrganizeCollectionView *self = PHOTOS_ORGANIZE_COLLECTION_VIEW (widget);
+  photos_organize_collection_model_destroy (PHOTOS_ORGANIZE_COLLECTION_MODEL (self->priv->model));
+}
+
+
+static void
+photos_organize_collection_view_dispose (GObject *object)
+{
+  PhotosOrganizeCollectionView *self = PHOTOS_ORGANIZE_COLLECTION_VIEW (object);
+  PhotosOrganizeCollectionViewPrivate *priv = self->priv;
+
+  if (priv->model != NULL)
+    {
+      g_object_unref (priv->model);
+      priv->model = NULL;
+    }
+
+  G_OBJECT_CLASS (photos_organize_collection_view_parent_class)->dispose (object);
+}
+
+
+static void
+photos_organize_collection_view_init (PhotosOrganizeCollectionView *self)
+{
+  PhotosOrganizeCollectionViewPrivate *priv;
+
+  self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self,
+                                            PHOTOS_TYPE_ORGANIZE_COLLECTION_VIEW,
+                                            PhotosOrganizeCollectionViewPrivate);
+  priv = self->priv;
+
+  priv->model = photos_organize_collection_model_new ();
+  gtk_tree_view_set_model (GTK_TREE_VIEW (self), GTK_TREE_MODEL (priv->model));
+
+  priv->view_col = gtk_tree_view_column_new ();
+  gtk_tree_view_append_column (GTK_TREE_VIEW (self), priv->view_col);
+
+  priv->renderer_check = gtk_cell_renderer_toggle_new ();
+  gtk_tree_view_column_pack_start (priv->view_col, priv->renderer_check, FALSE);
+  gtk_tree_view_column_set_cell_data_func (priv->view_col,
+                                           priv->renderer_check,
+                                           photos_organize_collection_view_check_cell,
+                                           self,
+                                           NULL);
+  g_signal_connect (priv->renderer_check,
+                    "toggled",
+                    G_CALLBACK (photos_organize_collection_view_check_toggled),
+                    self);
+
+  priv->renderer_text = gtk_cell_renderer_text_new ();
+  gtk_tree_view_column_pack_start (priv->view_col, priv->renderer_text, TRUE);
+  gtk_tree_view_column_add_attribute (priv->view_col, priv->renderer_text, "text", PHOTOS_ORGANIZE_MODEL_NAME);
+  g_signal_connect (priv->renderer_text,
+                    "edited",
+                    G_CALLBACK (photos_organize_collection_view_text_edited),
+                    self);
+  g_signal_connect (priv->renderer_text,
+                    "editing-canceled",
+                    G_CALLBACK (photos_organize_collection_view_text_editing_canceled),
+                    self);
+
+  priv->renderer_detail = gd_styled_text_renderer_new ();
+  gtk_cell_renderer_set_padding (priv->renderer_detail, 16, 0);
+  gd_styled_text_renderer_add_class (GD_STYLED_TEXT_RENDERER (priv->renderer_detail), "dim-label");
+  gtk_tree_view_column_pack_start (priv->view_col, priv->renderer_detail, FALSE);
+  gtk_tree_view_column_set_cell_data_func (priv->view_col,
+                                           priv->renderer_detail,
+                                           photos_organize_collection_view_detail_cell,
+                                           self,
+                                           NULL);
+
+  gtk_widget_show (GTK_WIDGET (self));
+}
+
+
+static void
+photos_organize_collection_view_class_init (PhotosOrganizeCollectionViewClass *class)
+{
+  GObjectClass *object_class = G_OBJECT_CLASS (class);
+  GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (class);
+
+  object_class->dispose = photos_organize_collection_view_dispose;
+  widget_class->destroy = photos_organize_collection_view_destroy;
+
+  g_type_class_add_private (class, sizeof (PhotosOrganizeCollectionViewPrivate));
+}
+
+
+GtkWidget *
+photos_organize_collection_view_new (void)
+{
+  return g_object_new (PHOTOS_TYPE_ORGANIZE_COLLECTION_VIEW,
+                       "headers-visible", FALSE,
+                       "vexpand", TRUE,
+                       "hexpand", TRUE,
+                       NULL);
+}
diff --git a/src/photos-organize-collection-view.h b/src/photos-organize-collection-view.h
new file mode 100644
index 0000000..4464003
--- /dev/null
+++ b/src/photos-organize-collection-view.h
@@ -0,0 +1,71 @@
+/*
+ * 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_ORGANIZE_COLLECTION_VIEW_H
+#define PHOTOS_ORGANIZE_COLLECTION_VIEW_H
+
+#include <gtk/gtk.h>
+
+G_BEGIN_DECLS
+
+#define PHOTOS_TYPE_ORGANIZE_COLLECTION_VIEW (photos_view_embed_get_type ())
+
+#define PHOTOS_ORGANIZE_COLLECTION_VIEW(obj) \
+  (G_TYPE_CHECK_INSTANCE_CAST ((obj), \
+   PHOTOS_TYPE_ORGANIZE_COLLECTION_VIEW, PhotosOrganizeCollectionView))
+
+#define PHOTOS_ORGANIZE_COLLECTION_VIEW_CLASS(klass) \
+  (G_TYPE_CHECK_CLASS_CAST ((klass), \
+   PHOTOS_TYPE_ORGANIZE_COLLECTION_VIEW, PhotosOrganizeCollectionViewClass))
+
+#define PHOTOS_IS_ORGANIZE_COLLECTION_VIEW(obj) \
+  (G_TYPE_CHECK_INSTANCE_TYPE ((obj), \
+   PHOTOS_TYPE_ORGANIZE_COLLECTION_VIEW))
+
+#define PHOTOS_IS_ORGANIZE_COLLECTION_VIEW_CLASS(klass) \
+  (G_TYPE_CHECK_CLASS_TYPE ((klass), \
+   PHOTOS_TYPE_ORGANIZE_COLLECTION_VIEW))
+
+#define PHOTOS_ORGANIZE_COLLECTION_VIEW_GET_CLASS(obj) \
+  (G_TYPE_INSTANCE_GET_CLASS ((obj), \
+   PHOTOS_TYPE_ORGANIZE_COLLECTION_VIEW, PhotosOrganizeCollectionViewClass))
+
+typedef struct _PhotosOrganizeCollectionView        PhotosOrganizeCollectionView;
+typedef struct _PhotosOrganizeCollectionViewClass   PhotosOrganizeCollectionViewClass;
+typedef struct _PhotosOrganizeCollectionViewPrivate PhotosOrganizeCollectionViewPrivate;
+
+struct _PhotosOrganizeCollectionView
+{
+  GtkTreeView parent_instance;
+  PhotosOrganizeCollectionViewPrivate *priv;
+};
+
+struct _PhotosOrganizeCollectionViewClass
+{
+  GtkTreeViewClass parent_class;
+};
+
+GType             photos_organize_collection_view_get_type               (void) G_GNUC_CONST;
+
+GtkWidget        *photos_organize_collection_view_new                    (void);
+
+G_END_DECLS
+
+#endif /* PHOTOS_ORGANIZE_COLLECTION_VIEW_H */



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