[gnome-photos/wip/rishi/manager-model: 7/7] base-manager: Implement GListModel
- From: Debarshi Ray <debarshir src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-photos/wip/rishi/manager-model: 7/7] base-manager: Implement GListModel
- Date: Tue, 8 Nov 2016 09:38:09 +0000 (UTC)
commit 3193c861f0e9a1b566d7a8c0b55a6af1843048ae
Author: Debarshi Ray <debarshir gnome org>
Date: Thu Oct 13 07:13:52 2016 +0200
base-manager: Implement GListModel
src/photos-base-manager.c | 239 ++++++++++++++++++++++++++++++++-----
src/photos-base-manager.h | 5 +-
src/photos-base-model.c | 17 ++--
src/photos-item-manager.c | 54 +++++----
src/photos-search-match-manager.c | 20 ++--
src/photos-share-point-manager.c | 53 +++++----
src/photos-source-manager.c | 43 ++++---
src/photos-view-model.c | 18 ++-
8 files changed, 325 insertions(+), 124 deletions(-)
---
diff --git a/src/photos-base-manager.c b/src/photos-base-manager.c
index ba0f5cb..1f0bad3 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"
@@ -33,16 +34,23 @@
struct _PhotosBaseManagerPrivate
{
+ GCompareDataFunc sort_func;
GHashTable *objects;
GObject *active_object;
+ GSequence *sequence;
+ GSequenceIter *last_iter;
gchar *action_id;
gchar *title;
+ gpointer sort_data;
+ guint last_position;
};
enum
{
PROP_0,
PROP_ACTION_ID,
+ PROP_SORT_DATA,
+ PROP_SORT_FUNC,
PROP_TITLE
};
@@ -57,8 +65,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 +124,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 +136,21 @@ 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));
+ if (priv->sort_func == NULL)
+ {
+ position = photos_base_manager_get_objects_count (self);
+ iter = g_sequence_append (priv->sequence, g_object_ref (object));
+ }
+ else
+ {
+ iter = g_sequence_insert_sorted (priv->sequence, g_object_ref (object), priv->sort_func,
priv->sort_data);
+ position = g_sequence_iter_get_position (iter);
+ }
+
+ 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 +176,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;
-static GHashTable *
-photos_base_manager_default_get_objects (PhotosBaseManager *self)
-{
- PhotosBaseManagerPrivate *priv;
+ ret_val = object_data->object;
- priv = photos_base_manager_get_instance_private (self);
- return priv->objects;
+ out:
+ return ret_val;
}
@@ -132,16 +204,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 +241,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 +310,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);
}
@@ -210,6 +345,14 @@ photos_base_manager_set_property (GObject *object, guint prop_id, const GValue *
priv->action_id = g_value_dup_string (value);
break;
+ case PROP_SORT_DATA:
+ priv->sort_data = g_value_get_pointer (value);
+ break;
+
+ case PROP_SORT_FUNC:
+ priv->sort_func = g_value_get_pointer (value);
+ break;
+
case PROP_TITLE:
priv->title = g_value_dup_string (value);
break;
@@ -227,7 +370,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 +391,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;
@@ -257,6 +404,20 @@ photos_base_manager_class_init (PhotosBaseManagerClass *class)
G_PARAM_CONSTRUCT_ONLY | G_PARAM_WRITABLE));
g_object_class_install_property (object_class,
+ PROP_SORT_DATA,
+ g_param_spec_pointer ("sort-data",
+ "Sort data",
+ "Arbitrary data to be passed to the comparison
function",
+ G_PARAM_CONSTRUCT_ONLY | G_PARAM_WRITABLE));
+
+ g_object_class_install_property (object_class,
+ PROP_SORT_FUNC,
+ g_param_spec_pointer ("sort-func",
+ "Sort function",
+ "Pairwise comparison function for sorting",
+ G_PARAM_CONSTRUCT_ONLY | G_PARAM_WRITABLE));
+
+ g_object_class_install_property (object_class,
PROP_TITLE,
g_param_spec_string ("title",
"Title",
@@ -309,10 +470,19 @@ 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)
+photos_base_manager_new (GCompareDataFunc sort_func, gpointer sort_data)
{
- return g_object_new (PHOTOS_TYPE_BASE_MANAGER, NULL);
+ return g_object_new (PHOTOS_TYPE_BASE_MANAGER, "sort-func", sort_func, NULL);
}
@@ -330,13 +500,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 +546,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 +564,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 +614,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 +656,7 @@ photos_base_manager_process_new_objects (PhotosBaseManager *self, GHashTable *ne
GList *l;
GList *removed_ids = NULL;
GObject *object;
+ PhotosBaseManagerObjectData *object_data;
const gchar *id;
g_return_if_fail (PHOTOS_IS_BASE_MANAGER (self));
@@ -491,14 +664,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_list_prepend (removed_ids, g_strdup (id));
}
diff --git a/src/photos-base-manager.h b/src/photos-base-manager.h
index e6298d5..3d90472 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);
@@ -55,7 +54,7 @@ struct _PhotosBaseManagerClass
void (*object_removed) (PhotosBaseManager *self, GObject *object);
};
-PhotosBaseManager *photos_base_manager_new (void);
+PhotosBaseManager *photos_base_manager_new (GCompareDataFunc sort_func, gpointer
sort_data);
void photos_base_manager_add_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..7242739 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,20 @@ photos_item_manager_get_active_object (PhotosBaseManager *mngr)
}
-static GObject *
-photos_item_manager_get_object_by_id (PhotosBaseManager *mngr, const gchar *id)
+static GType
+photos_item_manager_get_item_type (GListModel *list)
{
- PhotosItemManager *self = PHOTOS_ITEM_MANAGER (mngr);
- GObject *ret_val;
-
- ret_val = photos_base_manager_get_object_by_id (self->item_mngr_chldrn[0], id);
- return ret_val;
+ return PHOTOS_TYPE_BASE_ITEM;
}
-static GHashTable *
-photos_item_manager_get_objects (PhotosBaseManager *mngr)
+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;
}
@@ -653,7 +652,7 @@ photos_item_manager_init (PhotosItemManager *self)
self->item_mngr_chldrn = (PhotosBaseManager **) g_malloc0_n (window_mode_class->n_values + 1,
sizeof (PhotosBaseManager *));
for (i = 0; i < window_mode_class->n_values; i++)
- self->item_mngr_chldrn[i] = photos_base_manager_new ();
+ self->item_mngr_chldrn[i] = photos_base_manager_new (NULL, NULL);
self->mode = PHOTOS_WINDOW_MODE_NONE;
@@ -683,7 +682,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 +760,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 +884,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 +894,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 +922,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 0a351db..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,21 +127,24 @@ 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;
- const gchar *id;
+ 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)
- continue;
+ if (share_point != NULL)
+ {
+ const gchar *id;
- id = photos_filterable_get_id (PHOTOS_FILTERABLE (share_point));
- g_hash_table_insert (new_share_points, g_strdup (id), g_object_ref (share_point));
- g_object_unref (share_point);
+ id = photos_filterable_get_id (PHOTOS_FILTERABLE (share_point));
+ g_hash_table_insert (new_share_points, g_strdup (id), g_object_ref (share_point));
+ }
+
+ g_clear_object (&share_point);
+ g_object_unref (source);
}
photos_base_manager_process_new_objects (PHOTOS_BASE_MANAGER (self), new_share_points);
@@ -254,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);
@@ -268,15 +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++)
{
- if (g_strcmp0 (resource_urn, share_point_id) == 0)
- continue;
+ PhotosSharePoint *share_point;
+ const gchar *share_point_id;
- ret_val = g_list_prepend (ret_val, g_object_ref (share_point));
+ 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 e26c25e..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,25 +208,28 @@ 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++)
{
- GoaAccount *account;
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)
- continue;
+ if (object != NULL)
+ {
+ GoaAccount *account;
- account = goa_object_peek_account (object);
- if (g_strcmp0 (goa_account_get_provider_type (account), provider_type) == 0)
- items = g_list_prepend (items, g_object_ref (source));
+ account = goa_object_peek_account (object);
+ 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;
@@ -235,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]