[gnome-photos] Add PhotosSearchContext and make PhotosApplication implement it



commit a56c42478db7b0f1f727d2f0f4ebb6020badc5af
Author: Debarshi Ray <debarshir gnome org>
Date:   Sun Dec 1 01:14:52 2013 +0100

    Add PhotosSearchContext and make PhotosApplication implement it
    
    We want to split the application into two search contexts - one is for
    searches initiated from within the application, and the other is for
    searches initiated from gnome-shell.
    
    For that to happen certain classes which were singleton, and hence
    global to the entire application, now has to have a separate instance
    for each context. Each context will, therefore, have a state that
    encapsulates the instances of these classes that correspond to it.
    
    Currently, PhotosApplication is the only context. The future
    PhotosShellSearchProvider will be another implementation.

 src/Makefile.am                             |    2 +
 src/photos-application.c                    |   47 +++++++++++--
 src/photos-base-item.c                      |   12 +++-
 src/photos-camera-cache.c                   |   10 ++-
 src/photos-collection-icon-watcher.c        |   14 ++++-
 src/photos-collection-manager.c             |   24 +-------
 src/photos-collection-manager.h             |    4 +-
 src/photos-create-collection-job.c          |   11 +++-
 src/photos-delete-item-job.c                |   11 +++-
 src/photos-dropdown.c                       |   17 +++--
 src/photos-embed.c                          |   13 +++-
 src/photos-empty-results-box.c              |    9 ++-
 src/photos-facebook-item.c                  |   11 +++-
 src/photos-fetch-collection-state-job.c     |    9 ++-
 src/photos-fetch-collections-job.c          |   11 +++-
 src/photos-flickr-item.c                    |   12 +++-
 src/photos-item-manager.c                   |   15 ++++-
 src/photos-main-toolbar.c                   |   11 ++-
 src/photos-main-window.c                    |    9 ++-
 src/photos-offset-collections-controller.c  |   21 +++++-
 src/photos-offset-favorites-controller.c    |   21 +++++-
 src/photos-offset-overview-controller.c     |   13 +++-
 src/photos-offset-search-controller.c       |   11 +++-
 src/photos-organize-collection-model.c      |   12 +++-
 src/photos-organize-collection-view.c       |   16 +++--
 src/photos-overview-searchbar.c             |   19 +++---
 src/photos-query-builder.c                  |   95 ++++++++++++---------------
 src/photos-query-builder.h                  |   26 +++++---
 src/photos-query.c                          |   11 +--
 src/photos-query.h                          |    3 +-
 src/photos-search-context.c                 |   80 ++++++++++++++++++++++
 src/photos-search-context.h                 |   79 ++++++++++++++++++++++
 src/photos-search-controller.c              |   21 +------
 src/photos-search-controller.h              |    2 +-
 src/photos-search-match-manager.c           |   60 ++++++++++-------
 src/photos-search-match-manager.h           |    3 +-
 src/photos-search-type-manager.c            |   24 +-------
 src/photos-search-type-manager.h            |    4 +-
 src/photos-set-collection-job.c             |   11 +++-
 src/photos-single-item-job.c                |    5 +-
 src/photos-single-item-job.h                |    5 +-
 src/photos-source-manager.c                 |   23 +------
 src/photos-source-manager.h                 |    4 +-
 src/photos-tracker-collections-controller.c |   19 +++++-
 src/photos-tracker-controller.c             |   12 +++-
 src/photos-tracker-favorites-controller.c   |   19 +++++-
 src/photos-tracker-overview-controller.c    |   11 +++-
 src/photos-tracker-search-controller.c      |   31 ++++++---
 src/photos-update-mtime-job.c               |   11 +++-
 src/photos-view-model.c                     |   12 +++-
 50 files changed, 643 insertions(+), 293 deletions(-)
---
diff --git a/src/Makefile.am b/src/Makefile.am
index 438e0f9..bea51e0 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -163,6 +163,8 @@ gnome_photos_SOURCES = \
        photos-query-builder.c \
        photos-remote-display-manager.c \
        photos-remote-display-manager.h \
+       photos-search-context.c \
+       photos-search-context.h \
        photos-search-controller.c \
        photos-search-controller.h \
        photos-search-match.c \
diff --git a/src/photos-application.c b/src/photos-application.c
index c3fecc9..1356862 100644
--- a/src/photos-application.c
+++ b/src/photos-application.c
@@ -44,6 +44,7 @@
 #include "photos-mode-controller.h"
 #include "photos-properties-dialog.h"
 #include "photos-resources.h"
+#include "photos-search-context.h"
 #include "photos-source-manager.h"
 
 
@@ -66,13 +67,18 @@ struct _PhotosApplicationPrivate
   GomMiner *flickr_miner;
   GtkWidget *main_window;
   PhotosBaseManager *item_mngr;
-  PhotosBaseManager *src_mngr;
   PhotosCameraCache *camera_cache;
   PhotosModeController *mode_cntrlr;
+  PhotosSearchContextState *state;
 };
 
+static void photos_application_search_context_iface_init (PhotosSearchContextInterface *iface);
 
-G_DEFINE_TYPE_WITH_PRIVATE (PhotosApplication, photos_application, GTK_TYPE_APPLICATION)
+
+G_DEFINE_TYPE_WITH_CODE (PhotosApplication, photos_application, GTK_TYPE_APPLICATION,
+                         G_ADD_PRIVATE (PhotosApplication)
+                         G_IMPLEMENT_INTERFACE (PHOTOS_TYPE_SEARCH_CONTEXT,
+                                                photos_application_search_context_iface_init));
 
 
 enum
@@ -155,6 +161,14 @@ photos_application_fullscreen (PhotosApplication *self, GVariant *parameter)
 }
 
 
+static PhotosSearchContextState *
+photos_application_get_state (PhotosSearchContext *context)
+{
+  PhotosApplication *self = PHOTOS_APPLICATION (context);
+  return self->priv->state;
+}
+
+
 static void
 photos_application_open_current (PhotosApplication *self)
 {
@@ -272,10 +286,10 @@ photos_application_refresh_miners (PhotosApplication *self)
 {
   PhotosApplicationPrivate *priv = self->priv;
 
-  if (photos_source_manager_has_provider_type (PHOTOS_SOURCE_MANAGER (priv->src_mngr), "facebook"))
+  if (photos_source_manager_has_provider_type (PHOTOS_SOURCE_MANAGER (priv->state->src_mngr), "facebook"))
     photos_application_refresh_miner_now (self, priv->facebook_miner);
 
-  if (photos_source_manager_has_provider_type (PHOTOS_SOURCE_MANAGER (priv->src_mngr), "flickr"))
+  if (photos_source_manager_has_provider_type (PHOTOS_SOURCE_MANAGER (priv->state->src_mngr), "flickr"))
     photos_application_refresh_miner_now (self, priv->flickr_miner);
 }
 
@@ -359,12 +373,12 @@ photos_application_start_miners (PhotosApplication *self)
 
   photos_application_refresh_miners (self);
 
-  g_signal_connect_object (priv->src_mngr,
+  g_signal_connect_object (priv->state->src_mngr,
                            "object-added",
                            G_CALLBACK (photos_application_refresh_miners),
                            self,
                            G_CONNECT_SWAPPED);
-  g_signal_connect_object (priv->src_mngr,
+  g_signal_connect_object (priv->state->src_mngr,
                            "object-removed",
                            G_CALLBACK (photos_application_refresh_miners),
                            self,
@@ -470,7 +484,6 @@ photos_application_startup (GApplication *application)
                                                          NULL);
 
   priv->item_mngr = photos_item_manager_dup_singleton ();
-  priv->src_mngr = photos_source_manager_dup_singleton ();
 
   /* A dummy reference to keep it alive during the lifetime of the
    * application.
@@ -611,10 +624,15 @@ photos_application_dispose (GObject *object)
   g_clear_object (&priv->facebook_miner);
   g_clear_object (&priv->flickr_miner);
   g_clear_object (&priv->item_mngr);
-  g_clear_object (&priv->src_mngr);
   g_clear_object (&priv->camera_cache);
   g_clear_object (&priv->mode_cntrlr);
 
+  if (priv->state != NULL)
+    {
+      photos_search_context_state_free (priv->state);
+      priv->state = NULL;
+    }
+
   G_OBJECT_CLASS (photos_application_parent_class)->dispose (object);
 }
 
@@ -622,8 +640,14 @@ photos_application_dispose (GObject *object)
 static void
 photos_application_init (PhotosApplication *self)
 {
+  PhotosApplicationPrivate *priv;
+
   self->priv = photos_application_get_instance_private (self);
+  priv = self->priv;
+
   eog_debug_init ();
+
+  priv->state = photos_search_context_state_new (PHOTOS_SEARCH_CONTEXT (self));
 }
 
 
@@ -642,6 +666,13 @@ photos_application_class_init (PhotosApplicationClass *class)
 }
 
 
+static void
+photos_application_search_context_iface_init (PhotosSearchContextInterface *iface)
+{
+  iface->get_state = photos_application_get_state;
+}
+
+
 GtkApplication *
 photos_application_new (void)
 {
diff --git a/src/photos-base-item.c b/src/photos-base-item.c
index 8eb6f67..d7ebf4c 100644
--- a/src/photos-base-item.c
+++ b/src/photos-base-item.c
@@ -40,6 +40,7 @@
 #include "photos-icons.h"
 #include "photos-print-operation.h"
 #include "photos-query.h"
+#include "photos-search-context.h"
 #include "photos-selection-controller.h"
 #include "photos-single-item-job.h"
 #include "photos-utils.h"
@@ -1288,10 +1289,19 @@ photos_base_item_print (PhotosBaseItem *self, GtkWidget *toplevel)
 void
 photos_base_item_refresh (PhotosBaseItem *self)
 {
+  GApplication *app;
+  PhotosSearchContextState *state;
   PhotosSingleItemJob *job;
 
+  app = g_application_get_default ();
+  state = photos_search_context_get_state (PHOTOS_SEARCH_CONTEXT (app));
+
   job = photos_single_item_job_new (self->priv->id);
-  photos_single_item_job_run (job, PHOTOS_QUERY_FLAGS_NONE, photos_base_item_refresh_executed, g_object_ref 
(self));
+  photos_single_item_job_run (job,
+                              state,
+                              PHOTOS_QUERY_FLAGS_NONE,
+                              photos_base_item_refresh_executed,
+                              g_object_ref (self));
   g_object_unref (job);
 }
 
diff --git a/src/photos-camera-cache.c b/src/photos-camera-cache.c
index 5c1e1aa..1144bfe 100644
--- a/src/photos-camera-cache.c
+++ b/src/photos-camera-cache.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
@@ -25,6 +25,7 @@
 
 #include "photos-camera-cache.h"
 #include "photos-query-builder.h"
+#include "photos-search-context.h"
 #include "photos-tracker-queue.h"
 
 
@@ -188,8 +189,10 @@ photos_camera_cache_get_camera_async (PhotosCameraCache *self,
                                       gpointer user_data)
 {
   PhotosCameraCachePrivate *priv = self->priv;
+  GApplication *app;
   GTask *task;
   PhotosQuery *query;
+  PhotosSearchContextState *state;
   const gchar *camera;
 
   task = g_task_new (self, cancellable, callback, user_data);
@@ -210,7 +213,10 @@ photos_camera_cache_get_camera_async (PhotosCameraCache *self,
       goto out;
     }
 
-  query = photos_query_builder_equipment_query (id);
+  app = g_application_get_default ();
+  state = photos_search_context_get_state (PHOTOS_SEARCH_CONTEXT (app));
+
+  query = photos_query_builder_equipment_query (state, id);
   photos_tracker_queue_select (priv->queue,
                                query->sparql,
                                cancellable,
diff --git a/src/photos-collection-icon-watcher.c b/src/photos-collection-icon-watcher.c
index fa3b7db..334c5b6 100644
--- a/src/photos-collection-icon-watcher.c
+++ b/src/photos-collection-icon-watcher.c
@@ -34,6 +34,7 @@
 #include "photos-item-manager.h"
 #include "photos-query.h"
 #include "photos-query-builder.h"
+#include "photos-search-context.h"
 #include "photos-single-item-job.h"
 #include "photos-tracker-queue.h"
 #include "photos-utils.h"
@@ -186,12 +187,17 @@ static void
 photos_collection_icon_watcher_finished (PhotosCollectionIconWatcher *self)
 {
   PhotosCollectionIconWatcherPrivate *priv = self->priv;
+  GApplication *app;
   GList *l;
   GList *to_query = NULL;
+  PhotosSearchContextState *state;
 
   if (priv->urns == NULL)
     return;
 
+  app = g_application_get_default ();
+  state = photos_search_context_get_state (PHOTOS_SEARCH_CONTEXT (app));
+
   priv->to_query_remaining = 0;
 
   for (l = priv->urns; l != NULL; l = l->next)
@@ -222,6 +228,7 @@ photos_collection_icon_watcher_finished (PhotosCollectionIconWatcher *self)
 
       job = photos_single_item_job_new (urn);
       photos_single_item_job_run (job,
+                                  state,
                                   PHOTOS_QUERY_FLAGS_UNFILTERED,
                                   photos_collection_icon_watcher_to_query_executed,
                                   g_object_ref (self));
@@ -299,7 +306,9 @@ static void
 photos_collection_icon_watcher_start (PhotosCollectionIconWatcher *self)
 {
   PhotosCollectionIconWatcherPrivate *priv = self->priv;
+  GApplication *app;
   PhotosQuery *query;
+  PhotosSearchContextState *state;
   const gchar *id;
 
   photos_collection_icon_watcher_clear (self);
@@ -310,8 +319,11 @@ photos_collection_icon_watcher_start (PhotosCollectionIconWatcher *self)
   if (priv->collection == NULL)
     return;
 
+  app = g_application_get_default ();
+  state = photos_search_context_get_state (PHOTOS_SEARCH_CONTEXT (app));
+
   id = photos_filterable_get_id (PHOTOS_FILTERABLE (priv->collection));
-  query = photos_query_builder_collection_icon_query (id);
+  query = photos_query_builder_collection_icon_query (state, id);
   photos_tracker_queue_select (priv->queue,
                                query->sparql,
                                NULL,
diff --git a/src/photos-collection-manager.c b/src/photos-collection-manager.c
index bece01f..33276e7 100644
--- a/src/photos-collection-manager.c
+++ b/src/photos-collection-manager.c
@@ -47,26 +47,6 @@ photos_collection_manager_get_where (PhotosBaseManager *mngr, gint flags)
 }
 
 
-static GObject *
-photos_collection_manager_constructor (GType                  type,
-                                       guint                  n_construct_params,
-                                       GObjectConstructParam *construct_params)
-{
-  static GObject *self = NULL;
-
-  if (self == NULL)
-    {
-      self = G_OBJECT_CLASS (photos_collection_manager_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_collection_manager_init (PhotosCollectionManager *self)
 {
@@ -76,16 +56,14 @@ photos_collection_manager_init (PhotosCollectionManager *self)
 static void
 photos_collection_manager_class_init (PhotosCollectionManagerClass *class)
 {
-  GObjectClass *object_class = G_OBJECT_CLASS (class);
   PhotosBaseManagerClass *base_manager_class = PHOTOS_BASE_MANAGER_CLASS (class);
 
-  object_class->constructor = photos_collection_manager_constructor;
   base_manager_class->get_where = photos_collection_manager_get_where;
 }
 
 
 PhotosBaseManager *
-photos_collection_manager_dup_singleton (void)
+photos_collection_manager_new (void)
 {
   return g_object_new (PHOTOS_TYPE_COLLECTION_MANAGER, NULL);
 }
diff --git a/src/photos-collection-manager.h b/src/photos-collection-manager.h
index e8e5045..1336b5e 100644
--- a/src/photos-collection-manager.h
+++ b/src/photos-collection-manager.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
@@ -68,7 +68,7 @@ struct _PhotosCollectionManagerClass
 
 GType                     photos_collection_manager_get_type           (void) G_GNUC_CONST;
 
-PhotosBaseManager        *photos_collection_manager_dup_singleton      (void);
+PhotosBaseManager        *photos_collection_manager_new                (void);
 
 G_END_DECLS
 
diff --git a/src/photos-create-collection-job.c b/src/photos-create-collection-job.c
index d7f2eda..330fd57 100644
--- a/src/photos-create-collection-job.c
+++ b/src/photos-create-collection-job.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
@@ -25,12 +25,14 @@
 
 #include "config.h"
 
+#include <gio/gio.h>
 #include <glib.h>
 #include <tracker-sparql.h>
 
 #include "photos-create-collection-job.h"
 #include "photos-query.h"
 #include "photos-query-builder.h"
+#include "photos-search-context.h"
 #include "photos-tracker-queue.h"
 
 
@@ -193,7 +195,9 @@ photos_create_collection_job_run (PhotosCreateCollectionJob *self,
                                   gpointer user_data)
 {
   PhotosCreateCollectionJobPrivate *priv = self->priv;
+  GApplication *app;
   PhotosQuery *query;
+  PhotosSearchContextState *state;
 
   if (G_UNLIKELY (priv->queue == NULL))
     {
@@ -205,7 +209,10 @@ photos_create_collection_job_run (PhotosCreateCollectionJob *self,
   priv->callback = callback;
   priv->user_data = user_data;
 
-  query = photos_query_builder_create_collection_query (priv->name);
+  app = g_application_get_default ();
+  state = photos_search_context_get_state (PHOTOS_SEARCH_CONTEXT (app));
+
+  query = photos_query_builder_create_collection_query (state, priv->name);
   photos_tracker_queue_update_blank (priv->queue,
                                      query->sparql,
                                      NULL,
diff --git a/src/photos-delete-item-job.c b/src/photos-delete-item-job.c
index 92fa442..9268a90 100644
--- a/src/photos-delete-item-job.c
+++ b/src/photos-delete-item-job.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
@@ -25,12 +25,14 @@
 
 #include "config.h"
 
+#include <gio/gio.h>
 #include <glib.h>
 #include <tracker-sparql.h>
 
 #include "photos-delete-item-job.h"
 #include "photos-query.h"
 #include "photos-query-builder.h"
+#include "photos-search-context.h"
 #include "photos-tracker-queue.h"
 
 
@@ -159,7 +161,9 @@ photos_delete_item_job_run (PhotosDeleteItemJob *self,
                             gpointer user_data)
 {
   PhotosDeleteItemJobPrivate *priv = self->priv;
+  GApplication *app;
   PhotosQuery *query;
+  PhotosSearchContextState *state;
 
   if (G_UNLIKELY (priv->queue == NULL))
     {
@@ -171,7 +175,10 @@ photos_delete_item_job_run (PhotosDeleteItemJob *self,
   priv->callback = callback;
   priv->user_data = user_data;
 
-  query = photos_query_builder_delete_resource_query (priv->urn);
+  app = g_application_get_default ();
+  state = photos_search_context_get_state (PHOTOS_SEARCH_CONTEXT (app));
+
+  query = photos_query_builder_delete_resource_query (state, priv->urn);
   photos_tracker_queue_update (priv->queue,
                                query->sparql,
                                NULL,
diff --git a/src/photos-dropdown.c b/src/photos-dropdown.c
index fcf171a..3cf1fde 100644
--- a/src/photos-dropdown.c
+++ b/src/photos-dropdown.c
@@ -25,13 +25,11 @@
 
 #include "config.h"
 
-#include <glib.h>
+#include <gio/gio.h>
 
 #include "photos-base-view.h"
 #include "photos-dropdown.h"
-#include "photos-source-manager.h"
-#include "photos-search-match-manager.h"
-#include "photos-search-type-manager.h"
+#include "photos-search-context.h"
 
 
 struct _PhotosDropdownPrivate
@@ -82,15 +80,20 @@ static void
 photos_dropdown_init (PhotosDropdown *self)
 {
   PhotosDropdownPrivate *priv;
+  GApplication *app;
   GtkStyleContext *context;
   GtkWidget *frame;
+  PhotosSearchContextState *state;
 
   self->priv = photos_dropdown_get_instance_private (self);
   priv = self->priv;
 
-  priv->srch_mtch_mngr = photos_search_match_manager_dup_singleton ();
-  priv->srch_typ_mngr = photos_search_type_manager_dup_singleton ();
-  priv->src_mngr = photos_source_manager_dup_singleton ();
+  app = g_application_get_default ();
+  state = photos_search_context_get_state (PHOTOS_SEARCH_CONTEXT (app));
+
+  priv->srch_mtch_mngr = g_object_ref (state->srch_mtch_mngr);
+  priv->srch_typ_mngr = g_object_ref (state->srch_typ_mngr);
+  priv->src_mngr = g_object_ref (state->src_mngr);
 
   priv->match_view = photos_base_view_new (priv->srch_mtch_mngr);
   priv->source_view = photos_base_view_new (priv->src_mngr);
diff --git a/src/photos-embed.c b/src/photos-embed.c
index 281f68f..44c33f0 100644
--- a/src/photos-embed.c
+++ b/src/photos-embed.c
@@ -27,6 +27,7 @@
 
 #include <gdk-pixbuf/gdk-pixbuf.h>
 #include <gegl.h>
+#include <gio/gio.h>
 #include <glib/gi18n.h>
 
 #include "photos-collection-manager.h"
@@ -40,6 +41,7 @@
 #include "photos-search-controller.h"
 #include "photos-selection-toolbar.h"
 #include "photos-spinner-box.h"
+#include "photos-search-context.h"
 #include "photos-search-type.h"
 #include "photos-search-type-manager.h"
 #include "photos-source.h"
@@ -610,12 +612,15 @@ photos_embed_init (PhotosEmbed *self)
 {
   PhotosEmbedPrivate *priv;
   GApplication *app;
+  PhotosSearchContextState *state;
   gboolean querying;
 
   self->priv = photos_embed_get_instance_private (self);
   priv = self->priv;
 
   app = g_application_get_default ();
+  state = photos_search_context_get_state (PHOTOS_SEARCH_CONTEXT (app));
+
   priv->search_action = g_action_map_lookup_action (G_ACTION_MAP (app), "search");
   g_signal_connect_swapped (app, "window-added", G_CALLBACK (photos_embed_window_added), self);
 
@@ -685,22 +690,22 @@ photos_embed_init (PhotosEmbed *self)
                             G_CALLBACK (photos_embed_query_status_changed),
                             self);
 
-  priv->col_mngr = photos_collection_manager_dup_singleton ();
+  priv->col_mngr = g_object_ref (state->col_mngr);
   g_signal_connect (priv->col_mngr, "active-changed", G_CALLBACK (photos_embed_active_changed), self);
 
   priv->item_mngr = photos_item_manager_dup_singleton ();
   g_signal_connect (priv->item_mngr, "active-changed", G_CALLBACK (photos_embed_active_changed), self);
 
-  priv->src_mngr = photos_source_manager_dup_singleton ();
+  priv->src_mngr = g_object_ref (state->src_mngr);
   g_signal_connect_swapped (priv->src_mngr, "active-changed", G_CALLBACK (photos_embed_search_changed), 
self);
 
-  priv->srch_mngr = photos_search_type_manager_dup_singleton ();
+  priv->srch_mngr = g_object_ref (state->srch_typ_mngr);
   g_signal_connect_swapped (priv->srch_mngr, "active-changed", G_CALLBACK (photos_embed_search_changed), 
self);
 
   querying = photos_tracker_controller_get_query_status (priv->trk_ovrvw_cntrlr);
   photos_embed_query_status_changed (self, querying);
 
-  priv->srch_cntrlr = photos_search_controller_dup_singleton ();
+  priv->srch_cntrlr = g_object_ref (state->srch_cntrlr);
   g_signal_connect_swapped (priv->srch_cntrlr,
                             "search-string-changed",
                             G_CALLBACK (photos_embed_search_changed),
diff --git a/src/photos-empty-results-box.c b/src/photos-empty-results-box.c
index 768391c..8c0afc7 100644
--- a/src/photos-empty-results-box.c
+++ b/src/photos-empty-results-box.c
@@ -25,11 +25,13 @@
 
 #include "config.h"
 
+#include <gio/gio.h>
 #include <glib/gi18n.h>
 
 #include "photos-empty-results-box.h"
 #include "photos-enums.h"
 #include "photos-icons.h"
+#include "photos-search-context.h"
 #include "photos-source-manager.h"
 
 
@@ -272,11 +274,16 @@ static void
 photos_empty_results_box_init (PhotosEmptyResultsBox *self)
 {
   PhotosEmptyResultsBoxPrivate *priv;
+  GApplication *app;
+  PhotosSearchContextState *state;
 
   self->priv = photos_empty_results_box_get_instance_private (self);
   priv = self->priv;
 
-  priv->src_mngr = photos_source_manager_dup_singleton ();
+  app = g_application_get_default ();
+  state = photos_search_context_get_state (PHOTOS_SEARCH_CONTEXT (app));
+
+  priv->src_mngr = g_object_ref (state->src_mngr);
 }
 
 
diff --git a/src/photos-facebook-item.c b/src/photos-facebook-item.c
index d62ae5c..12c081b 100644
--- a/src/photos-facebook-item.c
+++ b/src/photos-facebook-item.c
@@ -1,6 +1,7 @@
 /*
  * Photos - access, organize and share your photos on GNOME
  * Copyright © 2013 Álvaro Peña
+ * Copyright © 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
@@ -33,9 +34,10 @@
 #include <goa/goa.h>
 #include <libgnome-desktop/gnome-desktop-thumbnail.h>
 
+#include "photos-base-manager.h"
 #include "photos-facebook-item.h"
+#include "photos-search-context.h"
 #include "photos-source.h"
-#include "photos-source-manager.h"
 #include "photos-utils.h"
 
 
@@ -234,11 +236,16 @@ static void
 photos_facebook_item_init (PhotosFacebookItem *self)
 {
   PhotosFacebookItemPrivate *priv;
+  GApplication *app;
+  PhotosSearchContextState *state;
 
   self->priv = photos_facebook_item_get_instance_private (self);
   priv = self->priv;
 
-  priv->src_mngr = photos_source_manager_dup_singleton ();
+  app = g_application_get_default ();
+  state = photos_search_context_get_state (PHOTOS_SEARCH_CONTEXT (app));
+
+  priv->src_mngr = g_object_ref (state->src_mngr);
 }
 
 
diff --git a/src/photos-fetch-collection-state-job.c b/src/photos-fetch-collection-state-job.c
index 811bcdc..dc347bf 100644
--- a/src/photos-fetch-collection-state-job.c
+++ b/src/photos-fetch-collection-state-job.c
@@ -28,13 +28,13 @@
 #include <glib.h>
 #include <tracker-sparql.h>
 
-#include "photos-collection-manager.h"
 #include "photos-fetch-collection-state-job.h"
 #include "photos-fetch-collections-job.h"
 #include "photos-filterable.h"
 #include "photos-item-manager.h"
 #include "photos-query.h"
 #include "photos-query-builder.h"
+#include "photos-search-context.h"
 #include "photos-selection-controller.h"
 
 
@@ -219,16 +219,21 @@ static void
 photos_fetch_collection_state_job_init (PhotosFetchCollectionStateJob *self)
 {
   PhotosFetchCollectionStateJobPrivate *priv = self->priv;
+  GApplication *app;
+  PhotosSearchContextState *state;
 
   self->priv = photos_fetch_collection_state_job_get_instance_private (self);
   priv = self->priv;
 
+  app = g_application_get_default ();
+  state = photos_search_context_get_state (PHOTOS_SEARCH_CONTEXT (app));
+
   priv->collections_for_items = g_hash_table_new_full (g_str_hash,
                                                        g_str_equal,
                                                        g_free,
                                                        photos_fetch_collection_state_job_value_destroy_func);
 
-  priv->col_mngr = photos_collection_manager_dup_singleton ();
+  priv->col_mngr = g_object_ref (state->col_mngr);
   priv->item_mngr = photos_item_manager_dup_singleton ();
   priv->sel_cntrlr = photos_selection_controller_dup_singleton ();
 }
diff --git a/src/photos-fetch-collections-job.c b/src/photos-fetch-collections-job.c
index 46b5d3e..cd4ed32 100644
--- a/src/photos-fetch-collections-job.c
+++ b/src/photos-fetch-collections-job.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
@@ -25,12 +25,14 @@
 
 #include "config.h"
 
+#include <gio/gio.h>
 #include <glib.h>
 #include <tracker-sparql.h>
 
 #include "photos-fetch-collections-job.h"
 #include "photos-query.h"
 #include "photos-query-builder.h"
+#include "photos-search-context.h"
 #include "photos-tracker-queue.h"
 
 
@@ -215,7 +217,9 @@ photos_fetch_collections_job_run (PhotosFetchCollectionsJob *self,
                                   gpointer user_data)
 {
   PhotosFetchCollectionsJobPrivate *priv = self->priv;
+  GApplication *app;
   PhotosQuery *query;
+  PhotosSearchContextState *state;
 
   if (G_UNLIKELY (priv->queue == NULL))
     {
@@ -227,7 +231,10 @@ photos_fetch_collections_job_run (PhotosFetchCollectionsJob *self,
   priv->callback = callback;
   priv->user_data = user_data;
 
-  query = photos_query_builder_fetch_collections_query (priv->urn);
+  app = g_application_get_default ();
+  state = photos_search_context_get_state (PHOTOS_SEARCH_CONTEXT (app));
+
+  query = photos_query_builder_fetch_collections_query (state, priv->urn);
   photos_tracker_queue_select (priv->queue,
                                query->sparql,
                                NULL,
diff --git a/src/photos-flickr-item.c b/src/photos-flickr-item.c
index 7bcff94..36bbc0c 100644
--- a/src/photos-flickr-item.c
+++ b/src/photos-flickr-item.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
@@ -34,9 +34,10 @@
 #include <grilo.h>
 #include <libgnome-desktop/gnome-desktop-thumbnail.h>
 
+#include "photos-base-manager.h"
 #include "photos-flickr-item.h"
+#include "photos-search-context.h"
 #include "photos-source.h"
-#include "photos-source-manager.h"
 #include "photos-utils.h"
 
 
@@ -338,11 +339,16 @@ static void
 photos_flickr_item_init (PhotosFlickrItem *self)
 {
   PhotosFlickrItemPrivate *priv;
+  GApplication *app;
+  PhotosSearchContextState *state;
 
   self->priv = photos_flickr_item_get_instance_private (self);
   priv = self->priv;
 
-  priv->src_mngr = photos_source_manager_dup_singleton ();
+  app = g_application_get_default ();
+  state = photos_search_context_get_state (PHOTOS_SEARCH_CONTEXT (app));
+
+  priv->src_mngr = g_object_ref (state->src_mngr);
 }
 
 
diff --git a/src/photos-item-manager.c b/src/photos-item-manager.c
index 07e441e..a2c9ef8 100644
--- a/src/photos-item-manager.c
+++ b/src/photos-item-manager.c
@@ -28,12 +28,12 @@
 #include <glib.h>
 #include <tracker-sparql.h>
 
-#include "photos-collection-manager.h"
 #include "photos-item-manager.h"
 #include "photos-local-item.h"
 #include "photos-facebook-item.h"
 #include "photos-flickr-item.h"
 #include "photos-query.h"
+#include "photos-search-context.h"
 #include "photos-single-item-job.h"
 #include "photos-tracker-change-event.h"
 #include "photos-tracker-change-monitor.h"
@@ -68,10 +68,16 @@ photos_item_manager_item_created_executed (TrackerSparqlCursor *cursor, gpointer
 static void
 photos_item_manager_item_created (PhotosItemManager *self, const gchar *urn)
 {
+  GApplication *app;
+  PhotosSearchContextState *state;
   PhotosSingleItemJob *job;
 
+  app = g_application_get_default ();
+  state = photos_search_context_get_state (PHOTOS_SEARCH_CONTEXT (app));
+
   job = photos_single_item_job_new (urn);
   photos_single_item_job_run (job,
+                              state,
                               PHOTOS_QUERY_FLAGS_NONE,
                               photos_item_manager_item_created_executed,
                               g_object_ref (self));
@@ -215,12 +221,17 @@ static void
 photos_item_manager_init (PhotosItemManager *self)
 {
   PhotosItemManagerPrivate *priv = self->priv;
+  GApplication *app;
+  PhotosSearchContextState *state;
 
   self->priv = photos_item_manager_get_instance_private (self);
   priv = self->priv;
 
+  app = g_application_get_default ();
+  state = photos_search_context_get_state (PHOTOS_SEARCH_CONTEXT (app));
+
   priv->collection_path = g_queue_new ();
-  priv->col_mngr = photos_collection_manager_dup_singleton ();
+  priv->col_mngr = g_object_ref (state->col_mngr);
 
   priv->monitor = photos_tracker_change_monitor_dup_singleton (NULL, NULL);
   if (G_LIKELY (priv->monitor != NULL))
diff --git a/src/photos-main-toolbar.c b/src/photos-main-toolbar.c
index f657c7a..35dd13b 100644
--- a/src/photos-main-toolbar.c
+++ b/src/photos-main-toolbar.c
@@ -40,8 +40,8 @@
 #include "photos-mode-controller.h"
 #include "photos-overview-searchbar.h"
 #include "photos-remote-display-manager.h"
+#include "photos-search-context.h"
 #include "photos-selection-controller.h"
-#include "photos-source-manager.h"
 
 
 struct _PhotosMainToolbarPrivate
@@ -704,10 +704,14 @@ photos_main_toolbar_init (PhotosMainToolbar *self)
   GMenu *selection_menu;
   GApplication *app;
   GtkBuilder *builder;
+  PhotosSearchContextState *state;
 
   self->priv = photos_main_toolbar_get_instance_private (self);
   priv = self->priv;
 
+  app = g_application_get_default ();
+  state = photos_search_context_get_state (PHOTOS_SEARCH_CONTEXT (app));
+
   gtk_orientable_set_orientation (GTK_ORIENTABLE (self), GTK_ORIENTATION_VERTICAL);
   gtk_widget_show (GTK_WIDGET (self));
 
@@ -715,7 +719,6 @@ photos_main_toolbar_init (PhotosMainToolbar *self)
   gtk_container_add (GTK_CONTAINER (self), priv->toolbar);
   gtk_widget_show (priv->toolbar);
 
-  app = g_application_get_default ();
   priv->gear_menu = G_SIMPLE_ACTION (g_action_map_lookup_action (G_ACTION_MAP (app), "gear-menu"));
   priv->search = g_action_map_lookup_action (G_ACTION_MAP (app), "search");
 
@@ -731,10 +734,10 @@ photos_main_toolbar_init (PhotosMainToolbar *self)
   photos_header_bar_set_selection_menu (PHOTOS_HEADER_BAR (priv->toolbar),
                                         GD_HEADER_BUTTON (priv->selection_menu));
 
-  priv->col_mngr = photos_collection_manager_dup_singleton ();
+  priv->col_mngr = g_object_ref (state->col_mngr);
   priv->item_mngr = photos_item_manager_dup_singleton ();
 
-  priv->src_mngr = photos_source_manager_dup_singleton ();
+  priv->src_mngr = g_object_ref (state->src_mngr);
   g_signal_connect_object (priv->src_mngr,
                            "active-changed",
                            G_CALLBACK (photos_main_toolbar_set_toolbar_title),
diff --git a/src/photos-main-window.c b/src/photos-main-window.c
index b3c92a4..26ab833 100644
--- a/src/photos-main-window.c
+++ b/src/photos-main-window.c
@@ -29,11 +29,11 @@
 #include <glib/gi18n.h>
 
 #include "photos-about-data.h"
-#include "photos-collection-manager.h"
 #include "photos-embed.h"
 #include "photos-item-manager.h"
 #include "photos-main-window.h"
 #include "photos-mode-controller.h"
+#include "photos-search-context.h"
 #include "photos-selection-controller.h"
 #include "photos-settings.h"
 
@@ -348,7 +348,9 @@ static void
 photos_main_window_init (PhotosMainWindow *self)
 {
   PhotosMainWindowPrivate *priv;
+  GApplication *app;
   GVariant *variant;
+  PhotosSearchContextState *state;
   gboolean maximized;
   const gint32 *position;
   const gint32 *size;
@@ -357,6 +359,9 @@ photos_main_window_init (PhotosMainWindow *self)
   self->priv = photos_main_window_get_instance_private (self);
   priv = self->priv;
 
+  app = g_application_get_default ();
+  state = photos_search_context_get_state (PHOTOS_SEARCH_CONTEXT (app));
+
   priv->settings = photos_settings_new ();
 
   variant = g_settings_get_value (priv->settings, "window-size");
@@ -375,7 +380,7 @@ photos_main_window_init (PhotosMainWindow *self)
   if (maximized)
     gtk_window_maximize (GTK_WINDOW (self));
 
-  priv->col_mngr = photos_collection_manager_dup_singleton ();
+  priv->col_mngr = g_object_ref (state->col_mngr);
   priv->item_mngr = photos_item_manager_dup_singleton ();
 
   priv->mode_cntrlr = photos_mode_controller_dup_singleton ();
diff --git a/src/photos-offset-collections-controller.c b/src/photos-offset-collections-controller.c
index 3b57a32..cc2af7a 100644
--- a/src/photos-offset-collections-controller.c
+++ b/src/photos-offset-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
@@ -25,9 +25,12 @@
 
 #include "config.h"
 
-#include "photos-collection-manager.h"
+#include <gio/gio.h>
+
+#include "photos-base-manager.h"
 #include "photos-query-builder.h"
 #include "photos-offset-collections-controller.h"
+#include "photos-search-context.h"
 
 
 struct _PhotosOffsetCollectionsControllerPrivate
@@ -45,7 +48,9 @@ static PhotosQuery *
 photos_offset_collections_controller_get_query (PhotosOffsetController *offset_cntrlr)
 {
   PhotosOffsetCollectionsController *self = PHOTOS_OFFSET_COLLECTIONS_CONTROLLER (offset_cntrlr);
+  GApplication *app;
   GObject *collection;
+  PhotosSearchContextState *state;
   gint flags;
 
   collection = photos_base_manager_get_active_object (self->priv->col_mngr);
@@ -54,7 +59,10 @@ photos_offset_collections_controller_get_query (PhotosOffsetController *offset_c
   else
     flags = PHOTOS_QUERY_FLAGS_COLLECTIONS;
 
-  return photos_query_builder_count_query (flags);
+  app = g_application_get_default ();
+  state = photos_search_context_get_state (PHOTOS_SEARCH_CONTEXT (app));
+
+  return photos_query_builder_count_query (state, flags);
 }
 
 
@@ -93,11 +101,16 @@ static void
 photos_offset_collections_controller_init (PhotosOffsetCollectionsController *self)
 {
   PhotosOffsetCollectionsControllerPrivate *priv;
+  GApplication *app;
+  PhotosSearchContextState *state;
 
   self->priv = photos_offset_collections_controller_get_instance_private (self);
   priv = self->priv;
 
-  priv->col_mngr = photos_collection_manager_dup_singleton ();
+  app = g_application_get_default ();
+  state = photos_search_context_get_state (PHOTOS_SEARCH_CONTEXT (app));
+
+  priv->col_mngr = g_object_ref (state->col_mngr);
 }
 
 
diff --git a/src/photos-offset-favorites-controller.c b/src/photos-offset-favorites-controller.c
index f4cd085..d1a097e 100644
--- a/src/photos-offset-favorites-controller.c
+++ b/src/photos-offset-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
@@ -25,9 +25,12 @@
 
 #include "config.h"
 
-#include "photos-collection-manager.h"
+#include <gio/gio.h>
+
+#include "photos-base-manager.h"
 #include "photos-query-builder.h"
 #include "photos-offset-favorites-controller.h"
+#include "photos-search-context.h"
 
 
 struct _PhotosOffsetFavoritesControllerPrivate
@@ -45,7 +48,9 @@ static PhotosQuery *
 photos_offset_favorites_controller_get_query (PhotosOffsetController *offset_cntrlr)
 {
   PhotosOffsetFavoritesController *self = PHOTOS_OFFSET_FAVORITES_CONTROLLER (offset_cntrlr);
+  GApplication *app;
   GObject *collection;
+  PhotosSearchContextState *state;
   gint flags;
 
   collection = photos_base_manager_get_active_object (self->priv->col_mngr);
@@ -54,7 +59,10 @@ photos_offset_favorites_controller_get_query (PhotosOffsetController *offset_cnt
   else
     flags = PHOTOS_QUERY_FLAGS_FAVORITES;
 
-  return photos_query_builder_count_query (flags);
+  app = g_application_get_default ();
+  state = photos_search_context_get_state (PHOTOS_SEARCH_CONTEXT (app));
+
+  return photos_query_builder_count_query (state, flags);
 }
 
 
@@ -93,11 +101,16 @@ static void
 photos_offset_favorites_controller_init (PhotosOffsetFavoritesController *self)
 {
   PhotosOffsetFavoritesControllerPrivate *priv;
+  GApplication *app;
+  PhotosSearchContextState *state;
 
   self->priv = photos_offset_favorites_controller_get_instance_private (self);
   priv = self->priv;
 
-  priv->col_mngr = photos_collection_manager_dup_singleton ();
+  app = g_application_get_default ();
+  state = photos_search_context_get_state (PHOTOS_SEARCH_CONTEXT (app));
+
+  priv->col_mngr = g_object_ref (state->col_mngr);
 }
 
 
diff --git a/src/photos-offset-overview-controller.c b/src/photos-offset-overview-controller.c
index d953dfe..4551fd9 100644
--- a/src/photos-offset-overview-controller.c
+++ b/src/photos-offset-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
@@ -25,8 +25,11 @@
 
 #include "config.h"
 
+#include <gio/gio.h>
+
 #include "photos-query-builder.h"
 #include "photos-offset-overview-controller.h"
+#include "photos-search-context.h"
 
 
 G_DEFINE_TYPE (PhotosOffsetOverviewController, photos_offset_overview_controller, 
PHOTOS_TYPE_OFFSET_CONTROLLER);
@@ -35,7 +38,13 @@ G_DEFINE_TYPE (PhotosOffsetOverviewController, photos_offset_overview_controller
 static PhotosQuery *
 photos_offset_overview_controller_get_query (PhotosOffsetController *offset_cntrlr)
 {
-  return photos_query_builder_count_query (PHOTOS_QUERY_FLAGS_OVERVIEW);
+  GApplication *app;
+  PhotosSearchContextState *state;
+
+  app = g_application_get_default ();
+  state = photos_search_context_get_state (PHOTOS_SEARCH_CONTEXT (app));
+
+  return photos_query_builder_count_query (state, PHOTOS_QUERY_FLAGS_OVERVIEW);
 }
 
 
diff --git a/src/photos-offset-search-controller.c b/src/photos-offset-search-controller.c
index e4c9e56..e1b4d7d 100644
--- a/src/photos-offset-search-controller.c
+++ b/src/photos-offset-search-controller.c
@@ -25,8 +25,11 @@
 
 #include "config.h"
 
+#include <gio/gio.h>
+
 #include "photos-query-builder.h"
 #include "photos-offset-search-controller.h"
+#include "photos-search-context.h"
 
 
 G_DEFINE_TYPE (PhotosOffsetSearchController, photos_offset_search_controller, PHOTOS_TYPE_OFFSET_CONTROLLER);
@@ -35,7 +38,13 @@ G_DEFINE_TYPE (PhotosOffsetSearchController, photos_offset_search_controller, PH
 static PhotosQuery *
 photos_offset_search_controller_get_query (PhotosOffsetController *offset_cntrlr)
 {
-  return photos_query_builder_count_query (PHOTOS_QUERY_FLAGS_SEARCH);
+  GApplication *app;
+  PhotosSearchContextState *state;
+
+  app = g_application_get_default ();
+  state = photos_search_context_get_state (PHOTOS_SEARCH_CONTEXT (app));
+
+  return photos_query_builder_count_query (state, PHOTOS_QUERY_FLAGS_SEARCH);
 }
 
 
diff --git a/src/photos-organize-collection-model.c b/src/photos-organize-collection-model.c
index ec7433a..dcb9533 100644
--- a/src/photos-organize-collection-model.c
+++ b/src/photos-organize-collection-model.c
@@ -25,11 +25,14 @@
 
 #include "config.h"
 
+#include <gio/gio.h>
+
 #include "photos-base-item.h"
-#include "photos-collection-manager.h"
+#include "photos-base-manager.h"
 #include "photos-fetch-collection-state-job.h"
 #include "photos-filterable.h"
 #include "photos-organize-collection-model.h"
+#include "photos-search-context.h"
 
 
 struct _PhotosOrganizeCollectionModelPrivate
@@ -195,16 +198,21 @@ static void
 photos_organize_collection_model_init (PhotosOrganizeCollectionModel *self)
 {
   PhotosOrganizeCollectionModelPrivate *priv;
+  GApplication *app;
   GType columns[] = {G_TYPE_STRING,  /* ID */
                      G_TYPE_STRING,  /* NAME */
                      G_TYPE_INT};    /* STATE */
+  PhotosSearchContextState *state;
 
   self->priv = photos_organize_collection_model_get_instance_private (self);
   priv = self->priv;
 
+  app = g_application_get_default ();
+  state = photos_search_context_get_state (PHOTOS_SEARCH_CONTEXT (app));
+
   gtk_list_store_set_column_types (GTK_LIST_STORE (self), sizeof (columns) / sizeof (columns[0]), columns);
 
-  priv->manager = photos_collection_manager_dup_singleton ();
+  priv->manager = g_object_ref (state->col_mngr);
 
   g_signal_connect_object (priv->manager,
                            "object-added",
diff --git a/src/photos-organize-collection-view.c b/src/photos-organize-collection-view.c
index bd29048..076bfd4 100644
--- a/src/photos-organize-collection-view.c
+++ b/src/photos-organize-collection-view.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
@@ -25,17 +25,18 @@
 
 #include "config.h"
 
+#include <gio/gio.h>
 #include <glib.h>
 #include <libgd/gd.h>
 
 #include "photos-base-item.h"
-#include "photos-collection-manager.h"
+#include "photos-base-manager.h"
 #include "photos-create-collection-job.h"
 #include "photos-fetch-collection-state-job.h"
 #include "photos-organize-collection-model.h"
 #include "photos-organize-collection-view.h"
 #include "photos-query.h"
-#include "photos-source-manager.h"
+#include "photos-search-context.h"
 #include "photos-set-collection-job.h"
 #include "photos-utils.h"
 
@@ -285,10 +286,15 @@ static void
 photos_organize_collection_view_init (PhotosOrganizeCollectionView *self)
 {
   PhotosOrganizeCollectionViewPrivate *priv;
+  GApplication *app;
+  PhotosSearchContextState *state;
 
   self->priv = photos_organize_collection_view_get_instance_private (self);
   priv = self->priv;
 
+  app = g_application_get_default ();
+  state = photos_search_context_get_state (PHOTOS_SEARCH_CONTEXT (app));
+
   priv->model = photos_organize_collection_model_new ();
   gtk_tree_view_set_model (GTK_TREE_VIEW (self), GTK_TREE_MODEL (priv->model));
 
@@ -329,8 +335,8 @@ photos_organize_collection_view_init (PhotosOrganizeCollectionView *self)
                                            self,
                                            NULL);
 
-  priv->col_mngr = photos_collection_manager_dup_singleton ();
-  priv->src_mngr = photos_source_manager_dup_singleton ();
+  priv->col_mngr = g_object_ref (state->src_mngr);
+  priv->src_mngr = g_object_ref (state->src_mngr);
 
   gtk_widget_show (GTK_WIDGET (self));
 }
diff --git a/src/photos-overview-searchbar.c b/src/photos-overview-searchbar.c
index ec5f592..8233527 100644
--- a/src/photos-overview-searchbar.c
+++ b/src/photos-overview-searchbar.c
@@ -28,14 +28,12 @@
 #include <gio/gio.h>
 #include <libgd/gd.h>
 
-#include "photos-collection-manager.h"
+#include "photos-base-manager.h"
 #include "photos-filterable.h"
 #include "photos-overview-searchbar.h"
+#include "photos-search-context.h"
 #include "photos-search-controller.h"
-#include "photos-search-match-manager.h"
 #include "photos-search-type.h"
-#include "photos-search-type-manager.h"
-#include "photos-source-manager.h"
 
 
 struct _PhotosOverviewSearchbarPrivate
@@ -345,42 +343,45 @@ photos_overview_searchbar_init (PhotosOverviewSearchbar *self)
 {
   PhotosOverviewSearchbarPrivate *priv;
   GApplication *app;
+  PhotosSearchContextState *state;
 
   self->priv = photos_overview_searchbar_get_instance_private (self);
   priv = self->priv;
 
   app = g_application_get_default ();
+  state = photos_search_context_get_state (PHOTOS_SEARCH_CONTEXT (app));
+
   priv->select_all = g_action_map_lookup_action (G_ACTION_MAP (app), "select-all");
 
-  priv->src_mngr = photos_source_manager_dup_singleton ();
+  priv->src_mngr = g_object_ref (state->src_mngr);
   g_signal_connect_object (priv->src_mngr,
                            "active-changed",
                            G_CALLBACK (photos_overview_searchbar_source_active_changed),
                            self,
                            G_CONNECT_SWAPPED);
 
-  priv->srch_mtch_mngr = photos_search_match_manager_dup_singleton ();
+  priv->srch_mtch_mngr = g_object_ref (state->srch_mtch_mngr);
   g_signal_connect_object (priv->srch_mtch_mngr,
                            "active-changed",
                            G_CALLBACK (photos_overview_searchbar_search_match_active_changed),
                            self,
                            G_CONNECT_SWAPPED);
 
-  priv->srch_typ_mngr = photos_search_type_manager_dup_singleton ();
+  priv->srch_typ_mngr = g_object_ref (state->srch_typ_mngr);
   g_signal_connect_object (priv->srch_typ_mngr,
                            "active-changed",
                            G_CALLBACK (photos_overview_searchbar_search_type_active_changed),
                            self,
                            G_CONNECT_SWAPPED);
 
-  priv->col_mngr = photos_collection_manager_dup_singleton ();
+  priv->col_mngr = g_object_ref (state->col_mngr);
   g_signal_connect_object (priv->col_mngr,
                            "active-changed",
                            G_CALLBACK (photos_overview_searchbar_collection_active_changed),
                            self,
                            G_CONNECT_SWAPPED);
 
-  priv->srch_cntrlr = photos_search_controller_dup_singleton ();
+  priv->srch_cntrlr = g_object_ref (state->srch_cntrlr);
 }
 
 
diff --git a/src/photos-query-builder.c b/src/photos-query-builder.c
index e617bfd..1daf62d 100644
--- a/src/photos-query-builder.c
+++ b/src/photos-query-builder.c
@@ -53,24 +53,16 @@ photos_query_builder_convert_path_to_uri (const gchar *path)
 
 
 static gchar *
-photos_query_builder_filter (gint flags)
+photos_query_builder_filter (PhotosSearchContextState *state, gint flags)
 {
-  PhotosBaseManager *src_mngr;
-  PhotosBaseManager *srch_mtch_mngr;
-  PhotosBaseManager *srch_typ_mngr;
   gchar *sparql;
   gchar *src_mngr_filter;
   gchar *srch_mtch_mngr_filter;
   gchar *srch_typ_mngr_filter;
 
-  src_mngr = photos_source_manager_dup_singleton ();
-  src_mngr_filter = photos_base_manager_get_filter (src_mngr, flags);
-
-  srch_mtch_mngr = photos_search_match_manager_dup_singleton ();
-  srch_mtch_mngr_filter = photos_base_manager_get_filter (srch_mtch_mngr, flags);
-
-  srch_typ_mngr = photos_search_type_manager_dup_singleton ();
-  srch_typ_mngr_filter = photos_base_manager_get_filter (srch_typ_mngr, flags);
+  src_mngr_filter = photos_base_manager_get_filter (state->src_mngr, flags);
+  srch_mtch_mngr_filter = photos_base_manager_get_filter (state->srch_mtch_mngr, flags);
+  srch_typ_mngr_filter = photos_base_manager_get_filter (state->srch_typ_mngr, flags);
 
   sparql = g_strdup_printf ("FILTER (%s && %s && %s)",
                             src_mngr_filter,
@@ -78,13 +70,8 @@ photos_query_builder_filter (gint flags)
                             srch_typ_mngr_filter);
 
   g_free (srch_typ_mngr_filter);
-  g_object_unref (srch_typ_mngr);
-
   g_free (srch_mtch_mngr_filter);
-  g_object_unref (srch_mtch_mngr);
-
   g_free (src_mngr_filter);
-  g_object_unref (src_mngr);
 
   return sparql;
 }
@@ -99,21 +86,15 @@ photos_query_builder_optional (void)
 
 
 static gchar *
-photos_query_builder_where (gboolean global, gint flags)
+photos_query_builder_where (PhotosSearchContextState *state, gboolean global, gint flags)
 {
-  PhotosBaseManager *col_mngr;
-  PhotosBaseManager *srch_typ_mngr;
   gchar *col_mngr_where = NULL;
   gchar *filter = NULL;
   gchar *optional = NULL;
   gchar *sparql;
   gchar *srch_typ_mngr_where = NULL;
 
-  col_mngr = photos_collection_manager_dup_singleton ();
-
-  srch_typ_mngr = photos_search_type_manager_dup_singleton ();
-  srch_typ_mngr_where = photos_base_manager_get_where (srch_typ_mngr, flags);
-
+  srch_typ_mngr_where = photos_base_manager_get_where (state->srch_typ_mngr, flags);
   optional = photos_query_builder_optional ();
 
   if (!(flags & PHOTOS_QUERY_FLAGS_UNFILTERED))
@@ -122,10 +103,10 @@ photos_query_builder_where (gboolean global, gint flags)
         {
           /* TODO: SearchCategoryManager */
 
-          col_mngr_where = photos_base_manager_get_where (col_mngr, flags);
+          col_mngr_where = photos_base_manager_get_where (state->col_mngr, flags);
         }
 
-      filter = photos_query_builder_filter (flags);
+      filter = photos_query_builder_filter (state, flags);
     }
 
   sparql = g_strdup_printf ("WHERE { %s %s %s %s }",
@@ -137,21 +118,22 @@ photos_query_builder_where (gboolean global, gint flags)
   g_free (col_mngr_where);
   g_free (filter);
   g_free (srch_typ_mngr_where);
-  g_object_unref (col_mngr);
-  g_object_unref (srch_typ_mngr);
 
   return sparql;
 }
 
 
 static gchar *
-photos_query_builder_query (gboolean global, gint flags, PhotosOffsetController *offset_cntrlr)
+photos_query_builder_query (PhotosSearchContextState *state,
+                            gboolean global,
+                            gint flags,
+                            PhotosOffsetController *offset_cntrlr)
 {
   gchar *sparql;
   gchar *tail_sparql = NULL;
   gchar *where_sparql;
 
-  where_sparql = photos_query_builder_where (global, flags);
+  where_sparql = photos_query_builder_where (state, global, flags);
 
   if (global)
     {
@@ -199,7 +181,7 @@ photos_query_builder_query (gboolean global, gint flags, PhotosOffsetController
 
 
 PhotosQuery *
-photos_query_builder_create_collection_query (const gchar *name)
+photos_query_builder_create_collection_query (PhotosSearchContextState *state, const gchar *name)
 {
   GTimeVal tv;
   gchar *sparql;
@@ -221,12 +203,12 @@ photos_query_builder_create_collection_query (const gchar *name)
                             name);
   g_free (time);
 
-  return photos_query_new (sparql);
+  return photos_query_new (state, sparql);
 }
 
 
 PhotosQuery *
-photos_query_builder_collection_icon_query (const gchar *resource)
+photos_query_builder_collection_icon_query (PhotosSearchContextState *state, const gchar *resource)
 {
   gchar *sparql;
 
@@ -235,68 +217,73 @@ photos_query_builder_collection_icon_query (const gchar *resource)
                             "WHERE { ?urn nie:isPartOf <%s> } "
                             "ORDER BY DESC (?mtime) LIMIT 4",
                             resource);
-  return photos_query_new (sparql);
+  return photos_query_new (state, sparql);
 }
 
 
 PhotosQuery *
-photos_query_builder_count_query (gint flags)
+photos_query_builder_count_query (PhotosSearchContextState *state, gint flags)
 {
   gchar *sparql;
   gchar *where_sparql;
 
-  where_sparql = photos_query_builder_where (TRUE, flags);
+  where_sparql = photos_query_builder_where (state, TRUE, flags);
   sparql = g_strconcat ("SELECT DISTINCT COUNT(?urn) ", where_sparql, NULL);
   g_free (where_sparql);
 
-  return photos_query_new (sparql);
+  return photos_query_new (state, sparql);
 }
 
 
 PhotosQuery *
-photos_query_builder_delete_resource_query (const gchar *resource)
+photos_query_builder_delete_resource_query (PhotosSearchContextState *state, const gchar *resource)
 {
   gchar *sparql;
 
   sparql = g_strdup_printf ("DELETE { <%s> a rdfs:Resource }", resource);
-  return photos_query_new (sparql);
+  return photos_query_new (state, sparql);
 }
 
 
 PhotosQuery *
-photos_query_builder_equipment_query (GQuark equipment)
+photos_query_builder_equipment_query (PhotosSearchContextState *state, GQuark equipment)
 {
   const gchar *resource;
   gchar *sparql;
 
   resource = g_quark_to_string (equipment);
   sparql = g_strdup_printf ("SELECT nfo:manufacturer (<%s>) nfo:model (<%s>) WHERE {}", resource, resource);
-  return photos_query_new (sparql);
+  return photos_query_new (state, sparql);
 }
 
 
 PhotosQuery *
-photos_query_builder_fetch_collections_query (const gchar *resource)
+photos_query_builder_fetch_collections_query (PhotosSearchContextState *state, const gchar *resource)
 {
   gchar *sparql;
 
   sparql = g_strdup_printf ("SELECT ?urn WHERE { ?urn a nfo:DataContainer . <%s> nie:isPartOf ?urn }", 
resource);
-  return photos_query_new (sparql);
+  return photos_query_new (state, sparql);
 }
 
 
 PhotosQuery *
-photos_query_builder_global_query (gint flags, PhotosOffsetController *offset_cntrlr)
+photos_query_builder_global_query (PhotosSearchContextState *state,
+                                   gint flags,
+                                   PhotosOffsetController *offset_cntrlr)
 {
   gchar *sparql;
 
-  sparql = photos_query_builder_query (TRUE, flags, offset_cntrlr);
-  return photos_query_new (sparql);
+  sparql = photos_query_builder_query (state, TRUE, flags, offset_cntrlr);
+  return photos_query_new (state, sparql);
 }
 
 
 PhotosQuery *
-photos_query_builder_set_collection_query (const gchar *item_urn, const gchar *collection_urn, gboolean 
setting)
+photos_query_builder_set_collection_query (PhotosSearchContextState *state,
+                                           const gchar *item_urn,
+                                           const gchar *collection_urn,
+                                           gboolean setting)
 {
   gchar *sparql;
 
@@ -304,19 +291,19 @@ photos_query_builder_set_collection_query (const gchar *item_urn, const gchar *c
                             setting ? "INSERT" : "DELETE",
                             item_urn,
                             collection_urn);
-  return photos_query_new (sparql);
+  return photos_query_new (state, sparql);
 }
 
 
 PhotosQuery *
-photos_query_builder_single_query (gint flags, const gchar *resource)
+photos_query_builder_single_query (PhotosSearchContextState *state, gint flags, const gchar *resource)
 {
   GRegex *regex;
   gchar *replacement;
   gchar *sparql;
   gchar *tmp;
 
-  tmp = photos_query_builder_query (FALSE, flags, NULL);
+  tmp = photos_query_builder_query (state, FALSE, flags, NULL);
 
   regex = g_regex_new ("\\?urn", 0, 0, NULL);
   replacement = g_strconcat ("<", resource, ">", NULL);
@@ -325,12 +312,12 @@ photos_query_builder_single_query (gint flags, const gchar *resource)
   g_free (tmp);
   g_regex_unref (regex);
 
-  return photos_query_new (sparql);
+  return photos_query_new (state, sparql);
 }
 
 
 PhotosQuery *
-photos_query_builder_update_mtime_query (const gchar *resource)
+photos_query_builder_update_mtime_query (PhotosSearchContextState *state, const gchar *resource)
 {
   GTimeVal tv;
   gchar *sparql;
@@ -345,7 +332,7 @@ photos_query_builder_update_mtime_query (const gchar *resource)
   sparql = g_strdup_printf ("INSERT OR REPLACE { <%s> nie:contentLastModified \"%s\" }", resource, time);
   g_free (time);
 
-  return photos_query_new (sparql);
+  return photos_query_new (state, sparql);
 }
 
 
diff --git a/src/photos-query-builder.h b/src/photos-query-builder.h
index 0a451aa..f7a9e23 100644
--- a/src/photos-query-builder.h
+++ b/src/photos-query-builder.h
@@ -29,30 +29,36 @@
 
 #include "photos-offset-controller.h"
 #include "photos-query.h"
+#include "photos-search-context.h"
 
 G_BEGIN_DECLS
 
-PhotosQuery  *photos_query_builder_create_collection_query (const gchar *name);
+PhotosQuery  *photos_query_builder_create_collection_query (PhotosSearchContextState *state, const gchar 
*name);
 
-PhotosQuery  *photos_query_builder_collection_icon_query (const gchar *resource);
+PhotosQuery  *photos_query_builder_collection_icon_query (PhotosSearchContextState *state, const gchar 
*resource);
 
-PhotosQuery  *photos_query_builder_count_query (gint flags);
+PhotosQuery  *photos_query_builder_count_query (PhotosSearchContextState *state, gint flags);
 
-PhotosQuery  *photos_query_builder_delete_resource_query (const gchar *resource);
+PhotosQuery  *photos_query_builder_delete_resource_query (PhotosSearchContextState *state, const gchar 
*resource);
 
-PhotosQuery  *photos_query_builder_equipment_query (GQuark equipment);
+PhotosQuery  *photos_query_builder_equipment_query (PhotosSearchContextState *state, GQuark equipment);
 
-PhotosQuery  *photos_query_builder_fetch_collections_query (const gchar *resource);
+PhotosQuery  *photos_query_builder_fetch_collections_query (PhotosSearchContextState *state, const gchar 
*resource);
 
-PhotosQuery  *photos_query_builder_global_query        (gint flags, PhotosOffsetController *offset_cntrlr);
+PhotosQuery  *photos_query_builder_global_query        (PhotosSearchContextState *state,
+                                                        gint flags,
+                                                        PhotosOffsetController *offset_cntrlr);
 
-PhotosQuery  *photos_query_builder_set_collection_query (const gchar *item_urn,
+PhotosQuery  *photos_query_builder_set_collection_query (PhotosSearchContextState *state,
+                                                         const gchar *item_urn,
                                                          const gchar *collection_urn,
                                                          gboolean setting);
 
-PhotosQuery  *photos_query_builder_single_query        (gint flags, const gchar *resource);
+PhotosQuery  *photos_query_builder_single_query        (PhotosSearchContextState *state,
+                                                        gint flags,
+                                                        const gchar *resource);
 
-PhotosQuery  *photos_query_builder_update_mtime_query (const gchar *resource);
+PhotosQuery  *photos_query_builder_update_mtime_query (PhotosSearchContextState *state, const gchar 
*resource);
 
 gchar        *photos_query_builder_filter_local        (void);
 
diff --git a/src/photos-query.c b/src/photos-query.c
index 7571360..dfc93e4 100644
--- a/src/photos-query.c
+++ b/src/photos-query.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
@@ -25,8 +25,8 @@
 
 #include "config.h"
 
+#include "photos-base-manager.h"
 #include "photos-query.h"
-#include "photos-source-manager.h"
 
 
 const gchar *PHOTOS_QUERY_COLLECTIONS_IDENTIFIER = "photos:collection:";
@@ -34,19 +34,16 @@ const gchar *PHOTOS_QUERY_LOCAL_COLLECTIONS_IDENTIFIER = "photos:collection:loca
 
 
 PhotosQuery *
-photos_query_new (gchar *sparql)
+photos_query_new (PhotosSearchContextState *state, gchar *sparql)
 {
-  PhotosBaseManager *src_mngr;
   GObject *active_object;
   PhotosQuery *query;
 
   query = g_slice_new0 (PhotosQuery);
 
-  src_mngr = photos_source_manager_dup_singleton ();
-  active_object = photos_base_manager_get_active_object (src_mngr);
+  active_object = photos_base_manager_get_active_object (state->src_mngr);
   if (active_object != NULL)
     query->source = PHOTOS_SOURCE (g_object_ref (active_object));
-  g_object_unref (src_mngr);
 
   query->sparql = sparql;
 
diff --git a/src/photos-query.h b/src/photos-query.h
index 78a59b0..36ebd35 100644
--- a/src/photos-query.h
+++ b/src/photos-query.h
@@ -28,6 +28,7 @@
 #include <glib.h>
 
 #include "photos-query.h"
+#include "photos-search-context.h"
 #include "photos-source.h"
 
 G_BEGIN_DECLS
@@ -78,7 +79,7 @@ struct _PhotosQuery
   gchar *sparql;
 };
 
-PhotosQuery    *photos_query_new     (gchar *sparql);
+PhotosQuery    *photos_query_new     (PhotosSearchContextState *state, gchar *sparql);
 
 void            photos_query_free    (PhotosQuery *query);
 
diff --git a/src/photos-search-context.c b/src/photos-search-context.c
new file mode 100644
index 0000000..b6b5214
--- /dev/null
+++ b/src/photos-search-context.c
@@ -0,0 +1,80 @@
+/*
+ * Photos - access, organize and share your photos on GNOME
+ * Copyright © 2013 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 <glib.h>
+
+#include "photos-collection-manager.h"
+#include "photos-search-context.h"
+#include "photos-search-controller.h"
+#include "photos-search-match-manager.h"
+#include "photos-search-type-manager.h"
+#include "photos-source-manager.h"
+
+
+G_DEFINE_INTERFACE (PhotosSearchContext, photos_search_context, G_TYPE_INVALID);
+
+
+static void
+photos_search_context_default_init (PhotosSearchContextInterface *iface)
+{
+}
+
+
+PhotosSearchContextState *
+photos_search_context_state_new (PhotosSearchContext *self)
+{
+  PhotosSearchContextState *state;
+
+  state = g_slice_new0 (PhotosSearchContextState);
+  state->col_mngr = photos_collection_manager_new ();
+  state->src_mngr = photos_source_manager_new ();
+  state->srch_cntrlr = photos_search_controller_new ();
+  state->srch_mtch_mngr = photos_search_match_manager_new (state->srch_cntrlr);
+  state->srch_typ_mngr = photos_search_type_manager_new ();
+
+  return state;
+}
+
+
+void
+photos_search_context_state_free (PhotosSearchContextState *state)
+{
+  g_object_unref (state->col_mngr);
+  g_object_unref (state->src_mngr);
+  g_object_unref (state->srch_mtch_mngr);
+  g_object_unref (state->srch_typ_mngr);
+  g_object_unref (state->srch_cntrlr);
+  g_slice_free (PhotosSearchContextState, state);
+}
+
+
+PhotosSearchContextState *
+photos_search_context_get_state (PhotosSearchContext *self)
+{
+  g_return_val_if_fail (PHOTOS_IS_SEARCH_CONTEXT (self), NULL);
+  return PHOTOS_SEARCH_CONTEXT_GET_INTERFACE (self)->get_state (self);
+}
diff --git a/src/photos-search-context.h b/src/photos-search-context.h
new file mode 100644
index 0000000..95303c1
--- /dev/null
+++ b/src/photos-search-context.h
@@ -0,0 +1,79 @@
+/*
+ * Photos - access, organize and share your photos on GNOME
+ * Copyright © 2013 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_SEARCH_CONTEXT_H
+#define PHOTOS_SEARCH_CONTEXT_H
+
+#include <glib-object.h>
+
+G_BEGIN_DECLS
+
+#define PHOTOS_TYPE_SEARCH_CONTEXT (photos_search_context_get_type ())
+
+#define PHOTOS_SEARCH_CONTEXT(obj) \
+  (G_TYPE_CHECK_INSTANCE_CAST ((obj), \
+   PHOTOS_TYPE_SEARCH_CONTEXT, PhotosSearchContext))
+
+#define PHOTOS_IS_SEARCH_CONTEXT(obj) \
+  (G_TYPE_CHECK_INSTANCE_TYPE ((obj), \
+   PHOTOS_TYPE_SEARCH_CONTEXT))
+
+#define PHOTOS_SEARCH_CONTEXT_GET_INTERFACE(inst) \
+  (G_TYPE_INSTANCE_GET_INTERFACE ((inst), \
+   PHOTOS_TYPE_SEARCH_CONTEXT, PhotosSearchContextInterface))
+
+typedef struct _PhotosSearchContextState PhotosSearchContextState;
+
+typedef struct _PhotosSearchContext          PhotosSearchContext;
+typedef struct _PhotosSearchContextInterface PhotosSearchContextInterface;
+
+struct _PhotosSearchContextState
+{
+  gpointer col_mngr;
+  gpointer src_mngr;
+  gpointer srch_mtch_mngr;
+  gpointer srch_typ_mngr;
+  gpointer offset_cntrlr;
+  gpointer srch_cntrlr;
+};
+
+PhotosSearchContextState      *photos_search_context_state_new      (PhotosSearchContext *self);
+
+void                           photos_search_context_state_free     (PhotosSearchContextState *state);
+
+struct _PhotosSearchContextInterface
+{
+  GTypeInterface parent_iface;
+
+  /* virtual methods */
+  PhotosSearchContextState *(*get_state) (PhotosSearchContext *self);
+};
+
+GType                        photos_search_context_get_type           (void) G_GNUC_CONST;
+
+PhotosSearchContextState    *photos_search_context_get_state          (PhotosSearchContext *self);
+
+G_END_DECLS
+
+#endif /* PHOTOS_SEARCH_CONTEXT_H */
diff --git a/src/photos-search-controller.c b/src/photos-search-controller.c
index 18fa666..a1a9681 100644
--- a/src/photos-search-controller.c
+++ b/src/photos-search-controller.c
@@ -48,24 +48,6 @@ static guint signals[LAST_SIGNAL] = { 0 };
 G_DEFINE_TYPE_WITH_PRIVATE (PhotosSearchController, photos_search_controller, G_TYPE_OBJECT);
 
 
-static GObject *
-photos_search_controller_constructor (GType type, guint n_construct_params, GObjectConstructParam 
*construct_params)
-{
-  static GObject *self = NULL;
-
-  if (self == NULL)
-    {
-      self = G_OBJECT_CLASS (photos_search_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_search_controller_finalize (GObject *object)
 {
@@ -94,7 +76,6 @@ photos_search_controller_class_init (PhotosSearchControllerClass *class)
 {
   GObjectClass *object_class = G_OBJECT_CLASS (class);
 
-  object_class->constructor = photos_search_controller_constructor;
   object_class->finalize = photos_search_controller_finalize;
 
   signals[SEARCH_STRING_CHANGED] = g_signal_new ("search-string-changed",
@@ -112,7 +93,7 @@ photos_search_controller_class_init (PhotosSearchControllerClass *class)
 
 
 PhotosSearchController *
-photos_search_controller_dup_singleton (void)
+photos_search_controller_new (void)
 {
   return g_object_new (PHOTOS_TYPE_SEARCH_CONTROLLER, NULL);
 }
diff --git a/src/photos-search-controller.h b/src/photos-search-controller.h
index e2337a2..d3d89f2 100644
--- a/src/photos-search-controller.h
+++ b/src/photos-search-controller.h
@@ -71,7 +71,7 @@ struct _PhotosSearchControllerClass
 
 GType                      photos_search_controller_get_type       (void) G_GNUC_CONST;
 
-PhotosSearchController    *photos_search_controller_dup_singleton  (void);
+PhotosSearchController    *photos_search_controller_new            (void);
 
 const gchar               *photos_search_controller_get_string     (PhotosSearchController *self);
 
diff --git a/src/photos-search-match-manager.c b/src/photos-search-match-manager.c
index 1f0c9f1..182ee36 100644
--- a/src/photos-search-match-manager.c
+++ b/src/photos-search-match-manager.c
@@ -30,7 +30,6 @@
 
 #include "photos-filterable.h"
 #include "photos-query.h"
-#include "photos-search-controller.h"
 #include "photos-search-match.h"
 #include "photos-search-match-manager.h"
 
@@ -40,6 +39,12 @@ struct _PhotosSearchMatchManagerPrivate
   PhotosSearchController *srch_cntrlr;
 };
 
+enum
+{
+  PROP_0,
+  PROP_SEARCH_CONTROLLER
+};
+
 
 G_DEFINE_TYPE_WITH_PRIVATE (PhotosSearchMatchManager, photos_search_match_manager, PHOTOS_TYPE_BASE_MANAGER);
 
@@ -100,49 +105,43 @@ photos_search_match_manager_get_filter (PhotosBaseManager *mngr, gint flags)
 }
 
 
-static GObject *
-photos_search_match_manager_constructor (GType                  type,
-                                         guint                  n_construct_params,
-                                         GObjectConstructParam *construct_params)
+static void
+photos_search_match_manager_dispose (GObject *object)
 {
-  static GObject *self = NULL;
+  PhotosSearchMatchManager *self = PHOTOS_SEARCH_MATCH_MANAGER (object);
 
-  if (self == NULL)
-    {
-      self = G_OBJECT_CLASS (photos_search_match_manager_parent_class)->constructor (type,
-                                                                                     n_construct_params,
-                                                                                     construct_params);
-      g_object_add_weak_pointer (self, (gpointer) &self);
-      return self;
-    }
+  g_clear_object (&self->priv->srch_cntrlr);
 
-  return g_object_ref (self);
+  G_OBJECT_CLASS (photos_search_match_manager_parent_class)->dispose (object);
 }
 
 
 static void
-photos_search_match_manager_dispose (GObject *object)
+photos_search_match_manager_set_property (GObject *object, guint prop_id, const GValue *value, GParamSpec 
*pspec)
 {
   PhotosSearchMatchManager *self = PHOTOS_SEARCH_MATCH_MANAGER (object);
 
-  g_clear_object (&self->priv->srch_cntrlr);
+  switch (prop_id)
+    {
+    case PROP_SEARCH_CONTROLLER:
+      self->priv->srch_cntrlr = PHOTOS_SEARCH_CONTROLLER (g_value_dup_object (value)); /* self is owned by 
context */
+      break;
 
-  G_OBJECT_CLASS (photos_search_match_manager_parent_class)->dispose (object);
+    default:
+      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+      break;
+    }
 }
 
 
 static void
 photos_search_match_manager_init (PhotosSearchMatchManager *self)
 {
-  PhotosSearchMatchManagerPrivate *priv;
   PhotosSearchMatch *search_match;
   const gchar *author_filter;
   const gchar *title_filter;
 
   self->priv = photos_search_match_manager_get_instance_private (self);
-  priv = self->priv;
-
-  priv->srch_cntrlr = photos_search_controller_dup_singleton ();
 
   author_filter = "fn:contains ("
                   "  tracker:case-fold (tracker:coalesce (nco:fullname (?creator), 
nco:fullname(?publisher))),"
@@ -181,17 +180,28 @@ photos_search_match_manager_class_init (PhotosSearchMatchManagerClass *class)
   GObjectClass *object_class = G_OBJECT_CLASS (class);
   PhotosBaseManagerClass *base_manager_class = PHOTOS_BASE_MANAGER_CLASS (class);
 
-  object_class->constructor = photos_search_match_manager_constructor;
   object_class->dispose = photos_search_match_manager_dispose;
+  object_class->set_property = photos_search_match_manager_set_property;
   base_manager_class->get_filter = photos_search_match_manager_get_filter;
+
+  g_object_class_install_property (object_class,
+                                   PROP_SEARCH_CONTROLLER,
+                                   g_param_spec_object ("search-controller",
+                                                        "A PhotosSearchController",
+                                                        "The search controller for this manager",
+                                                        PHOTOS_TYPE_SEARCH_CONTROLLER,
+                                                        G_PARAM_CONSTRUCT_ONLY | G_PARAM_WRITABLE));
 }
 
 
 PhotosBaseManager *
-photos_search_match_manager_dup_singleton (void)
+photos_search_match_manager_new (PhotosSearchController *srch_cntrlr)
 {
   /* Translators: this is a verb that refers to "All", "Title" and
    * "Author", as in "Match All", "Match Title" and "Match Author".
    */
-  return g_object_new (PHOTOS_TYPE_SEARCH_MATCH_MANAGER, "title", _("Match"), NULL);
+  return g_object_new (PHOTOS_TYPE_SEARCH_MATCH_MANAGER,
+                       "search-controller", srch_cntrlr,
+                       "title", _("Match"),
+                       NULL);
 }
diff --git a/src/photos-search-match-manager.h b/src/photos-search-match-manager.h
index 04df7f0..85d3c8e 100644
--- a/src/photos-search-match-manager.h
+++ b/src/photos-search-match-manager.h
@@ -26,6 +26,7 @@
 #define PHOTOS_SEARCH_MATCH_MANAGER_H
 
 #include "photos-base-manager.h"
+#include "photos-search-controller.h"
 
 G_BEGIN_DECLS
 
@@ -68,7 +69,7 @@ struct _PhotosSearchMatchManagerClass
 
 GType                     photos_search_match_manager_get_type           (void) G_GNUC_CONST;
 
-PhotosBaseManager        *photos_search_match_manager_dup_singleton      (void);
+PhotosBaseManager        *photos_search_match_manager_new                (PhotosSearchController 
*srch_cntrlr);
 
 G_END_DECLS
 
diff --git a/src/photos-search-type-manager.c b/src/photos-search-type-manager.c
index 440ea14..28c7734 100644
--- a/src/photos-search-type-manager.c
+++ b/src/photos-search-type-manager.c
@@ -85,26 +85,6 @@ photos_search_type_manager_get_where (PhotosBaseManager *mngr, gint flags)
 }
 
 
-static GObject *
-photos_search_type_manager_constructor (GType                  type,
-                                        guint                  n_construct_params,
-                                        GObjectConstructParam *construct_params)
-{
-  static GObject *self = NULL;
-
-  if (self == NULL)
-    {
-      self = G_OBJECT_CLASS (photos_search_type_manager_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_search_type_manager_init (PhotosSearchTypeManager *self)
 {
@@ -157,17 +137,15 @@ photos_search_type_manager_init (PhotosSearchTypeManager *self)
 static void
 photos_search_type_manager_class_init (PhotosSearchTypeManagerClass *class)
 {
-  GObjectClass *object_class = G_OBJECT_CLASS (class);
   PhotosBaseManagerClass *base_manager_class = PHOTOS_BASE_MANAGER_CLASS (class);
 
-  object_class->constructor = photos_search_type_manager_constructor;
   base_manager_class->get_filter = photos_search_type_manager_get_filter;
   base_manager_class->get_where = photos_search_type_manager_get_where;
 }
 
 
 PhotosBaseManager *
-photos_search_type_manager_dup_singleton (void)
+photos_search_type_manager_new (void)
 {
   /* Translators: "Type" refers to a search filter. eg., All, Albums,
    * Favorites and Photos.
diff --git a/src/photos-search-type-manager.h b/src/photos-search-type-manager.h
index 0b0dc41..5c2a88a 100644
--- a/src/photos-search-type-manager.h
+++ b/src/photos-search-type-manager.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
@@ -68,7 +68,7 @@ struct _PhotosSearchTypeManagerClass
 
 GType                     photos_search_type_manager_get_type           (void) G_GNUC_CONST;
 
-PhotosBaseManager        *photos_search_type_manager_dup_singleton      (void);
+PhotosBaseManager        *photos_search_type_manager_new                (void);
 
 G_END_DECLS
 
diff --git a/src/photos-set-collection-job.c b/src/photos-set-collection-job.c
index 3c5f222..ec698d2 100644
--- a/src/photos-set-collection-job.c
+++ b/src/photos-set-collection-job.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
@@ -25,11 +25,13 @@
 
 #include "config.h"
 
+#include <gio/gio.h>
 #include <glib.h>
 #include <tracker-sparql.h>
 
 #include "photos-query.h"
 #include "photos-query-builder.h"
+#include "photos-search-context.h"
 #include "photos-selection-controller.h"
 #include "photos-set-collection-job.h"
 #include "photos-tracker-queue.h"
@@ -212,8 +214,10 @@ photos_set_collection_job_run (PhotosSetCollectionJob *self,
                                gpointer user_data)
 {
   PhotosSetCollectionJobPrivate *priv = self->priv;
+  GApplication *app;
   GList *l;
   GList *urns;
+  PhotosSearchContextState *state;
 
   if (G_UNLIKELY (priv->queue == NULL))
     {
@@ -225,6 +229,9 @@ photos_set_collection_job_run (PhotosSetCollectionJob *self,
   priv->callback = callback;
   priv->user_data = user_data;
 
+  app = g_application_get_default ();
+  state = photos_search_context_get_state (PHOTOS_SEARCH_CONTEXT (app));
+
   urns = photos_selection_controller_get_selection (priv->sel_cntrlr);
   for (l = urns; l != NULL; l = l->next)
     {
@@ -235,7 +242,7 @@ photos_set_collection_job_run (PhotosSetCollectionJob *self,
         continue;
 
       priv->running_jobs++;
-      query = photos_query_builder_set_collection_query (urn, priv->collection_urn, priv->setting);
+      query = photos_query_builder_set_collection_query (state, urn, priv->collection_urn, priv->setting);
       photos_tracker_queue_update (priv->queue,
                                    query->sparql,
                                    NULL,
diff --git a/src/photos-single-item-job.c b/src/photos-single-item-job.c
index b74339b..7434c71 100644
--- a/src/photos-single-item-job.c
+++ b/src/photos-single-item-job.c
@@ -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
@@ -201,6 +201,7 @@ photos_single_item_job_new (const gchar *urn)
 
 void
 photos_single_item_job_run (PhotosSingleItemJob *self,
+                            PhotosSearchContextState *state,
                             gint flags,
                             PhotosSingleItemJobCallback callback,
                             gpointer user_data)
@@ -218,7 +219,7 @@ photos_single_item_job_run (PhotosSingleItemJob *self,
   priv->callback = callback;
   priv->user_data = user_data;
 
-  query = photos_query_builder_single_query (flags, priv->urn);
+  query = photos_query_builder_single_query (state, flags, priv->urn);
   photos_tracker_queue_select (priv->queue,
                                query->sparql,
                                NULL,
diff --git a/src/photos-single-item-job.h b/src/photos-single-item-job.h
index 24e5c6b..fdad9d0 100644
--- a/src/photos-single-item-job.h
+++ b/src/photos-single-item-job.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
@@ -28,6 +28,8 @@
 #include <gio/gio.h>
 #include <tracker-sparql.h>
 
+#include "photos-search-context.h"
+
 G_BEGIN_DECLS
 
 #define PHOTOS_TYPE_SINGLE_ITEM_JOB (photos_single_item_job_get_type ())
@@ -74,6 +76,7 @@ GType                  photos_single_item_job_get_type             (void) G_GNUC
 PhotosSingleItemJob   *photos_single_item_job_new                  (const gchar *urn);
 
 void                   photos_single_item_job_run                  (PhotosSingleItemJob *self,
+                                                                    PhotosSearchContextState *state,
                                                                     gint flags,
                                                                     PhotosSingleItemJobCallback callback,
                                                                     gpointer user_data);
diff --git a/src/photos-source-manager.c b/src/photos-source-manager.c
index 6ca8d7b..54bbc66 100644
--- a/src/photos-source-manager.c
+++ b/src/photos-source-manager.c
@@ -107,26 +107,6 @@ photos_source_manager_refresh_accounts (PhotosSourceManager *self)
 }
 
 
-static GObject *
-photos_source_manager_constructor (GType                  type,
-                                   guint                  n_construct_params,
-                                   GObjectConstructParam *construct_params)
-{
-  static GObject *self = NULL;
-
-  if (self == NULL)
-    {
-      self = G_OBJECT_CLASS (photos_source_manager_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_source_manager_dispose (GObject *object)
 {
@@ -183,14 +163,13 @@ photos_source_manager_class_init (PhotosSourceManagerClass *class)
   GObjectClass *object_class = G_OBJECT_CLASS (class);
   PhotosBaseManagerClass *base_manager_class = PHOTOS_BASE_MANAGER_CLASS (class);
 
-  object_class->constructor = photos_source_manager_constructor;
   object_class->dispose = photos_source_manager_dispose;
   base_manager_class->get_filter = photos_source_manager_get_filter;
 }
 
 
 PhotosBaseManager *
-photos_source_manager_dup_singleton (void)
+photos_source_manager_new (void)
 {
   return g_object_new (PHOTOS_TYPE_SOURCE_MANAGER, "title", _("Sources"), NULL);
 }
diff --git a/src/photos-source-manager.h b/src/photos-source-manager.h
index 4dff9ac..e764ee8 100644
--- a/src/photos-source-manager.h
+++ b/src/photos-source-manager.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
@@ -68,7 +68,7 @@ struct _PhotosSourceManagerClass
 
 GType                     photos_source_manager_get_type           (void) G_GNUC_CONST;
 
-PhotosBaseManager        *photos_source_manager_dup_singleton      (void);
+PhotosBaseManager        *photos_source_manager_new                (void);
 
 GList                    *photos_source_manager_get_for_provider_type (PhotosSourceManager *self,
                                                                        const gchar *provider_type);
diff --git a/src/photos-tracker-collections-controller.c b/src/photos-tracker-collections-controller.c
index 120f45f..2776501 100644
--- a/src/photos-tracker-collections-controller.c
+++ b/src/photos-tracker-collections-controller.c
@@ -21,10 +21,13 @@
 
 #include "config.h"
 
-#include "photos-collection-manager.h"
+#include <gio/gio.h>
+
+#include "photos-base-manager.h"
 #include "photos-mode-controller.h"
 #include "photos-offset-collections-controller.h"
 #include "photos-query-builder.h"
+#include "photos-search-context.h"
 #include "photos-tracker-collections-controller.h"
 
 
@@ -67,7 +70,9 @@ photos_tracker_collections_controller_get_query (PhotosTrackerController *trk_cn
 {
   PhotosTrackerCollectionsController *self = PHOTOS_TRACKER_COLLECTIONS_CONTROLLER (trk_cntrlr);
   PhotosTrackerCollectionsControllerPrivate *priv = self->priv;
+  GApplication *app;
   GObject *collection;
+  PhotosSearchContextState *state;
   gint flags;
 
   collection = photos_base_manager_get_active_object (priv->col_mngr);
@@ -76,7 +81,10 @@ photos_tracker_collections_controller_get_query (PhotosTrackerController *trk_cn
   else
     flags = PHOTOS_QUERY_FLAGS_COLLECTIONS;
 
-  return photos_query_builder_global_query (flags, priv->offset_cntrlr);
+  app = g_application_get_default ();
+  state = photos_search_context_get_state (PHOTOS_SEARCH_CONTEXT (app));
+
+  return photos_query_builder_global_query (state, flags, priv->offset_cntrlr);
 }
 
 
@@ -118,11 +126,16 @@ static void
 photos_tracker_collections_controller_init (PhotosTrackerCollectionsController *self)
 {
   PhotosTrackerCollectionsControllerPrivate *priv;
+  GApplication *app;
+  PhotosSearchContextState *state;
 
   self->priv = photos_tracker_collections_controller_get_instance_private (self);
   priv = self->priv;
 
-  priv->col_mngr = photos_collection_manager_dup_singleton ();
+  app = g_application_get_default ();
+  state = photos_search_context_get_state (PHOTOS_SEARCH_CONTEXT (app));
+
+  priv->col_mngr = g_object_ref (state->col_mngr);
   g_signal_connect_swapped (priv->col_mngr,
                             "active-changed",
                             G_CALLBACK (photos_tracker_collections_controller_col_active_changed),
diff --git a/src/photos-tracker-controller.c b/src/photos-tracker-controller.c
index f13a713..ced4a70 100644
--- a/src/photos-tracker-controller.c
+++ b/src/photos-tracker-controller.c
@@ -28,13 +28,16 @@
 #include <glib.h>
 #include <glib/gi18n.h>
 
+#include <gio/gio.h>
+
+#include "photos-base-manager.h"
 #include "photos-enums.h"
 #include "photos-filterable.h"
 #include "photos-item-manager.h"
 #include "photos-marshalers.h"
 #include "photos-mode-controller.h"
 #include "photos-query-builder.h"
-#include "photos-source-manager.h"
+#include "photos-search-context.h"
 #include "photos-tracker-controller.h"
 #include "photos-tracker-queue.h"
 
@@ -371,14 +374,19 @@ static void
 photos_tracker_controller_init (PhotosTrackerController *self)
 {
   PhotosTrackerControllerPrivate *priv;
+  GApplication *app;
+  PhotosSearchContextState *state;
 
   self->priv = photos_tracker_controller_get_instance_private (self);
   priv = self->priv;
 
+  app = g_application_get_default ();
+  state = photos_search_context_get_state (PHOTOS_SEARCH_CONTEXT (app));
+
   priv->cancellable = g_cancellable_new ();
   priv->item_mngr = photos_item_manager_dup_singleton ();
 
-  priv->src_mngr = photos_source_manager_dup_singleton ();
+  priv->src_mngr = g_object_ref (state->src_mngr);
   g_signal_connect_swapped (priv->src_mngr,
                             "object-added",
                             G_CALLBACK (photos_tracker_controller_source_object_added_removed),
diff --git a/src/photos-tracker-favorites-controller.c b/src/photos-tracker-favorites-controller.c
index 24795c1..a3a86cc 100644
--- a/src/photos-tracker-favorites-controller.c
+++ b/src/photos-tracker-favorites-controller.c
@@ -21,10 +21,13 @@
 
 #include "config.h"
 
-#include "photos-collection-manager.h"
+#include <gio/gio.h>
+
+#include "photos-base-manager.h"
 #include "photos-mode-controller.h"
 #include "photos-offset-favorites-controller.h"
 #include "photos-query-builder.h"
+#include "photos-search-context.h"
 #include "photos-tracker-favorites-controller.h"
 
 
@@ -67,7 +70,9 @@ photos_tracker_favorites_controller_get_query (PhotosTrackerController *trk_cntr
 {
   PhotosTrackerFavoritesController *self = PHOTOS_TRACKER_FAVORITES_CONTROLLER (trk_cntrlr);
   PhotosTrackerFavoritesControllerPrivate *priv = self->priv;
+  GApplication *app;
   GObject *collection;
+  PhotosSearchContextState *state;
   gint flags;
 
   collection = photos_base_manager_get_active_object (priv->col_mngr);
@@ -76,7 +81,10 @@ photos_tracker_favorites_controller_get_query (PhotosTrackerController *trk_cntr
   else
     flags = PHOTOS_QUERY_FLAGS_FAVORITES;
 
-  return photos_query_builder_global_query (flags, priv->offset_cntrlr);
+  app = g_application_get_default ();
+  state = photos_search_context_get_state (PHOTOS_SEARCH_CONTEXT (app));
+
+  return photos_query_builder_global_query (state, flags, priv->offset_cntrlr);
 }
 
 
@@ -118,11 +126,16 @@ static void
 photos_tracker_favorites_controller_init (PhotosTrackerFavoritesController *self)
 {
   PhotosTrackerFavoritesControllerPrivate *priv;
+  GApplication *app;
+  PhotosSearchContextState *state;
 
   self->priv = photos_tracker_favorites_controller_get_instance_private (self);
   priv = self->priv;
 
-  priv->col_mngr = photos_collection_manager_dup_singleton ();
+  app = g_application_get_default ();
+  state = photos_search_context_get_state (PHOTOS_SEARCH_CONTEXT (app));
+
+  priv->col_mngr = g_object_ref (state->col_mngr);
   g_signal_connect_swapped (priv->col_mngr,
                             "active-changed",
                             G_CALLBACK (photos_tracker_favorites_controller_col_active_changed),
diff --git a/src/photos-tracker-overview-controller.c b/src/photos-tracker-overview-controller.c
index 3cb7dfe..4a01c5e 100644
--- a/src/photos-tracker-overview-controller.c
+++ b/src/photos-tracker-overview-controller.c
@@ -25,9 +25,12 @@
 
 #include "config.h"
 
+#include <gio/gio.h>
+
 #include "photos-mode-controller.h"
 #include "photos-offset-overview-controller.h"
 #include "photos-query-builder.h"
+#include "photos-search-context.h"
 #include "photos-tracker-overview-controller.h"
 
 
@@ -54,7 +57,13 @@ static PhotosQuery *
 photos_tracker_overview_controller_get_query (PhotosTrackerController *trk_cntrlr)
 {
   PhotosTrackerOverviewController *self = PHOTOS_TRACKER_OVERVIEW_CONTROLLER (trk_cntrlr);
-  return photos_query_builder_global_query (PHOTOS_QUERY_FLAGS_OVERVIEW, self->priv->offset_cntrlr);
+  GApplication *app;
+  PhotosSearchContextState *state;
+
+  app = g_application_get_default ();
+  state = photos_search_context_get_state (PHOTOS_SEARCH_CONTEXT (app));
+
+  return photos_query_builder_global_query (state, PHOTOS_QUERY_FLAGS_OVERVIEW, self->priv->offset_cntrlr);
 }
 
 
diff --git a/src/photos-tracker-search-controller.c b/src/photos-tracker-search-controller.c
index c764502..eaa4498 100644
--- a/src/photos-tracker-search-controller.c
+++ b/src/photos-tracker-search-controller.c
@@ -25,14 +25,14 @@
 
 #include "config.h"
 
-#include "photos-collection-manager.h"
+#include <gio/gio.h>
+
+#include "photos-base-manager.h"
 #include "photos-mode-controller.h"
 #include "photos-offset-search-controller.h"
 #include "photos-query-builder.h"
+#include "photos-search-context.h"
 #include "photos-search-controller.h"
-#include "photos-search-match-manager.h"
-#include "photos-search-type-manager.h"
-#include "photos-source-manager.h"
 #include "photos-tracker-search-controller.h"
 
 
@@ -78,7 +78,13 @@ static PhotosQuery *
 photos_tracker_search_controller_get_query (PhotosTrackerController *trk_cntrlr)
 {
   PhotosTrackerSearchController *self = PHOTOS_TRACKER_SEARCH_CONTROLLER (trk_cntrlr);
-  return photos_query_builder_global_query (PHOTOS_QUERY_FLAGS_SEARCH, self->priv->offset_cntrlr);
+  GApplication *app;
+  PhotosSearchContextState *state;
+
+  app = g_application_get_default ();
+  state = photos_search_context_get_state (PHOTOS_SEARCH_CONTEXT (app));
+
+  return photos_query_builder_global_query (state, PHOTOS_QUERY_FLAGS_SEARCH, self->priv->offset_cntrlr);
 }
 
 
@@ -137,29 +143,34 @@ static void
 photos_tracker_search_controller_init (PhotosTrackerSearchController *self)
 {
   PhotosTrackerSearchControllerPrivate *priv;
+  GApplication *app;
+  PhotosSearchContextState *state;
 
   self->priv = photos_tracker_search_controller_get_instance_private (self);
   priv = self->priv;
 
-  priv->col_mngr = photos_collection_manager_dup_singleton ();
+  app = g_application_get_default ();
+  state = photos_search_context_get_state (PHOTOS_SEARCH_CONTEXT (app));
+
+  priv->col_mngr = g_object_ref (state->col_mngr);
   g_signal_connect_swapped (priv->col_mngr,
                             "active-changed",
                             G_CALLBACK (photos_tracker_search_controller_col_active_changed),
                             self);
 
-  priv->src_mngr = photos_source_manager_dup_singleton ();
+  priv->src_mngr = g_object_ref (state->src_mngr);
   g_signal_connect_swapped (priv->src_mngr,
                             "active-changed",
                             G_CALLBACK (photos_tracker_controller_refresh_for_object),
                             self);
 
-  priv->srch_mtch_mngr = photos_search_match_manager_dup_singleton ();
+  priv->srch_mtch_mngr = g_object_ref (state->srch_mtch_mngr);
   g_signal_connect_swapped (priv->srch_mtch_mngr,
                             "active-changed",
                             G_CALLBACK (photos_tracker_search_controller_search_match_active_changed),
                             self);
 
-  priv->srch_typ_mngr = photos_search_type_manager_dup_singleton ();
+  priv->srch_typ_mngr = g_object_ref (state->srch_typ_mngr);
   g_signal_connect_swapped (priv->srch_typ_mngr,
                             "active-changed",
                             G_CALLBACK (photos_tracker_controller_refresh_for_object),
@@ -168,7 +179,7 @@ photos_tracker_search_controller_init (PhotosTrackerSearchController *self)
   priv->mode_cntrlr = photos_mode_controller_dup_singleton ();
   priv->offset_cntrlr = photos_offset_search_controller_dup_singleton ();
 
-  priv->srch_cntrlr = photos_search_controller_dup_singleton ();
+  priv->srch_cntrlr = g_object_ref (state->srch_cntrlr);
   g_signal_connect_swapped (priv->srch_cntrlr,
                             "search-string-changed",
                             G_CALLBACK (photos_tracker_controller_refresh_for_object),
diff --git a/src/photos-update-mtime-job.c b/src/photos-update-mtime-job.c
index 7234362..fd9b10f 100644
--- a/src/photos-update-mtime-job.c
+++ b/src/photos-update-mtime-job.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
@@ -25,12 +25,14 @@
 
 #include "config.h"
 
+#include <gio/gio.h>
 #include <glib.h>
 #include <tracker-sparql.h>
 
 #include "photos-query.h"
 #include "photos-query-builder.h"
 #include "photos-update-mtime-job.h"
+#include "photos-search-context.h"
 #include "photos-tracker-queue.h"
 
 
@@ -160,7 +162,9 @@ photos_update_mtime_job_run (PhotosUpdateMtimeJob *self,
                              gpointer user_data)
 {
   PhotosUpdateMtimeJobPrivate *priv = self->priv;
+  GApplication *app;
   PhotosQuery *query;
+  PhotosSearchContextState *state;
 
   if (G_UNLIKELY (priv->queue == NULL))
     {
@@ -172,7 +176,10 @@ photos_update_mtime_job_run (PhotosUpdateMtimeJob *self,
   priv->callback = callback;
   priv->user_data = user_data;
 
-  query = photos_query_builder_update_mtime_query (priv->urn);
+  app = g_application_get_default ();
+  state = photos_search_context_get_state (PHOTOS_SEARCH_CONTEXT (app));
+
+  query = photos_query_builder_update_mtime_query (state, priv->urn);
   photos_tracker_queue_update (priv->queue,
                                query->sparql,
                                NULL,
diff --git a/src/photos-view-model.c b/src/photos-view-model.c
index d9ea4cc..3a9575e 100644
--- a/src/photos-view-model.c
+++ b/src/photos-view-model.c
@@ -25,7 +25,9 @@
 
 #include "config.h"
 
-#include "photos-collection-manager.h"
+#include <gio/gio.h>
+
+#include "photos-base-manager.h"
 #include "photos-enums.h"
 #include "photos-filterable.h"
 #include "photos-item-manager.h"
@@ -34,6 +36,7 @@
 #include "photos-offset-favorites-controller.h"
 #include "photos-offset-overview-controller.h"
 #include "photos-offset-search-controller.h"
+#include "photos-search-context.h"
 #include "photos-tracker-collections-controller.h"
 #include "photos-tracker-favorites-controller.h"
 #include "photos-tracker-overview-controller.h"
@@ -417,6 +420,7 @@ static void
 photos_view_model_init (PhotosViewModel *self)
 {
   PhotosViewModelPrivate *priv;
+  GApplication *app;
   GType columns[] = {G_TYPE_STRING,    /* URN */
                      G_TYPE_STRING,    /* URI */
                      G_TYPE_STRING,    /* NAME */
@@ -425,14 +429,18 @@ photos_view_model_init (PhotosViewModel *self)
                      G_TYPE_INT64,     /* MTIME */
                      G_TYPE_BOOLEAN,   /* STATE */
                      G_TYPE_UINT};     /* PULSE (unused) */
+  PhotosSearchContextState *state;
 
   self->priv = photos_view_model_get_instance_private (self);
   priv = self->priv;
 
+  app = g_application_get_default ();
+  state = photos_search_context_get_state (PHOTOS_SEARCH_CONTEXT (app));
+
   gtk_list_store_set_column_types (GTK_LIST_STORE (self), sizeof (columns) / sizeof (columns[0]), columns);
   gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (self), PHOTOS_VIEW_MODEL_MTIME, 
GTK_SORT_DESCENDING);
 
-  priv->col_mngr = photos_collection_manager_dup_singleton ();
+  priv->col_mngr = g_object_ref (state->col_mngr);
   priv->item_mngr = photos_item_manager_dup_singleton ();
   priv->mode_cntrlr = photos_mode_controller_dup_singleton ();
 


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