[gnome-photos] tracker-controller, query-builder: Simplify the use of PhotosQueryFlags



commit b8f8c2c83a3077051bbdb06e627e3b087c1f5ca4
Author: Debarshi Ray <debarshir gnome org>
Date:   Mon Jan 13 10:31:51 2014 +0100

    tracker-controller, query-builder: Simplify the use of PhotosQueryFlags
    
    ... by passing the relevant PhotosOffsetController from the
    PhotosTrackerController itself, instead of figuring it out based on
    PhotosQueryFlags inside the query builder.
    
    Fixes: https://bugzilla.gnome.org/709367

 src/photos-query-builder.c                  |   23 +++------------
 src/photos-query-builder.h                  |    5 ++-
 src/photos-tracker-collections-controller.c |   18 ++++++++----
 src/photos-tracker-controller.c             |    2 +-
 src/photos-tracker-controller.h             |    4 +-
 src/photos-tracker-favorites-controller.c   |   18 ++++++++----
 src/photos-tracker-overview-controller.c    |   38 +++++++++++++++++++++++---
 src/photos-tracker-overview-controller.h    |    4 ++-
 8 files changed, 71 insertions(+), 41 deletions(-)
---
diff --git a/src/photos-query-builder.c b/src/photos-query-builder.c
index f39f22e..d25d147 100644
--- a/src/photos-query-builder.c
+++ b/src/photos-query-builder.c
@@ -1,6 +1,6 @@
 /*
  * Photos - access, organize and share your photos on GNOME
- * Copyright © 2012, 2013 Red Hat, Inc.
+ * Copyright © 2012, 2013, 2014 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
@@ -28,9 +28,6 @@
 #include <gio/gio.h>
 
 #include "photos-collection-manager.h"
-#include "photos-offset-collections-controller.h"
-#include "photos-offset-favorites-controller.h"
-#include "photos-offset-overview-controller.h"
 #include "photos-query-builder.h"
 #include "photos-search-type.h"
 #include "photos-source-manager.h"
@@ -158,7 +155,7 @@ photos_query_builder_where (gboolean global, gint flags)
 
 
 static gchar *
-photos_query_builder_query (gboolean global, gint flags)
+photos_query_builder_query (gboolean global, gint flags, PhotosOffsetController *offset_cntrlr)
 {
   gchar *sparql;
   gchar *tail_sparql = NULL;
@@ -168,21 +165,11 @@ photos_query_builder_query (gboolean global, gint flags)
 
   if (global)
     {
-      PhotosOffsetController *offset_cntrlr;
       gint offset;
       gint step;
 
-      if (flags & PHOTOS_QUERY_FLAGS_COLLECTIONS)
-        offset_cntrlr = photos_offset_collections_controller_dup_singleton ();
-      else if (flags & PHOTOS_QUERY_FLAGS_FAVORITES)
-        offset_cntrlr = photos_offset_favorites_controller_dup_singleton ();
-      else
-        offset_cntrlr = photos_offset_overview_controller_dup_singleton ();
-
       offset = photos_offset_controller_get_offset (offset_cntrlr);
       step = photos_offset_controller_get_step (offset_cntrlr);
-      g_object_unref (offset_cntrlr);
-
       tail_sparql = g_strdup_printf ("ORDER BY DESC (?mtime) LIMIT %d OFFSET %d", step, offset);
     }
 
@@ -305,11 +292,11 @@ photos_query_builder_fetch_collections_query (const gchar *resource)
 
 
 PhotosQuery *
-photos_query_builder_global_query (gint flags)
+photos_query_builder_global_query (gint flags, PhotosOffsetController *offset_cntrlr)
 {
   gchar *sparql;
 
-  sparql = photos_query_builder_query (TRUE, flags);
+  sparql = photos_query_builder_query (TRUE, flags, offset_cntrlr);
   return photos_query_new (sparql);
 }
 
@@ -335,7 +322,7 @@ photos_query_builder_single_query (gint flags, const gchar *resource)
   gchar *sparql;
   gchar *tmp;
 
-  tmp = photos_query_builder_query (FALSE, flags);
+  tmp = photos_query_builder_query (FALSE, flags, NULL);
 
   regex = g_regex_new ("\\?urn", 0, 0, NULL);
   replacement = g_strconcat ("<", resource, ">", NULL);
diff --git a/src/photos-query-builder.h b/src/photos-query-builder.h
index d2cf5c5..0a451aa 100644
--- a/src/photos-query-builder.h
+++ b/src/photos-query-builder.h
@@ -1,6 +1,6 @@
 /*
  * Photos - access, organize and share your photos on GNOME
- * Copyright © 2012, 2013 Red Hat, Inc.
+ * Copyright © 2012, 2013, 2014 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
@@ -27,6 +27,7 @@
 
 #include <glib.h>
 
+#include "photos-offset-controller.h"
 #include "photos-query.h"
 
 G_BEGIN_DECLS
@@ -43,7 +44,7 @@ PhotosQuery  *photos_query_builder_equipment_query (GQuark equipment);
 
 PhotosQuery  *photos_query_builder_fetch_collections_query (const gchar *resource);
 
-PhotosQuery  *photos_query_builder_global_query        (gint flags);
+PhotosQuery  *photos_query_builder_global_query        (gint flags, PhotosOffsetController *offset_cntrlr);
 
 PhotosQuery  *photos_query_builder_set_collection_query (const gchar *item_urn,
                                                          const gchar *collection_urn,
diff --git a/src/photos-tracker-collections-controller.c b/src/photos-tracker-collections-controller.c
index f5658c5..aa9c48b 100644
--- a/src/photos-tracker-collections-controller.c
+++ b/src/photos-tracker-collections-controller.c
@@ -1,6 +1,6 @@
 /*
  * Photos - access, organize and share your photos on GNOME
- * Copyright © 2013 Red Hat, Inc.
+ * Copyright © 2013, 2014 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
@@ -31,6 +31,7 @@
 struct _PhotosTrackerCollectionsControllerPrivate
 {
   PhotosBaseManager *col_mngr;
+  PhotosOffsetController *offset_cntrlr;
 };
 
 
@@ -40,9 +41,10 @@ G_DEFINE_TYPE_WITH_PRIVATE (PhotosTrackerCollectionsController,
 
 
 static PhotosOffsetController *
-photos_tracker_collections_controller_get_offset_controller (void)
+photos_tracker_collections_controller_get_offset_controller (PhotosTrackerController *trk_cntrlr)
 {
-  return photos_offset_collections_controller_dup_singleton ();
+  PhotosTrackerCollectionsController *self = PHOTOS_TRACKER_COLLECTIONS_CONTROLLER (trk_cntrlr);
+  return g_object_ref (self->priv->offset_cntrlr);
 }
 
 
@@ -50,16 +52,17 @@ static PhotosQuery *
 photos_tracker_collections_controller_get_query (PhotosTrackerController *trk_cntrlr)
 {
   PhotosTrackerCollectionsController *self = PHOTOS_TRACKER_COLLECTIONS_CONTROLLER (trk_cntrlr);
+  PhotosTrackerCollectionsControllerPrivate *priv = self->priv;
   GObject *collection;
   gint flags;
 
-  collection = photos_base_manager_get_active_object (self->priv->col_mngr);
+  collection = photos_base_manager_get_active_object (priv->col_mngr);
   if (collection != NULL)
     flags = PHOTOS_QUERY_FLAGS_NONE;
   else
     flags = PHOTOS_QUERY_FLAGS_COLLECTIONS;
 
-  return photos_query_builder_global_query (flags);
+  return photos_query_builder_global_query (flags, priv->offset_cntrlr);
 }
 
 
@@ -87,8 +90,10 @@ static void
 photos_tracker_collections_controller_dispose (GObject *object)
 {
   PhotosTrackerCollectionsController *self = PHOTOS_TRACKER_COLLECTIONS_CONTROLLER (object);
+  PhotosTrackerCollectionsControllerPrivate *priv = self->priv;
 
-  g_clear_object (&self->priv->col_mngr);
+  g_clear_object (&priv->col_mngr);
+  g_clear_object (&priv->offset_cntrlr);
 
   G_OBJECT_CLASS (photos_tracker_collections_controller_parent_class)->dispose (object);
 }
@@ -103,6 +108,7 @@ photos_tracker_collections_controller_init (PhotosTrackerCollectionsController *
   priv = self->priv;
 
   priv->col_mngr = photos_collection_manager_dup_singleton ();
+  priv->offset_cntrlr = photos_offset_collections_controller_dup_singleton ();
 }
 
 
diff --git a/src/photos-tracker-controller.c b/src/photos-tracker-controller.c
index ecbbf00..9d2c796 100644
--- a/src/photos-tracker-controller.c
+++ b/src/photos-tracker-controller.c
@@ -322,7 +322,7 @@ photos_tracker_controller_constructed (GObject *object)
                             G_CALLBACK (photos_tracker_controller_window_mode_changed),
                             self);
 
-  priv->offset_cntrlr = PHOTOS_TRACKER_CONTROLLER_GET_CLASS (self)->get_offset_controller ();
+  priv->offset_cntrlr = PHOTOS_TRACKER_CONTROLLER_GET_CLASS (self)->get_offset_controller (self);
   g_signal_connect_swapped (priv->offset_cntrlr,
                             "offset-changed",
                             G_CALLBACK (photos_tracker_controller_offset_changed),
diff --git a/src/photos-tracker-controller.h b/src/photos-tracker-controller.h
index 639a1b3..2cadf74 100644
--- a/src/photos-tracker-controller.h
+++ b/src/photos-tracker-controller.h
@@ -1,6 +1,6 @@
 /*
  * Photos - access, organize and share your photos on GNOME
- * Copyright © 2012 Red Hat, Inc.
+ * Copyright © 2012, 2014 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
@@ -69,7 +69,7 @@ struct _PhotosTrackerControllerClass
   GObjectClass parent_class;
 
   /* virtual methods */
-  PhotosOffsetController *(*get_offset_controller) (void);
+  PhotosOffsetController *(*get_offset_controller) (PhotosTrackerController *self);
   PhotosQuery *(*get_query) (PhotosTrackerController *self);
 
   /* signals */
diff --git a/src/photos-tracker-favorites-controller.c b/src/photos-tracker-favorites-controller.c
index 68a4c64..41f21d9 100644
--- a/src/photos-tracker-favorites-controller.c
+++ b/src/photos-tracker-favorites-controller.c
@@ -1,6 +1,6 @@
 /*
  * Photos - access, organize and share your photos on GNOME
- * Copyright © 2012, 2013 Red Hat, Inc.
+ * Copyright © 2012, 2013, 2014 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
@@ -31,6 +31,7 @@
 struct _PhotosTrackerFavoritesControllerPrivate
 {
   PhotosBaseManager *col_mngr;
+  PhotosOffsetController *offset_cntrlr;
 };
 
 
@@ -40,9 +41,10 @@ G_DEFINE_TYPE_WITH_PRIVATE (PhotosTrackerFavoritesController,
 
 
 static PhotosOffsetController *
-photos_tracker_favorites_controller_get_offset_controller (void)
+photos_tracker_favorites_controller_get_offset_controller (PhotosTrackerController *trk_cntrlr)
 {
-  return photos_offset_favorites_controller_dup_singleton ();
+  PhotosTrackerFavoritesController *self = PHOTOS_TRACKER_FAVORITES_CONTROLLER (trk_cntrlr);
+  return g_object_ref (self->priv->offset_cntrlr);
 }
 
 
@@ -50,16 +52,17 @@ static PhotosQuery *
 photos_tracker_favorites_controller_get_query (PhotosTrackerController *trk_cntrlr)
 {
   PhotosTrackerFavoritesController *self = PHOTOS_TRACKER_FAVORITES_CONTROLLER (trk_cntrlr);
+  PhotosTrackerFavoritesControllerPrivate *priv = self->priv;
   GObject *collection;
   gint flags;
 
-  collection = photos_base_manager_get_active_object (self->priv->col_mngr);
+  collection = photos_base_manager_get_active_object (priv->col_mngr);
   if (collection != NULL)
     flags = PHOTOS_QUERY_FLAGS_NONE;
   else
     flags = PHOTOS_QUERY_FLAGS_FAVORITES;
 
-  return photos_query_builder_global_query (flags);
+  return photos_query_builder_global_query (flags, priv->offset_cntrlr);
 }
 
 
@@ -87,8 +90,10 @@ static void
 photos_tracker_favorites_controller_dispose (GObject *object)
 {
   PhotosTrackerFavoritesController *self = PHOTOS_TRACKER_FAVORITES_CONTROLLER (object);
+  PhotosTrackerFavoritesControllerPrivate *priv = self->priv;
 
-  g_clear_object (&self->priv->col_mngr);
+  g_clear_object (&priv->col_mngr);
+  g_clear_object (&priv->offset_cntrlr);
 
   G_OBJECT_CLASS (photos_tracker_favorites_controller_parent_class)->dispose (object);
 }
@@ -103,6 +108,7 @@ photos_tracker_favorites_controller_init (PhotosTrackerFavoritesController *self
   priv = self->priv;
 
   priv->col_mngr = photos_collection_manager_dup_singleton ();
+  priv->offset_cntrlr = photos_offset_favorites_controller_dup_singleton ();
 }
 
 
diff --git a/src/photos-tracker-overview-controller.c b/src/photos-tracker-overview-controller.c
index 4ccfd5b..3ff9dde 100644
--- a/src/photos-tracker-overview-controller.c
+++ b/src/photos-tracker-overview-controller.c
@@ -1,6 +1,6 @@
 /*
  * Photos - access, organize and share your photos on GNOME
- * Copyright © 2012, 2013 Red Hat, Inc.
+ * Copyright © 2012, 2013, 2014 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
@@ -31,20 +31,30 @@
 #include "photos-tracker-overview-controller.h"
 
 
-G_DEFINE_TYPE (PhotosTrackerOverviewController, photos_tracker_overview_controller, 
PHOTOS_TYPE_TRACKER_CONTROLLER);
+struct _PhotosTrackerOverviewControllerPrivate
+{
+  PhotosOffsetController *offset_cntrlr;
+};
+
+
+G_DEFINE_TYPE_WITH_PRIVATE (PhotosTrackerOverviewController,
+                            photos_tracker_overview_controller,
+                            PHOTOS_TYPE_TRACKER_CONTROLLER);
 
 
 static PhotosOffsetController *
-photos_tracker_overview_controller_get_offset_controller (void)
+photos_tracker_overview_controller_get_offset_controller (PhotosTrackerController *trk_cntrlr)
 {
-  return photos_offset_overview_controller_dup_singleton ();
+  PhotosTrackerOverviewController *self = PHOTOS_TRACKER_OVERVIEW_CONTROLLER (trk_cntrlr);
+  return g_object_ref (self->priv->offset_cntrlr);
 }
 
 
 static PhotosQuery *
 photos_tracker_overview_controller_get_query (PhotosTrackerController *trk_cntrlr)
 {
-  return photos_query_builder_global_query (PHOTOS_QUERY_FLAGS_NONE);
+  PhotosTrackerOverviewController *self = PHOTOS_TRACKER_OVERVIEW_CONTROLLER (trk_cntrlr);
+  return photos_query_builder_global_query (PHOTOS_QUERY_FLAGS_NONE, self->priv->offset_cntrlr);
 }
 
 
@@ -69,8 +79,25 @@ photos_tracker_overview_controller_constructor (GType type,
 
 
 static void
+photos_tracker_overview_controller_dispose (GObject *object)
+{
+  PhotosTrackerOverviewController *self = PHOTOS_TRACKER_OVERVIEW_CONTROLLER (object);
+
+  g_clear_object (&self->priv->offset_cntrlr);
+
+  G_OBJECT_CLASS (photos_tracker_overview_controller_parent_class)->dispose (object);
+}
+
+
+static void
 photos_tracker_overview_controller_init (PhotosTrackerOverviewController *self)
 {
+  PhotosTrackerOverviewControllerPrivate *priv;
+
+  self->priv = photos_tracker_overview_controller_get_instance_private (self);
+  priv = self->priv;
+
+  priv->offset_cntrlr = photos_offset_overview_controller_dup_singleton ();
 }
 
 
@@ -81,6 +108,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;
+  object_class->dispose = photos_tracker_overview_controller_dispose;
   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-tracker-overview-controller.h b/src/photos-tracker-overview-controller.h
index 984b7c3..f37f9d6 100644
--- a/src/photos-tracker-overview-controller.h
+++ b/src/photos-tracker-overview-controller.h
@@ -1,6 +1,6 @@
 /*
  * Photos - access, organize and share your photos on GNOME
- * Copyright © 2012 Red Hat, Inc.
+ * Copyright © 2012, 2014 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
@@ -53,10 +53,12 @@ G_BEGIN_DECLS
 
 typedef struct _PhotosTrackerOverviewController        PhotosTrackerOverviewController;
 typedef struct _PhotosTrackerOverviewControllerClass   PhotosTrackerOverviewControllerClass;
+typedef struct _PhotosTrackerOverviewControllerPrivate PhotosTrackerOverviewControllerPrivate;
 
 struct _PhotosTrackerOverviewController
 {
   PhotosTrackerController parent_instance;
+  PhotosTrackerOverviewControllerPrivate *priv;
 };
 
 struct _PhotosTrackerOverviewControllerClass


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