[gnome-photos] Add PhotosSelectionController



commit 4516553c9500bc45825566f876f84bc5cfa05362
Author: Debarshi Ray <debarshir gnome org>
Date:   Tue Apr 24 17:34:16 2012 +0200

    Add PhotosSelectionController

 src/Makefile.am                   |    2 +
 src/photos-selection-controller.c |  190 +++++++++++++++++++++++++++++++++++++
 src/photos-selection-controller.h |   86 +++++++++++++++++
 3 files changed, 278 insertions(+), 0 deletions(-)
---
diff --git a/src/Makefile.am b/src/Makefile.am
index 10083ca..be521be 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -19,6 +19,8 @@ gnome_photos_SOURCES = \
 	photos-main-window.h \
 	photos-mode-controller.c \
 	photos-mode-controller.h \
+	photos-selection-controller.c \
+	photos-selection-controller.h \
 	photos-main.c \
 	$(NULL)
 
diff --git a/src/photos-selection-controller.c b/src/photos-selection-controller.c
new file mode 100644
index 0000000..4cb012a
--- /dev/null
+++ b/src/photos-selection-controller.c
@@ -0,0 +1,190 @@
+/*
+ * 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 "photos-selection-controller.h"
+
+
+struct _PhotosSelectionControllerPrivate
+{
+  GList *selection;
+  gboolean is_frozen;
+  gboolean selection_mode;
+};
+
+enum
+{
+  SELECTION_CHANGED,
+  SELECTION_MODE_CHANGED,
+  LAST_SIGNAL
+};
+
+static guint signals[LAST_SIGNAL] = { 0 };
+
+
+G_DEFINE_TYPE (PhotosSelectionController, photos_selection_controller, G_TYPE_OBJECT);
+
+
+static GObject *
+photos_selection_controller_constructor (GType                  type,
+                                         guint                  n_construct_params,
+                                         GObjectConstructParam *construct_params)
+{
+  static GObject *self = NULL;
+
+  if (self == NULL)
+    {
+      self = G_OBJECT_CLASS (photos_selection_controller_parent_class)->constructor (type,
+                                                                                     n_construct_params,
+                                                                                     construct_params);
+      g_object_add_weak_pointer (self, (gpointer) &self);
+      return self;
+    }
+
+  return g_object_ref (self);
+}
+
+
+static void
+photos_selection_controller_finalize (GObject *object)
+{
+  PhotosSelectionController *self = PHOTOS_SELECTION_CONTROLLER (object);
+  PhotosSelectionControllerPrivate *priv = self->priv;
+
+  if (priv->selection != NULL)
+    g_list_free_full (priv->selection, g_free);
+
+  G_OBJECT_CLASS (photos_selection_controller_parent_class)->finalize (object);
+}
+
+
+static void
+photos_selection_controller_init (PhotosSelectionController *self)
+{
+  PhotosSelectionControllerPrivate *priv;
+
+  self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self,
+                                            PHOTOS_TYPE_SELECTION_CONTROLLER,
+                                            PhotosSelectionControllerPrivate);
+  priv = self->priv;
+}
+
+
+static void
+photos_selection_controller_class_init (PhotosSelectionControllerClass *class)
+{
+  GObjectClass *object_class = G_OBJECT_CLASS (class);
+
+  object_class->constructor = photos_selection_controller_constructor;
+  object_class->finalize = photos_selection_controller_finalize;
+
+  signals[SELECTION_CHANGED] = g_signal_new ("selection-changed",
+                                             G_TYPE_FROM_CLASS (class),
+                                             G_SIGNAL_RUN_LAST,
+                                             G_STRUCT_OFFSET (PhotosSelectionControllerClass,
+                                                              selection_changed),
+                                             NULL, /*accumulator */
+                                             NULL, /*accu_data */
+                                             g_cclosure_marshal_VOID__VOID,
+                                             G_TYPE_NONE,
+                                             0);
+
+  signals[SELECTION_MODE_CHANGED] = g_signal_new ("selection-mode-changed",
+                                                  G_TYPE_FROM_CLASS (class),
+                                                  G_SIGNAL_RUN_LAST,
+                                                  G_STRUCT_OFFSET (PhotosSelectionControllerClass,
+                                                                   selection_mode_changed),
+                                                  NULL, /*accumulator */
+                                                  NULL, /*accu_data */
+                                                  g_cclosure_marshal_VOID__BOOLEAN,
+                                                  G_TYPE_NONE,
+                                                  1,
+                                                  G_TYPE_BOOLEAN);
+
+  g_type_class_add_private (class, sizeof (PhotosSelectionControllerPrivate));
+}
+
+
+PhotosSelectionController *
+photos_selection_controller_new (void)
+{
+  return g_object_new (PHOTOS_TYPE_SELECTION_CONTROLLER, NULL);
+}
+
+
+void
+photos_selection_controller_freeze_selection (PhotosSelectionController *self, gboolean freeze)
+{
+  self->priv->is_frozen = freeze;
+}
+
+
+GList *
+photos_selection_controller_get_selection (PhotosSelectionController *self)
+{
+  return self->priv->selection;
+}
+
+
+gboolean
+photos_selection_controller_get_selection_mode (PhotosSelectionController *self)
+{
+  return self->priv->selection_mode;
+}
+
+
+void
+photos_selection_controller_set_selection (PhotosSelectionController *self, GList *selection)
+{
+  PhotosSelectionControllerPrivate *priv = self->priv;
+
+  if (priv->is_frozen)
+    return;
+
+  g_list_free_full (priv->selection, g_free);
+  priv->selection = NULL;
+
+  if (selection != NULL)
+    {
+      GList *l;
+
+      for (l = selection; l!= NULL; l = l->next)
+        priv->selection = g_list_prepend (priv->selection, g_strdup (l->data));
+    }
+
+  g_signal_emit (self, signals[SELECTION_CHANGED], 0);
+}
+
+
+void
+photos_selection_controller_set_selection_mode (PhotosSelectionController *self, gboolean mode)
+{
+  PhotosSelectionControllerPrivate *priv = self->priv;
+
+  if (priv->selection_mode == mode)
+    return;
+
+  priv->selection_mode = mode;
+  g_signal_emit (self, signals[SELECTION_MODE_CHANGED], 0, priv->selection_mode);
+}
diff --git a/src/photos-selection-controller.h b/src/photos-selection-controller.h
new file mode 100644
index 0000000..ab53d4a
--- /dev/null
+++ b/src/photos-selection-controller.h
@@ -0,0 +1,86 @@
+/*
+ * 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_CONTROLLER_H
+#define PHOTOS_SELECTION_CONTROLLER_H
+
+#include <glib-object.h>
+
+G_BEGIN_DECLS
+
+#define PHOTOS_TYPE_SELECTION_CONTROLLER (photos_selection_controller_get_type ())
+#define PHOTOS_SELECTION_CONTROLLER(obj) \
+  (G_TYPE_CHECK_INSTANCE_CAST ((obj), \
+   PHOTOS_TYPE_SELECTION_CONTROLLER, PhotosSelectionController))
+
+#define PHOTOS_SELECTION_CONTROLLER_CLASS(klass) \
+  (G_TYPE_CHECK_CLASS_CAST ((klass), \
+   PHOTOS_TYPE_SELECTION_CONTROLLER, PhotosSelectionControllerClass))
+
+#define PHOTOS_IS_SELECTION_CONTROLLER(obj) \
+  (G_TYPE_CHECK_INSTANCE_TYPE ((obj), \
+   PHOTOS_TYPE_SELECTION_CONTROLLER))
+
+#define PHOTOS_IS_SELECTION_CONTROLLER_CLASS(klass) \
+  (G_TYPE_CHECK_CLASS_TYPE ((klass), \
+   PHOTOS_TYPE_SELECTION_CONTROLLER))
+
+#define PHOTOS_SELECTION_CONTROLLER_GET_CLASS(obj) \
+  (G_TYPE_INSTANCE_GET_CLASS ((obj), \
+   PHOTOS_TYPE_SELECTION_CONTROLLER, PhotosSelectionControllerClass))
+
+typedef struct _PhotosSelectionController        PhotosSelectionController;
+typedef struct _PhotosSelectionControllerClass   PhotosSelectionControllerClass;
+typedef struct _PhotosSelectionControllerPrivate PhotosSelectionControllerPrivate;
+
+struct _PhotosSelectionController
+{
+  GObject parent_instance;
+  PhotosSelectionControllerPrivate *priv;
+};
+
+struct _PhotosSelectionControllerClass
+{
+  GObjectClass parent_class;
+
+  void (*selection_changed)      (PhotosSelectionController *self);
+  void (*selection_mode_changed) (PhotosSelectionController *self);
+};
+
+GType                       photos_selection_controller_get_type           (void) G_GNUC_CONST;
+
+PhotosSelectionController  *photos_selection_controller_new                (void);
+
+void                        photos_selection_controller_freeze_selection   (PhotosSelectionController *self,
+                                                                            gboolean                   freeze);
+
+GList                      *photos_selection_controller_get_selection      (PhotosSelectionController *self);
+
+gboolean                    photos_selection_controller_get_selection_mode (PhotosSelectionController *self);
+
+void                        photos_selection_controller_set_selection      (PhotosSelectionController *self,
+                                                                            GList                     *selection);
+
+void                        photos_selection_controller_set_selection_mode (PhotosSelectionController *self,
+                                                                            gboolean mode);
+
+G_END_DECLS
+
+#endif /* PHOTOS_SELECTION_CONTROLLER_H */



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