[gnome-photos] Add PhotosFetchCollectionStateJob
- From: Debarshi Ray <debarshir src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-photos] Add PhotosFetchCollectionStateJob
- Date: Tue, 2 Apr 2013 12:46:51 +0000 (UTC)
commit a3f8d16a53ae7ea6d74d0a4955f9490742a8743f
Author: Debarshi Ray <debarshir gnome org>
Date: Sun Mar 31 04:22:29 2013 +0200
Add PhotosFetchCollectionStateJob
src/Makefile.am | 2 +
src/photos-fetch-collection-state-job.c | 282 +++++++++++++++++++++++++++++++
src/photos-fetch-collection-state-job.h | 89 ++++++++++
src/photos-organize-collection-model.c | 3 +-
src/photos-organize-collection-model.h | 8 -
src/photos-organize-collection-view.c | 5 +-
6 files changed, 378 insertions(+), 11 deletions(-)
---
diff --git a/src/Makefile.am b/src/Makefile.am
index 43391c6..026eaa8 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -68,6 +68,8 @@ gnome_photos_SOURCES = \
photos-empty-results-box.h \
photos-error-box.c \
photos-error-box.h \
+ photos-fetch-collection-state-job.c \
+ photos-fetch-collection-state-job.h \
photos-fetch-collections-job.c \
photos-fetch-collections-job.h \
photos-filterable.c \
diff --git a/src/photos-fetch-collection-state-job.c b/src/photos-fetch-collection-state-job.c
new file mode 100644
index 0000000..ca61e4b
--- /dev/null
+++ b/src/photos-fetch-collection-state-job.c
@@ -0,0 +1,282 @@
+/*
+ * Photos - access, organize and share your photos on GNOME
+ * Copyright © 2013 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-collection-manager.h"
+#include "photos-fetch-collection-state-job.h"
+#include "photos-fetch-collections-job.h"
+#include "photos-item-manager.h"
+#include "photos-query.h"
+#include "photos-query-builder.h"
+#include "photos-selection-controller.h"
+#include "photos-tracker-queue.h"
+
+
+struct _PhotosFetchCollectionStateJobPrivate
+{
+ GHashTable *collections_for_items;
+ PhotosBaseManager *col_mngr;
+ PhotosBaseManager *item_mngr;
+ PhotosSelectionController *sel_cntrlr;
+ PhotosFetchCollectionStateJobCallback callback;
+ PhotosTrackerQueue *queue;
+ gint running_jobs;
+ gpointer user_data;
+};
+
+
+G_DEFINE_TYPE (PhotosFetchCollectionStateJob, photos_fetch_collection_state_job, G_TYPE_OBJECT);
+
+
+typedef struct _PhotosFetchCollectionStateJobData PhotosFetchCollectionStateJobData;
+
+struct _PhotosFetchCollectionStateJobData
+{
+ PhotosFetchCollectionStateJob *job;
+ gchar *urn;
+};
+
+
+static void
+photos_fetch_collection_state_job_data_free (PhotosFetchCollectionStateJobData *data)
+{
+ g_object_unref (data->job);
+ g_free (data->urn);
+ g_slice_free (PhotosFetchCollectionStateJobData, data);
+}
+
+
+static PhotosFetchCollectionStateJobData *
+photos_fetch_collection_state_job_data_new (PhotosFetchCollectionStateJob *job, const gchar *urn)
+{
+ PhotosFetchCollectionStateJobData *data;
+
+ data = g_slice_new0 (PhotosFetchCollectionStateJobData);
+ data->job = g_object_ref (job);
+ data->urn = g_strdup (urn);
+ return data;
+}
+
+
+static void
+photos_fetch_collection_state_job_emit_callback (PhotosFetchCollectionStateJob *self)
+{
+ PhotosFetchCollectionStateJobPrivate *priv = self->priv;
+ GHashTable *collection_state;
+ GHashTable *collections;
+ GHashTableIter iter1;
+ PhotosBaseItem *collection;
+ const gchar *coll_idx;
+
+ collection_state = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL);
+ collections = photos_base_manager_get_objects (priv->col_mngr);
+
+ /* For all the registered collections... */
+ g_hash_table_iter_init (&iter1, collections);
+ while (g_hash_table_iter_next (&iter1, (gpointer) &coll_idx, (gpointer) &collection))
+ {
+ GHashTableIter iter2;
+ GList *collections_for_item;
+ GList *keys;
+ PhotosBaseItem *item;
+ gboolean found = FALSE;
+ gboolean hidden = FALSE;
+ gboolean not_found = FALSE;
+ const gchar *item_idx;
+ gint state = PHOTOS_COLLECTION_STATE_NORMAL;
+
+ /* If the only object we are fetching collection state for is a
+ * collection itself, hide this if it is the same collection.
+ */
+ keys = g_hash_table_get_keys (priv->collections_for_items);
+ if (g_list_length (keys) == 1)
+ {
+ item_idx = (gchar *) keys->data;
+ item = PHOTOS_BASE_ITEM (photos_base_manager_get_object_by_id (priv->item_mngr, item_idx));
+ if (g_strcmp0 (photos_base_item_get_id (item), photos_base_item_get_id (collection)) == 0)
+ hidden = TRUE;
+ }
+ g_list_free (keys);
+
+ g_hash_table_iter_init (&iter2, priv->collections_for_items);
+ while (g_hash_table_iter_next (&iter2, (gpointer) &item_idx, (gpointer) &collections_for_item))
+ {
+ item = PHOTOS_BASE_ITEM (photos_base_manager_get_object_by_id (priv->item_mngr, item_idx));
+
+ /* If one of the selected items is part of this collection... */
+ if (g_list_find_custom (collections_for_item, coll_idx, (GCompareFunc) g_strcmp0) != NULL)
+ found = TRUE;
+ else
+ not_found = TRUE;
+
+ if (g_strcmp0 (photos_base_item_get_resource_urn (item),
+ photos_base_item_get_resource_urn (collection)) != 0
+ && !g_str_has_prefix (photos_base_item_get_identifier (collection),
+ PHOTOS_QUERY_LOCAL_COLLECTIONS_IDENTIFIER))
+ hidden = TRUE;
+ }
+
+ if (found && not_found)
+ state != PHOTOS_COLLECTION_STATE_INCONSISTENT;
+ else if (found)
+ state != PHOTOS_COLLECTION_STATE_ACTIVE;
+
+ if (hidden)
+ state != PHOTOS_COLLECTION_STATE_HIDDEN;
+
+ g_hash_table_insert (collection_state, g_strdup (coll_idx), GINT_TO_POINTER (state));
+ }
+
+ if (priv->callback != NULL)
+ (*priv->callback) (collection_state, priv->user_data);
+
+ g_hash_table_unref (collection_state);
+}
+
+
+static void
+photos_fetch_collection_state_job_job_collector (GList *collections_for_item, gpointer user_data)
+{
+ PhotosFetchCollectionStateJobData *data = user_data;
+ PhotosFetchCollectionStateJob *self = data->job;
+ PhotosFetchCollectionStateJobPrivate *priv = self->priv;
+ const gchar *urn = data->urn;
+
+ g_hash_table_insert (priv->collections_for_items,
+ g_strdup (urn),
+ g_list_copy_deep (collections_for_item, (GCopyFunc) g_strdup, NULL));
+
+ priv->running_jobs--;
+ if (priv->running_jobs == 0)
+ photos_fetch_collection_state_job_emit_callback (self);
+
+ photos_fetch_collection_state_job_data_free (data);
+}
+
+
+static void
+photos_fetch_collection_state_job_value_destroy_func (gpointer data)
+{
+ g_list_free_full ((GList *) data, g_free);
+}
+
+
+static void
+photos_fetch_collection_state_job_dispose (GObject *object)
+{
+ PhotosFetchCollectionStateJob *self = PHOTOS_FETCH_COLLECTION_STATE_JOB (object);
+ PhotosFetchCollectionStateJobPrivate *priv = self->priv;
+
+ g_clear_object (&priv->col_mngr);
+ g_clear_object (&priv->item_mngr);
+ g_clear_object (&priv->sel_cntrlr);
+ g_clear_object (&priv->queue);
+
+ G_OBJECT_CLASS (photos_fetch_collection_state_job_parent_class)->dispose (object);
+}
+
+
+static void
+photos_fetch_collection_state_job_finalize (GObject *object)
+{
+ PhotosFetchCollectionStateJob *self = PHOTOS_FETCH_COLLECTION_STATE_JOB (object);
+
+ g_hash_table_unref (self->priv->collections_for_items);
+
+ G_OBJECT_CLASS (photos_fetch_collection_state_job_parent_class)->finalize (object);
+}
+
+
+static void
+photos_fetch_collection_state_job_init (PhotosFetchCollectionStateJob *self)
+{
+ PhotosFetchCollectionStateJobPrivate *priv = self->priv;
+
+ self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self,
+ PHOTOS_TYPE_FETCH_COLLECTION_STATE_JOB,
+ PhotosFetchCollectionStateJobPrivate);
+ priv = self->priv;
+
+ priv->collections_for_items = g_hash_table_new_full (g_str_hash,
+ g_str_equal,
+ g_free,
+ photos_fetch_collection_state_job_value_destroy_func);
+
+ priv->col_mngr = photos_collection_manager_new ();
+ priv->item_mngr = photos_item_manager_new ();
+ priv->sel_cntrlr = photos_selection_controller_new ();
+ priv->queue = photos_tracker_queue_new ();
+}
+
+
+static void
+photos_fetch_collection_state_job_class_init (PhotosFetchCollectionStateJobClass *class)
+{
+ GObjectClass *object_class = G_OBJECT_CLASS (class);
+
+ object_class->dispose = photos_fetch_collection_state_job_dispose;
+ object_class->finalize = photos_fetch_collection_state_job_finalize;
+
+ g_type_class_add_private (class, sizeof (PhotosFetchCollectionStateJobPrivate));
+}
+
+
+PhotosFetchCollectionStateJob *
+photos_fetch_collection_state_job_new (void)
+{
+ return g_object_new (PHOTOS_TYPE_FETCH_COLLECTION_STATE_JOB, NULL);
+}
+
+
+void
+photos_fetch_collection_state_job_run (PhotosFetchCollectionStateJob *self,
+ PhotosFetchCollectionStateJobCallback callback,
+ gpointer user_data)
+{
+ PhotosFetchCollectionStateJobPrivate *priv = self->priv;
+ GList *l;
+ GList *urns;
+
+ priv->callback = callback;
+ priv->user_data = user_data;
+
+ urns = photos_selection_controller_get_selection (priv->sel_cntrlr);
+ for (l = urns; l != NULL; l = l->next)
+ {
+ PhotosFetchCollectionStateJobData *data;
+ PhotosFetchCollectionsJob *job;
+ const gchar *urn = (gchar *) l->data;
+
+ priv->running_jobs++;
+ job = photos_fetch_collections_job_new (urn);
+ data = photos_fetch_collection_state_job_data_new (self, urn);
+ photos_fetch_collections_job_run (job, photos_fetch_collection_state_job_job_collector, data);
+ g_object_unref (job);
+ }
+}
diff --git a/src/photos-fetch-collection-state-job.h b/src/photos-fetch-collection-state-job.h
new file mode 100644
index 0000000..44f398c
--- /dev/null
+++ b/src/photos-fetch-collection-state-job.h
@@ -0,0 +1,89 @@
+/*
+ * Photos - access, organize and share your photos on GNOME
+ * Copyright © 2013 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_COLLECTION_STATE_JOB_H
+#define PHOTOS_FETCH_COLLECTION_STATE_JOB_H
+
+#include <glib-object.h>
+
+G_BEGIN_DECLS
+
+#define PHOTOS_TYPE_FETCH_COLLECTION_STATE_JOB (photos_fetch_collection_state_job_get_type ())
+
+#define PHOTOS_FETCH_COLLECTION_STATE_JOB(obj) \
+ (G_TYPE_CHECK_INSTANCE_CAST ((obj), \
+ PHOTOS_TYPE_FETCH_COLLECTION_STATE_JOB, PhotosFetchCollectionStateJob))
+
+#define PHOTOS_FETCH_COLLECTION_STATE_JOB_CLASS(klass) \
+ (G_TYPE_CHECK_CLASS_CAST ((klass), \
+ PHOTOS_TYPE_FETCH_COLLECTION_STATE_JOB, PhotosFetchCollectionStateJobClass))
+
+#define PHOTOS_IS_FETCH_COLLECTION_STATE_JOB(obj) \
+ (G_TYPE_CHECK_INSTANCE_TYPE ((obj), \
+ PHOTOS_TYPE_FETCH_COLLECTION_STATE_JOB))
+
+#define PHOTOS_IS_FETCH_COLLECTION_STATE_JOB_CLASS(klass) \
+ (G_TYPE_CHECK_CLASS_TYPE ((klass), \
+ PHOTOS_TYPE_FETCH_COLLECTION_STATE_JOB))
+
+#define PHOTOS_FETCH_COLLECTION_STATE_JOB_GET_CLASS(obj) \
+ (G_TYPE_INSTANCE_GET_CLASS ((obj), \
+ PHOTOS_TYPE_FETCH_COLLECTION_STATE_JOB, PhotosFetchCollectionStateJobClass))
+
+typedef enum
+{
+ PHOTOS_COLLECTION_STATE_NORMAL = 0,
+ PHOTOS_COLLECTION_STATE_ACTIVE = 1 << 0,
+ PHOTOS_COLLECTION_STATE_INCONSISTENT = 1 << 1,
+ PHOTOS_COLLECTION_STATE_HIDDEN = 1 << 2
+} PhotosCollectionState;
+
+typedef void (*PhotosFetchCollectionStateJobCallback) (GHashTable *, gpointer);
+
+typedef struct _PhotosFetchCollectionStateJob PhotosFetchCollectionStateJob;
+typedef struct _PhotosFetchCollectionStateJobClass PhotosFetchCollectionStateJobClass;
+typedef struct _PhotosFetchCollectionStateJobPrivate PhotosFetchCollectionStateJobPrivate;
+
+struct _PhotosFetchCollectionStateJob
+{
+ GObject parent_instance;
+ PhotosFetchCollectionStateJobPrivate *priv;
+};
+
+struct _PhotosFetchCollectionStateJobClass
+{
+ GObjectClass parent_class;
+};
+
+GType photos_fetch_collection_state_job_get_type (void) G_GNUC_CONST;
+
+PhotosFetchCollectionStateJob *photos_fetch_collection_state_job_new (void);
+
+void photos_fetch_collection_state_job_run (PhotosFetchCollectionStateJob *self,
+ PhotosFetchCollectionStateJobCallback
callback,
+ gpointer user_data);
+
+G_END_DECLS
+
+#endif /* PHOTOS_FETCH_COLLECTION_STATE_JOB_H */
diff --git a/src/photos-organize-collection-model.c b/src/photos-organize-collection-model.c
index 848adaa..a565594 100644
--- a/src/photos-organize-collection-model.c
+++ b/src/photos-organize-collection-model.c
@@ -26,6 +26,7 @@
#include "config.h"
#include "photos-collection-manager.h"
+#include "photos-fetch-collection-state-job.h"
#include "photos-organize-collection-model.h"
@@ -150,7 +151,7 @@ photos_organize_collection_model_add_placeholder (PhotosOrganizeCollectionModel
&iter,
PHOTOS_ORGANIZE_MODEL_ID, PHOTOS_COLLECTION_PLACEHOLDER_ID,
PHOTOS_ORGANIZE_MODEL_NAME, "",
- PHOTOS_ORGANIZE_MODEL_STATE, PHOTOS_ORGANIZE_COLLECTION_STATE_ACTIVE,
+ PHOTOS_ORGANIZE_MODEL_STATE, PHOTOS_COLLECTION_STATE_ACTIVE,
-1);
placeholder_path = gtk_tree_model_get_path (GTK_TREE_MODEL (self), &iter);
diff --git a/src/photos-organize-collection-model.h b/src/photos-organize-collection-model.h
index 19cae93..0ec1526 100644
--- a/src/photos-organize-collection-model.h
+++ b/src/photos-organize-collection-model.h
@@ -60,14 +60,6 @@ typedef enum
PHOTOS_ORGANIZE_MODEL_STATE
} PhotosOrganizeModelColumns;
-typedef enum
-{
- PHOTOS_ORGANIZE_COLLECTION_STATE_NORMAL = 0,
- PHOTOS_ORGANIZE_COLLECTION_STATE_ACTIVE = 1 << 0,
- PHOTOS_ORGANIZE_COLLECTION_STATE_INCONSISTENT = 1 << 1,
- PHOTOS_ORGANIZE_COLLECTION_STATE_HIDDEN = 1 << 2,
-} PhotosOrganizeCollectionState;
-
typedef struct _PhotosOrganizeCollectionModel PhotosOrganizeCollectionModel;
typedef struct _PhotosOrganizeCollectionModelClass PhotosOrganizeCollectionModelClass;
typedef struct _PhotosOrganizeCollectionModelPrivate PhotosOrganizeCollectionModelPrivate;
diff --git a/src/photos-organize-collection-view.c b/src/photos-organize-collection-view.c
index 5ae350e..c6f14b7 100644
--- a/src/photos-organize-collection-view.c
+++ b/src/photos-organize-collection-view.c
@@ -28,6 +28,7 @@
#include <glib.h>
#include <libgd/gd.h>
+#include "photos-fetch-collection-state-job.h"
#include "photos-organize-collection-model.h"
#include "photos-organize-collection-view.h"
@@ -59,8 +60,8 @@ photos_organize_collection_view_check_cell (GtkTreeViewColumn *tree_column,
gtk_tree_model_get (tree_model, iter, PHOTOS_ORGANIZE_MODEL_ID, &id, PHOTOS_ORGANIZE_MODEL_STATE, &state,
-1);
gtk_cell_renderer_toggle_set_active (GTK_CELL_RENDERER_TOGGLE (cell_renderer),
- state & PHOTOS_ORGANIZE_COLLECTION_STATE_ACTIVE);
- g_object_set (cell_renderer, "inconsistent", state & PHOTOS_ORGANIZE_COLLECTION_STATE_INCONSISTENT, NULL);
+ state & PHOTOS_COLLECTION_STATE_ACTIVE);
+ g_object_set (cell_renderer, "inconsistent", state & PHOTOS_COLLECTION_STATE_INCONSISTENT, NULL);
gtk_cell_renderer_set_visible (cell_renderer, g_strcmp0 (id, PHOTOS_COLLECTION_PLACEHOLDER_ID));
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]