[gnome-photos/wip/rishi/manager-model: 8/8] base-manager: Implement GListModel
- From: Debarshi Ray <debarshir src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-photos/wip/rishi/manager-model: 8/8] base-manager: Implement GListModel
- Date: Sat, 5 Nov 2016 12:32:23 +0000 (UTC)
commit 8ac5e1c673440e88394554e5d303eff41f2e25af
Author: Debarshi Ray <debarshir gnome org>
Date: Thu Oct 13 07:13:52 2016 +0200
base-manager: Implement GListModel
src/photos-base-manager.c | 88 ++++++++++++++++++++++++++++++++++++++++++--
1 files changed, 84 insertions(+), 4 deletions(-)
---
diff --git a/src/photos-base-manager.c b/src/photos-base-manager.c
index 26d89b3..59aa88d 100644
--- a/src/photos-base-manager.c
+++ b/src/photos-base-manager.c
@@ -25,6 +25,7 @@
#include "config.h"
+#include <gio/gio.h>
#include <glib.h>
#include "photos-base-manager.h"
@@ -35,6 +36,7 @@ struct _PhotosBaseManagerPrivate
{
GHashTable *objects;
GObject *active_object;
+ GSequence *sequence;
gchar *action_id;
gchar *title;
};
@@ -57,8 +59,41 @@ enum
static guint signals[LAST_SIGNAL] = { 0 };
+static void photos_base_manager_list_model_iface_init (GListModelInterface *iface);
-G_DEFINE_TYPE_WITH_PRIVATE (PhotosBaseManager, photos_base_manager, G_TYPE_OBJECT);
+
+G_DEFINE_TYPE_WITH_CODE (PhotosBaseManager, photos_base_manager, G_TYPE_OBJECT,
+ G_ADD_PRIVATE (PhotosBaseManager)
+ G_IMPLEMENT_INTERFACE (G_TYPE_LIST_MODEL,
photos_base_manager_list_model_iface_init));
+
+
+typedef struct _PhotosBaseManagerObjectData PhotosBaseManagerObjectData;
+
+struct _PhotosBaseManagerObjectData
+{
+ GObject *object;
+ GSequenceIter *iter;
+};
+
+
+static PhotosBaseManagerObjectData *
+photos_base_manager_object_data_new (GObject *object, GSequenceIter *iter)
+{
+ PhotosBaseManagerObjectData *object_data;
+
+ object_data = g_slice_new0 (PhotosBaseManagerObjectData);
+ object_data->object = g_object_ref (object);
+ object_data->iter = iter;
+ return object_data;
+}
+
+
+static void
+photos_base_manager_object_data_free (PhotosBaseManagerObjectData *object_data)
+{
+ g_object_unref (object_data->object);
+ g_slice_free (PhotosBaseManagerObjectData, object_data);
+}
static void
@@ -66,6 +101,7 @@ photos_base_manager_default_add_object (PhotosBaseManager *self, GObject *object
{
PhotosBaseManagerPrivate *priv;
GObject *old_object;
+ GSequenceIter *iter;
const gchar *id;
priv = photos_base_manager_get_instance_private (self);
@@ -75,7 +111,10 @@ photos_base_manager_default_add_object (PhotosBaseManager *self, GObject *object
if (old_object != NULL)
return;
- g_hash_table_insert (priv->objects, g_strdup (id), g_object_ref (object));
+ iter = g_sequence_append (priv->sequence, g_object_ref (object));
+ object_data = photos_base_manager_object_data_new (object, iter);
+ g_hash_table_insert (priv->objects, g_strdup (id), object_data);
+
g_signal_emit (self, signals[OBJECT_ADDED], 0, object);
}
@@ -102,13 +141,15 @@ photos_base_manager_default_get_object_by_id (PhotosBaseManager *self, const gch
{
PhotosBaseManagerPrivate *priv;
GObject *ret_val = NULL;
+ PhotosBaseManagerObjectData *object_data;
priv = photos_base_manager_get_instance_private (self);
if (id == NULL)
goto out;
- ret_val = g_hash_table_lookup (priv->objects, id);
+ object_data = g_hash_table_lookup (priv->objects, id);
+ ret_val = object_data->object;
out:
return ret_val;
@@ -166,6 +207,31 @@ photos_base_manager_default_set_active_object (PhotosBaseManager *self, GObject
}
+static gpointer
+photos_base_manager_get_item (GListModel *list, guint position)
+{
+ return NULL;
+}
+
+
+static GType
+photos_base_manager_get_item_type (GListModel *list)
+{
+ return PHOTOS_TYPE_FILTERABLE;
+}
+
+
+static guint
+photos_base_manager_get_n_items (GListModel *list)
+{
+ PhotosBaseManager *self = PHOTOS_BASE_MANAGER (list);
+ guint count;
+
+ count = photos_base_manager_get_objects_count (self);
+ return count;
+}
+
+
static void
photos_base_manager_dispose (GObject *object)
{
@@ -181,6 +247,7 @@ photos_base_manager_dispose (GObject *object)
}
g_clear_object (&priv->active_object);
+ g_clear_pointer (&priv->sequence, (GDestroyNotify) g_sequence_free);
G_OBJECT_CLASS (photos_base_manager_parent_class)->dispose (object);
}
@@ -232,7 +299,11 @@ photos_base_manager_init (PhotosBaseManager *self)
PhotosBaseManagerPrivate *priv;
priv = photos_base_manager_get_instance_private (self);
- priv->objects = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_object_unref);
+ priv->objects = g_hash_table_new_full (g_str_hash,
+ g_str_equal,
+ g_free,
+ (GDestroyNotify) photos_base_manager_object_data_free);
+ priv->sequence = g_sequence_new (g_object_unref);
}
@@ -314,6 +385,15 @@ photos_base_manager_class_init (PhotosBaseManagerClass *class)
}
+static void
+photos_base_manager_list_model_iface_init (GListModelInterface *iface)
+{
+ iface->get_item = photos_base_manager_get_item;
+ iface->get_item_type = photos_base_manager_get_item_type;
+ iface->get_n_items = photos_base_manager_get_n_items;
+}
+
+
PhotosBaseManager *
photos_base_manager_new (void)
{
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]