[gnome-photos/wip/rishi/manager-model: 4/5] Turn PhotosBaseManager and PhotosItemManager into GListModels
- From: Debarshi Ray <debarshir src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-photos/wip/rishi/manager-model: 4/5] Turn PhotosBaseManager and PhotosItemManager into GListModels
- Date: Tue, 15 Nov 2016 11:09:05 +0000 (UTC)
commit 21b8108fe0dc172a0b6e478af0f65039e0f490a6
Author: Debarshi Ray <debarshir gnome org>
Date: Thu Oct 13 07:13:52 2016 +0200
Turn PhotosBaseManager and PhotosItemManager into GListModels
Based on ideas from Alessandro Bono.
https://bugzilla.gnome.org/show_bug.cgi?id=774191
src/photos-base-manager.c | 202 +++++++++++++++++++++++++++++++------
src/photos-base-manager.h | 3 -
src/photos-base-model.c | 17 ++--
src/photos-item-manager.c | 72 ++++++++++----
src/photos-search-match-manager.c | 20 ++--
src/photos-share-point-manager.c | 33 ++++---
src/photos-source-manager.c | 30 ++++--
src/photos-view-model.c | 18 ++--
8 files changed, 292 insertions(+), 103 deletions(-)
---
diff --git a/src/photos-base-manager.c b/src/photos-base-manager.c
index b59a0cc..9f1ad9e 100644
--- a/src/photos-base-manager.c
+++ b/src/photos-base-manager.c
@@ -20,11 +20,13 @@
/* Based on code from:
* + Documents
+ * + GLib
*/
#include "config.h"
+#include <gio/gio.h>
#include <glib.h>
#include "photos-base-manager.h"
@@ -35,8 +37,11 @@ struct _PhotosBaseManagerPrivate
{
GHashTable *objects;
GObject *active_object;
+ GSequence *sequence;
+ GSequenceIter *last_iter;
gchar *action_id;
gchar *title;
+ guint last_position;
};
enum
@@ -57,8 +62,58 @@ 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
+photos_base_manager_objects_changed (PhotosBaseManager *self, guint position, guint removed, guint added)
+{
+ PhotosBaseManagerPrivate *priv;
+
+ priv = photos_base_manager_get_instance_private (self);
+
+ if (position <= priv->last_position)
+ {
+ priv->last_iter = NULL;
+ priv->last_position = G_MAXUINT;
+ }
+
+ g_list_model_items_changed (G_LIST_MODEL (self), position, removed, added);
+}
static void
@@ -66,7 +121,10 @@ photos_base_manager_default_add_object (PhotosBaseManager *self, GObject *object
{
PhotosBaseManagerPrivate *priv;
GObject *old_object;
+ GSequenceIter *iter;
+ PhotosBaseManagerObjectData *object_data;
const gchar *id;
+ guint position;
priv = photos_base_manager_get_instance_private (self);
@@ -75,7 +133,13 @@ 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));
+ position = photos_base_manager_get_objects_count (self);
+ 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);
+
+ photos_base_manager_objects_changed (self, position, 0, 1);
g_signal_emit (self, signals[OBJECT_ADDED], 0, object);
}
@@ -101,22 +165,19 @@ static GObject *
photos_base_manager_default_get_object_by_id (PhotosBaseManager *self, const gchar *id)
{
PhotosBaseManagerPrivate *priv;
- GObject *ret_val;
+ GObject *ret_val = NULL;
+ PhotosBaseManagerObjectData *object_data;
priv = photos_base_manager_get_instance_private (self);
- ret_val = g_hash_table_lookup (priv->objects, id);
- return ret_val;
-}
+ object_data = g_hash_table_lookup (priv->objects, id);
+ if (object_data == NULL)
+ goto out;
+ ret_val = object_data->object;
-static GHashTable *
-photos_base_manager_default_get_objects (PhotosBaseManager *self)
-{
- PhotosBaseManagerPrivate *priv;
-
- priv = photos_base_manager_get_instance_private (self);
- return priv->objects;
+ out:
+ return ret_val;
}
@@ -132,16 +193,24 @@ photos_base_manager_default_remove_object_by_id (PhotosBaseManager *self, const
{
PhotosBaseManagerPrivate *priv;
GObject *object;
+ PhotosBaseManagerObjectData *object_data;
+ guint position;
priv = photos_base_manager_get_instance_private (self);
- object = g_hash_table_lookup (priv->objects, id);
- if (object == NULL)
+ object_data = g_hash_table_lookup (priv->objects, id);
+ if (object_data == NULL)
return;
- g_object_ref (object);
+ position = g_sequence_iter_get_position (object_data->iter);
+ g_sequence_remove (object_data->iter);
+
+ object = g_object_ref (object_data->object);
g_hash_table_remove (priv->objects, id);
+
+ photos_base_manager_objects_changed (self, position, 1, 0);
g_signal_emit (self, signals[OBJECT_REMOVED], 0, object);
+
g_object_unref (object);
}
@@ -161,6 +230,60 @@ photos_base_manager_default_set_active_object (PhotosBaseManager *self, GObject
}
+static gpointer
+photos_base_manager_get_item (GListModel *list, guint position)
+{
+ PhotosBaseManager *self = PHOTOS_BASE_MANAGER (list);
+ PhotosBaseManagerPrivate *priv;
+ GSequenceIter *iter = NULL;
+ gpointer ret_val = NULL;
+
+ priv = photos_base_manager_get_instance_private (self);
+
+ if (priv->last_position != G_MAXUINT)
+ {
+ if (priv->last_position == position + 1)
+ iter = g_sequence_iter_prev (priv->last_iter);
+ else if (priv->last_position == position - 1)
+ iter = g_sequence_iter_next (priv->last_iter);
+ else if (priv->last_position == position)
+ iter = priv->last_iter;
+ }
+
+ if (iter == NULL)
+ iter = g_sequence_get_iter_at_pos (priv->sequence, position);
+
+ priv->last_iter = iter;
+ priv->last_position = position;
+
+ if (g_sequence_iter_is_end (iter))
+ goto out;
+
+ ret_val = g_object_ref (g_sequence_get (iter));
+
+ out:
+ return ret_val;
+}
+
+
+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)
{
@@ -176,6 +299,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);
}
@@ -227,7 +351,12 @@ 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);
+ priv->last_position = G_MAXUINT;
}
@@ -243,7 +372,6 @@ photos_base_manager_class_init (PhotosBaseManagerClass *class)
class->get_active_object = photos_base_manager_default_get_active_object;
class->get_filter = photos_base_manager_default_get_filter;
class->get_object_by_id = photos_base_manager_default_get_object_by_id;
- class->get_objects = photos_base_manager_default_get_objects;
class->get_where = photos_base_manager_default_get_where;
class->remove_object_by_id = photos_base_manager_default_remove_object_by_id;
class->set_active_object = photos_base_manager_default_set_active_object;
@@ -309,6 +437,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)
{
@@ -330,13 +467,23 @@ void
photos_base_manager_clear (PhotosBaseManager *self)
{
PhotosBaseManagerPrivate *priv;
+ GSequenceIter *begin_iter;
+ GSequenceIter *end_iter;
+ guint count;
g_return_if_fail (PHOTOS_IS_BASE_MANAGER (self));
priv = photos_base_manager_get_instance_private (self);
+ begin_iter = g_sequence_get_begin_iter (priv->sequence);
+ end_iter = g_sequence_get_end_iter (priv->sequence);
+ g_sequence_remove_range (begin_iter, end_iter);
+
g_hash_table_remove_all (priv->objects);
g_clear_object (&priv->active_object);
+
+ count = photos_base_manager_get_objects_count (self);
+ photos_base_manager_objects_changed (self, 0, count, 0);
g_signal_emit (self, signals[CLEAR], 0);
}
@@ -366,7 +513,7 @@ photos_base_manager_get_all_filter (PhotosBaseManager *self)
{
PhotosBaseManagerPrivate *priv;
GHashTableIter iter;
- GObject *object;
+ PhotosBaseManagerObjectData *object_data;
const gchar *blank = "(true)";
const gchar *id;
gchar *filter;
@@ -384,13 +531,13 @@ photos_base_manager_get_all_filter (PhotosBaseManager *self)
i = 0;
g_hash_table_iter_init (&iter, priv->objects);
- while (g_hash_table_iter_next (&iter, (gpointer *) &id, (gpointer *) &object))
+ while (g_hash_table_iter_next (&iter, (gpointer *) &id, (gpointer *) &object_data))
{
if (g_strcmp0 (id, "all") != 0)
{
gchar *str;
- str = photos_filterable_get_filter (PHOTOS_FILTERABLE (object));
+ str = photos_filterable_get_filter (PHOTOS_FILTERABLE (object_data->object));
if (g_strcmp0 (str, blank) == 0)
g_free (str);
else
@@ -434,14 +581,6 @@ photos_base_manager_get_object_by_id (PhotosBaseManager *self, const gchar *id)
}
-GHashTable *
-photos_base_manager_get_objects (PhotosBaseManager *self)
-{
- g_return_val_if_fail (PHOTOS_IS_BASE_MANAGER (self), NULL);
- return PHOTOS_BASE_MANAGER_GET_CLASS (self)->get_objects (self);
-}
-
-
guint
photos_base_manager_get_objects_count (PhotosBaseManager *self)
{
@@ -484,6 +623,7 @@ photos_base_manager_process_new_objects (PhotosBaseManager *self, GHashTable *ne
GObject *object;
GSList *l;
GSList *removed_ids = NULL;
+ PhotosBaseManagerObjectData *object_data;
const gchar *id;
g_return_if_fail (PHOTOS_IS_BASE_MANAGER (self));
@@ -491,14 +631,14 @@ photos_base_manager_process_new_objects (PhotosBaseManager *self, GHashTable *ne
priv = photos_base_manager_get_instance_private (self);
g_hash_table_iter_init (&iter, priv->objects);
- while (g_hash_table_iter_next (&iter, (gpointer *) &id, (gpointer *) &object))
+ while (g_hash_table_iter_next (&iter, (gpointer *) &id, (gpointer *) &object_data))
{
gboolean builtin;
/* If old objects are not found in the newer hash table, remove
* them.
*/
- builtin = photos_filterable_get_builtin (PHOTOS_FILTERABLE (object));
+ builtin = photos_filterable_get_builtin (PHOTOS_FILTERABLE (object_data->object));
if (g_hash_table_lookup (new_objects, id) == NULL && !builtin)
removed_ids = g_slist_prepend (removed_ids, g_strdup (id));
}
diff --git a/src/photos-base-manager.h b/src/photos-base-manager.h
index e6298d5..493cc39 100644
--- a/src/photos-base-manager.h
+++ b/src/photos-base-manager.h
@@ -43,7 +43,6 @@ struct _PhotosBaseManagerClass
GObject *(*get_active_object) (PhotosBaseManager *self);
gchar *(*get_filter) (PhotosBaseManager *self, gint flags);
GObject *(*get_object_by_id) (PhotosBaseManager *self, const gchar *id);
- GHashTable *(*get_objects) (PhotosBaseManager *self);
gchar *(*get_where) (PhotosBaseManager *self, gint flags);
void (*remove_object_by_id) (PhotosBaseManager *self, const gchar *id);
gboolean (*set_active_object) (PhotosBaseManager *self, GObject *object);
@@ -71,8 +70,6 @@ gchar *photos_base_manager_get_filter (PhotosBaseMana
GObject *photos_base_manager_get_object_by_id (PhotosBaseManager *self, const gchar *id);
-GHashTable *photos_base_manager_get_objects (PhotosBaseManager *self);
-
guint photos_base_manager_get_objects_count (PhotosBaseManager *self);
const gchar *photos_base_manager_get_title (PhotosBaseManager *self);
diff --git a/src/photos-base-model.c b/src/photos-base-model.c
index 9679e00..9bbb894 100644
--- a/src/photos-base-model.c
+++ b/src/photos-base-model.c
@@ -78,13 +78,11 @@ photos_base_model_active_changed (PhotosBaseModel *self, GObject *active_object)
static void
photos_base_model_refresh (PhotosBaseModel *self)
{
- GHashTable *objects;
- GHashTableIter hash_iter;
GMenu *section;
- GObject *object;
const gchar *action_id;
- const gchar *id;
const gchar *title;
+ guint i;
+ guint n_items;
g_menu_remove_all (self->model);
@@ -94,15 +92,17 @@ photos_base_model_refresh (PhotosBaseModel *self)
section = g_menu_new ();
g_menu_append_section (self->model, title, G_MENU_MODEL (section));
- objects = photos_base_manager_get_objects (self->mngr);
-
- g_hash_table_iter_init (&hash_iter, objects);
- while (g_hash_table_iter_next (&hash_iter, (gpointer *) &id, (gpointer *) &object))
+ n_items = g_list_model_get_n_items (G_LIST_MODEL (self->mngr));
+ for (i = 0; i < n_items; i++)
{
GMenuItem *menu_item;
+ GObject *object;
GVariant *target_value;
+ const gchar *id;
gchar *name;
+ object = g_list_model_get_object (G_LIST_MODEL (self->mngr), i);
+ id = photos_filterable_get_id (PHOTOS_FILTERABLE (object));
g_object_get (object, "name", &name, NULL);
menu_item = g_menu_item_new (name, NULL);
@@ -112,6 +112,7 @@ photos_base_model_refresh (PhotosBaseModel *self)
g_free (name);
g_object_unref (menu_item);
+ g_object_unref (object);
}
g_object_unref (section);
diff --git a/src/photos-item-manager.c b/src/photos-item-manager.c
index ef71c23..62645a7 100644
--- a/src/photos-item-manager.c
+++ b/src/photos-item-manager.c
@@ -90,8 +90,11 @@ enum
static guint signals[LAST_SIGNAL] = { 0 };
+static void photos_item_manager_list_model_iface_init (GListModelInterface *iface);
-G_DEFINE_TYPE (PhotosItemManager, photos_item_manager, PHOTOS_TYPE_BASE_MANAGER);
+
+G_DEFINE_TYPE_WITH_CODE (PhotosItemManager, photos_item_manager, PHOTOS_TYPE_BASE_MANAGER,
+ G_IMPLEMENT_INTERFACE (G_TYPE_LIST_MODEL,
photos_item_manager_list_model_iface_init));
EGG_DEFINE_COUNTER (instances, "PhotosItemManager", "Instances", "Number of PhotosItemManager instances")
@@ -327,24 +330,42 @@ photos_item_manager_get_active_object (PhotosBaseManager *mngr)
}
-static GObject *
-photos_item_manager_get_object_by_id (PhotosBaseManager *mngr, const gchar *id)
+static gpointer
+photos_item_manager_get_item (GListModel *list, guint position)
{
- PhotosItemManager *self = PHOTOS_ITEM_MANAGER (mngr);
- GObject *ret_val;
+ PhotosItemManager *self = PHOTOS_ITEM_MANAGER (list);
+ gpointer item;
- ret_val = photos_base_manager_get_object_by_id (self->item_mngr_chldrn[0], id);
- return ret_val;
+ item = g_list_model_get_item (G_LIST_MODEL (self->item_mngr_chldrn[0]), position);
+ return item;
}
-static GHashTable *
-photos_item_manager_get_objects (PhotosBaseManager *mngr)
+static GType
+photos_item_manager_get_item_type (GListModel *list)
+{
+ return PHOTOS_TYPE_BASE_ITEM;
+}
+
+
+static guint
+photos_item_manager_get_n_items (GListModel *list)
+{
+ PhotosItemManager *self = PHOTOS_ITEM_MANAGER (list);
+ guint n_items;
+
+ n_items = g_list_model_get_n_items (G_LIST_MODEL (self->item_mngr_chldrn[0]));
+ return n_items;
+}
+
+
+static GObject *
+photos_item_manager_get_object_by_id (PhotosBaseManager *mngr, const gchar *id)
{
PhotosItemManager *self = PHOTOS_ITEM_MANAGER (mngr);
- GHashTable *ret_val;
+ GObject *ret_val;
- ret_val = photos_base_manager_get_objects (self->item_mngr_chldrn[0]);
+ ret_val = photos_base_manager_get_object_by_id (self->item_mngr_chldrn[0], id);
return ret_val;
}
@@ -683,7 +704,6 @@ photos_item_manager_class_init (PhotosItemManagerClass *class)
base_manager_class->get_active_object = photos_item_manager_get_active_object;
base_manager_class->get_where = photos_item_manager_get_where;
base_manager_class->get_object_by_id = photos_item_manager_get_object_by_id;
- base_manager_class->get_objects = photos_item_manager_get_objects;
base_manager_class->set_active_object = photos_item_manager_set_active_object;
base_manager_class->remove_object_by_id = photos_item_manager_remove_object_by_id;
@@ -762,6 +782,15 @@ photos_item_manager_class_init (PhotosItemManagerClass *class)
}
+static void
+photos_item_manager_list_model_iface_init (GListModelInterface *iface)
+{
+ iface->get_item = photos_item_manager_get_item;
+ iface->get_item_type = photos_item_manager_get_item_type;
+ iface->get_n_items = photos_item_manager_get_n_items;
+}
+
+
PhotosBaseManager *
photos_item_manager_new (void)
{
@@ -877,11 +906,9 @@ photos_item_manager_add_item_for_mode (PhotosItemManager *self, PhotosWindowMode
void
photos_item_manager_clear (PhotosItemManager *self, PhotosWindowMode mode)
{
- GHashTable *items;
- GHashTableIter iter;
- PhotosBaseItem *item;
PhotosBaseManager *item_mngr_chld;
- const gchar *id;
+ guint i;
+ guint n_items;
g_return_if_fail (PHOTOS_IS_ITEM_MANAGER (self));
g_return_if_fail (mode != PHOTOS_WINDOW_MODE_NONE);
@@ -889,14 +916,17 @@ photos_item_manager_clear (PhotosItemManager *self, PhotosWindowMode mode)
g_return_if_fail (mode != PHOTOS_WINDOW_MODE_PREVIEW);
item_mngr_chld = self->item_mngr_chldrn[mode];
- items = photos_base_manager_get_objects (item_mngr_chld);
-
- g_hash_table_iter_init (&iter, items);
- while (g_hash_table_iter_next (&iter, (gpointer *) &id, (gpointer *) &item))
+ n_items = g_list_model_get_n_items (G_LIST_MODEL (item_mngr_chld));
+ for (i = 0; i < n_items; i++)
{
+ PhotosBaseItem *item;
PhotosBaseItem *item1 = NULL;
+ const gchar *id;
guint j;
+ item = PHOTOS_BASE_ITEM (g_list_model_get_object (G_LIST_MODEL (item_mngr_chld), i));
+ id = photos_filterable_get_id (PHOTOS_FILTERABLE (item));
+
for (j = 1; self->item_mngr_chldrn[j] != NULL; j++)
{
if (item_mngr_chld == self->item_mngr_chldrn[j])
@@ -914,6 +944,8 @@ photos_item_manager_clear (PhotosItemManager *self, PhotosWindowMode mode)
photos_base_manager_remove_object_by_id (self->item_mngr_chldrn[0], id);
}
+
+ g_object_unref (item);
}
photos_base_manager_clear (item_mngr_chld);
diff --git a/src/photos-search-match-manager.c b/src/photos-search-match-manager.c
index 8e898cb..8a4f004 100644
--- a/src/photos-search-match-manager.c
+++ b/src/photos-search-match-manager.c
@@ -25,6 +25,7 @@
#include "config.h"
+#include <gio/gio.h>
#include <glib.h>
#include <glib/gi18n.h>
@@ -59,8 +60,6 @@ static gchar *
photos_search_match_manager_get_filter (PhotosBaseManager *mngr, gint flags)
{
PhotosSearchMatchManager *self = PHOTOS_SEARCH_MATCH_MANAGER (mngr);
- GHashTable *objects;
- PhotosSearchMatch *search_match;
const gchar *blank = "(true)";
gchar *filter = NULL;
gchar *ret_val = NULL;
@@ -77,17 +76,22 @@ photos_search_match_manager_get_filter (PhotosBaseManager *mngr, gint flags)
if (n_terms == 0)
goto out;
- objects = photos_base_manager_get_objects (PHOTOS_BASE_MANAGER (self));
filters = (gchar **) g_malloc0_n (n_terms + 1, sizeof (gchar *));
for (i = 0; terms[i] != NULL; i++)
{
- GHashTableIter iter;
+ PhotosSearchMatch *search_match;
const gchar *id;
-
- g_hash_table_iter_init (&iter, objects);
- while (g_hash_table_iter_next (&iter, NULL, (gpointer *) &search_match))
- photos_search_match_set_filter_term (search_match, terms[i]);
+ guint j;
+ guint n_items;
+
+ n_items = g_list_model_get_n_items (G_LIST_MODEL (self));
+ for (j = 0; j < n_items; j++)
+ {
+ search_match = PHOTOS_SEARCH_MATCH (g_list_model_get_object (G_LIST_MODEL (self), j));
+ photos_search_match_set_filter_term (search_match, terms[i]);
+ g_object_unref (search_match);
+ }
search_match = PHOTOS_SEARCH_MATCH (photos_base_manager_get_active_object (PHOTOS_BASE_MANAGER
(self)));
id = photos_filterable_get_id (PHOTOS_FILTERABLE (search_match));
diff --git a/src/photos-share-point-manager.c b/src/photos-share-point-manager.c
index 47a9271..d0b0bcf 100644
--- a/src/photos-share-point-manager.c
+++ b/src/photos-share-point-manager.c
@@ -86,11 +86,10 @@ static void
photos_share_point_manager_refresh_share_points (PhotosSharePointManager *self)
{
GHashTable *new_share_points;
- GHashTable *sources;
- GHashTableIter iter;
GList *extensions;
GList *l;
- PhotosSource *source;
+ guint i;
+ guint n_items;
new_share_points = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_object_unref);
@@ -128,13 +127,13 @@ photos_share_point_manager_refresh_share_points (PhotosSharePointManager *self)
g_object_unref (share_point);
}
- sources = photos_base_manager_get_objects (self->src_mngr);
-
- g_hash_table_iter_init (&iter, sources);
- while (g_hash_table_iter_next (&iter, NULL, (gpointer *) &source))
+ n_items = g_list_model_get_n_items (G_LIST_MODEL (self->src_mngr));
+ for (i = 0; i < n_items; i++)
{
PhotosSharePoint *share_point = NULL;
+ PhotosSource *source;
+ source = PHOTOS_SOURCE (g_list_model_get_object (G_LIST_MODEL (self->src_mngr), i));
share_point = photos_share_point_manager_create_share_point_online (self, source);
if (share_point != NULL)
{
@@ -145,6 +144,7 @@ photos_share_point_manager_refresh_share_points (PhotosSharePointManager *self)
}
g_clear_object (&share_point);
+ g_object_unref (source);
}
photos_base_manager_process_new_objects (PHOTOS_BASE_MANAGER (self), new_share_points);
@@ -256,12 +256,10 @@ photos_share_point_manager_can_share (PhotosSharePointManager *self, PhotosBaseI
GList *
photos_share_point_manager_get_for_item (PhotosSharePointManager *self, PhotosBaseItem *item)
{
- GHashTable *share_points;
- GHashTableIter iter;
GList *ret_val = NULL;
- PhotosSharePoint *share_point;
const gchar *resource_urn;
- const gchar *share_point_id;
+ guint i;
+ guint n_items;
g_return_val_if_fail (PHOTOS_IS_SHARE_POINT_MANAGER (self), FALSE);
g_return_val_if_fail (PHOTOS_IS_BASE_ITEM (item), FALSE);
@@ -270,13 +268,20 @@ photos_share_point_manager_get_for_item (PhotosSharePointManager *self, PhotosBa
goto out;
resource_urn = photos_base_item_get_resource_urn (item);
- share_points = photos_base_manager_get_objects (PHOTOS_BASE_MANAGER (self));
- g_hash_table_iter_init (&iter, share_points);
- while (g_hash_table_iter_next (&iter, (gpointer *) &share_point_id, (gpointer *) &share_point))
+ n_items = g_list_model_get_n_items (G_LIST_MODEL (self));
+ for (i = 0; i < n_items; i++)
{
+ PhotosSharePoint *share_point;
+ const gchar *share_point_id;
+
+ share_point = PHOTOS_SHARE_POINT (g_list_model_get_object (G_LIST_MODEL (self), i));
+ share_point_id = photos_filterable_get_id (PHOTOS_FILTERABLE (share_point));
+
if (g_strcmp0 (resource_urn, share_point_id) != 0)
ret_val = g_list_prepend (ret_val, g_object_ref (share_point));
+
+ g_object_unref (share_point);
}
out:
diff --git a/src/photos-source-manager.c b/src/photos-source-manager.c
index 88d56d2..fbfa037 100644
--- a/src/photos-source-manager.c
+++ b/src/photos-source-manager.c
@@ -25,6 +25,7 @@
#include "config.h"
+#include <gio/gio.h>
#include <glib.h>
#include <glib/gi18n.h>
#include <goa/goa.h>
@@ -207,17 +208,17 @@ photos_source_manager_new (void)
GList *
photos_source_manager_get_for_provider_type (PhotosSourceManager *self, const gchar *provider_type)
{
- GHashTable *sources;
- GHashTableIter iter;
GList *items = NULL;
- PhotosSource *source;
+ guint i;
+ guint n_items;
- sources = photos_base_manager_get_objects (PHOTOS_BASE_MANAGER (self));
- g_hash_table_iter_init (&iter, sources);
- while (g_hash_table_iter_next (&iter, NULL, (gpointer *) &source))
+ n_items = g_list_model_get_n_items (G_LIST_MODEL (self));
+ for (i = 0; i < n_items; i++)
{
GoaObject *object;
+ PhotosSource *source;
+ source = PHOTOS_SOURCE (g_list_model_get_object (G_LIST_MODEL (self), i));
object = photos_source_get_goa_object (source);
if (object != NULL)
{
@@ -227,6 +228,8 @@ photos_source_manager_get_for_provider_type (PhotosSourceManager *self, const gc
if (g_strcmp0 (goa_account_get_provider_type (account), provider_type) == 0)
items = g_list_prepend (items, g_object_ref (source));
}
+
+ g_object_unref (source);
}
return items;
@@ -236,25 +239,28 @@ photos_source_manager_get_for_provider_type (PhotosSourceManager *self, const gc
gboolean
photos_source_manager_has_online_sources (PhotosSourceManager *self)
{
- GHashTable *sources;
- GHashTableIter iter;
- PhotosSource *source;
+ PhotosSource *source = NULL;
gboolean ret_val = FALSE;
+ guint i;
+ guint n_items;
- sources = photos_base_manager_get_objects (PHOTOS_BASE_MANAGER (self));
- g_hash_table_iter_init (&iter, sources);
- while (g_hash_table_iter_next (&iter, NULL, (gpointer *) &source))
+ n_items = g_list_model_get_n_items (G_LIST_MODEL (self));
+ for (i = 0; i < n_items; i++)
{
GoaObject *object;
+ source = PHOTOS_SOURCE (g_list_model_get_object (G_LIST_MODEL (self), i));
object = photos_source_get_goa_object (source);
if (object != NULL)
{
ret_val = TRUE;
break;
}
+
+ g_clear_object (&source);
}
+ g_clear_object (&source);
return ret_val;
}
diff --git a/src/photos-view-model.c b/src/photos-view-model.c
index cc78a31..b2160ef 100644
--- a/src/photos-view-model.c
+++ b/src/photos-view-model.c
@@ -156,16 +156,20 @@ photos_view_model_add_item (PhotosViewModel *self, PhotosBaseItem *item)
static void
photos_view_model_clear (PhotosViewModel *self)
{
- GHashTable *items;
- GHashTableIter iter;
- PhotosBaseItem *item;
+ guint i;
+ guint n_items;
g_return_if_fail (self->item_mngr != NULL);
- items = photos_base_manager_get_objects (self->item_mngr);
- g_hash_table_iter_init (&iter, items);
- while (g_hash_table_iter_next (&iter, NULL, (gpointer *) &item))
- g_object_set_data (G_OBJECT (item), self->row_ref_key, NULL);
+ n_items = g_list_model_get_n_items (G_LIST_MODEL (self->item_mngr));
+ for (i = 0; i < n_items; i++)
+ {
+ PhotosBaseItem *item;
+
+ item = PHOTOS_BASE_ITEM (g_list_model_get_object (G_LIST_MODEL (self->item_mngr), i));
+ g_object_set_data (G_OBJECT (item), self->row_ref_key, NULL);
+ g_object_unref (item);
+ }
gtk_list_store_clear (GTK_LIST_STORE (self));
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]