[gnome-photos] Add PhotosOffsetController



commit cf26885e425c587bd7365aa008deb888983b5c55
Author: Debarshi Ray <debarshir gnome org>
Date:   Wed May 2 23:25:52 2012 +0200

    Add PhotosOffsetController

 src/Makefile.am                |    2 +
 src/photos-offset-controller.c |  164 ++++++++++++++++++++++++++++++++++++++++
 src/photos-offset-controller.h |   84 ++++++++++++++++++++
 3 files changed, 250 insertions(+), 0 deletions(-)
---
diff --git a/src/Makefile.am b/src/Makefile.am
index 4205b41..0ffe5e8 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -43,6 +43,8 @@ gnome_photos_SOURCES = \
 	photos-main-window.h \
 	photos-mode-controller.c \
 	photos-mode-controller.h \
+	photos-offset-controller.c \
+	photos-offset-controller.h \
 	photos-organize-collection-dialog.c \
 	photos-organize-collection-dialog.h \
 	photos-organize-collection-model.c \
diff --git a/src/photos-offset-controller.c b/src/photos-offset-controller.c
new file mode 100644
index 0000000..bf14d0d
--- /dev/null
+++ b/src/photos-offset-controller.c
@@ -0,0 +1,164 @@
+/*
+ * 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-offset-controller.h"
+
+
+struct _PhotosOffsetControllerPrivate
+{
+  gint count;
+  gint offset;
+};
+
+enum
+{
+  COUNT_CHANGED,
+  OFFSET_CHANGED,
+  LAST_SIGNAL
+};
+
+static guint signals[LAST_SIGNAL] = { 0 };
+
+
+G_DEFINE_TYPE (PhotosOffsetController, photos_offset_controller, G_TYPE_OBJECT);
+
+
+enum
+{
+  OFFSET_STEP = 50
+};
+
+
+static GObject *
+photos_offset_controller_constructor (GType                  type,
+                                      guint                  n_construct_params,
+                                      GObjectConstructParam *construct_params)
+{
+  static GObject *self = NULL;
+
+  if (self == NULL)
+    {
+      self = G_OBJECT_CLASS (photos_offset_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_offset_controller_init (PhotosOffsetController *self)
+{
+  PhotosOffsetControllerPrivate *priv;
+
+  self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self,
+                                            PHOTOS_TYPE_OFFSET_CONTROLLER,
+                                            PhotosOffsetControllerPrivate);
+  priv = self->priv;
+}
+
+
+static void
+photos_offset_controller_class_init (PhotosOffsetControllerClass *class)
+{
+  GObjectClass *object_class = G_OBJECT_CLASS (class);
+
+  object_class->constructor = photos_offset_controller_constructor;
+
+  signals[COUNT_CHANGED] = g_signal_new ("count-changed",
+                                         G_TYPE_FROM_CLASS (class),
+                                         G_SIGNAL_RUN_LAST,
+                                         G_STRUCT_OFFSET (PhotosOffsetControllerClass,
+                                                          count_changed),
+                                         NULL, /*accumulator */
+                                         NULL, /*accu_data */
+                                         g_cclosure_marshal_VOID__INT,
+                                         G_TYPE_NONE,
+                                         1,
+                                         G_TYPE_INT);
+
+  signals[OFFSET_CHANGED] = g_signal_new ("offset-changed",
+                                          G_TYPE_FROM_CLASS (class),
+                                          G_SIGNAL_RUN_LAST,
+                                          G_STRUCT_OFFSET (PhotosOffsetControllerClass,
+                                                           offset_changed),
+                                          NULL, /*accumulator */
+                                          NULL, /*accu_data */
+                                          g_cclosure_marshal_VOID__INT,
+                                          G_TYPE_NONE,
+                                          1,
+                                          G_TYPE_INT);
+
+  g_type_class_add_private (class, sizeof (PhotosOffsetControllerPrivate));
+}
+
+
+PhotosOffsetController *
+photos_offset_controller_new (void)
+{
+  return g_object_new (PHOTOS_TYPE_OFFSET_CONTROLLER, NULL);
+}
+
+
+gint
+photos_offset_controller_get_offset (PhotosOffsetController *self)
+{
+  return self->priv->offset;
+}
+
+
+gint
+photos_offset_controller_get_remaining (PhotosOffsetController *self)
+{
+  PhotosOffsetControllerPrivate *priv = self->priv;
+  return priv->count - (priv->offset + OFFSET_STEP);
+}
+
+
+gint
+photos_offset_controller_get_step (PhotosOffsetController *self)
+{
+  return OFFSET_STEP;
+}
+
+
+void
+photos_offset_controller_increase_offset (PhotosOffsetController *self)
+{
+  PhotosOffsetControllerPrivate *priv = self->priv;
+
+  priv->offset += OFFSET_STEP;
+  g_signal_emit (self, signals[OFFSET_CHANGED], 0, priv->offset);
+}
+
+
+void
+photos_offset_controller_reset_offset (PhotosOffsetController *self)
+{
+  self->priv->offset = 0;
+}
diff --git a/src/photos-offset-controller.h b/src/photos-offset-controller.h
new file mode 100644
index 0000000..b89f8c5
--- /dev/null
+++ b/src/photos-offset-controller.h
@@ -0,0 +1,84 @@
+/*
+ * 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_OFFSET_CONTROLLER_H
+#define PHOTOS_OFFSET_CONTROLLER_H
+
+#include <glib-object.h>
+
+G_BEGIN_DECLS
+
+#define PHOTOS_TYPE_OFFSET_CONTROLLER (photos_offset_controller_get_type ())
+
+#define PHOTOS_OFFSET_CONTROLLER(obj) \
+  (G_TYPE_CHECK_INSTANCE_CAST ((obj), \
+   PHOTOS_TYPE_OFFSET_CONTROLLER, PhotosOffsetController))
+
+#define PHOTOS_OFFSET_CONTROLLER_CLASS(klass) \
+  (G_TYPE_CHECK_CLASS_CAST ((klass), \
+   PHOTOS_TYPE_OFFSET_CONTROLLER, PhotosOffsetControllerClass))
+
+#define PHOTOS_IS_OFFSET_CONTROLLER(obj) \
+  (G_TYPE_CHECK_INSTANCE_TYPE ((obj), \
+   PHOTOS_TYPE_OFFSET_CONTROLLER))
+
+#define PHOTOS_IS_OFFSET_CONTROLLER_CLASS(klass) \
+  (G_TYPE_CHECK_CLASS_TYPE ((klass), \
+   PHOTOS_TYPE_OFFSET_CONTROLLER))
+
+#define PHOTOS_OFFSET_CONTROLLER_GET_CLASS(obj) \
+  (G_TYPE_INSTANCE_GET_CLASS ((obj), \
+   PHOTOS_TYPE_OFFSET_CONTROLLER, PhotosOffsetControllerClass))
+
+typedef struct _PhotosOffsetController        PhotosOffsetController;
+typedef struct _PhotosOffsetControllerClass   PhotosOffsetControllerClass;
+typedef struct _PhotosOffsetControllerPrivate PhotosOffsetControllerPrivate;
+
+struct _PhotosOffsetController
+{
+  GObject parent_instance;
+  PhotosOffsetControllerPrivate *priv;
+};
+
+struct _PhotosOffsetControllerClass
+{
+  GObjectClass parent_class;
+
+  void (*count_changed)      (PhotosOffsetController *self, gint count);
+  void (*offset_changed)     (PhotosOffsetController *self, gint offset);
+};
+
+GType                       photos_offset_controller_get_type           (void) G_GNUC_CONST;
+
+PhotosOffsetController     *photos_offset_controller_new                (void);
+
+gint                        photos_offset_controller_get_offset         (PhotosOffsetController *self);
+
+gint                        photos_offset_controller_get_remaining      (PhotosOffsetController *self);
+
+gint                        photos_offset_controller_get_step           (PhotosOffsetController *self);
+
+void                        photos_offset_controller_increase_offset    (PhotosOffsetController *self);
+
+void                        photos_offset_controller_reset_offset       (PhotosOffsetController *self);
+
+G_END_DECLS
+
+#endif /* PHOTOS_OFFSET_CONTROLLER_H */



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