[gnome-photos] item-manager: Make use of extensions to create items
- From: Debarshi Ray <debarshir src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-photos] item-manager: Make use of extensions to create items
- Date: Mon, 23 Jun 2014 14:04:56 +0000 (UTC)
commit 57819f5d7340fac0703f5c28614bbd31f0cb7b13
Author: Pranav Kant <pranav913 gmail com>
Date: Thu Jun 19 16:31:36 2014 +0530
item-manager: Make use of extensions to create items
Fixes: https://bugzilla.gnome.org/731865
src/photos-facebook-item.c | 10 ----------
src/photos-facebook-item.h | 2 --
src/photos-flickr-item.c | 10 ----------
src/photos-flickr-item.h | 2 --
src/photos-item-manager.c | 43 +++++++++++++++++++++++++++++++++++--------
src/photos-local-item.c | 10 ----------
src/photos-local-item.h | 2 --
7 files changed, 35 insertions(+), 44 deletions(-)
---
diff --git a/src/photos-facebook-item.c b/src/photos-facebook-item.c
index 9e6245c..b0ad9cb 100644
--- a/src/photos-facebook-item.c
+++ b/src/photos-facebook-item.c
@@ -269,13 +269,3 @@ photos_facebook_item_class_init (PhotosFacebookItemClass *class)
base_item_class->get_source_name = photos_facebook_item_get_source_name;
base_item_class->open = photos_facebook_item_open;
}
-
-
-PhotosBaseItem *
-photos_facebook_item_new (TrackerSparqlCursor *cursor)
-{
- return g_object_new (PHOTOS_TYPE_FACEBOOK_ITEM,
- "cursor", cursor,
- "failed-thumbnailing", FALSE,
- NULL);
-}
diff --git a/src/photos-facebook-item.h b/src/photos-facebook-item.h
index 5157a46..e356c45 100644
--- a/src/photos-facebook-item.h
+++ b/src/photos-facebook-item.h
@@ -70,8 +70,6 @@ struct _PhotosFacebookItemClass
GType photos_facebook_item_get_type (void) G_GNUC_CONST;
-PhotosBaseItem *photos_facebook_item_new (TrackerSparqlCursor *cursor);
-
G_END_DECLS
#endif /* PHOTOS_FACEBOOK_ITEM_H */
diff --git a/src/photos-flickr-item.c b/src/photos-flickr-item.c
index 51b1b76..b2168ab 100644
--- a/src/photos-flickr-item.c
+++ b/src/photos-flickr-item.c
@@ -371,13 +371,3 @@ photos_flickr_item_class_init (PhotosFlickrItemClass *class)
base_item_class->get_source_name = photos_flickr_item_get_source_name;
base_item_class->open = photos_flickr_item_open;
}
-
-
-PhotosBaseItem *
-photos_flickr_item_new (TrackerSparqlCursor *cursor)
-{
- return g_object_new (PHOTOS_TYPE_FLICKR_ITEM,
- "cursor", cursor,
- "failed-thumbnailing", FALSE,
- NULL);
-}
diff --git a/src/photos-flickr-item.h b/src/photos-flickr-item.h
index 0d26b56..8221c3c 100644
--- a/src/photos-flickr-item.h
+++ b/src/photos-flickr-item.h
@@ -70,8 +70,6 @@ struct _PhotosFlickrItemClass
GType photos_flickr_item_get_type (void) G_GNUC_CONST;
-PhotosBaseItem *photos_flickr_item_new (TrackerSparqlCursor *cursor);
-
G_END_DECLS
#endif /* PHOTOS_LOCAL_ITEM_H */
diff --git a/src/photos-item-manager.c b/src/photos-item-manager.c
index a3ca2a7..5678f08 100644
--- a/src/photos-item-manager.c
+++ b/src/photos-item-manager.c
@@ -37,10 +37,12 @@
#include "photos-single-item-job.h"
#include "photos-tracker-change-event.h"
#include "photos-tracker-change-monitor.h"
+#include "photos-utils.h"
struct _PhotosItemManagerPrivate
{
+ GIOExtensionPoint *extension_point;
GQueue *collection_path;
PhotosBaseManager *col_mngr;
PhotosTrackerChangeMonitor *monitor;
@@ -230,6 +232,7 @@ photos_item_manager_init (PhotosItemManager *self)
app = g_application_get_default ();
state = photos_search_context_get_state (PHOTOS_SEARCH_CONTEXT (app));
+ priv->extension_point = g_io_extension_point_lookup (PHOTOS_BASE_ITEM_EXTENSION_POINT_NAME);
priv->collection_path = g_queue_new ();
priv->col_mngr = g_object_ref (state->col_mngr);
@@ -307,22 +310,46 @@ PhotosBaseItem *
photos_item_manager_create_item (PhotosItemManager *self, TrackerSparqlCursor *cursor)
{
PhotosBaseItem *ret_val = NULL;
+ GIOExtension *extension;
+ GType type;
+ const gchar *extension_name = "local";
gchar *identifier = NULL;
+ gchar **split_identifier = NULL;
identifier = g_strdup (tracker_sparql_cursor_get_string (cursor, PHOTOS_QUERY_COLUMNS_IDENTIFIER, NULL));
+ if (identifier == NULL)
+ goto final;
- if (identifier != NULL)
+ split_identifier = g_strsplit (identifier, ":", 4);
+
+ if (g_str_has_prefix (identifier, "photos:collection:"))
+ {
+ /* 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];
+ }
+
+ final:
+ extension = g_io_extension_point_get_extension_by_name (self->priv->extension_point, extension_name);
+ if (G_UNLIKELY (extension == NULL))
{
- if (g_str_has_prefix (identifier, "flickr:") || g_str_has_prefix (identifier,
"photos:collection:flickr:"))
- ret_val = photos_flickr_item_new (cursor);
- else if (g_str_has_prefix (identifier, "facebook:")
- || g_str_has_prefix (identifier, "photos:collection:facebook:"))
- ret_val = photos_facebook_item_new (cursor);
+ g_warning ("Unable to find extension %s for identifier: %s", extension_name, identifier);
+ goto out;
}
- if (ret_val == NULL)
- ret_val = photos_local_item_new (cursor);
+ type = g_io_extension_get_type (extension);
+ ret_val = PHOTOS_BASE_ITEM (g_object_new (type,
+ "cursor", cursor,
+ "failed-thumbnailing", FALSE,
+ NULL));
+ out:
+ g_strfreev (split_identifier);
g_free (identifier);
return ret_val;
}
diff --git a/src/photos-local-item.c b/src/photos-local-item.c
index 8c8faba..35d67e3 100644
--- a/src/photos-local-item.c
+++ b/src/photos-local-item.c
@@ -118,13 +118,3 @@ photos_local_item_class_init (PhotosLocalItemClass *class)
base_item_class->download = photos_local_item_download;
base_item_class->get_source_name = photos_local_item_get_source_name;
}
-
-
-PhotosBaseItem *
-photos_local_item_new (TrackerSparqlCursor *cursor)
-{
- return g_object_new (PHOTOS_TYPE_LOCAL_ITEM,
- "cursor", cursor,
- "failed-thumbnailing", FALSE,
- NULL);
-}
diff --git a/src/photos-local-item.h b/src/photos-local-item.h
index fa62510..9b98d04 100644
--- a/src/photos-local-item.h
+++ b/src/photos-local-item.h
@@ -70,8 +70,6 @@ struct _PhotosLocalItemClass
GType photos_local_item_get_type (void) G_GNUC_CONST;
-PhotosBaseItem *photos_local_item_new (TrackerSparqlCursor *cursor);
-
G_END_DECLS
#endif /* PHOTOS_LOCAL_ITEM_H */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]