[gnome-photos] query-builder: Implement photos_query_builder_global_query



commit cd2ba0c4f371968f1062449c27a5a8ae01df4d1a
Author: Debarshi Ray <debarshir gnome org>
Date:   Wed May 2 23:28:17 2012 +0200

    query-builder: Implement photos_query_builder_global_query

 src/Makefile.am            |    1 +
 src/photos-query-builder.c |   82 ++++++++++++++++++++++++++++++++++++++++++++
 src/photos-query-builder.h |    4 ++-
 src/photos-query.c         |   52 ++++++++++++++++++++++++++++
 src/photos-query.h         |   23 ++++++++++++
 5 files changed, 161 insertions(+), 1 deletions(-)
---
diff --git a/src/Makefile.am b/src/Makefile.am
index 0ffe5e8..6dfd730 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -51,6 +51,7 @@ gnome_photos_SOURCES = \
 	photos-organize-collection-model.h \
 	photos-organize-collection-view.c \
 	photos-organize-collection-view.h \
+	photos-query.c \
 	photos-query.h \
 	photos-query-builder.h \
 	photos-query-builder.c \
diff --git a/src/photos-query-builder.c b/src/photos-query-builder.c
index c536003..9562584 100644
--- a/src/photos-query-builder.c
+++ b/src/photos-query-builder.c
@@ -23,6 +23,7 @@
 
 #include <gio/gio.h>
 
+#include "photos-offset-controller.h"
 #include "photos-query-builder.h"
 
 
@@ -43,6 +44,87 @@ photos_query_builder_convert_path_to_uri (const gchar *path)
 }
 
 
+static gchar *
+photos_query_builder_optional (void)
+{
+  return g_strdup ("OPTIONAL { ?urn nco:creator ?creater . } "
+                   "OPTIONAL { ?urn nco:publisher ?publisher . }");
+}
+
+
+static gchar *
+photos_query_builder_query (gboolean global, gint flags)
+{
+  gchar *global_sparql;
+  gchar *optional;
+  gchar *sparql;
+  gchar *tmp;
+
+  optional = photos_query_builder_optional ();
+  global_sparql = g_strconcat ("WHERE { ?urn a rdfs:Resource ", optional, NULL);
+
+  if (global)
+    {
+      PhotosOffsetController *offset_cntrlr;
+      gint offset;
+      gint step;
+
+      if (!(flags & PHOTOS_QUERY_FLAGS_UNFILTERED))
+        {
+        }
+
+      offset_cntrlr = photos_offset_controller_new ();
+      offset = photos_offset_controller_get_offset (offset_cntrlr);
+      step = photos_offset_controller_get_step (offset_cntrlr);
+      g_object_unref (offset_cntrlr);
+
+      tmp = global_sparql;
+      global_sparql = g_strdup_printf ("%s } ORDER BY DESC (?mtime) LIMIT %d OFFSET %d",
+                                       global_sparql,
+                                       step,
+                                       offset);
+      g_free (tmp);
+    }
+  else
+    {
+      if (!(flags & PHOTOS_QUERY_FLAGS_UNFILTERED))
+        {
+        }
+
+      tmp = global_sparql;
+      global_sparql = g_strconcat (global_sparql, " }", NULL);
+      g_free (tmp);
+    }
+
+  sparql = g_strconcat ("SELECT DISTINCT ?urn "
+                        "nie:url (?urn) "
+                        "nfo:fileName (?urn) "
+                        "nie:mimeType (?urn) "
+                        "nie:title (?urn) "
+                        "tracker:coalesce (nco:fullname (?creator), nco:fullname (?publisher), '') "
+                        "tracker:coalesce (nfo:fileLastModified (?urn), nie:contentLastModified (?urn)) AS ?mtime "
+                        "nao:identifier (?urn) "
+                        "rdf:type (?urn) "
+                        "nie:dataSource(?urn) "
+                        "( EXISTS { ?urn nao:hasTag nao:predefined-tag-favorite } ) "
+                        "( EXISTS { ?urn nco:contributor ?contributor FILTER ( ?contributor != ?creator ) } ) ",
+                        global_sparql,
+                        NULL);
+  g_free (global_sparql);
+  return sparql;
+}
+
+
+PhotosQuery *
+photos_query_builder_global_query (void)
+{
+  gchar *sparql;
+
+  sparql = photos_query_builder_query (TRUE, PHOTOS_QUERY_FLAGS_NONE);
+  return photos_query_new (sparql);
+}
+
+
 gchar *
 photos_query_builder_filter_local (void)
 {
diff --git a/src/photos-query-builder.h b/src/photos-query-builder.h
index e8083bd..b1fde82 100644
--- a/src/photos-query-builder.h
+++ b/src/photos-query-builder.h
@@ -21,10 +21,12 @@
 #ifndef PHOTOS_QUERY_BUILDER_H
 #define PHOTOS_QUERY_BUILDER_H
 
-#include <glib.h>
+#include "photos-query.h"
 
 G_BEGIN_DECLS
 
+PhotosQuery  *photos_query_builder_global_query        (void);
+
 gchar        *photos_query_builder_filter_local        (void);
 
 G_END_DECLS
diff --git a/src/photos-query.c b/src/photos-query.c
new file mode 100644
index 0000000..898d9b0
--- /dev/null
+++ b/src/photos-query.c
@@ -0,0 +1,52 @@
+/*
+ * Photos - access, organize and share your photos on GNOME
+ * Copyright  2012 Red Hat, Inc.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301, USA.
+ */
+
+
+#include "config.h"
+
+#include "photos-query.h"
+#include "photos-source-manager.h"
+
+
+PhotosQuery *
+photos_query_new (gchar *sparql)
+{
+  PhotosBaseManager *src_mngr;
+  PhotosQuery *query;
+
+  query = g_slice_new0 (PhotosQuery);
+
+  src_mngr = photos_source_manager_new ();
+  query->source = PHOTOS_SOURCE (photos_base_manager_get_active_object (src_mngr));
+  g_object_unref (src_mngr);
+
+  query->sparql = sparql;
+
+  return query;
+}
+
+
+void
+photos_query_free (PhotosQuery *query)
+{
+  g_object_unref (query->source);
+  g_free (query->sparql);
+  g_slice_free (PhotosQuery, query);
+}
diff --git a/src/photos-query.h b/src/photos-query.h
index e47c155..42fcaa6 100644
--- a/src/photos-query.h
+++ b/src/photos-query.h
@@ -21,6 +21,11 @@
 #ifndef PHOTOS_QUERY_H
 #define PHOTOS_QUERY_H
 
+#include <glib.h>
+
+#include "photos-query.h"
+#include "photos-source.h"
+
 G_BEGIN_DECLS
 
 typedef enum
@@ -39,6 +44,24 @@ typedef enum
   PHOTOS_QUERY_COLUMNS_RESOURCE_SHARED
 } PhotosQueryColumns;
 
+typedef enum
+{
+  PHOTOS_QUERY_FLAGS_NONE = 0,
+  PHOTOS_QUERY_FLAGS_UNFILTERED = 1 << 0
+} PhotosQueryFlags;
+
+typedef struct _PhotosQuery PhotosQuery;
+
+struct _PhotosQuery
+{
+  PhotosSource *source;
+  gchar *sparql;
+};
+
+PhotosQuery    *photos_query_new     (gchar *sparql);
+
+void            photos_query_free    (PhotosQuery *query);
+
 G_END_DECLS
 
 #endif /* PHOTOS_QUERY_H */



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