[gnome-photos] Add PhotosTrackerController
- From: Debarshi Ray <debarshir src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-photos] Add PhotosTrackerController
- Date: Thu, 3 May 2012 22:40:39 +0000 (UTC)
commit bc9e570f115cb2e40814a6576dc39b04bbcb0ea0
Author: Debarshi Ray <debarshir gnome org>
Date: Fri May 4 00:39:41 2012 +0200
Add PhotosTrackerController
src/Makefile.am | 2 +
src/photos-tracker-controller.c | 366 +++++++++++++++++++++++++++++++++++++++
src/photos-tracker-controller.h | 75 ++++++++
3 files changed, 443 insertions(+), 0 deletions(-)
---
diff --git a/src/Makefile.am b/src/Makefile.am
index 68df3b9..61e9433 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -67,6 +67,8 @@ gnome_photos_SOURCES = \
photos-source.h \
photos-source-manager.c \
photos-source-manager.h \
+ photos-tracker-controller.c \
+ photos-tracker-controller.h \
photos-tracker-queue.c \
photos-tracker-queue.h \
photos-utils.c \
diff --git a/src/photos-tracker-controller.c b/src/photos-tracker-controller.c
new file mode 100644
index 0000000..eb3f4d5
--- /dev/null
+++ b/src/photos-tracker-controller.c
@@ -0,0 +1,366 @@
+/*
+ * 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 <glib.h>
+
+#include "photos-item-manager.h"
+#include "photos-offset-controller.h"
+#include "photos-query-builder.h"
+#include "photos-source-manager.h"
+#include "photos-tracker-controller.h"
+#include "photos-tracker-queue.h"
+
+
+struct _PhotosTrackerControllerPrivate
+{
+ GCancellable *cancellable;
+ PhotosBaseManager *item_mngr;
+ PhotosBaseManager *src_mngr;
+ PhotosOffsetController *offset_cntrlr;
+ PhotosQuery *current_query;
+ PhotosTrackerQueue *queue;
+ gboolean is_started;
+ gboolean query_queued;
+ gboolean querying;
+ gint query_queued_flags;
+ gint64 last_query_time;
+};
+
+enum
+{
+ QUERY_STATUS_CHANGED,
+ LAST_SIGNAL
+};
+
+static guint signals[LAST_SIGNAL] = { 0 };
+
+
+G_DEFINE_TYPE (PhotosTrackerController, photos_tracker_controller, G_TYPE_OBJECT);
+
+
+typedef enum
+{
+ PHOTOS_TRACKER_REFRESH_FLAGS_NONE = 0,
+ PHOTOS_TRACKER_REFRESH_FLAGS_RESET_OFFSET = 1 << 0
+} PhotosTrackerRefreshFlags;
+
+static void photos_tracker_controller_refresh_internal (PhotosTrackerController *self, gint flags);
+static void photos_tracker_controller_set_query_status (PhotosTrackerController *self, gboolean query_status);
+
+
+static void
+photos_tracker_controller_query_finished (PhotosTrackerController *self, GError *error)
+{
+ PhotosTrackerControllerPrivate *priv = self->priv;
+
+ photos_tracker_controller_set_query_status (self, FALSE);
+
+ /* TODO: print error,
+ * photos_offset_controller_reset_count (priv->offset_cntrlr)
+ */
+
+ if (priv->query_queued)
+ {
+ priv->query_queued = FALSE;
+ photos_tracker_controller_refresh_internal (self, priv->query_queued_flags);
+ }
+}
+
+
+static void
+photos_tracker_controller_cursor_next (GObject *source_object, GAsyncResult *res, gpointer user_data)
+{
+ PhotosTrackerController *self = PHOTOS_TRACKER_CONTROLLER (user_data);
+ PhotosTrackerControllerPrivate *priv = self->priv;
+ TrackerSparqlCursor *cursor = TRACKER_SPARQL_CURSOR (source_object);
+ gboolean valid;
+ gint64 now;
+
+ valid = tracker_sparql_cursor_next_finish (cursor, res, NULL); /* TODO: use GError */
+ if (!valid)
+ {
+ tracker_sparql_cursor_close (cursor);
+ photos_tracker_controller_query_finished (self, NULL);
+ g_object_unref (cursor);
+ g_object_unref (self);
+ return;
+ }
+
+ now = g_get_monotonic_time ();
+ g_debug ("Query Cursor: %" G_GINT64_FORMAT, (now - priv->last_query_time) / 1000000);
+
+ photos_item_manager_add_item (PHOTOS_ITEM_MANAGER (priv->item_mngr), cursor);
+ tracker_sparql_cursor_next_async (cursor,
+ priv->cancellable,
+ photos_tracker_controller_cursor_next,
+ self);
+}
+
+
+static void
+photos_tracker_controller_offset_changed (PhotosOffsetController *offset_cntrlr, gint offset, gpointer user_data)
+{
+}
+
+
+static void
+photos_tracker_controller_query_executed (GObject *source_object, GAsyncResult *res, gpointer user_data)
+{
+ PhotosTrackerController *self = PHOTOS_TRACKER_CONTROLLER (user_data);
+ TrackerSparqlConnection *connection = TRACKER_SPARQL_CONNECTION (source_object);
+ GError *error;
+ TrackerSparqlCursor *cursor;
+
+ error = NULL;
+ cursor = tracker_sparql_connection_query_finish (connection, res, &error);
+ if (error != NULL)
+ {
+ photos_tracker_controller_query_finished (self, error);
+ g_error_free (error);
+ return;
+ }
+
+ tracker_sparql_cursor_next_async (cursor,
+ self->priv->cancellable,
+ photos_tracker_controller_cursor_next,
+ g_object_ref (self));
+}
+
+
+static void
+photos_tracker_controller_perform_current_query (PhotosTrackerController *self)
+{
+ PhotosTrackerControllerPrivate *priv = self->priv;
+
+ if (priv->current_query != NULL)
+ photos_query_free (priv->current_query);
+
+ priv->current_query = photos_query_builder_global_query ();
+ g_cancellable_reset (priv->cancellable);
+
+ photos_tracker_queue_select (priv->queue,
+ priv->current_query->sparql,
+ priv->cancellable,
+ photos_tracker_controller_query_executed,
+ g_object_ref (self),
+ g_object_unref);
+}
+
+
+static void
+photos_tracker_controller_refresh_for_object (PhotosBaseManager *manager, GObject *object, gpointer user_data)
+{
+}
+
+
+static void
+photos_tracker_controller_set_query_status (PhotosTrackerController *self, gboolean query_status)
+{
+ PhotosTrackerControllerPrivate *priv = self->priv;
+ gint64 now;
+
+ if (priv->querying == query_status)
+ return;
+
+ now = g_get_monotonic_time ();
+ if (query_status)
+ priv->last_query_time = now;
+ else
+ {
+ g_debug ("Query Elapsed: %" G_GINT64_FORMAT, (now - priv->last_query_time) / 1000000);
+ priv->last_query_time = 0;
+ }
+
+ priv->querying = query_status;
+ g_signal_emit (self, signals[QUERY_STATUS_CHANGED], 0, priv->querying);
+}
+
+
+static void
+photos_tracker_controller_refresh_internal (PhotosTrackerController *self, gint flags)
+{
+ PhotosTrackerControllerPrivate *priv = self->priv;
+
+ priv->is_started = TRUE;
+
+ if (flags & PHOTOS_TRACKER_REFRESH_FLAGS_RESET_OFFSET)
+ photos_offset_controller_reset_offset (priv->offset_cntrlr);
+
+ if (photos_tracker_controller_get_query_status (self))
+ {
+ g_cancellable_cancel (priv->cancellable);
+ priv->query_queued = TRUE;
+ priv->query_queued_flags = flags;
+ return;
+ }
+
+ photos_tracker_controller_set_query_status (self, TRUE);
+ photos_base_manager_clear (priv->item_mngr);
+ photos_tracker_controller_perform_current_query (self);
+}
+
+
+static void
+photos_tracker_controller_source_object_added (PhotosBaseManager *manager, GObject *object, gpointer user_data)
+{
+}
+
+
+static void
+photos_tracker_controller_source_object_removed (PhotosBaseManager *manager, GObject *object, gpointer user_data)
+{
+}
+
+
+static GObject *
+photos_tracker_controller_constructor (GType type,
+ guint n_construct_params,
+ GObjectConstructParam *construct_params)
+{
+ static GObject *self = NULL;
+
+ if (self == NULL)
+ {
+ self = G_OBJECT_CLASS (photos_tracker_controller_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_tracker_controller_dispose (GObject *object)
+{
+ PhotosTrackerController *self = PHOTOS_TRACKER_CONTROLLER (object);
+ PhotosTrackerControllerPrivate *priv = self->priv;
+
+ g_clear_object (&priv->item_mngr);
+ g_clear_object (&priv->src_mngr);
+ g_clear_object (&priv->offset_cntrlr);
+ g_clear_object (&priv->queue);
+
+ G_OBJECT_CLASS (photos_tracker_controller_parent_class)->dispose (object);
+}
+
+
+static void
+photos_tracker_controller_finalize (GObject *object)
+{
+ PhotosTrackerController *self = PHOTOS_TRACKER_CONTROLLER (object);
+ PhotosTrackerControllerPrivate *priv = self->priv;
+
+ if (priv->current_query != NULL)
+ photos_query_free (priv->current_query);
+
+ G_OBJECT_CLASS (photos_tracker_controller_parent_class)->finalize (object);
+}
+
+
+static void
+photos_tracker_controller_init (PhotosTrackerController *self)
+{
+ PhotosTrackerControllerPrivate *priv;
+
+ self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self, PHOTOS_TYPE_TRACKER_CONTROLLER, PhotosTrackerControllerPrivate);
+ priv = self->priv;
+
+ priv->cancellable = g_cancellable_new ();
+ priv->item_mngr = photos_item_manager_new ();
+
+ priv->src_mngr = photos_source_manager_new ();
+ g_signal_connect (priv->src_mngr,
+ "object-added",
+ G_CALLBACK (photos_tracker_controller_source_object_added),
+ self);
+ g_signal_connect (priv->src_mngr,
+ "object-removed",
+ G_CALLBACK (photos_tracker_controller_source_object_removed),
+ self);
+ g_signal_connect (priv->src_mngr,
+ "active-changed",
+ G_CALLBACK (photos_tracker_controller_refresh_for_object),
+ self);
+
+ priv->offset_cntrlr = photos_offset_controller_new ();
+ g_signal_connect (priv->offset_cntrlr,
+ "offset-changed",
+ G_CALLBACK (photos_tracker_controller_offset_changed),
+ self);
+
+ priv->queue = photos_tracker_queue_new ();
+}
+
+
+static void
+photos_tracker_controller_class_init (PhotosTrackerControllerClass *class)
+{
+ GObjectClass *object_class = G_OBJECT_CLASS (class);
+
+ object_class->constructor = photos_tracker_controller_constructor;
+ object_class->dispose = photos_tracker_controller_dispose;
+ object_class->finalize = photos_tracker_controller_finalize;
+
+ signals[QUERY_STATUS_CHANGED] = g_signal_new ("query-status-changed",
+ G_TYPE_FROM_CLASS (class),
+ G_SIGNAL_RUN_LAST,
+ G_STRUCT_OFFSET (PhotosTrackerControllerClass,
+ query_status_changed),
+ NULL, /*accumulator */
+ NULL, /*accu_data */
+ g_cclosure_marshal_VOID__BOOLEAN,
+ G_TYPE_NONE,
+ 1,
+ G_TYPE_BOOLEAN);
+
+ g_type_class_add_private (class, sizeof (PhotosTrackerControllerPrivate));
+}
+
+
+PhotosTrackerController *
+photos_tracker_controller_new (void)
+{
+ return g_object_new (PHOTOS_TYPE_TRACKER_CONTROLLER, NULL);
+}
+
+
+void
+photos_tracker_controller_start (PhotosTrackerController *self)
+{
+ PhotosTrackerControllerPrivate *priv = self->priv;
+
+ if (priv->is_started)
+ return;
+
+ photos_tracker_controller_refresh_internal (self, PHOTOS_TRACKER_REFRESH_FLAGS_NONE);
+}
+
+
+gboolean
+photos_tracker_controller_get_query_status (PhotosTrackerController *self)
+{
+ return self->priv->querying;
+}
diff --git a/src/photos-tracker-controller.h b/src/photos-tracker-controller.h
new file mode 100644
index 0000000..c8bb489
--- /dev/null
+++ b/src/photos-tracker-controller.h
@@ -0,0 +1,75 @@
+/*
+ * 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.
+ */
+
+#ifndef PHOTOS_TRACKER_CONTROLLER_H
+#define PHOTOS_TRACKER_CONTROLLER_H
+
+#include <glib-object.h>
+
+G_BEGIN_DECLS
+
+#define PHOTOS_TYPE_TRACKER_CONTROLLER (photos_tracker_controller_get_type ())
+
+#define PHOTOS_TRACKER_CONTROLLER(obj) \
+ (G_TYPE_CHECK_INSTANCE_CAST ((obj), \
+ PHOTOS_TYPE_TRACKER_CONTROLLER, PhotosTrackerController))
+
+#define PHOTOS_TRACKER_CONTROLLER_CLASS(klass) \
+ (G_TYPE_CHECK_CLASS_CAST ((klass), \
+ PHOTOS_TYPE_TRACKER_CONTROLLER, PhotosTrackerControllerClass))
+
+#define PHOTOS_IS_TRACKER_CONTROLLER(obj) \
+ (G_TYPE_CHECK_INSTANCE_TYPE ((obj), \
+ PHOTOS_TYPE_TRACKER_CONTROLLER))
+
+#define PHOTOS_IS_TRACKER_CONTROLLER_CLASS(klass) \
+ (G_TYPE_CHECK_CLASS_TYPE ((klass), \
+ PHOTOS_TYPE_TRACKER_CONTROLLER))
+
+#define PHOTOS_TRACKER_CONTROLLER_GET_CLASS(obj) \
+ (G_TYPE_INSTANCE_GET_CLASS ((obj), \
+ PHOTOS_TYPE_TRACKER_CONTROLLER, PhotosTrackerControllerClass))
+
+typedef struct _PhotosTrackerController PhotosTrackerController;
+typedef struct _PhotosTrackerControllerClass PhotosTrackerControllerClass;
+typedef struct _PhotosTrackerControllerPrivate PhotosTrackerControllerPrivate;
+
+struct _PhotosTrackerController
+{
+ GObject parent_instance;
+ PhotosTrackerControllerPrivate *priv;
+};
+
+struct _PhotosTrackerControllerClass
+{
+ GObjectClass parent_class;
+
+ void (*query_status_changed) (PhotosTrackerController *self, gboolean querying);
+};
+
+GType photos_tracker_controller_get_type (void) G_GNUC_CONST;
+
+PhotosTrackerController *photos_tracker_controller_new (void);
+
+void photos_tracker_controller_start (PhotosTrackerController *self);
+
+G_END_DECLS
+
+#endif /* PHOTOS_TRACKER_CONTROLLER_H */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]