[gnome-photos/wip/search: 6/6] Add PhotosFetchMetasJob



commit ba268a69ea0221b67a97ad90739e0cb46309ea52
Author: Debarshi Ray <debarshir gnome org>
Date:   Sun Feb 9 13:37:40 2014 +0100

    Add PhotosFetchMetasJob

 src/Makefile.am              |    2 +
 src/photos-fetch-metas-job.c |  245 ++++++++++++++++++++++++++++++++++++++++++
 src/photos-fetch-metas-job.h |   81 ++++++++++++++
 3 files changed, 328 insertions(+), 0 deletions(-)
---
diff --git a/src/Makefile.am b/src/Makefile.am
index 9bcd65e..30b27f8 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -106,6 +106,8 @@ gnome_photos_SOURCES = \
        photos-fetch-collections-job.h \
        photos-fetch-ids-job.c \
        photos-fetch-ids-job.h \
+       photos-fetch-metas-job.c \
+       photos-fetch-metas-job.h \
        photos-filterable.c \
        photos-filterable.h \
        photos-flickr-item.c \
diff --git a/src/photos-fetch-metas-job.c b/src/photos-fetch-metas-job.c
new file mode 100644
index 0000000..fb16798
--- /dev/null
+++ b/src/photos-fetch-metas-job.c
@@ -0,0 +1,245 @@
+/*
+ * 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 <tracker-sparql.h>
+
+#include "photos-fetch-metas-job.h"
+#include "photos-query.h"
+#include "photos-query-builder.h"
+#include "photos-single-item-job.h"
+#include "photos-tracker-queue.h"
+
+
+struct _PhotosFetchMetasJobPrivate
+{
+  GPtrArray *ids;
+  PhotosFetchMetasJobCallback callback;
+  PhotosTrackerQueue *queue;
+  gchar **ids;
+  gpointer user_data;
+  guint active_jobs;
+};
+
+enum
+{
+  PROP_0,
+  PROP_IDS
+};
+
+
+G_DEFINE_TYPE_WITH_PRIVATE (PhotosFetchMetasJob, photos_fetch_metas_job, G_TYPE_OBJECT);
+
+
+static void
+photos_fetch_metas_job_emit_callback (PhotosFetchMetasJob *self)
+{
+  PhotosFetchMetasJobPrivate *priv = self->priv;
+
+  if (priv->callback == NULL)
+    return;
+
+  g_ptr_array_add (priv->ids, NULL);
+  (*priv->callback) ((const gchar *const *) priv->ids->pdata, priv->user_data);
+}
+
+
+static void
+photos_fetch_metas_job_cursor_next (GObject *source_object, GAsyncResult *res, gpointer user_data)
+{
+  PhotosFetchMetasJob *self = PHOTOS_FETCH_METAS_JOB (user_data);
+  PhotosFetchMetasJobPrivate *priv = self->priv;
+  TrackerSparqlCursor *cursor = TRACKER_SPARQL_CURSOR (source_object);
+  GError *error;
+  gboolean valid;
+  const gchar *id;
+
+  error = NULL;
+  valid = tracker_sparql_cursor_next_finish (cursor, res, &error);
+  if (error != NULL)
+    {
+      g_warning ("Unable to read results of FetchMetasJob: %s", error->message);
+      g_error_free (error);
+      goto end;
+    }
+  if(!valid)
+    goto end;
+
+  id = tracker_sparql_cursor_get_string (cursor, PHOTOS_QUERY_COLUMNS_URN, NULL);
+  g_ptr_array_add (priv->ids, g_strdup (id));
+
+  tracker_sparql_cursor_next_async (cursor, priv->cancellable, photos_fetch_metas_job_cursor_next, self);
+  return;
+
+ end:
+  photos_fetch_metas_job_emit_callback (self);
+  tracker_sparql_cursor_close (cursor);
+  g_object_unref (self);
+}
+
+
+static void
+photos_fetch_metas_job_query_executed (GObject *source_object, GAsyncResult *res, gpointer user_data)
+{
+  PhotosFetchMetasJob *self = PHOTOS_FETCH_METAS_JOB (user_data);
+  TrackerSparqlConnection *connection = TRACKER_SPARQL_CONNECTION (source_object);
+  TrackerSparqlCursor *cursor;
+  GError *error;
+
+  error = NULL;
+  cursor = tracker_sparql_connection_query_finish (connection, res, &error);
+  if (error != NULL)
+    {
+      g_warning ("Unable to run FetchMetasJob: %s", error->message);
+      g_error_free (error);
+      photos_fetch_metas_job_emit_callback (self);
+      return;
+    }
+
+  tracker_sparql_cursor_next_async (cursor,
+                                    self->priv->cancellable,
+                                    photos_fetch_metas_job_cursor_next,
+                                    g_object_ref (self));
+  g_object_unref (cursor);
+}
+
+
+static void
+photos_fetch_metas_job_dispose (GObject *object)
+{
+  PhotosFetchMetasJob *self = PHOTOS_FETCH_METAS_JOB (object);
+  PhotosFetchMetasJobPrivate *priv = self->priv;
+
+  //g_clear_pointer (&priv->ids, (GDestroyNotify) g_ptr_array_unref);
+  g_clear_object (&priv->queue);
+
+  G_OBJECT_CLASS (photos_fetch_metas_job_parent_class)->dispose (object);
+}
+
+
+static void
+photos_fetch_metas_job_finalize (GObject *object)
+{
+  PhotosFetchMetasJob *self = PHOTOS_FETCH_METAS_JOB (object);
+
+  g_strfreev (self->priv->ids);
+
+  G_OBJECT_CLASS (photos_fetch_metas_job_parent_class)->finalize (object);
+}
+
+
+static void
+photos_fetch_metas_job_set_property (GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec)
+{
+  PhotosFetchMetasJob *self = PHOTOS_FETCH_METAS_JOB (object);
+
+  switch (prop_id)
+    {
+    case PROP_IDS:
+      self->priv->ids = g_value_dup_boxed (value);
+      break;
+
+    default:
+      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+      break;
+    }
+}
+
+
+static void
+photos_fetch_metas_job_init (PhotosFetchMetasJob *self)
+{
+  PhotosFetchMetasJobPrivate *priv = self->priv;
+
+  self->priv = photos_fetch_metas_job_get_instance_private (self);
+  priv = self->priv;
+
+  //priv->ids = g_ptr_array_new_with_free_func (g_free);
+  priv->queue = photos_tracker_queue_dup_singleton (NULL, NULL);
+}
+
+
+static void
+photos_fetch_metas_job_class_init (PhotosFetchMetasJobClass *class)
+{
+  GObjectClass *object_class = G_OBJECT_CLASS (class);
+
+  object_class->dispose = photos_fetch_metas_job_dispose;
+  object_class->finalize = photos_fetch_metas_job_finalize;
+  object_class->set_property = photos_fetch_metas_job_set_property;
+
+  g_object_class_install_property (object_class,
+                                   PROP_IDS,
+                                   g_param_spec_boxed ("ids",
+                                                       "Identifiers",
+                                                       "Identifiers of items whose metadata is needed",
+                                                       G_TYPE_STRV,
+                                                       G_PARAM_CONSTRUCT_ONLY | G_PARAM_WRITABLE));
+}
+
+
+PhotosFetchMetasJob *
+photos_fetch_metas_job_new (const gchar *const *ids)
+{
+  return g_object_new (PHOTOS_TYPE_FETCH_METAS_JOB, "ids", ids, NULL);
+}
+
+
+void
+photos_fetch_metas_job_run (PhotosFetchMetasJob *self, PhotosFetchMetasJobCallback callback, gpointer 
user_data)
+{
+  PhotosFetchMetasJobPrivate *priv = self->priv;
+  PhotosQuery *query;
+  guint i;
+
+  priv->callback = callback;
+  priv->user_data = user_data;
+
+  if (G_UNLIKELY (priv->queue == NULL))
+    {
+      photos_fetch_metas_job_emit_callback (self);
+      return;
+    }
+
+  priv->active_jobs = g_strv_length (priv->ids);
+
+  for (i = 0; priv->ids[i] != NULL; i++)
+    {
+      const gchar *id = priv->ids[i];
+    }
+
+  /* TODO: search controller */
+
+  query = photos_query_builder_global_query (PHOTOS_QUERY_FLAGS_NONE, NULL);
+  photos_tracker_queue_select (priv->queue,
+                               query->sparql,
+                               priv->cancellable,
+                               photos_fetch_metas_job_query_executed,
+                               g_object_ref (self),
+                               g_object_unref);
+  photos_query_free (query);
+}
diff --git a/src/photos-fetch-metas-job.h b/src/photos-fetch-metas-job.h
new file mode 100644
index 0000000..e51704b
--- /dev/null
+++ b/src/photos-fetch-metas-job.h
@@ -0,0 +1,81 @@
+/*
+ * 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_FETCH_METAS_JOB_H
+#define PHOTOS_FETCH_METAS_JOB_H
+
+#include <glib-object.h>
+
+G_BEGIN_DECLS
+
+#define PHOTOS_TYPE_FETCH_METAS_JOB (photos_fetch_metas_job_get_type ())
+
+#define PHOTOS_FETCH_METAS_JOB(obj) \
+  (G_TYPE_CHECK_INSTANCE_CAST ((obj), \
+   PHOTOS_TYPE_FETCH_METAS_JOB, PhotosFetchMetasJob))
+
+#define PHOTOS_FETCH_METAS_JOB_CLASS(klass) \
+  (G_TYPE_CHECK_CLASS_CAST ((klass), \
+   PHOTOS_TYPE_FETCH_METAS_JOB, PhotosFetchMetasJobClass))
+
+#define PHOTOS_IS_FETCH_METAS_JOB(obj) \
+  (G_TYPE_CHECK_INSTANCE_TYPE ((obj), \
+   PHOTOS_TYPE_FETCH_METAS_JOB))
+
+#define PHOTOS_IS_FETCH_METAS_JOB_CLASS(klass) \
+  (G_TYPE_CHECK_CLASS_TYPE ((klass), \
+   PHOTOS_TYPE_FETCH_METAS_JOB))
+
+#define PHOTOS_FETCH_METAS_JOB_GET_CLASS(obj) \
+  (G_TYPE_INSTANCE_GET_CLASS ((obj), \
+   PHOTOS_TYPE_FETCH_METAS_JOB, PhotosFetchMetasJobClass))
+
+typedef void (*PhotosFetchMetasJobCallback) (const gchar *const *, gpointer);
+
+typedef struct _PhotosFetchMetasJob        PhotosFetchMetasJob;
+typedef struct _PhotosFetchMetasJobClass   PhotosFetchMetasJobClass;
+typedef struct _PhotosFetchMetasJobPrivate PhotosFetchMetasJobPrivate;
+
+struct _PhotosFetchMetasJob
+{
+  GObject parent_instance;
+  PhotosFetchMetasJobPrivate *priv;
+};
+
+struct _PhotosFetchMetasJobClass
+{
+  GObjectClass parent_class;
+};
+
+GType                  photos_fetch_metas_job_get_type          (void) G_GNUC_CONST;
+
+PhotosFetchMetasJob   *photos_fetch_metas_job_new               (const gchar *const *ids);
+
+void                   photos_fetch_metas_job_run               (PhotosFetchMetasJob *self,
+                                                                 PhotosFetchMetasJobCallback callback,
+                                                                 gpointer user_data);
+
+G_END_DECLS
+
+#endif /* PHOTOS_FETCH_METAS_JOB_H */


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