[gnome-photos/wip/search: 24/35] base-manager: Make get_filter a virtual method
- From: Debarshi Ray <debarshir src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-photos/wip/search: 24/35] base-manager: Make get_filter a virtual method
- Date: Tue, 28 Jan 2014 17:50:39 +0000 (UTC)
commit df550ca0a453062be49874a749d645db431c8a85
Author: Debarshi Ray <debarshir gnome org>
Date: Fri Jan 24 16:11:43 2014 +0100
base-manager: Make get_filter a virtual method
... and make PhotosSearchTypeManager and PhotosSourceManager override
it. This is required for implementing a separate mode for showing the
search results. The filter should only be dynamic (based on the
current active object) in the search mode. Otherwise it should be
static.
Being able to tweak the filter based on the PhotosQueryFlags from the
individual managers lets do that.
src/photos-base-manager.c | 121 +++++++++++++++++--------------------
src/photos-base-manager.h | 5 +-
src/photos-query-builder.c | 26 +--------
src/photos-search-type-manager.c | 30 +++++++++
src/photos-source-manager.c | 29 +++++++++-
5 files changed, 120 insertions(+), 91 deletions(-)
---
diff --git a/src/photos-base-manager.c b/src/photos-base-manager.c
index 54b163f..eb6b468 100644
--- a/src/photos-base-manager.c
+++ b/src/photos-base-manager.c
@@ -60,6 +60,13 @@ G_DEFINE_TYPE_WITH_PRIVATE (PhotosBaseManager, photos_base_manager, G_TYPE_OBJEC
static gchar *
+photos_base_manager_default_get_filter (PhotosBaseManager *self, gint flags)
+{
+ return g_strdup ("(true)");
+}
+
+
+static gchar *
photos_base_manager_default_get_where (PhotosBaseManager *self, gint flags)
{
return g_strdup ("");
@@ -85,59 +92,6 @@ photos_base_manager_default_set_active_object (PhotosBaseManager *self, GObject
}
-static gchar *
-photos_base_manager_get_all_filter (PhotosBaseManager *self)
-{
- GList *l;
- GList *values;
- const gchar *blank = "(true)";
- gchar *filter;
- gchar **strv;
- gchar *tmp;
- guint i;
- guint length;
-
- values = g_hash_table_get_values (self->priv->objects);
- length = g_list_length (values);
- strv = (gchar **) g_malloc0_n (length + 1, sizeof (gchar *));
-
- for (i = 0, l = values; l != NULL; l = l->next)
- {
- gchar *id;
-
- g_object_get (l->data, "id", &id, NULL);
- if (g_strcmp0 (id, "all") != 0)
- {
- gchar *str;
-
- str = photos_filterable_get_filter (PHOTOS_FILTERABLE (l->data));
- if (g_strcmp0 (str, blank) == 0)
- g_free (str);
- else
- {
- strv[i] = str;
- i++;
- }
- }
- g_free (id);
- }
-
- length = g_strv_length (strv);
- if (length == 0)
- strv[0] = g_strdup (blank);
-
- filter = g_strjoinv (" || ", strv);
- g_strfreev (strv);
-
- tmp = filter;
- filter = g_strconcat ("(", filter, ")", NULL);
- g_free (tmp);
-
- g_list_free (values);
- return filter;
-}
-
-
static void
photos_base_manager_dispose (GObject *object)
{
@@ -205,6 +159,7 @@ photos_base_manager_class_init (PhotosBaseManagerClass *class)
object_class->dispose = photos_base_manager_dispose;
object_class->finalize = photos_base_manager_finalize;
object_class->set_property = photos_base_manager_set_property;
+ class->get_filter = photos_base_manager_default_get_filter;
class->get_where = photos_base_manager_default_get_where;
class->set_active_object = photos_base_manager_default_set_active_object;
@@ -303,29 +258,65 @@ photos_base_manager_get_active_object (PhotosBaseManager *self)
gchar *
-photos_base_manager_get_filter (PhotosBaseManager *self)
+photos_base_manager_get_all_filter (PhotosBaseManager *self)
{
- PhotosBaseManagerPrivate *priv = self->priv;
+ GList *l;
+ GList *values;
const gchar *blank = "(true)";
gchar *filter;
- gchar *id;
+ gchar **strv;
+ gchar *tmp;
+ guint i;
+ guint length;
- if (priv->active_object == NULL)
- return g_strdup (blank);
+ values = g_hash_table_get_values (self->priv->objects);
+ length = g_list_length (values);
+ strv = (gchar **) g_malloc0_n (length + 1, sizeof (gchar *));
- g_return_val_if_fail (PHOTOS_IS_FILTERABLE (priv->active_object), g_strdup (blank));
+ for (i = 0, l = values; l != NULL; l = l->next)
+ {
+ gchar *id;
- g_object_get (priv->active_object, "id", &id, NULL);
- if (g_strcmp0 (id, "all") == 0)
- filter = photos_base_manager_get_all_filter (self);
- else
- filter = photos_filterable_get_filter (PHOTOS_FILTERABLE (priv->active_object));
+ g_object_get (l->data, "id", &id, NULL);
+ if (g_strcmp0 (id, "all") != 0)
+ {
+ gchar *str;
- g_free (id);
+ str = photos_filterable_get_filter (PHOTOS_FILTERABLE (l->data));
+ if (g_strcmp0 (str, blank) == 0)
+ g_free (str);
+ else
+ {
+ strv[i] = str;
+ i++;
+ }
+ }
+ g_free (id);
+ }
+
+ length = g_strv_length (strv);
+ if (length == 0)
+ strv[0] = g_strdup (blank);
+
+ filter = g_strjoinv (" || ", strv);
+ g_strfreev (strv);
+
+ tmp = filter;
+ filter = g_strconcat ("(", filter, ")", NULL);
+ g_free (tmp);
+
+ g_list_free (values);
return filter;
}
+gchar *
+photos_base_manager_get_filter (PhotosBaseManager *self, gint flags)
+{
+ return PHOTOS_BASE_MANAGER_GET_CLASS (self)->get_filter (self, flags);
+}
+
+
GObject *
photos_base_manager_get_object_by_id (PhotosBaseManager *self, const gchar *id)
{
diff --git a/src/photos-base-manager.h b/src/photos-base-manager.h
index 2e0cfcd..21b696d 100644
--- a/src/photos-base-manager.h
+++ b/src/photos-base-manager.h
@@ -66,6 +66,7 @@ struct _PhotosBaseManagerClass
GObjectClass parent_class;
/* virtual methods */
+ gchar *(*get_filter) (PhotosBaseManager *self, gint flags);
gchar *(*get_where) (PhotosBaseManager *self, gint flags);
gboolean (*set_active_object) (PhotosBaseManager *self, GObject *object);
@@ -84,7 +85,9 @@ void photos_base_manager_clear (PhotosBaseMana
GObject *photos_base_manager_get_active_object (PhotosBaseManager *self);
-gchar *photos_base_manager_get_filter (PhotosBaseManager *self);
+gchar *photos_base_manager_get_all_filter (PhotosBaseManager *self);
+
+gchar *photos_base_manager_get_filter (PhotosBaseManager *self, gint flags);
GObject *photos_base_manager_get_object_by_id (PhotosBaseManager *self, const gchar *id);
diff --git a/src/photos-query-builder.c b/src/photos-query-builder.c
index fb78eb7..28b925d 100644
--- a/src/photos-query-builder.c
+++ b/src/photos-query-builder.c
@@ -51,26 +51,6 @@ photos_query_builder_convert_path_to_uri (const gchar *path)
}
-static void
-photos_query_builder_set_search_type (gint flags)
-{
- PhotosBaseManager *srch_typ_mngr;
-
- srch_typ_mngr = photos_search_type_manager_dup_singleton ();
-
- if (flags & PHOTOS_QUERY_FLAGS_COLLECTIONS)
- photos_base_manager_set_active_object_by_id (srch_typ_mngr, PHOTOS_SEARCH_TYPE_STOCK_COLLECTIONS);
- else if (flags & PHOTOS_QUERY_FLAGS_FAVORITES)
- photos_base_manager_set_active_object_by_id (srch_typ_mngr, PHOTOS_SEARCH_TYPE_STOCK_FAVORITES);
- else if (flags & PHOTOS_QUERY_FLAGS_OVERVIEW)
- photos_base_manager_set_active_object_by_id (srch_typ_mngr, PHOTOS_SEARCH_TYPE_STOCK_PHOTOS);
- else
- photos_base_manager_set_active_object_by_id (srch_typ_mngr, PHOTOS_SEARCH_TYPE_STOCK_ALL);
-
- g_object_unref (srch_typ_mngr);
-}
-
-
static gchar *
photos_query_builder_filter (gint flags)
{
@@ -81,15 +61,13 @@ photos_query_builder_filter (gint flags)
gchar *srch_typ_mngr_filter;
src_mngr = photos_source_manager_dup_singleton ();
- src_mngr_filter = photos_base_manager_get_filter (src_mngr);
+ src_mngr_filter = photos_base_manager_get_filter (src_mngr, flags);
srch_typ_mngr = photos_search_type_manager_dup_singleton ();
- photos_query_builder_set_search_type (flags);
- srch_typ_mngr_filter = photos_base_manager_get_filter (srch_typ_mngr);
+ srch_typ_mngr_filter = photos_base_manager_get_filter (srch_typ_mngr, flags);
sparql = g_strdup_printf ("FILTER (%s && %s)", src_mngr_filter, srch_typ_mngr_filter);
- photos_query_builder_set_search_type (PHOTOS_QUERY_FLAGS_NONE);
g_free (srch_typ_mngr_filter);
g_object_unref (srch_typ_mngr);
diff --git a/src/photos-search-type-manager.c b/src/photos-search-type-manager.c
index 461b695..a4e3492 100644
--- a/src/photos-search-type-manager.c
+++ b/src/photos-search-type-manager.c
@@ -38,6 +38,35 @@ G_DEFINE_TYPE (PhotosSearchTypeManager, photos_search_type_manager, PHOTOS_TYPE_
static gchar *
+photos_search_type_manager_get_filter (PhotosBaseManager *mngr, gint flags)
+{
+ GObject *search_type;
+ gchar *filter;
+ gchar *id;
+
+ if (flags & PHOTOS_QUERY_FLAGS_COLLECTIONS)
+ search_type = photos_base_manager_get_object_by_id (mngr, PHOTOS_SEARCH_TYPE_STOCK_COLLECTIONS);
+ else if (flags & PHOTOS_QUERY_FLAGS_FAVORITES)
+ search_type = photos_base_manager_get_object_by_id (mngr, PHOTOS_SEARCH_TYPE_STOCK_FAVORITES);
+ else if (flags & PHOTOS_QUERY_FLAGS_OVERVIEW)
+ search_type = photos_base_manager_get_object_by_id (mngr, PHOTOS_SEARCH_TYPE_STOCK_PHOTOS);
+ else if (flags & PHOTOS_QUERY_FLAGS_SEARCH)
+ search_type = photos_base_manager_get_active_object (mngr);
+ else
+ search_type = photos_base_manager_get_object_by_id (mngr, PHOTOS_SEARCH_TYPE_STOCK_ALL);
+
+ g_object_get (search_type, "id", &id, NULL);
+ if (g_strcmp0 (id, PHOTOS_SEARCH_TYPE_STOCK_ALL) == 0)
+ filter = photos_base_manager_get_all_filter (mngr);
+ else
+ filter = photos_filterable_get_filter (PHOTOS_FILTERABLE (search_type));
+
+ g_free (id);
+ return filter;
+}
+
+
+static gchar *
photos_search_type_manager_get_where (PhotosBaseManager *mngr, gint flags)
{
GObject *search_type;
@@ -133,6 +162,7 @@ photos_search_type_manager_class_init (PhotosSearchTypeManagerClass *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;
}
diff --git a/src/photos-source-manager.c b/src/photos-source-manager.c
index a897a1b..5b357e0 100644
--- a/src/photos-source-manager.c
+++ b/src/photos-source-manager.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
@@ -29,6 +29,8 @@
#include <glib/gi18n.h>
#include <goa/goa.h>
+#include "photos-filterable.h"
+#include "photos-query.h"
#include "photos-source.h"
#include "photos-source-manager.h"
@@ -42,6 +44,29 @@ struct _PhotosSourceManagerPrivate
G_DEFINE_TYPE_WITH_PRIVATE (PhotosSourceManager, photos_source_manager, PHOTOS_TYPE_BASE_MANAGER);
+static gchar *
+photos_source_manager_get_filter (PhotosBaseManager *mngr, gint flags)
+{
+ GObject *source;
+ gchar *filter;
+ gchar *id;
+
+ if (flags & PHOTOS_QUERY_FLAGS_SEARCH)
+ source = photos_base_manager_get_active_object (mngr);
+ else
+ source = photos_base_manager_get_object_by_id (mngr, PHOTOS_SOURCE_STOCK_ALL);
+
+ g_object_get (source, "id", &id, NULL);
+ if (g_strcmp0 (id, PHOTOS_SOURCE_STOCK_ALL) == 0)
+ filter = photos_base_manager_get_all_filter (mngr);
+ else
+ filter = photos_filterable_get_filter (PHOTOS_FILTERABLE (source));
+
+ g_free (id);
+ return filter;
+}
+
+
static void
photos_source_manager_refresh_accounts (PhotosSourceManager *self)
{
@@ -157,9 +182,11 @@ static void
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;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]