From df2ba5034bbb3b275b61eb2c3b69da310896ffdc Mon Sep 17 00:00:00 2001 From: Debarshi Ray Date: Thu, 10 Sep 2020 19:00:39 +0200 Subject: [PATCH] base-item, utils: Split out the code to get mtime from SparqlCursor The subsequent commit will use this elsewhere in the codebase to avoid a CRITICAL. https://gitlab.gnome.org/GNOME/gnome-photos/-/merge_requests/149 --- src/photos-base-item.c | 14 +------------- src/photos-utils.c | 25 ++++++++++++++++++++++++- src/photos-utils.h | 4 +++- 3 files changed, 28 insertions(+), 15 deletions(-) diff --git a/src/photos-base-item.c b/src/photos-base-item.c index 143431f9..d3d49dd8 100644 --- a/src/photos-base-item.c +++ b/src/photos-base-item.c @@ -2769,7 +2769,6 @@ photos_base_item_populate_from_cursor (PhotosBaseItem *self, TrackerSparqlCursor const gchar *identifier; const gchar *location; const gchar *mime_type; - const gchar *mtime; const gchar *orientation; const gchar *rdf_type; const gchar *resource_urn; @@ -2807,18 +2806,7 @@ photos_base_item_populate_from_cursor (PhotosBaseItem *self, TrackerSparqlCursor favorite = tracker_sparql_cursor_get_boolean (cursor, PHOTOS_QUERY_COLUMNS_RESOURCE_FAVORITE); - priv->mtime = -1; - mtime = tracker_sparql_cursor_get_string (cursor, PHOTOS_QUERY_COLUMNS_MTIME, NULL); - if (mtime != NULL) - { - g_autoptr (GDateTime) date_modified = NULL; - - date_modified = g_date_time_new_from_iso8601 (mtime, NULL); - if (date_modified != NULL) - priv->mtime = g_date_time_to_unix (date_modified); - } - if (priv->mtime == -1) - priv->mtime = g_get_real_time () / 1000000; + priv->mtime = photos_utils_get_mtime_from_sparql_cursor (cursor); g_object_notify (G_OBJECT (self), "mtime"); mime_type = tracker_sparql_cursor_get_string (cursor, PHOTOS_QUERY_COLUMNS_MIME_TYPE, NULL); diff --git a/src/photos-utils.c b/src/photos-utils.c index 21bf4e20..d2d7fb51 100644 --- a/src/photos-utils.c +++ b/src/photos-utils.c @@ -1,6 +1,6 @@ /* * Photos - access, organize and share your photos on GNOME - * Copyright © 2012 – 2019 Red Hat, Inc. + * Copyright © 2012 – 2020 Red Hat, Inc. * Copyright © 2009 Yorba Foundation * * This program is free software: you can redistribute it and/or modify @@ -971,6 +971,29 @@ photos_utils_get_icon_size_unscaled (void) } +gint64 +photos_utils_get_mtime_from_sparql_cursor (TrackerSparqlCursor *cursor) +{ + const gchar *mtime_str; + gint64 mtime = -1; + + mtime_str = tracker_sparql_cursor_get_string (cursor, PHOTOS_QUERY_COLUMNS_MTIME, NULL); + if (mtime_str != NULL) + { + g_autoptr (GDateTime) date_modified = NULL; + + date_modified = g_date_time_new_from_iso8601 (mtime_str, NULL); + if (date_modified != NULL) + mtime = g_date_time_to_unix (date_modified); + } + + if (mtime == -1) + mtime = g_get_real_time () / 1000000; + + return mtime; +} + + gchar * photos_utils_get_pixbuf_common_suffix (GdkPixbufFormat *format) { diff --git a/src/photos-utils.h b/src/photos-utils.h index 78ec3668..132d7558 100644 --- a/src/photos-utils.h +++ b/src/photos-utils.h @@ -1,6 +1,6 @@ /* * Photos - access, organize and share your photos on GNOME - * Copyright © 2012 – 2019 Red Hat, Inc. + * Copyright © 2012 – 2020 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 as published by @@ -134,6 +134,8 @@ gint photos_utils_get_icon_size (void); gint photos_utils_get_icon_size_unscaled (void); +gint64 photos_utils_get_mtime_from_sparql_cursor (TrackerSparqlCursor *cursor); + char* photos_utils_get_pixbuf_common_suffix (GdkPixbufFormat *format); const gchar *photos_utils_get_provider_name (PhotosBaseManager *src_mngr, PhotosBaseItem *item); -- GitLab