[gnome-photos/wip/favorites: 14/15] offset-controller: Make it an abstract type with a pluggable query



commit 6f2fe5a62cdf35977869115157d73e2ca14b004a
Author: Debarshi Ray <debarshir gnome org>
Date:   Fri Dec 14 11:55:08 2012 +0530

    offset-controller: Make it an abstract type with a pluggable query
    
    This way we can reuse most of it for the Favorites mode, but plug in a
    different query by implementing the get_query virtual method.
    PhotosOffsetFavoritesController and PhotosOffsetOverviewController are
    the two implementations of it.

 src/Makefile.am                           |    4 +
 src/photos-embed.c                        |    4 +-
 src/photos-load-more-button.c             |   88 ++++++++++++++++++++++++----
 src/photos-load-more-button.h             |    4 +-
 src/photos-offset-controller.c            |   25 +--------
 src/photos-offset-controller.h            |    8 ++-
 src/photos-offset-favorites-controller.c  |   83 +++++++++++++++++++++++++++
 src/photos-offset-favorites-controller.h  |   73 ++++++++++++++++++++++++
 src/photos-offset-overview-controller.c   |   83 +++++++++++++++++++++++++++
 src/photos-offset-overview-controller.h   |   73 ++++++++++++++++++++++++
 src/photos-query-builder.c                |    9 ++-
 src/photos-tracker-controller.c           |   24 ++++++--
 src/photos-tracker-controller.h           |    2 +
 src/photos-tracker-favorites-controller.c |    9 +++
 src/photos-tracker-overview-controller.c  |    9 +++
 src/photos-view-container.c               |    2 +-
 16 files changed, 449 insertions(+), 51 deletions(-)
---
diff --git a/src/Makefile.am b/src/Makefile.am
index 76527ab..f906ed7 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -86,6 +86,10 @@ gnome_photos_SOURCES = \
 	photos-notification-manager.h \
 	photos-offset-controller.c \
 	photos-offset-controller.h \
+	photos-offset-favorites-controller.c \
+	photos-offset-favorites-controller.h \
+	photos-offset-overview-controller.c \
+	photos-offset-overview-controller.h \
 	photos-organize-collection-dialog.c \
 	photos-organize-collection-dialog.h \
 	photos-organize-collection-model.c \
diff --git a/src/photos-embed.c b/src/photos-embed.c
index 4fbf360..809166d 100644
--- a/src/photos-embed.c
+++ b/src/photos-embed.c
@@ -37,7 +37,7 @@
 #include "photos-main-toolbar.h"
 #include "photos-mode-controller.h"
 #include "photos-notification-manager.h"
-#include "photos-offset-controller.h"
+#include "photos-offset-overview-controller.h"
 #include "photos-selection-toolbar.h"
 #include "photos-spinner-box.h"
 #include "photos-tracker-change-monitor.h"
@@ -497,7 +497,7 @@ photos_embed_init (PhotosEmbed *self)
                     G_CALLBACK (photos_embed_query_status_changed),
                     self);
 
-  priv->offset_cntrlr = photos_offset_controller_new ();
+  priv->offset_cntrlr = photos_offset_overview_controller_new ();
   g_signal_connect_swapped (priv->offset_cntrlr, "count-changed", G_CALLBACK (photos_embed_count_changed), self);
 
   priv->item_mngr = photos_item_manager_new ();
diff --git a/src/photos-load-more-button.c b/src/photos-load-more-button.c
index 3f2aabc..0ee2e1b 100644
--- a/src/photos-load-more-button.c
+++ b/src/photos-load-more-button.c
@@ -29,8 +29,10 @@
 #include <glib/gi18n.h>
 #include <glib/gprintf.h>
 
+#include "photos-enums.h"
 #include "photos-load-more-button.h"
-#include "photos-offset-controller.h"
+#include "photos-offset-favorites-controller.h"
+#include "photos-offset-overview-controller.h"
 
 
 struct _PhotosLoadMoreButtonPrivate
@@ -38,10 +40,17 @@ struct _PhotosLoadMoreButtonPrivate
   GtkWidget *label;
   GtkWidget *spinner;
   PhotosOffsetController *offset_cntrlr;
+  PhotosWindowMode mode;
   gboolean block;
   gulong offset_cntrlr_id;
 };
 
+enum
+{
+  PROP_0,
+  PROP_MODE
+};
+
 
 G_DEFINE_TYPE (PhotosLoadMoreButton, photos_load_more_button, GTK_TYPE_BUTTON);
 
@@ -82,6 +91,40 @@ photos_load_more_button_clicked (GtkButton *button)
 
 
 static void
+photos_load_more_button_constructed (GObject *object)
+{
+  PhotosLoadMoreButton *self = PHOTOS_LOAD_MORE_BUTTON (object);
+  PhotosLoadMoreButtonPrivate *priv = self->priv;
+  gint count;
+
+  G_OBJECT_CLASS (photos_load_more_button_parent_class)->constructed (object);
+
+  switch (priv->mode)
+    {
+    case PHOTOS_WINDOW_MODE_FAVORITES:
+      priv->offset_cntrlr = photos_offset_favorites_controller_new ();
+      break;
+
+    case PHOTOS_WINDOW_MODE_OVERVIEW:
+      priv->offset_cntrlr = photos_offset_overview_controller_new ();
+      break;
+
+    default:
+      g_assert_not_reached ();
+      break;
+    }
+
+  priv->offset_cntrlr_id = g_signal_connect (priv->offset_cntrlr,
+                                             "count-changed",
+                                             G_CALLBACK (photos_load_more_button_count_changed),
+                                             self);
+
+  count = photos_offset_controller_get_count (priv->offset_cntrlr);
+  photos_load_more_button_count_changed (priv->offset_cntrlr, count, self);
+}
+
+
+static void
 photos_load_more_button_dispose (GObject *object)
 {
   PhotosLoadMoreButton *self = PHOTOS_LOAD_MORE_BUTTON (object);
@@ -100,12 +143,29 @@ photos_load_more_button_dispose (GObject *object)
 
 
 static void
+photos_load_more_button_set_property (GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec)
+{
+  PhotosLoadMoreButton *self = PHOTOS_LOAD_MORE_BUTTON (object);
+
+  switch (prop_id)
+    {
+    case PROP_MODE:
+      self->priv->mode = (PhotosWindowMode) g_value_get_enum (value);
+      break;
+
+    default:
+      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+      break;
+    }
+}
+
+
+static void
 photos_load_more_button_init (PhotosLoadMoreButton *self)
 {
   PhotosLoadMoreButtonPrivate *priv;
   GtkStyleContext *context;
   GtkWidget *child;
-  gint count;
 
   self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self, PHOTOS_TYPE_LOAD_MORE_BUTTON, PhotosLoadMoreButtonPrivate);
   priv = self->priv;
@@ -130,15 +190,6 @@ photos_load_more_button_init (PhotosLoadMoreButton *self)
   priv->label = gtk_label_new (_("Load More"));
   gtk_widget_set_visible (priv->label, TRUE);
   gtk_container_add (GTK_CONTAINER (child), priv->label);
-
-  priv->offset_cntrlr = photos_offset_controller_new ();
-  priv->offset_cntrlr_id = g_signal_connect (priv->offset_cntrlr,
-                                            "count-changed",
-                                            G_CALLBACK (photos_load_more_button_count_changed),
-                                            self);
-
-  count = photos_offset_controller_get_count (priv->offset_cntrlr);
-  photos_load_more_button_count_changed (priv->offset_cntrlr, count, self);
 }
 
 
@@ -148,17 +199,28 @@ photos_load_more_button_class_init (PhotosLoadMoreButtonClass *class)
   GObjectClass *object_class = G_OBJECT_CLASS (class);
   GtkButtonClass *button_class = GTK_BUTTON_CLASS (class);
 
+  object_class->constructed = photos_load_more_button_constructed;
   object_class->dispose = photos_load_more_button_dispose;
+  object_class->set_property = photos_load_more_button_set_property;
   button_class->clicked = photos_load_more_button_clicked;
 
+  g_object_class_install_property (object_class,
+                                   PROP_MODE,
+                                   g_param_spec_enum ("mode",
+                                                      "PhotosWindowMode enum",
+                                                      "The mode for which the widget is a load button",
+                                                      PHOTOS_TYPE_WINDOW_MODE,
+                                                      PHOTOS_WINDOW_MODE_NONE,
+                                                      G_PARAM_CONSTRUCT_ONLY | G_PARAM_WRITABLE));
+
   g_type_class_add_private (class, sizeof (PhotosLoadMoreButtonPrivate));
 }
 
 
 GtkWidget *
-photos_load_more_button_new (void)
+photos_load_more_button_new (PhotosWindowMode mode)
 {
-  return g_object_new (PHOTOS_TYPE_LOAD_MORE_BUTTON, NULL);
+  return g_object_new (PHOTOS_TYPE_LOAD_MORE_BUTTON, "mode", mode, NULL);
 }
 
 
diff --git a/src/photos-load-more-button.h b/src/photos-load-more-button.h
index 9d1719a..bde5455 100644
--- a/src/photos-load-more-button.h
+++ b/src/photos-load-more-button.h
@@ -27,6 +27,8 @@
 
 #include <gtk/gtk.h>
 
+#include "photos-mode-controller.h"
+
 G_BEGIN_DECLS
 
 #define PHOTOS_TYPE_LOAD_MORE_BUTTON (photos_load_more_button_get_type ())
@@ -68,7 +70,7 @@ struct _PhotosLoadMoreButtonClass
 
 GType                  photos_load_more_button_get_type               (void) G_GNUC_CONST;
 
-GtkWidget             *photos_load_more_button_new                    (void);
+GtkWidget             *photos_load_more_button_new                    (PhotosWindowMode mode);
 
 void                   photos_load_more_button_set_block              (PhotosLoadMoreButton *self, gboolean block);
 
diff --git a/src/photos-offset-controller.c b/src/photos-offset-controller.c
index 1ddac4d..33d29b6 100644
--- a/src/photos-offset-controller.c
+++ b/src/photos-offset-controller.c
@@ -50,7 +50,7 @@ enum
 static guint signals[LAST_SIGNAL] = { 0 };
 
 
-G_DEFINE_TYPE (PhotosOffsetController, photos_offset_controller, G_TYPE_OBJECT);
+G_DEFINE_ABSTRACT_TYPE (PhotosOffsetController, photos_offset_controller, G_TYPE_OBJECT);
 
 
 enum
@@ -100,26 +100,6 @@ photos_offset_controller_reset_count_query_executed (GObject *source_object, GAs
 }
 
 
-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_dispose (GObject *object)
 {
@@ -150,7 +130,6 @@ photos_offset_controller_class_init (PhotosOffsetControllerClass *class)
 {
   GObjectClass *object_class = G_OBJECT_CLASS (class);
 
-  object_class->constructor = photos_offset_controller_constructor;
   object_class->dispose = photos_offset_controller_dispose;
 
   signals[COUNT_CHANGED] = g_signal_new ("count-changed",
@@ -233,7 +212,7 @@ photos_offset_controller_reset_count (PhotosOffsetController *self)
   PhotosOffsetControllerPrivate *priv = self->priv;
   PhotosQuery *query;
 
-  query = photos_query_builder_count_query ();
+  query = PHOTOS_OFFSET_CONTROLLER_GET_CLASS (self)->get_query ();
   photos_tracker_queue_select (priv->queue,
                                query->sparql,
                                NULL,
diff --git a/src/photos-offset-controller.h b/src/photos-offset-controller.h
index 6ca4b48..c895d0a 100644
--- a/src/photos-offset-controller.h
+++ b/src/photos-offset-controller.h
@@ -27,6 +27,8 @@
 
 #include <glib-object.h>
 
+#include "photos-query.h"
+
 G_BEGIN_DECLS
 
 #define PHOTOS_TYPE_OFFSET_CONTROLLER (photos_offset_controller_get_type ())
@@ -65,14 +67,16 @@ struct _PhotosOffsetControllerClass
 {
   GObjectClass parent_class;
 
+  /* virtual methods */
+  PhotosQuery *(*get_query) (void);
+
+  /* signals */
   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_count          (PhotosOffsetController *self);
 
 gint                        photos_offset_controller_get_offset         (PhotosOffsetController *self);
diff --git a/src/photos-offset-favorites-controller.c b/src/photos-offset-favorites-controller.c
new file mode 100644
index 0000000..baaf16d
--- /dev/null
+++ b/src/photos-offset-favorites-controller.c
@@ -0,0 +1,83 @@
+/*
+ * 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.
+ */
+
+/* Based on code from:
+ *   + Documents
+ */
+
+
+#include "config.h"
+
+#include "photos-query-builder.h"
+#include "photos-offset-favorites-controller.h"
+
+
+G_DEFINE_TYPE (PhotosOffsetFavoritesController, photos_offset_favorites_controller, PHOTOS_TYPE_OFFSET_CONTROLLER);
+
+
+static PhotosQuery *
+photos_offset_favorites_controller_get_query (void)
+{
+  return photos_query_builder_count_favorites_query ();
+}
+
+
+static GObject *
+photos_offset_favorites_controller_constructor (GType type,
+                                                guint n_construct_params,
+                                                GObjectConstructParam *construct_params)
+{
+  static GObject *self = NULL;
+
+  if (self == NULL)
+    {
+      self = G_OBJECT_CLASS (photos_offset_favorites_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_favorites_controller_init (PhotosOffsetFavoritesController *self)
+{
+}
+
+
+static void
+photos_offset_favorites_controller_class_init (PhotosOffsetFavoritesControllerClass *class)
+{
+  GObjectClass *object_class = G_OBJECT_CLASS (class);
+  PhotosOffsetControllerClass *offset_controller_class = PHOTOS_OFFSET_CONTROLLER_CLASS (class);
+
+  object_class->constructor = photos_offset_favorites_controller_constructor;
+  offset_controller_class->get_query = photos_offset_favorites_controller_get_query;
+}
+
+
+PhotosOffsetController *
+photos_offset_favorites_controller_new (void)
+{
+  return g_object_new (PHOTOS_TYPE_OFFSET_FAVORITES_CONTROLLER, NULL);
+}
diff --git a/src/photos-offset-favorites-controller.h b/src/photos-offset-favorites-controller.h
new file mode 100644
index 0000000..2f608a8
--- /dev/null
+++ b/src/photos-offset-favorites-controller.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.
+ */
+
+/* Based on code from:
+ *   + Documents
+ */
+
+#ifndef PHOTOS_OFFSET_FAVORITES_CONTROLLER_H
+#define PHOTOS_OFFSET_FAVORITES_CONTROLLER_H
+
+#include "photos-offset-controller.h"
+
+G_BEGIN_DECLS
+
+#define PHOTOS_TYPE_OFFSET_FAVORITES_CONTROLLER (photos_offset_favorites_controller_get_type ())
+
+#define PHOTOS_OFFSET_FAVORITES_CONTROLLER(obj) \
+  (G_TYPE_CHECK_INSTANCE_CAST ((obj), \
+   PHOTOS_TYPE_OFFSET_FAVORITES_CONTROLLER, PhotosOffsetFavoritesController))
+
+#define PHOTOS_OFFSET_FAVORITES_CONTROLLER_CLASS(klass) \
+  (G_TYPE_CHECK_CLASS_CAST ((klass), \
+   PHOTOS_TYPE_OFFSET_FAVORITES_CONTROLLER, PhotosOffsetFavoritesControllerClass))
+
+#define PHOTOS_IS_OFFSET_FAVORITES_CONTROLLER(obj) \
+  (G_TYPE_CHECK_INSTANCE_TYPE ((obj), \
+   PHOTOS_TYPE_OFFSET_FAVORITES_CONTROLLER))
+
+#define PHOTOS_IS_OFFSET_FAVORITES_CONTROLLER_CLASS(klass) \
+  (G_TYPE_CHECK_CLASS_TYPE ((klass), \
+   PHOTOS_TYPE_OFFSET_FAVORITES_CONTROLLER))
+
+#define PHOTOS_OFFSET_FAVORITES_CONTROLLER_GET_CLASS(obj) \
+  (G_TYPE_INSTANCE_GET_CLASS ((obj), \
+   PHOTOS_TYPE_OFFSET_FAVORITES_CONTROLLER, PhotosOffsetFavoritesControllerClass))
+
+typedef struct _PhotosOffsetFavoritesController        PhotosOffsetFavoritesController;
+typedef struct _PhotosOffsetFavoritesControllerClass   PhotosOffsetFavoritesControllerClass;
+
+struct _PhotosOffsetFavoritesController
+{
+  PhotosOffsetController parent_instance;
+};
+
+struct _PhotosOffsetFavoritesControllerClass
+{
+  PhotosOffsetControllerClass parent_class;
+};
+
+GType                    photos_offset_favorites_controller_get_type          (void) G_GNUC_CONST;
+
+PhotosOffsetController  *photos_offset_favorites_controller_new               (void);
+
+G_END_DECLS
+
+#endif /* PHOTOS_OFFSET_FAVORITES_CONTROLLER_H */
diff --git a/src/photos-offset-overview-controller.c b/src/photos-offset-overview-controller.c
new file mode 100644
index 0000000..b4e8dbe
--- /dev/null
+++ b/src/photos-offset-overview-controller.c
@@ -0,0 +1,83 @@
+/*
+ * 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.
+ */
+
+/* Based on code from:
+ *   + Documents
+ */
+
+
+#include "config.h"
+
+#include "photos-query-builder.h"
+#include "photos-offset-overview-controller.h"
+
+
+G_DEFINE_TYPE (PhotosOffsetOverviewController, photos_offset_overview_controller, PHOTOS_TYPE_OFFSET_CONTROLLER);
+
+
+static PhotosQuery *
+photos_offset_overview_controller_get_query (void)
+{
+  return photos_query_builder_count_query ();
+}
+
+
+static GObject *
+photos_offset_overview_controller_constructor (GType type,
+                                                guint n_construct_params,
+                                                GObjectConstructParam *construct_params)
+{
+  static GObject *self = NULL;
+
+  if (self == NULL)
+    {
+      self = G_OBJECT_CLASS (photos_offset_overview_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_overview_controller_init (PhotosOffsetOverviewController *self)
+{
+}
+
+
+static void
+photos_offset_overview_controller_class_init (PhotosOffsetOverviewControllerClass *class)
+{
+  GObjectClass *object_class = G_OBJECT_CLASS (class);
+  PhotosOffsetControllerClass *offset_controller_class = PHOTOS_OFFSET_CONTROLLER_CLASS (class);
+
+  object_class->constructor = photos_offset_overview_controller_constructor;
+  offset_controller_class->get_query = photos_offset_overview_controller_get_query;
+}
+
+
+PhotosOffsetController *
+photos_offset_overview_controller_new (void)
+{
+  return g_object_new (PHOTOS_TYPE_OFFSET_OVERVIEW_CONTROLLER, NULL);
+}
diff --git a/src/photos-offset-overview-controller.h b/src/photos-offset-overview-controller.h
new file mode 100644
index 0000000..fab1482
--- /dev/null
+++ b/src/photos-offset-overview-controller.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.
+ */
+
+/* Based on code from:
+ *   + Documents
+ */
+
+#ifndef PHOTOS_OFFSET_OVERVIEW_CONTROLLER_H
+#define PHOTOS_OFFSET_OVERVIEW_CONTROLLER_H
+
+#include "photos-offset-controller.h"
+
+G_BEGIN_DECLS
+
+#define PHOTOS_TYPE_OFFSET_OVERVIEW_CONTROLLER (photos_offset_overview_controller_get_type ())
+
+#define PHOTOS_OFFSET_OVERVIEW_CONTROLLER(obj) \
+  (G_TYPE_CHECK_INSTANCE_CAST ((obj), \
+   PHOTOS_TYPE_OFFSET_OVERVIEW_CONTROLLER, PhotosOffsetOverviewController))
+
+#define PHOTOS_OFFSET_OVERVIEW_CONTROLLER_CLASS(klass) \
+  (G_TYPE_CHECK_CLASS_CAST ((klass), \
+   PHOTOS_TYPE_OFFSET_OVERVIEW_CONTROLLER, PhotosOffsetOverviewControllerClass))
+
+#define PHOTOS_IS_OFFSET_OVERVIEW_CONTROLLER(obj) \
+  (G_TYPE_CHECK_INSTANCE_TYPE ((obj), \
+   PHOTOS_TYPE_OFFSET_OVERVIEW_CONTROLLER))
+
+#define PHOTOS_IS_OFFSET_OVERVIEW_CONTROLLER_CLASS(klass) \
+  (G_TYPE_CHECK_CLASS_TYPE ((klass), \
+   PHOTOS_TYPE_OFFSET_OVERVIEW_CONTROLLER))
+
+#define PHOTOS_OFFSET_OVERVIEW_CONTROLLER_GET_CLASS(obj) \
+  (G_TYPE_INSTANCE_GET_CLASS ((obj), \
+   PHOTOS_TYPE_OFFSET_OVERVIEW_CONTROLLER, PhotosOffsetOverviewControllerClass))
+
+typedef struct _PhotosOffsetOverviewController        PhotosOffsetOverviewController;
+typedef struct _PhotosOffsetOverviewControllerClass   PhotosOffsetOverviewControllerClass;
+
+struct _PhotosOffsetOverviewController
+{
+  PhotosOffsetController parent_instance;
+};
+
+struct _PhotosOffsetOverviewControllerClass
+{
+  PhotosOffsetControllerClass parent_class;
+};
+
+GType                    photos_offset_overview_controller_get_type          (void) G_GNUC_CONST;
+
+PhotosOffsetController  *photos_offset_overview_controller_new               (void);
+
+G_END_DECLS
+
+#endif /* PHOTOS_OFFSET_OVERVIEW_CONTROLLER_H */
diff --git a/src/photos-query-builder.c b/src/photos-query-builder.c
index 2dcf571..cc2cc18 100644
--- a/src/photos-query-builder.c
+++ b/src/photos-query-builder.c
@@ -27,7 +27,8 @@
 
 #include <gio/gio.h>
 
-#include "photos-offset-controller.h"
+#include "photos-offset-favorites-controller.h"
+#include "photos-offset-overview-controller.h"
 #include "photos-query-builder.h"
 #include "photos-source-manager.h"
 #include "photos-search-type-manager.h"
@@ -126,7 +127,11 @@ photos_query_builder_query (gboolean global, gint flags)
       gint offset;
       gint step;
 
-      offset_cntrlr = photos_offset_controller_new ();
+      if (flags & PHOTOS_QUERY_FLAGS_FAVORITES)
+        offset_cntrlr = photos_offset_favorites_controller_new ();
+      else
+        offset_cntrlr = photos_offset_overview_controller_new ();
+
       offset = photos_offset_controller_get_offset (offset_cntrlr);
       step = photos_offset_controller_get_step (offset_cntrlr);
       g_object_unref (offset_cntrlr);
diff --git a/src/photos-tracker-controller.c b/src/photos-tracker-controller.c
index 941bfaf..0730663 100644
--- a/src/photos-tracker-controller.c
+++ b/src/photos-tracker-controller.c
@@ -30,7 +30,6 @@
 
 #include "photos-item-manager.h"
 #include "photos-marshalers.h"
-#include "photos-offset-controller.h"
 #include "photos-query-builder.h"
 #include "photos-source-manager.h"
 #include "photos-tracker-controller.h"
@@ -255,6 +254,22 @@ photos_tracker_controller_source_object_removed (PhotosBaseManager *manager, GOb
 
 
 static void
+photos_tracker_controller_constructed (GObject *object)
+{
+  PhotosTrackerController *self = PHOTOS_TRACKER_CONTROLLER (object);
+  PhotosTrackerControllerPrivate *priv = self->priv;
+
+  G_OBJECT_CLASS (photos_tracker_controller_parent_class)->constructed (object);
+
+  priv->offset_cntrlr = PHOTOS_TRACKER_CONTROLLER_GET_CLASS (self)->get_offset_controller ();
+  g_signal_connect (priv->offset_cntrlr,
+                    "offset-changed",
+                    G_CALLBACK (photos_tracker_controller_offset_changed),
+                    self);
+}
+
+
+static void
 photos_tracker_controller_dispose (GObject *object)
 {
   PhotosTrackerController *self = PHOTOS_TRACKER_CONTROLLER (object);
@@ -307,12 +322,6 @@ photos_tracker_controller_init (PhotosTrackerController *self)
                     G_CALLBACK (photos_tracker_controller_refresh_for_object),
                     self);
 
-  priv->offset_cntrlr = photos_offset_controller_new ();
-  g_signal_connect (priv->offset_cntrlr,
-                    "offset-changed",
-                    G_CALLBACK (photos_tracker_controller_offset_changed),
-                    self);
-
   priv->queue = photos_tracker_queue_new ();
 }
 
@@ -322,6 +331,7 @@ photos_tracker_controller_class_init (PhotosTrackerControllerClass *class)
 {
   GObjectClass *object_class = G_OBJECT_CLASS (class);
 
+  object_class->constructed = photos_tracker_controller_constructed;
   object_class->dispose = photos_tracker_controller_dispose;
   object_class->finalize = photos_tracker_controller_finalize;
 
diff --git a/src/photos-tracker-controller.h b/src/photos-tracker-controller.h
index 91aa21f..a6ac72d 100644
--- a/src/photos-tracker-controller.h
+++ b/src/photos-tracker-controller.h
@@ -27,6 +27,7 @@
 
 #include <glib-object.h>
 
+#include "photos-offset-controller.h"
 #include "photos-query.h"
 
 G_BEGIN_DECLS
@@ -68,6 +69,7 @@ struct _PhotosTrackerControllerClass
   GObjectClass parent_class;
 
   /* virtual methods */
+  PhotosOffsetController *(*get_offset_controller) (void);
   PhotosQuery *(*get_query) (void);
 
   /* signals */
diff --git a/src/photos-tracker-favorites-controller.c b/src/photos-tracker-favorites-controller.c
index d4a164d..9289f53 100644
--- a/src/photos-tracker-favorites-controller.c
+++ b/src/photos-tracker-favorites-controller.c
@@ -21,6 +21,7 @@
 
 #include "config.h"
 
+#include "photos-offset-favorites-controller.h"
 #include "photos-query-builder.h"
 #include "photos-tracker-favorites-controller.h"
 
@@ -30,6 +31,13 @@ G_DEFINE_TYPE (PhotosTrackerFavoritesController,
                PHOTOS_TYPE_TRACKER_CONTROLLER);
 
 
+static PhotosOffsetController *
+photos_tracker_favorites_controller_get_offset_controller (void)
+{
+  return photos_offset_favorites_controller_new ();
+}
+
+
 static PhotosQuery *
 photos_tracker_favorites_controller_get_query (void)
 {
@@ -70,6 +78,7 @@ photos_tracker_favorites_controller_class_init (PhotosTrackerFavoritesController
   PhotosTrackerControllerClass *tracker_controller_class = PHOTOS_TRACKER_CONTROLLER_CLASS (class);
 
   object_class->constructor = photos_tracker_favorites_controller_constructor;
+  tracker_controller_class->get_offset_controller = photos_tracker_favorites_controller_get_offset_controller;
   tracker_controller_class->get_query = photos_tracker_favorites_controller_get_query;
 }
 
diff --git a/src/photos-tracker-overview-controller.c b/src/photos-tracker-overview-controller.c
index 0d56819..c80023b 100644
--- a/src/photos-tracker-overview-controller.c
+++ b/src/photos-tracker-overview-controller.c
@@ -25,6 +25,7 @@
 
 #include "config.h"
 
+#include "photos-offset-overview-controller.h"
 #include "photos-query-builder.h"
 #include "photos-tracker-overview-controller.h"
 
@@ -32,6 +33,13 @@
 G_DEFINE_TYPE (PhotosTrackerOverviewController, photos_tracker_overview_controller, PHOTOS_TYPE_TRACKER_CONTROLLER);
 
 
+static PhotosOffsetController *
+photos_tracker_overview_controller_get_offset_controller (void)
+{
+  return photos_offset_overview_controller_new ();
+}
+
+
 static PhotosQuery *
 photos_tracker_overview_controller_get_query (void)
 {
@@ -72,6 +80,7 @@ photos_tracker_overview_controller_class_init (PhotosTrackerOverviewControllerCl
   PhotosTrackerControllerClass *tracker_controller_class = PHOTOS_TRACKER_CONTROLLER_CLASS (class);
 
   object_class->constructor = photos_tracker_overview_controller_constructor;
+  tracker_controller_class->get_offset_controller = photos_tracker_overview_controller_get_offset_controller;
   tracker_controller_class->get_query = photos_tracker_overview_controller_get_query;
 }
 
diff --git a/src/photos-view-container.c b/src/photos-view-container.c
index 9444537..0125d84 100644
--- a/src/photos-view-container.c
+++ b/src/photos-view-container.c
@@ -253,7 +253,7 @@ photos_view_container_constructed (GObject *object)
   priv->view = gd_main_view_new (GD_MAIN_VIEW_ICON);
   gtk_container_add (GTK_CONTAINER (self), GTK_WIDGET (priv->view));
 
-  priv->load_more = photos_load_more_button_new ();
+  priv->load_more = photos_load_more_button_new (priv->mode);
   gtk_container_add (GTK_CONTAINER (self), priv->load_more);
 
   gtk_widget_show_all (GTK_WIDGET (self));



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