[gnome-photos/wip/rishi/collection: 3/6] fetch-metas-job, utils: Use BaseItem API instead of the SparqlCursor
- From: Debarshi Ray <debarshir src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-photos/wip/rishi/collection: 3/6] fetch-metas-job, utils: Use BaseItem API instead of the SparqlCursor
- Date: Wed, 24 Jan 2018 21:27:05 +0000 (UTC)
commit 23a96285353fea67faceb8b3facd420b2f6238a0
Author: Debarshi Ray <debarshir gnome org>
Date: Wed Jan 24 20:42:28 2018 +0100
fetch-metas-job, utils: Use BaseItem API instead of the SparqlCursor
A subsequent patch will directly use the BaseItem to query the
GFileInfo, instead of creating a GFile out of the URI. This is a step
in that direction.
It's also better to not do the same thing, parsing the
TrackerSparqlCursor in this case, in subtly different ways through
different code paths.
po/POTFILES.in | 1 -
src/photos-fetch-metas-job.c | 36 +++++++++++++++++++++++++-----------
src/photos-utils.c | 35 ++++++++++++-----------------------
src/photos-utils.h | 5 +----
4 files changed, 38 insertions(+), 39 deletions(-)
---
diff --git a/po/POTFILES.in b/po/POTFILES.in
index f890ca5b..7859510e 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -14,7 +14,6 @@ src/photos-export-dialog.ui
src/photos-export-dialog.c
src/photos-export-notification.c
src/photos-facebook-item.c
-src/photos-fetch-metas-job.c
src/photos-flickr-item.c
src/photos-google-item.c
src/photos-help-overlay.ui
diff --git a/src/photos-fetch-metas-job.c b/src/photos-fetch-metas-job.c
index 845149d0..fcf88f18 100644
--- a/src/photos-fetch-metas-job.c
+++ b/src/photos-fetch-metas-job.c
@@ -26,12 +26,14 @@
#include <string.h>
#include <glib.h>
-#include <glib/gi18n.h>
#include <gio/gio.h>
#include <tracker-sparql.h>
#include "photos-create-collection-icon-job.h"
+#include "photos-base-item.h"
#include "photos-fetch-metas-job.h"
+#include "photos-filterable.h"
+#include "photos-item-manager.h"
#include "photos-query.h"
#include "photos-single-item-job.h"
#include "photos-utils.h"
@@ -41,6 +43,7 @@ struct _PhotosFetchMetasJob
{
GObject parent_instance;
GList *metas;
+ PhotosBaseManager *item_mngr;
PhotosFetchMetasJobCallback callback;
gchar **ids;
gpointer user_data;
@@ -146,12 +149,12 @@ photos_fetch_metas_job_executed (GObject *source_object, GAsyncResult *res, gpoi
PhotosFetchMetasJob *self = PHOTOS_FETCH_METAS_JOB (user_data);
GError *error = NULL;
GIcon *icon = NULL;
+ PhotosBaseItem *item = NULL;
PhotosFetchMeta *meta;
PhotosSingleItemJob *job = PHOTOS_SINGLE_ITEM_JOB (source_object);
TrackerSparqlCursor *cursor = NULL;
gboolean is_collection;
const gchar *id;
- const gchar *rdf_type;
const gchar *title;
cursor = photos_single_item_job_finish (job, res, &error);
@@ -162,17 +165,13 @@ photos_fetch_metas_job_executed (GObject *source_object, GAsyncResult *res, gpoi
goto out;
}
- id = tracker_sparql_cursor_get_string (cursor, PHOTOS_QUERY_COLUMNS_URN, NULL);
- title = tracker_sparql_cursor_get_string (cursor, PHOTOS_QUERY_COLUMNS_TITLE, NULL);
- rdf_type = tracker_sparql_cursor_get_string (cursor, PHOTOS_QUERY_COLUMNS_RDF_TYPE, NULL);
-
- is_collection = (strstr (rdf_type, "nfo#DataContainer") != NULL);
+ item = photos_item_manager_create_item (PHOTOS_ITEM_MANAGER (self->item_mngr), G_TYPE_NONE, cursor, FALSE);
+ id = photos_filterable_get_id (PHOTOS_FILTERABLE (item));
+ title = photos_base_item_get_name_with_fallback (item);
+ is_collection = photos_base_item_is_collection (item);
if (!is_collection)
- icon = photos_utils_get_icon_from_cursor (cursor);
-
- if (title == NULL || title[0] == '\0')
- title = _("Untitled Photo");
+ icon = photos_utils_get_icon_from_item (item);
meta = photos_fetch_meta_new (icon, id, title);
@@ -187,10 +186,22 @@ photos_fetch_metas_job_executed (GObject *source_object, GAsyncResult *res, gpoi
out:
g_clear_object (&cursor);
g_clear_object (&icon);
+ g_clear_object (&item);
g_object_unref (self);
}
+static void
+photos_fetch_metas_job_dispose (GObject *object)
+{
+ PhotosFetchMetasJob *self = PHOTOS_FETCH_METAS_JOB (object);
+
+ g_clear_object (&self->item_mngr);
+
+ G_OBJECT_CLASS (photos_fetch_metas_job_parent_class)->dispose (object);
+}
+
+
static void
photos_fetch_metas_job_finalize (GObject *object)
{
@@ -232,6 +243,7 @@ photos_fetch_metas_job_class_init (PhotosFetchMetasJobClass *class)
{
GObjectClass *object_class = G_OBJECT_CLASS (class);
+ object_class->dispose = photos_fetch_metas_job_dispose;
object_class->finalize = photos_fetch_metas_job_finalize;
object_class->set_property = photos_fetch_metas_job_set_property;
@@ -290,6 +302,8 @@ photos_fetch_metas_job_run (PhotosFetchMetasJob *self,
self->user_data = user_data;
self->active_jobs = g_strv_length (self->ids);
+ g_set_object (&self->item_mngr, state->item_mngr);
+
for (i = 0; self->ids[i] != NULL; i++)
{
PhotosSingleItemJob *job;
diff --git a/src/photos-utils.c b/src/photos-utils.c
index b1817775..549ee1b2 100644
--- a/src/photos-utils.c
+++ b/src/photos-utils.c
@@ -462,15 +462,14 @@ photos_utils_get_thumbnail_icon (const gchar *uri)
GIcon *
-photos_utils_get_icon_from_cursor (TrackerSparqlCursor *cursor)
+photos_utils_get_icon_from_item (PhotosBaseItem *item)
{
GIcon *icon = NULL;
gboolean is_remote = FALSE;
const gchar *identifier;
const gchar *mime_type;
- const gchar *rdf_type;
- identifier = tracker_sparql_cursor_get_string (cursor, PHOTOS_QUERY_COLUMNS_IDENTIFIER, NULL);
+ identifier = photos_base_item_get_identifier (item);
if (identifier != NULL)
{
if (g_str_has_prefix (identifier, "facebook:") ||
@@ -483,24 +482,28 @@ photos_utils_get_icon_from_cursor (TrackerSparqlCursor *cursor)
{
const gchar *uri;
- uri = tracker_sparql_cursor_get_string (cursor, PHOTOS_QUERY_COLUMNS_URI, NULL);
- if (uri != NULL)
+ uri = photos_base_item_get_uri (item);
+ if (uri != NULL && uri[0] != '\0')
icon = photos_utils_get_thumbnail_icon (uri);
}
if (icon != NULL)
goto out;
- mime_type = tracker_sparql_cursor_get_string (cursor, PHOTOS_QUERY_COLUMNS_MIME_TYPE, NULL);
+ mime_type = photos_base_item_get_mime_type (item);
if (mime_type != NULL)
icon = g_content_type_get_icon (mime_type);
if (icon != NULL)
goto out;
- rdf_type = tracker_sparql_cursor_get_string (cursor, PHOTOS_QUERY_COLUMNS_RDF_TYPE, NULL);
- if (rdf_type != NULL)
- icon = photos_utils_icon_from_rdf_type (rdf_type);
+ if (photos_base_item_is_collection (item))
+ {
+ gint size;
+
+ size = photos_utils_get_icon_size ();
+ icon = photos_utils_create_collection_icon (size, NULL);
+ }
if (icon != NULL)
goto out;
@@ -1250,20 +1253,6 @@ photos_utils_get_version (void)
}
-GIcon *
-photos_utils_icon_from_rdf_type (const gchar *type)
-{
- GIcon *ret_val = NULL;
- gint size;
-
- size = photos_utils_get_icon_size ();
- if (strstr (type, "nfo#DataContainer") != NULL)
- ret_val = photos_utils_create_collection_icon (size, NULL);
-
- return ret_val;
-}
-
-
void
photos_utils_list_box_header_func (GtkListBoxRow *row, GtkListBoxRow *before, gpointer user_data)
{
diff --git a/src/photos-utils.h b/src/photos-utils.h
index fad7c0d1..e5aec5e1 100644
--- a/src/photos-utils.h
+++ b/src/photos-utils.h
@@ -30,7 +30,6 @@
#include <gio/gio.h>
#include <glib.h>
#include <gtk/gtk.h>
-#include <tracker-sparql.h>
#include "photos-base-item.h"
#include "photos-base-manager.h"
@@ -82,7 +81,7 @@ gboolean photos_utils_create_thumbnail (GFile *file,
GVariant *photos_utils_create_zoom_target_value (gdouble delta, PhotosZoomEvent event);
-GIcon *photos_utils_get_icon_from_cursor (TrackerSparqlCursor *cursor);
+GIcon *photos_utils_get_icon_from_item (PhotosBaseItem *item);
gdouble photos_utils_get_zoom_delta (GVariant *dictionary);
@@ -165,8 +164,6 @@ GList *photos_utils_get_urns_from_items (GList *items);
const gchar *photos_utils_get_version (void);
-GIcon *photos_utils_icon_from_rdf_type (const gchar *type);
-
void photos_utils_list_box_header_func (GtkListBoxRow *row,
GtkListBoxRow *before,
gpointer user_data);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]