[gnome-photos/wip/rishi/constrained-add: 1/4] item-manager: Shuffle some code around
- From: Debarshi Ray <debarshir src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-photos/wip/rishi/constrained-add: 1/4] item-manager: Shuffle some code around
- Date: Thu, 12 Jan 2017 11:09:36 +0000 (UTC)
commit fc0b41d14fb0609024d734d80b77420d31b77ee9
Author: Debarshi Ray <debarshir gnome org>
Date: Thu Jan 12 10:54:28 2017 +0100
item-manager: Shuffle some code around
This will make the subsequent commit easier to read.
src/photos-item-manager.c | 242 +++++++++++++++++++++++---------------------
1 files changed, 126 insertions(+), 116 deletions(-)
---
diff --git a/src/photos-item-manager.c b/src/photos-item-manager.c
index dc7c6d6..d87b354 100644
--- a/src/photos-item-manager.c
+++ b/src/photos-item-manager.c
@@ -1,6 +1,6 @@
/*
* Photos - access, organize and share your photos on GNOME
- * Copyright © 2012 – 2016 Red Hat, Inc.
+ * Copyright © 2012 – 2017 Red Hat, Inc.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
@@ -142,6 +142,127 @@ photos_item_manager_add_object (PhotosBaseManager *mngr, GObject *object)
}
+static gboolean
+photos_item_manager_cursor_is_collection (TrackerSparqlCursor *cursor)
+{
+ gboolean ret_val;
+ const gchar *rdf_type;
+
+ rdf_type = tracker_sparql_cursor_get_string (cursor, PHOTOS_QUERY_COLUMNS_RDF_TYPE, NULL);
+ ret_val = strstr (rdf_type, "nfo#DataContainer") != NULL;
+ return ret_val;
+}
+
+
+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));
+ if (updated_item == NULL)
+ return;
+
+ 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));
+
+ if (!is_favorite)
+ photos_base_manager_remove_object (self->item_mngr_chldrn[PHOTOS_WINDOW_MODE_FAVORITES], G_OBJECT
(item));
+ }
+}
+
+
+static void
+photos_item_manager_add_cursor_for_mode (PhotosItemManager *self,
+ TrackerSparqlCursor *cursor,
+ PhotosWindowMode mode)
+{
+ PhotosBaseItem *item = NULL;
+ PhotosBaseManager *item_mngr_chld;
+ gboolean is_collection;
+ const gchar *id;
+
+ g_return_if_fail (PHOTOS_IS_ITEM_MANAGER (self));
+ g_return_if_fail (TRACKER_SPARQL_IS_CURSOR (cursor));
+ g_return_if_fail (mode != PHOTOS_WINDOW_MODE_NONE);
+ g_return_if_fail (mode != PHOTOS_WINDOW_MODE_EDIT);
+ g_return_if_fail (mode != PHOTOS_WINDOW_MODE_PREVIEW);
+
+ is_collection = photos_item_manager_cursor_is_collection (cursor);
+ g_return_if_fail ((is_collection && (mode == PHOTOS_WINDOW_MODE_COLLECTIONS || mode ==
PHOTOS_WINDOW_MODE_SEARCH))
+ || (!is_collection && (mode != PHOTOS_WINDOW_MODE_COLLECTIONS || self->active_collection
!= NULL)));
+
+ item_mngr_chld = self->item_mngr_chldrn[mode];
+ id = tracker_sparql_cursor_get_string (cursor, PHOTOS_QUERY_COLUMNS_URN, NULL);
+
+ item = PHOTOS_BASE_ITEM (photos_base_manager_get_object_by_id (item_mngr_chld, id));
+ if (item != NULL)
+ {
+ g_object_ref (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));
+ }
+
+ out:
+ g_clear_object (&item);
+}
+
+
static void
photos_item_manager_check_wait_for_changes (PhotosItemManager *self, const gchar *id, const gchar *uri)
{
@@ -162,18 +283,6 @@ photos_item_manager_check_wait_for_changes (PhotosItemManager *self, const gchar
}
-static gboolean
-photos_item_manager_cursor_is_collection (TrackerSparqlCursor *cursor)
-{
- gboolean ret_val;
- const gchar *rdf_type;
-
- rdf_type = tracker_sparql_cursor_get_string (cursor, PHOTOS_QUERY_COLUMNS_RDF_TYPE, NULL);
- ret_val = strstr (rdf_type, "nfo#DataContainer") != NULL;
- return ret_val;
-}
-
-
static void
photos_item_manager_item_created_executed (GObject *source_object, GAsyncResult *res, gpointer user_data)
{
@@ -393,56 +502,6 @@ 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));
- if (updated_item == NULL)
- return;
-
- 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));
-
- if (!is_favorite)
- photos_base_manager_remove_object (self->item_mngr_chldrn[PHOTOS_WINDOW_MODE_FAVORITES], 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);
@@ -880,14 +939,14 @@ photos_item_manager_add_item (PhotosItemManager *self, TrackerSparqlCursor *curs
photos_item_manager_activate_previous_collection (self);
if (self->active_collection == NULL)
- photos_item_manager_add_item_for_mode (self, PHOTOS_WINDOW_MODE_COLLECTIONS, cursor);
+ photos_item_manager_add_cursor_for_mode (self, cursor, PHOTOS_WINDOW_MODE_COLLECTIONS);
}
else
{
if (photos_item_manager_cursor_is_favorite (cursor))
- photos_item_manager_add_item_for_mode (self, PHOTOS_WINDOW_MODE_FAVORITES, cursor);
+ photos_item_manager_add_cursor_for_mode (self, cursor, PHOTOS_WINDOW_MODE_FAVORITES);
- photos_item_manager_add_item_for_mode (self, PHOTOS_WINDOW_MODE_OVERVIEW, cursor);
+ photos_item_manager_add_cursor_for_mode (self, cursor, PHOTOS_WINDOW_MODE_OVERVIEW);
}
}
@@ -895,56 +954,7 @@ photos_item_manager_add_item (PhotosItemManager *self, TrackerSparqlCursor *curs
void
photos_item_manager_add_item_for_mode (PhotosItemManager *self, PhotosWindowMode mode, TrackerSparqlCursor
*cursor)
{
- PhotosBaseItem *item = NULL;
- PhotosBaseManager *item_mngr_chld;
- gboolean is_collection;
- const gchar *id;
-
- g_return_if_fail (PHOTOS_IS_ITEM_MANAGER (self));
- g_return_if_fail (TRACKER_SPARQL_IS_CURSOR (cursor));
- g_return_if_fail (mode != PHOTOS_WINDOW_MODE_NONE);
- g_return_if_fail (mode != PHOTOS_WINDOW_MODE_EDIT);
- g_return_if_fail (mode != PHOTOS_WINDOW_MODE_PREVIEW);
-
- is_collection = photos_item_manager_cursor_is_collection (cursor);
- g_return_if_fail ((is_collection && (mode == PHOTOS_WINDOW_MODE_COLLECTIONS || mode ==
PHOTOS_WINDOW_MODE_SEARCH))
- || (!is_collection && (mode != PHOTOS_WINDOW_MODE_COLLECTIONS || self->active_collection
!= NULL)));
-
- item_mngr_chld = self->item_mngr_chldrn[mode];
- id = tracker_sparql_cursor_get_string (cursor, PHOTOS_QUERY_COLUMNS_URN, NULL);
-
- item = PHOTOS_BASE_ITEM (photos_base_manager_get_object_by_id (item_mngr_chld, id));
- if (item != NULL)
- {
- g_object_ref (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_clear_object (&item);
+ photos_item_manager_add_cursor_for_mode (self, cursor, mode);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]