[gnome-photos/wip/search: 26/35] Add PhotosSearchMatchManager
- From: Debarshi Ray <debarshir src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-photos/wip/search: 26/35] Add PhotosSearchMatchManager
- Date: Tue, 28 Jan 2014 17:50:49 +0000 (UTC)
commit 04a7bd407a4898d6801a7d4be14b3383ebbfb185
Author: Debarshi Ray <debarshir gnome org>
Date: Mon Jan 27 11:01:16 2014 +0100
Add PhotosSearchMatchManager
po/POTFILES.in | 1 +
src/Makefile.am | 2 +
src/photos-search-match-manager.c | 198 +++++++++++++++++++++++++++++++++++++
src/photos-search-match-manager.h | 75 ++++++++++++++
4 files changed, 276 insertions(+), 0 deletions(-)
---
diff --git a/po/POTFILES.in b/po/POTFILES.in
index 6e859e6..3a6ffc6 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -27,6 +27,7 @@ src/photos-preview-nav-buttons.c
src/photos-print-operation.c
src/photos-print-setup.c
src/photos-properties-dialog.c
+src/photos-search-match-manager.c
src/photos-search-type-manager.c
[type: gettext/glade]src/photos-selection-menu.ui
src/photos-selection-toolbar.c
diff --git a/src/Makefile.am b/src/Makefile.am
index cf634ea..dd7bdb9 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -170,6 +170,8 @@ gnome_photos_SOURCES = \
photos-search-controller.h \
photos-search-match.c \
photos-search-match.h \
+ photos-search-match-manager.c \
+ photos-search-match-manager.h \
photos-search-type.c \
photos-search-type.h \
photos-search-type-manager.c \
diff --git a/src/photos-search-match-manager.c b/src/photos-search-match-manager.c
new file mode 100644
index 0000000..cb0c475
--- /dev/null
+++ b/src/photos-search-match-manager.c
@@ -0,0 +1,198 @@
+/*
+ * Photos - access, organize and share your photos on GNOME
+ * 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
+ * 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 <glib/gi18n.h>
+
+#include "photos-filterable.h"
+#include "photos-query.h"
+#include "photos-search-controller.h"
+#include "photos-search-match.h"
+#include "photos-search-match-manager.h"
+
+
+struct _PhotosSearchMatchManagerPrivate
+{
+ PhotosSearchController *srch_cntrlr;
+};
+
+
+G_DEFINE_TYPE_WITH_PRIVATE (PhotosSearchMatchManager, photos_search_match_manager, PHOTOS_TYPE_BASE_MANAGER);
+
+
+static gchar *
+photos_search_match_manager_get_filter (PhotosBaseManager *mngr, gint flags)
+{
+ PhotosSearchMatchManager *self = PHOTOS_SEARCH_MATCH_MANAGER (mngr);
+ GHashTable *objects;
+ PhotosSearchMatch *search_match;
+ const gchar *blank = "(true)";
+ gchar *filter = NULL;
+ gchar *ret_val = NULL;
+ gchar **filters = NULL;
+ gchar **terms = NULL;
+ guint i;
+ guint n_terms;
+
+ if (!(flags & PHOTOS_QUERY_FLAGS_SEARCH))
+ goto out;
+
+ terms = photos_search_controller_get_terms (self->priv->srch_cntrlr);
+ n_terms = g_strv_length (terms);
+ if (n_terms == 0)
+ goto out;
+
+ objects = photos_base_manager_get_objects (PHOTOS_BASE_MANAGER (self));
+ filters = (gchar **) g_malloc0_n (n_terms + 1, sizeof (gchar *));
+
+ for (i = 0; terms[i] != NULL; i++)
+ {
+ GHashTableIter iter;
+ gchar *id;
+
+ g_hash_table_iter_init (&iter, objects);
+ while (g_hash_table_iter_next (&iter, NULL, (gpointer *) &search_match))
+ photos_search_match_set_filter_term (search_match, terms[i]);
+
+ search_match = PHOTOS_SEARCH_MATCH (photos_base_manager_get_active_object (PHOTOS_BASE_MANAGER
(self)));
+ g_object_get (search_match, "id", &id, NULL);
+ if (g_strcmp0 (id, PHOTOS_SEARCH_MATCH_STOCK_ALL) == 0)
+ filter = photos_base_manager_get_all_filter (PHOTOS_BASE_MANAGER (self));
+ else
+ filter = photos_filterable_get_filter (PHOTOS_FILTERABLE (search_match));
+
+ filters[i] = filter;
+ filter = NULL;
+ g_free (id);
+ }
+
+ filter = g_strjoinv (" && ", filters);
+ ret_val = g_strconcat ("(", filter, ")", NULL);
+
+ out:
+ g_free (filter);
+ g_strfreev (filters);
+ g_strfreev (terms);
+ return (ret_val == NULL) ? g_strdup (blank) : ret_val;
+}
+
+
+static GObject *
+photos_search_match_manager_constructor (GType type,
+ guint n_construct_params,
+ GObjectConstructParam *construct_params)
+{
+ static GObject *self = NULL;
+
+ 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;
+ }
+
+ return g_object_ref (self);
+}
+
+
+static void
+photos_search_match_manager_dispose (GObject *object)
+{
+ PhotosSearchMatchManager *self = PHOTOS_SEARCH_MATCH_MANAGER (object);
+
+ g_clear_object (&self->priv->srch_cntrlr);
+
+ G_OBJECT_CLASS (photos_search_match_manager_parent_class)->dispose (object);
+}
+
+
+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))),"
+ " \"%s\")";
+ title_filter = "fn:contains ("
+ " tracker:case-fold (tracker:coalesce (nie:title (?urn), nfo:fileName(?urn))),"
+ " \"%s\")";
+
+ search_match = photos_search_match_new (PHOTOS_SEARCH_MATCH_STOCK_ALL,
+ _("All"),
+ "(false)"); /* unused */
+ photos_base_manager_add_object (PHOTOS_BASE_MANAGER (self), G_OBJECT (search_match));
+ g_object_unref (search_match);
+
+ search_match = photos_search_match_new (PHOTOS_SEARCH_MATCH_STOCK_TITLE,
+ /* Translators: "Title" refers to "Match Title" when searching. */
+ C_("Search Filter", "Title"),
+ title_filter);
+ photos_base_manager_add_object (PHOTOS_BASE_MANAGER (self), G_OBJECT (search_match));
+ g_object_unref (search_match);
+
+ search_match = photos_search_match_new (PHOTOS_SEARCH_MATCH_STOCK_AUTHOR,
+ /* Translators: "Author" refers to "Match Author" when searching.
*/
+ C_("Search Filter", "Author"),
+ author_filter);
+ photos_base_manager_add_object (PHOTOS_BASE_MANAGER (self), G_OBJECT (search_match));
+ g_object_unref (search_match);
+
+ photos_base_manager_set_active_object_by_id (PHOTOS_BASE_MANAGER (self), PHOTOS_SEARCH_MATCH_STOCK_ALL);
+}
+
+
+static void
+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;
+ base_manager_class->get_filter = photos_search_match_manager_get_filter;
+}
+
+
+PhotosBaseManager *
+photos_search_match_manager_dup_singleton (void)
+{
+ /* 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);
+}
diff --git a/src/photos-search-match-manager.h b/src/photos-search-match-manager.h
new file mode 100644
index 0000000..04df7f0
--- /dev/null
+++ b/src/photos-search-match-manager.h
@@ -0,0 +1,75 @@
+/*
+ * Photos - access, organize and share your photos on GNOME
+ * 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
+ * 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_MATCH_MANAGER_H
+#define PHOTOS_SEARCH_MATCH_MANAGER_H
+
+#include "photos-base-manager.h"
+
+G_BEGIN_DECLS
+
+#define PHOTOS_TYPE_SEARCH_MATCH_MANAGER (photos_search_match_manager_get_type ())
+
+#define PHOTOS_SEARCH_MATCH_MANAGER(obj) \
+ (G_TYPE_CHECK_INSTANCE_CAST ((obj), \
+ PHOTOS_TYPE_SEARCH_MATCH_MANAGER, PhotosSearchMatchManager))
+
+#define PHOTOS_SEARCH_MATCH_MANAGER_CLASS(klass) \
+ (G_TYPE_CHECK_CLASS_CAST ((klass), \
+ PHOTOS_TYPE_SEARCH_MATCH_MANAGER, PhotosSearchMatchManagerClass))
+
+#define PHOTOS_IS_SEARCH_MATCH_MANAGER(obj) \
+ (G_TYPE_CHECK_INSTANCE_TYPE ((obj), \
+ PHOTOS_TYPE_SEARCH_MATCH_MANAGER))
+
+#define PHOTOS_IS_SEARCH_MATCH_MANAGER_CLASS(klass) \
+ (G_TYPE_CHECK_CLASS_TYPE ((klass), \
+ PHOTOS_TYPE_SEARCH_MATCH_MANAGER))
+
+#define PHOTOS_SEARCH_MATCH_MANAGER_GET_CLASS(obj) \
+ (G_TYPE_INSTANCE_GET_CLASS ((obj), \
+ PHOTOS_TYPE_SEARCH_MATCH_MANAGER, PhotosSearchMatchManagerClass))
+
+typedef struct _PhotosSearchMatchManager PhotosSearchMatchManager;
+typedef struct _PhotosSearchMatchManagerClass PhotosSearchMatchManagerClass;
+typedef struct _PhotosSearchMatchManagerPrivate PhotosSearchMatchManagerPrivate;
+
+struct _PhotosSearchMatchManager
+{
+ PhotosBaseManager parent_instance;
+ PhotosSearchMatchManagerPrivate *priv;
+};
+
+struct _PhotosSearchMatchManagerClass
+{
+ PhotosBaseManagerClass parent_class;
+};
+
+GType photos_search_match_manager_get_type (void) G_GNUC_CONST;
+
+PhotosBaseManager *photos_search_match_manager_dup_singleton (void);
+
+G_END_DECLS
+
+#endif /* PHOTOS_SEARCH_MATCH_MANAGER_H */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]