[gnome-photos/wip/rishi/collection: 29/39] Support explicitly specifying the BaseItem sub-class to create
- From: Debarshi Ray <debarshir src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-photos/wip/rishi/collection: 29/39] Support explicitly specifying the BaseItem sub-class to create
- Date: Wed, 24 Jan 2018 20:04:39 +0000 (UTC)
commit df33db929f571898e6ae187b87f0f8f76bf88b0a
Author: Debarshi Ray <debarshir gnome org>
Date: Wed Jan 24 13:43:16 2018 +0100
Support explicitly specifying the BaseItem sub-class to create
The specific BaseItem sub-class that gets instantiated from a
TrackerSparqlCursor used to be auto-detected based on the
nao:identifier. Each sub-class had a matching Source, and a Tracker
miner that set an nao:identifier with an unique prefix that identified
the sub-class.
However, it is not going to be possible to differentiate between local
BaseItems already present on the system and those that are on a device
device attached to it because both are going to be indexed by Tracker's
filesystem miner. Fortunately the cases where one needs to create a
DeviceItem, as opposed to a LocalItem, are very well defined.
Therefore, it's desirable to be able to specify the GType of the
sub-class and override the auto-detection machinery.
https://bugzilla.gnome.org/show_bug.cgi?id=751212
src/photos-application.c | 2 +-
src/photos-collection-icon-watcher.c | 2 +-
src/photos-item-manager.c | 104 +++++++++++++++++++++++++----------
src/photos-item-manager.h | 3 +
src/photos-tracker-controller.c | 8 ++-
src/photos-tracker-controller.h | 2 +
6 files changed, 89 insertions(+), 32 deletions(-)
---
diff --git a/src/photos-application.c b/src/photos-application.c
index bd78fde7..66af55f7 100644
--- a/src/photos-application.c
+++ b/src/photos-application.c
@@ -791,7 +791,7 @@ photos_application_activate_query_executed (GObject *source_object, GAsyncResult
if (cursor == NULL)
goto out;
- photos_item_manager_add_item (PHOTOS_ITEM_MANAGER (self->state->item_mngr), cursor, TRUE);
+ photos_item_manager_add_item (PHOTOS_ITEM_MANAGER (self->state->item_mngr), G_TYPE_NONE, cursor, TRUE);
identifier = tracker_sparql_cursor_get_string (cursor, PHOTOS_QUERY_COLUMNS_URN, NULL);
item = photos_base_manager_get_object_by_id (self->state->item_mngr, identifier);
diff --git a/src/photos-collection-icon-watcher.c b/src/photos-collection-icon-watcher.c
index 96d14092..9cbb548a 100644
--- a/src/photos-collection-icon-watcher.c
+++ b/src/photos-collection-icon-watcher.c
@@ -177,7 +177,7 @@ photos_collection_icon_watcher_to_query_executed (GObject *source_object, GAsync
{
PhotosBaseItem *item;
- item = photos_item_manager_create_item (PHOTOS_ITEM_MANAGER (self->item_mngr), cursor);
+ item = photos_item_manager_create_item (PHOTOS_ITEM_MANAGER (self->item_mngr), G_TYPE_NONE, cursor);
self->items = g_list_prepend (self->items, item);
}
diff --git a/src/photos-item-manager.c b/src/photos-item-manager.c
index 2da064fc..5deb007a 100644
--- a/src/photos-item-manager.c
+++ b/src/photos-item-manager.c
@@ -270,6 +270,7 @@ photos_item_manager_info_updated (PhotosBaseItem *item, gpointer user_data)
static void
photos_item_manager_add_cursor_for_mode (PhotosItemManager *self,
+ GType base_item_type,
TrackerSparqlCursor *cursor,
PhotosWindowMode mode,
gboolean force)
@@ -280,6 +281,9 @@ photos_item_manager_add_cursor_for_mode (PhotosItemManager *self,
const gchar *id;
g_return_if_fail (PHOTOS_IS_ITEM_MANAGER (self));
+ g_return_if_fail (base_item_type == G_TYPE_NONE
+ || (base_item_type != PHOTOS_TYPE_BASE_ITEM
+ && g_type_is_a (base_item_type, PHOTOS_TYPE_BASE_ITEM)));
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);
@@ -313,7 +317,7 @@ photos_item_manager_add_cursor_for_mode (PhotosItemManager *self,
}
else
{
- item = photos_item_manager_create_item (self, cursor);
+ item = photos_item_manager_create_item (self, base_item_type, cursor);
if (photos_base_item_is_collection (item))
g_hash_table_insert (self->collections, g_strdup (id), g_object_ref (item));
@@ -371,7 +375,7 @@ photos_item_manager_item_created_executed (GObject *source_object, GAsyncResult
if (cursor == NULL)
goto out;
- photos_item_manager_add_item (self, cursor, FALSE);
+ photos_item_manager_add_item (self, G_TYPE_NONE, cursor, FALSE);
if (!photos_item_manager_cursor_is_collection (cursor))
{
@@ -975,12 +979,18 @@ photos_item_manager_new (void)
void
-photos_item_manager_add_item (PhotosItemManager *self, TrackerSparqlCursor *cursor, gboolean force)
+photos_item_manager_add_item (PhotosItemManager *self,
+ GType base_item_type,
+ TrackerSparqlCursor *cursor,
+ gboolean force)
{
PhotosItemManagerHiddenItem *old_hidden_item;
const gchar *id;
g_return_if_fail (PHOTOS_IS_ITEM_MANAGER (self));
+ g_return_if_fail (base_item_type == G_TYPE_NONE
+ || (base_item_type != PHOTOS_TYPE_BASE_ITEM
+ && g_type_is_a (base_item_type, PHOTOS_TYPE_BASE_ITEM)));
g_return_if_fail (TRACKER_SPARQL_IS_CURSOR (cursor));
id = tracker_sparql_cursor_get_string (cursor, PHOTOS_QUERY_COLUMNS_URN, NULL);
@@ -992,14 +1002,28 @@ photos_item_manager_add_item (PhotosItemManager *self, TrackerSparqlCursor *curs
if (photos_item_manager_cursor_is_collection (cursor))
{
- photos_item_manager_add_cursor_for_mode (self, cursor, PHOTOS_WINDOW_MODE_COLLECTIONS, force);
+ photos_item_manager_add_cursor_for_mode (self,
+ base_item_type,
+ cursor,
+ PHOTOS_WINDOW_MODE_COLLECTIONS,
+ force);
}
else
{
if (photos_item_manager_cursor_is_favorite (cursor))
- photos_item_manager_add_cursor_for_mode (self, cursor, PHOTOS_WINDOW_MODE_FAVORITES, force);
+ {
+ photos_item_manager_add_cursor_for_mode (self,
+ base_item_type,
+ cursor,
+ PHOTOS_WINDOW_MODE_FAVORITES,
+ force);
+ }
- photos_item_manager_add_cursor_for_mode (self, cursor, PHOTOS_WINDOW_MODE_OVERVIEW, force);
+ photos_item_manager_add_cursor_for_mode (self,
+ base_item_type,
+ cursor,
+ PHOTOS_WINDOW_MODE_OVERVIEW,
+ force);
}
out:
@@ -1008,11 +1032,18 @@ photos_item_manager_add_item (PhotosItemManager *self, TrackerSparqlCursor *curs
void
-photos_item_manager_add_item_for_mode (PhotosItemManager *self, PhotosWindowMode mode, TrackerSparqlCursor
*cursor)
+photos_item_manager_add_item_for_mode (PhotosItemManager *self,
+ GType base_item_type,
+ PhotosWindowMode mode,
+ TrackerSparqlCursor *cursor)
{
PhotosItemManagerHiddenItem *old_hidden_item;
const gchar *id;
+ g_return_if_fail (base_item_type == G_TYPE_NONE
+ || (base_item_type != PHOTOS_TYPE_BASE_ITEM
+ && g_type_is_a (base_item_type, PHOTOS_TYPE_BASE_ITEM)));
+
id = tracker_sparql_cursor_get_string (cursor, PHOTOS_QUERY_COLUMNS_URN, NULL);
g_return_if_fail (id != NULL && id[0] != '\0');
@@ -1020,7 +1051,7 @@ photos_item_manager_add_item_for_mode (PhotosItemManager *self, PhotosWindowMode
if (old_hidden_item != NULL)
goto out;
- photos_item_manager_add_cursor_for_mode (self, cursor, mode, FALSE);
+ photos_item_manager_add_cursor_for_mode (self, base_item_type, cursor, mode, FALSE);
out:
return;
@@ -1087,44 +1118,59 @@ photos_item_manager_clear (PhotosItemManager *self, PhotosWindowMode mode)
PhotosBaseItem *
-photos_item_manager_create_item (PhotosItemManager *self, TrackerSparqlCursor *cursor)
+photos_item_manager_create_item (PhotosItemManager *self, GType base_item_type, TrackerSparqlCursor *cursor)
{
- GIOExtension *extension;
- g_auto (GStrv) split_identifier = NULL;
GType type;
PhotosBaseItem *ret_val = NULL;
- const gchar *extension_name = "local";
- g_autofree gchar *identifier = NULL;
g_return_val_if_fail (PHOTOS_IS_ITEM_MANAGER (self), NULL);
+ g_return_val_if_fail (base_item_type == G_TYPE_NONE
+ || (base_item_type != PHOTOS_TYPE_BASE_ITEM
+ && g_type_is_a (base_item_type, PHOTOS_TYPE_BASE_ITEM)), NULL);
g_return_val_if_fail (TRACKER_SPARQL_IS_CURSOR (cursor), NULL);
- identifier = g_strdup (tracker_sparql_cursor_get_string (cursor, PHOTOS_QUERY_COLUMNS_IDENTIFIER, NULL));
- if (identifier != NULL)
+ if (base_item_type == G_TYPE_NONE)
{
- split_identifier = g_strsplit (identifier, ":", 4);
+ GIOExtension *extension;
+ g_auto (GStrv) split_identifier = NULL;
+ const gchar *extension_name = "local";
+ g_autofree gchar *identifier = NULL;
- if (photos_item_manager_cursor_is_collection (cursor))
+ identifier = g_strdup (tracker_sparql_cursor_get_string (cursor, PHOTOS_QUERY_COLUMNS_IDENTIFIER,
NULL));
+ if (identifier != NULL)
{
- /* Its a collection. */
- extension_name = split_identifier[2];
+ split_identifier = g_strsplit (identifier, ":", 4);
+
+ if (photos_item_manager_cursor_is_collection (cursor))
+ {
+ /* Its a collection. */
+ extension_name = split_identifier[2];
+ }
+ else
+ {
+ /* Its a normal photo item. */
+ if (g_strv_length (split_identifier) > 1)
+ extension_name = split_identifier[0];
+ }
}
- else
+
+ extension = g_io_extension_point_get_extension_by_name (self->extension_point, extension_name);
+ if (G_UNLIKELY (extension == NULL))
{
- /* Its a normal photo item. */
- if (g_strv_length (split_identifier) > 1)
- extension_name = split_identifier[0];
+ g_warning ("Unable to find extension %s for identifier: %s", extension_name, identifier);
+ goto out;
}
- }
- extension = g_io_extension_point_get_extension_by_name (self->extension_point, extension_name);
- if (G_UNLIKELY (extension == NULL))
+ type = g_io_extension_get_type (extension);
+ }
+ else
{
- g_warning ("Unable to find extension %s for identifier: %s", extension_name, identifier);
- goto out;
+ type = base_item_type;
}
- type = g_io_extension_get_type (extension);
+ g_return_val_if_fail (type != G_TYPE_NONE, NULL);
+ g_return_val_if_fail (type != PHOTOS_TYPE_BASE_ITEM && g_type_is_a (type, PHOTOS_TYPE_BASE_ITEM), NULL);
+
ret_val = PHOTOS_BASE_ITEM (g_object_new (type,
"cursor", cursor,
"failed-thumbnailing", FALSE,
diff --git a/src/photos-item-manager.h b/src/photos-item-manager.h
index fe203c02..bd5b06e8 100644
--- a/src/photos-item-manager.h
+++ b/src/photos-item-manager.h
@@ -71,10 +71,12 @@ typedef struct _PhotosItemManagerClass PhotosModeControllerClass;
PhotosBaseManager *photos_item_manager_new (void);
void photos_item_manager_add_item (PhotosItemManager *self,
+ GType base_item_type,
TrackerSparqlCursor *cursor,
gboolean force);
void photos_item_manager_add_item_for_mode (PhotosItemManager *self,
+ GType base_item_type,
PhotosWindowMode mode,
TrackerSparqlCursor *cursor);
@@ -82,6 +84,7 @@ void photos_item_manager_clear (Phot
PhotosWindowMode mode);
PhotosBaseItem *photos_item_manager_create_item (PhotosItemManager *self,
+ GType base_item_type,
TrackerSparqlCursor *cursor);
PhotosBaseItem *photos_item_manager_get_active_collection (PhotosItemManager *self);
diff --git a/src/photos-tracker-controller.c b/src/photos-tracker-controller.c
index ccf81aba..6bcd05be 100644
--- a/src/photos-tracker-controller.c
+++ b/src/photos-tracker-controller.c
@@ -233,7 +233,11 @@ photos_tracker_controller_cursor_next (GObject *source_object, GAsyncResult *res
now = g_get_monotonic_time ();
photos_debug (PHOTOS_DEBUG_TRACKER, "Query Cursor: %" G_GINT64_FORMAT, (now - priv->last_query_time) /
1000000);
- photos_item_manager_add_item_for_mode (PHOTOS_ITEM_MANAGER (priv->item_mngr), priv->mode, cursor);
+ photos_item_manager_add_item_for_mode (PHOTOS_ITEM_MANAGER (priv->item_mngr),
+ PHOTOS_TRACKER_CONTROLLER_GET_CLASS (self)->base_item_type,
+ priv->mode,
+ cursor);
+
tracker_sparql_cursor_next_async (cursor,
priv->cancellable,
photos_tracker_controller_cursor_next,
@@ -578,6 +582,8 @@ photos_tracker_controller_class_init (PhotosTrackerControllerClass *class)
{
GObjectClass *object_class = G_OBJECT_CLASS (class);
+ class->base_item_type = G_TYPE_NONE;
+
object_class->constructed = photos_tracker_controller_constructed;
object_class->dispose = photos_tracker_controller_dispose;
object_class->set_property = photos_tracker_controller_set_property;
diff --git a/src/photos-tracker-controller.h b/src/photos-tracker-controller.h
index 1cb597f5..5f4028f0 100644
--- a/src/photos-tracker-controller.h
+++ b/src/photos-tracker-controller.h
@@ -39,6 +39,8 @@ struct _PhotosTrackerControllerClass
{
GObjectClass parent_class;
+ GType base_item_type;
+
/* virtual methods */
PhotosOffsetController *(*get_offset_controller) (PhotosTrackerController *self);
PhotosQuery *(*get_query) (PhotosTrackerController *self);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]