[gnome-photos/wip/rishi/view-model: 5/5] Remove the mode-specific filtering from PhotosViewModel
- From: Debarshi Ray <debarshir src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-photos/wip/rishi/view-model: 5/5] Remove the mode-specific filtering from PhotosViewModel
- Date: Tue, 30 Aug 2016 09:22:56 +0000 (UTC)
commit 912605ddba4adad8128566daf40ed36fa849a9f2
Author: Debarshi Ray <debarshir gnome org>
Date: Tue Aug 23 21:14:09 2016 +0200
Remove the mode-specific filtering from PhotosViewModel
Now that ItemManager has separate child BaseManagers for each mode, we
can greatly simplify ViewModel by removing the mode-specific filtering
logic. This was needed earlier when we had one single global bucket
inside ItemManager where the results of the mode-specific queries, and
we had to filter the contents of the bucket for each ViewModel. Not any
more.
From now on, ViewModel will simply mirror the contents of each
mode-specific child BaseManager.
The code to move a BaseItem from one mode to another, when any of its
attributes change (eg., it gets favorited), now resides inside
ItemManager.
https://bugzilla.gnome.org/show_bug.cgi?id=770342
src/photos-item-manager.c | 55 +++++++++++++++++++++++-
src/photos-tracker-controller.c | 5 ++-
src/photos-view-model.c | 90 +++------------------------------------
3 files changed, 64 insertions(+), 86 deletions(-)
---
diff --git a/src/photos-item-manager.c b/src/photos-item-manager.c
index 50caa05..09e089d 100644
--- a/src/photos-item-manager.c
+++ b/src/photos-item-manager.c
@@ -331,6 +331,50 @@ photos_item_manager_get_where (PhotosBaseManager *mngr, gint flags)
static void
+photos_item_manager_info_updated (PhotosBaseItem *item, gpointer user_data)
+{
+ PhotosItemManager *self = PHOTOS_ITEM_MANAGER (user_data);
+ PhotosBaseItem *updated_item;
+ gboolean is_collection;
+ gboolean is_favorite;
+ const gchar *id;
+
+ g_return_if_fail (PHOTOS_IS_BASE_ITEM (item));
+
+ id = photos_filterable_get_id (PHOTOS_FILTERABLE (item));
+ updated_item = PHOTOS_BASE_ITEM (photos_base_manager_get_object_by_id (PHOTOS_BASE_MANAGER (self), id));
+ g_return_if_fail (updated_item == item);
+
+ is_collection = photos_base_item_is_collection (item);
+ is_favorite = photos_base_item_is_favorite (item);
+
+ if (is_collection)
+ {
+ if (self->active_collection == NULL)
+ photos_base_manager_add_object (self->item_mngr_chldrn[PHOTOS_WINDOW_MODE_COLLECTIONS], G_OBJECT
(item));
+ }
+ else
+ {
+ if (is_favorite)
+ photos_base_manager_add_object (self->item_mngr_chldrn[PHOTOS_WINDOW_MODE_FAVORITES], G_OBJECT
(item));
+
+ photos_base_manager_add_object (self->item_mngr_chldrn[PHOTOS_WINDOW_MODE_OVERVIEW], G_OBJECT (item));
+ }
+
+ if (is_collection)
+ {
+ photos_base_manager_remove_object (self->item_mngr_chldrn[PHOTOS_WINDOW_MODE_FAVORITES], G_OBJECT
(item));
+ photos_base_manager_remove_object (self->item_mngr_chldrn[PHOTOS_WINDOW_MODE_OVERVIEW], G_OBJECT
(item));
+ }
+ else
+ {
+ if (self->active_collection == NULL)
+ photos_base_manager_remove_object (self->item_mngr_chldrn[PHOTOS_WINDOW_MODE_COLLECTIONS], G_OBJECT
(item));
+ }
+}
+
+
+static void
photos_item_manager_item_load (GObject *source_object, GAsyncResult *res, gpointer user_data)
{
PhotosItemManager *self = PHOTOS_ITEM_MANAGER (user_data);
@@ -375,6 +419,7 @@ photos_item_manager_remove_object_by_id (PhotosBaseManager *mngr, const gchar *i
if (item == NULL)
return;
+ g_signal_handlers_disconnect_by_func (item, photos_item_manager_info_updated, self);
g_object_ref (item);
for (i = 0; self->item_mngr_chldrn[i] != NULL; i++)
@@ -754,27 +799,33 @@ photos_item_manager_add_item_for_mode (PhotosItemManager *self, PhotosWindowMode
if (item != NULL)
{
g_object_ref (item);
- g_signal_emit_by_name (item_mngr_chld, "object-added", G_OBJECT (item));
}
else
{
+ gboolean already_present = FALSE;
+
item = PHOTOS_BASE_ITEM (photos_base_manager_get_object_by_id (PHOTOS_BASE_MANAGER (self), id));
if (item != NULL)
{
g_object_ref (item);
+ already_present = TRUE;
}
else
{
item = photos_item_manager_create_item (self, cursor);
if (photos_base_item_is_collection (item))
g_hash_table_insert (self->collections, g_strdup (id), g_object_ref (item));
+
+ g_signal_connect_object (item, "info-updated", G_CALLBACK (photos_item_manager_info_updated),
self, 0);
}
photos_base_manager_add_object (item_mngr_chld, G_OBJECT (item));
photos_base_manager_add_object (self->item_mngr_chldrn[0], G_OBJECT (item));
+
+ if (!already_present)
+ g_signal_emit_by_name (self, "object-added", G_OBJECT (item));
}
- g_signal_emit_by_name (self, "object-added", G_OBJECT (item));
g_clear_object (&item);
}
diff --git a/src/photos-tracker-controller.c b/src/photos-tracker-controller.c
index bfb766b..041a0cf 100644
--- a/src/photos-tracker-controller.c
+++ b/src/photos-tracker-controller.c
@@ -283,7 +283,10 @@ photos_tracker_controller_refresh_internal (PhotosTrackerController *self, gint
}
if (!(flags & PHOTOS_TRACKER_REFRESH_FLAGS_DONT_SET_QUERY_STATUS))
- photos_tracker_controller_set_query_status (self, TRUE);
+ {
+ photos_tracker_controller_set_query_status (self, TRUE);
+ photos_item_manager_clear (PHOTOS_ITEM_MANAGER (priv->item_mngr), priv->mode);
+ }
photos_tracker_controller_perform_current_query (self);
}
diff --git a/src/photos-view-model.c b/src/photos-view-model.c
index f331e59..cc78a31 100644
--- a/src/photos-view-model.c
+++ b/src/photos-view-model.c
@@ -232,43 +232,6 @@ photos_view_model_info_updated (PhotosBaseItem *item, gpointer user_data)
GtkTreeIter iter;
GtkTreePath *path;
GtkTreeRowReference *row_ref;
- PhotosBaseItem *active_collection;
-
- g_return_if_fail (self->item_mngr != NULL);
-
- active_collection = photos_item_manager_get_active_collection (PHOTOS_ITEM_MANAGER (self->item_mngr));
- row_ref = (GtkTreeRowReference *) g_object_get_data (G_OBJECT (item), self->row_ref_key);
-
- if (self->mode == PHOTOS_WINDOW_MODE_COLLECTIONS)
- {
- gboolean is_collection;
-
- is_collection = photos_base_item_is_collection (item);
- if (!is_collection && row_ref != NULL && active_collection == NULL)
- photos_view_model_remove_item (self, item);
- else if (is_collection && row_ref == NULL && active_collection == NULL)
- photos_view_model_add_item (self, item);
- }
- else if (self->mode == PHOTOS_WINDOW_MODE_FAVORITES)
- {
- gboolean is_favorite;
-
- is_favorite = photos_base_item_is_favorite (item);
- if (!is_favorite && row_ref != NULL && active_collection == NULL)
- photos_view_model_remove_item (self, item);
- else if (is_favorite && row_ref == NULL && active_collection == NULL)
- photos_view_model_add_item (self, item);
- }
- else if (self->mode == PHOTOS_WINDOW_MODE_OVERVIEW)
- {
- gboolean is_collection;
-
- is_collection = photos_base_item_is_collection (item);
- if (is_collection && row_ref != NULL)
- photos_view_model_remove_item (self, item);
- else if (!is_collection && row_ref == NULL)
- photos_view_model_add_item (self, item);
- }
row_ref = (GtkTreeRowReference *) g_object_get_data (G_OBJECT (item), self->row_ref_key);
if (row_ref != NULL)
@@ -288,13 +251,8 @@ static void
photos_view_model_object_added (PhotosViewModel *self, GObject *object)
{
PhotosBaseItem *item = PHOTOS_BASE_ITEM (object);
- PhotosBaseItem *active_collection;
- PhotosWindowMode mode;
GtkTreeRowReference *row_ref;
- gboolean is_collection;
- gboolean is_favorite;
const gchar *id;
- gpointer data;
guint info_updated_id;
g_return_if_fail (self->item_mngr != NULL);
@@ -304,36 +262,15 @@ photos_view_model_object_added (PhotosViewModel *self, GObject *object)
if (row_ref != NULL)
return;
- id = photos_filterable_get_id (PHOTOS_FILTERABLE (item));
- data = g_hash_table_lookup (self->info_updated_ids, id);
- if (data != NULL)
- {
- info_updated_id = GPOINTER_TO_UINT (data);
- g_signal_handler_disconnect (item, (gulong) info_updated_id);
- g_hash_table_remove (self->info_updated_ids, id);
- }
-
- active_collection = photos_item_manager_get_active_collection (PHOTOS_ITEM_MANAGER (self->item_mngr));
- is_collection = photos_base_item_is_collection (item);
- is_favorite = photos_base_item_is_favorite (item);
- mode = photos_mode_controller_get_window_mode (self->mode_cntrlr);
-
- if (active_collection == NULL || self->mode != mode)
- {
- if ((self->mode == PHOTOS_WINDOW_MODE_COLLECTIONS && !is_collection)
- || (self->mode == PHOTOS_WINDOW_MODE_FAVORITES && !is_favorite)
- || (self->mode == PHOTOS_WINDOW_MODE_OVERVIEW && is_collection))
- goto out;
- }
-
photos_view_model_add_item (self, item);
- out:
info_updated_id = (guint) g_signal_connect_object (item,
"info-updated",
G_CALLBACK (photos_view_model_info_updated),
self,
0);
+
+ id = photos_filterable_get_id (PHOTOS_FILTERABLE (item));
g_hash_table_insert (self->info_updated_ids, g_strdup (id), GUINT_TO_POINTER (info_updated_id));
}
@@ -360,19 +297,10 @@ photos_view_model_object_removed (PhotosViewModel *self, GObject *object)
static void
-photos_view_model_query_status_changed (PhotosViewModel *self, gboolean query_status)
-{
- if (query_status == FALSE)
- return;
-
- photos_view_model_clear (self);
-}
-
-
-static void
photos_view_model_constructed (GObject *object)
{
PhotosViewModel *self = PHOTOS_VIEW_MODEL (object);
+ PhotosBaseManager *item_mngr_chld;
G_OBJECT_CLASS (photos_view_model_parent_class)->constructed (object);
@@ -406,22 +334,18 @@ photos_view_model_constructed (GObject *object)
break;
}
- g_signal_connect_object (self->item_mngr,
+ item_mngr_chld = photos_item_manager_get_for_mode (PHOTOS_ITEM_MANAGER (self->item_mngr), self->mode);
+ g_signal_connect_object (item_mngr_chld,
"object-added",
G_CALLBACK (photos_view_model_object_added),
self,
G_CONNECT_SWAPPED);
- g_signal_connect_object (self->item_mngr,
+ g_signal_connect_object (item_mngr_chld,
"object-removed",
G_CALLBACK (photos_view_model_object_removed),
self,
G_CONNECT_SWAPPED);
-
- g_signal_connect_object (self->trk_cntrlr,
- "query-status-changed",
- G_CALLBACK (photos_view_model_query_status_changed),
- self,
- G_CONNECT_SWAPPED);
+ g_signal_connect_object (item_mngr_chld, "clear", G_CALLBACK (photos_view_model_clear), self,
G_CONNECT_SWAPPED);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]