[gnome-photos/wip/rishi/view-model: 5/5] WIP
- From: Debarshi Ray <debarshir src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-photos/wip/rishi/view-model: 5/5] WIP
- Date: Tue, 23 Aug 2016 19:19:04 +0000 (UTC)
commit edfc2f9e6dae20af7c29cb82431ba588e6dbe93f
Author: Debarshi Ray <debarshir gnome org>
Date: Tue Aug 23 21:14:09 2016 +0200
WIP
src/photos-item-manager.c | 52 +++++++++++++++++++++++++++++++++++++-
src/photos-tracker-controller.c | 9 ++++++-
src/photos-view-model.c | 47 ++++++++++++----------------------
3 files changed, 75 insertions(+), 33 deletions(-)
---
diff --git a/src/photos-item-manager.c b/src/photos-item-manager.c
index 924d08f..c8feb14 100644
--- a/src/photos-item-manager.c
+++ b/src/photos-item-manager.c
@@ -329,6 +329,45 @@ 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);
+ gboolean is_collection;
+ gboolean is_favorite;
+
+ g_return_if_fail (PHOTOS_IS_BASE_ITEM (item));
+
+ is_collection = photos_base_item_is_collection (item);
+ is_favorite = photos_base_item_is_favorite (item);
+
+ if (self->mode == PHOTOS_WINDOW_MODE_COLLECTIONS)
+ {
+ 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)
+ {
+ 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);
+ }
+}
+
+
+static void
photos_item_manager_item_load (GObject *source_object, GAsyncResult *res, gpointer user_data)
{
PhotosItemManager *self = PHOTOS_ITEM_MANAGER (user_data);
@@ -373,6 +412,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++)
@@ -742,27 +782,35 @@ 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));
+ //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_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..6d16e10 100644
--- a/src/photos-tracker-controller.c
+++ b/src/photos-tracker-controller.c
@@ -283,7 +283,14 @@ 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);
+ {
+ PhotosBaseManager *item_mngr_chld;
+
+ photos_tracker_controller_set_query_status (self, TRUE);
+
+ item_mngr_chld = photos_item_manager_get_for_mode (priv->item_mngr, self->mode);
+ photos_base_manager_clear (item_mngr_chld);
+ }
photos_tracker_controller_perform_current_query (self);
}
diff --git a/src/photos-view-model.c b/src/photos-view-model.c
index f331e59..adb4ff9 100644
--- a/src/photos-view-model.c
+++ b/src/photos-view-model.c
@@ -313,18 +313,18 @@ photos_view_model_object_added (PhotosViewModel *self, GObject *object)
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;
- }
+ /* 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);
@@ -360,19 +360,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);
+ PohtosBaseManager *item_mngr_chld;
G_OBJECT_CLASS (photos_view_model_parent_class)->constructed (object);
@@ -406,22 +397,18 @@ photos_view_model_constructed (GObject *object)
break;
}
- g_signal_connect_object (self->item_mngr,
+ item_mngr_chld = photos_item_manager_get_for_mode (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]