Commit cd2ba0c4 authored by Debarshi Ray's avatar Debarshi Ray

query-builder: Implement photos_query_builder_global_query

parent cf26885e
......@@ -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 \
......
......@@ -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)
{
......
......@@ -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
......
/*
* 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);
}
......@@ -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 */
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment