[gnome-photos/wip/rishi/collection: 32/40] base-item: Add a populate_from_cursor virtual method
- From: Debarshi Ray <debarshir src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-photos/wip/rishi/collection: 32/40] base-item: Add a populate_from_cursor virtual method
- Date: Thu, 25 Jan 2018 12:59:46 +0000 (UTC)
commit 3a5622c66288ec0ef9e874b4b25a47d69342579b
Author: Debarshi Ray <debarshir gnome org>
Date: Thu Jan 25 02:25:31 2018 +0100
base-item: Add a populate_from_cursor virtual method
https://bugzilla.gnome.org/show_bug.cgi?id=751212
src/photos-base-item.c | 298 ++++++++++++++++++++++++-------------------------
src/photos-base-item.h | 2 +
2 files changed, 151 insertions(+), 149 deletions(-)
---
diff --git a/src/photos-base-item.c b/src/photos-base-item.c
index 5139404a..35281796 100644
--- a/src/photos-base-item.c
+++ b/src/photos-base-item.c
@@ -35,7 +35,6 @@
#include <glib.h>
#include <glib/gi18n.h>
#include <libgd/gd.h>
-#include <tracker-sparql.h>
#include "egg-counter.h"
#include "egg-task-cache.h"
@@ -189,7 +188,7 @@ static GThreadPool *create_thumbnail_pool;
static const gint PIXEL_SIZES[] = {2048, 1024};
-static void photos_base_item_populate_from_cursor (PhotosBaseItem *self, TrackerSparqlCursor *cursor);
+static void photos_base_item_refresh_icon (PhotosBaseItem *self);
static PhotosBaseItemMetadataAddSharedData *
@@ -639,6 +638,151 @@ photos_base_item_default_open (PhotosBaseItem *self, GtkWindow *parent, guint32
}
+static void
+photos_base_item_default_populate_from_cursor (PhotosBaseItem *self, TrackerSparqlCursor *cursor)
+{
+ PhotosBaseItemPrivate *priv;
+ GTimeVal timeval;
+ gboolean favorite;
+ const gchar *author;
+ const gchar *date_created;
+ const gchar *equipment;
+ const gchar *flash;
+ const gchar *id;
+ const gchar *identifier;
+ const gchar *location;
+ const gchar *mime_type;
+ const gchar *mtime;
+ const gchar *orientation;
+ const gchar *rdf_type;
+ const gchar *resource_urn;
+ const gchar *title;
+ const gchar *uri;
+ gchar *filename;
+ gchar *name_fallback;
+ gint64 height;
+ gint64 width;
+
+ priv = photos_base_item_get_instance_private (self);
+
+ uri = tracker_sparql_cursor_get_string (cursor, PHOTOS_QUERY_COLUMNS_URI, NULL);
+ if (uri == NULL)
+ uri = "";
+ photos_utils_set_string (&priv->uri, uri);
+ g_object_notify (G_OBJECT (self), "uri");
+
+ id = tracker_sparql_cursor_get_string (cursor, PHOTOS_QUERY_COLUMNS_URN, NULL);
+ photos_utils_set_string (&priv->id, id);
+ g_object_notify (G_OBJECT (self), "id");
+
+ identifier = tracker_sparql_cursor_get_string (cursor, PHOTOS_QUERY_COLUMNS_IDENTIFIER, NULL);
+ photos_utils_set_string (&priv->identifier, identifier);
+
+ author = tracker_sparql_cursor_get_string (cursor, PHOTOS_QUERY_COLUMNS_AUTHOR, NULL);
+ photos_utils_set_string (&priv->author, author);
+ g_object_notify (G_OBJECT (self), "secondary-text");
+
+ location = tracker_sparql_cursor_get_string (cursor, PHOTOS_QUERY_COLUMNS_LOCATION, NULL);
+ photos_utils_set_string (&priv->location, location);
+
+ resource_urn = tracker_sparql_cursor_get_string (cursor, PHOTOS_QUERY_COLUMNS_RESOURCE_URN, NULL);
+ photos_utils_set_string (&priv->resource_urn, resource_urn);
+
+ favorite = tracker_sparql_cursor_get_boolean (cursor, PHOTOS_QUERY_COLUMNS_RESOURCE_FAVORITE);
+
+ mtime = tracker_sparql_cursor_get_string (cursor, PHOTOS_QUERY_COLUMNS_MTIME, NULL);
+ if (mtime != NULL)
+ {
+ g_time_val_from_iso8601 (mtime, &timeval);
+ priv->mtime = (gint64) timeval.tv_sec;
+ }
+ else
+ priv->mtime = g_get_real_time () / 1000000;
+ g_object_notify (G_OBJECT (self), "mtime");
+
+ mime_type = tracker_sparql_cursor_get_string (cursor, PHOTOS_QUERY_COLUMNS_MIME_TYPE, NULL);
+ photos_utils_set_string (&priv->mime_type, mime_type);
+
+ rdf_type = tracker_sparql_cursor_get_string (cursor, PHOTOS_QUERY_COLUMNS_RDF_TYPE, NULL);
+ photos_utils_set_string (&priv->rdf_type, rdf_type);
+
+ photos_base_item_update_info_from_type (self);
+ priv->favorite = favorite && !priv->collection;
+
+ date_created = tracker_sparql_cursor_get_string (cursor, PHOTOS_QUERY_COLUMNS_DATE_CREATED, NULL);
+ if (date_created != NULL)
+ {
+ g_time_val_from_iso8601 (date_created, &timeval);
+ priv->date_created = (gint64) timeval.tv_sec;
+ }
+ else
+ priv->date_created = -1;
+
+ if (g_strcmp0 (priv->id, PHOTOS_COLLECTION_SCREENSHOT) == 0)
+ title = _("Screenshots");
+ else
+ title = tracker_sparql_cursor_get_string (cursor, PHOTOS_QUERY_COLUMNS_TITLE, NULL);
+
+ if (title == NULL)
+ title = "";
+ photos_utils_set_string (&priv->name, title);
+ g_object_notify (G_OBJECT (self), "primary-text");
+
+ filename = g_strdup (tracker_sparql_cursor_get_string (cursor, PHOTOS_QUERY_COLUMNS_FILENAME, NULL));
+ if ((filename == NULL || filename[0] == '\0') && !priv->collection)
+ filename = PHOTOS_BASE_ITEM_GET_CLASS (self)->create_filename_fallback (self);
+ photos_utils_take_string (&priv->filename, filename);
+
+ equipment = tracker_sparql_cursor_get_string (cursor, PHOTOS_QUERY_COLUMNS_EQUIPMENT, NULL);
+ priv->equipment = g_quark_from_string (equipment);
+
+ orientation = tracker_sparql_cursor_get_string (cursor, PHOTOS_QUERY_COLUMNS_ORIENTATION, NULL);
+ priv->orientation = g_quark_from_string (orientation);
+ if (priv->orientation != PHOTOS_ORIENTATION_BOTTOM
+ && priv->orientation != PHOTOS_ORIENTATION_BOTTOM_MIRROR
+ && priv->orientation != PHOTOS_ORIENTATION_LEFT
+ && priv->orientation != PHOTOS_ORIENTATION_LEFT_MIRROR
+ && priv->orientation != PHOTOS_ORIENTATION_RIGHT
+ && priv->orientation != PHOTOS_ORIENTATION_RIGHT_MIRROR
+ && priv->orientation != PHOTOS_ORIENTATION_TOP
+ && priv->orientation != PHOTOS_ORIENTATION_TOP_MIRROR)
+ {
+ if (orientation != NULL)
+ g_warning ("Unknown value for nfo:orientation: %s", orientation);
+ priv->orientation = PHOTOS_ORIENTATION_TOP;
+ }
+
+ height = tracker_sparql_cursor_get_integer (cursor, PHOTOS_QUERY_COLUMNS_HEIGHT);
+ width = tracker_sparql_cursor_get_integer (cursor, PHOTOS_QUERY_COLUMNS_WIDTH);
+ if (priv->orientation == PHOTOS_ORIENTATION_BOTTOM
+ || priv->orientation == PHOTOS_ORIENTATION_BOTTOM_MIRROR
+ || priv->orientation == PHOTOS_ORIENTATION_TOP
+ || priv->orientation == PHOTOS_ORIENTATION_TOP_MIRROR)
+ {
+ priv->height = height;
+ priv->width = width;
+ }
+ else
+ {
+ priv->height = width;
+ priv->width = height;
+ }
+
+ priv->exposure_time = tracker_sparql_cursor_get_double (cursor, PHOTOS_QUERY_COLUMNS_EXPOSURE_TIME);
+ priv->fnumber = tracker_sparql_cursor_get_double (cursor, PHOTOS_QUERY_COLUMNS_FNUMBER);
+ priv->focal_length = tracker_sparql_cursor_get_double (cursor, PHOTOS_QUERY_COLUMNS_FOCAL_LENGTH);
+ priv->iso_speed = tracker_sparql_cursor_get_double (cursor, PHOTOS_QUERY_COLUMNS_ISO_SPEED);
+
+ flash = tracker_sparql_cursor_get_string (cursor, PHOTOS_QUERY_COLUMNS_FLASH, NULL);
+ priv->flash = g_quark_from_string (flash);
+
+ name_fallback = PHOTOS_BASE_ITEM_GET_CLASS (self)->create_name_fallback (self);
+ photos_utils_take_string (&priv->name_fallback, name_fallback);
+
+ photos_base_item_refresh_icon (self);
+}
+
+
static void
photos_base_item_default_update_type_description (PhotosBaseItem *self)
{
@@ -807,7 +951,7 @@ photos_base_item_refresh_executed (GObject *source_object, GAsyncResult *res, gp
if (cursor == NULL)
goto out;
- photos_base_item_populate_from_cursor (self, cursor);
+ PHOTOS_BASE_ITEM_GET_CLASS (self)->populate_from_cursor (self, cursor);
out:
g_clear_object (&cursor);
@@ -2617,151 +2761,6 @@ photos_base_item_refresh_icon (PhotosBaseItem *self)
}
-static void
-photos_base_item_populate_from_cursor (PhotosBaseItem *self, TrackerSparqlCursor *cursor)
-{
- PhotosBaseItemPrivate *priv;
- GTimeVal timeval;
- gboolean favorite;
- const gchar *author;
- const gchar *date_created;
- const gchar *equipment;
- const gchar *flash;
- const gchar *id;
- const gchar *identifier;
- const gchar *location;
- const gchar *mime_type;
- const gchar *mtime;
- const gchar *orientation;
- const gchar *rdf_type;
- const gchar *resource_urn;
- const gchar *title;
- const gchar *uri;
- gchar *filename;
- gchar *name_fallback;
- gint64 height;
- gint64 width;
-
- priv = photos_base_item_get_instance_private (self);
-
- uri = tracker_sparql_cursor_get_string (cursor, PHOTOS_QUERY_COLUMNS_URI, NULL);
- if (uri == NULL)
- uri = "";
- photos_utils_set_string (&priv->uri, uri);
- g_object_notify (G_OBJECT (self), "uri");
-
- id = tracker_sparql_cursor_get_string (cursor, PHOTOS_QUERY_COLUMNS_URN, NULL);
- photos_utils_set_string (&priv->id, id);
- g_object_notify (G_OBJECT (self), "id");
-
- identifier = tracker_sparql_cursor_get_string (cursor, PHOTOS_QUERY_COLUMNS_IDENTIFIER, NULL);
- photos_utils_set_string (&priv->identifier, identifier);
-
- author = tracker_sparql_cursor_get_string (cursor, PHOTOS_QUERY_COLUMNS_AUTHOR, NULL);
- photos_utils_set_string (&priv->author, author);
- g_object_notify (G_OBJECT (self), "secondary-text");
-
- location = tracker_sparql_cursor_get_string (cursor, PHOTOS_QUERY_COLUMNS_LOCATION, NULL);
- photos_utils_set_string (&priv->location, location);
-
- resource_urn = tracker_sparql_cursor_get_string (cursor, PHOTOS_QUERY_COLUMNS_RESOURCE_URN, NULL);
- photos_utils_set_string (&priv->resource_urn, resource_urn);
-
- favorite = tracker_sparql_cursor_get_boolean (cursor, PHOTOS_QUERY_COLUMNS_RESOURCE_FAVORITE);
-
- mtime = tracker_sparql_cursor_get_string (cursor, PHOTOS_QUERY_COLUMNS_MTIME, NULL);
- if (mtime != NULL)
- {
- g_time_val_from_iso8601 (mtime, &timeval);
- priv->mtime = (gint64) timeval.tv_sec;
- }
- else
- priv->mtime = g_get_real_time () / 1000000;
- g_object_notify (G_OBJECT (self), "mtime");
-
- mime_type = tracker_sparql_cursor_get_string (cursor, PHOTOS_QUERY_COLUMNS_MIME_TYPE, NULL);
- photos_utils_set_string (&priv->mime_type, mime_type);
-
- rdf_type = tracker_sparql_cursor_get_string (cursor, PHOTOS_QUERY_COLUMNS_RDF_TYPE, NULL);
- photos_utils_set_string (&priv->rdf_type, rdf_type);
-
- photos_base_item_update_info_from_type (self);
- priv->favorite = favorite && !priv->collection;
-
- date_created = tracker_sparql_cursor_get_string (cursor, PHOTOS_QUERY_COLUMNS_DATE_CREATED, NULL);
- if (date_created != NULL)
- {
- g_time_val_from_iso8601 (date_created, &timeval);
- priv->date_created = (gint64) timeval.tv_sec;
- }
- else
- priv->date_created = -1;
-
- if (g_strcmp0 (priv->id, PHOTOS_COLLECTION_SCREENSHOT) == 0)
- title = _("Screenshots");
- else
- title = tracker_sparql_cursor_get_string (cursor, PHOTOS_QUERY_COLUMNS_TITLE, NULL);
-
- if (title == NULL)
- title = "";
- photos_utils_set_string (&priv->name, title);
- g_object_notify (G_OBJECT (self), "primary-text");
-
- filename = g_strdup (tracker_sparql_cursor_get_string (cursor, PHOTOS_QUERY_COLUMNS_FILENAME, NULL));
- if ((filename == NULL || filename[0] == '\0') && !priv->collection)
- filename = PHOTOS_BASE_ITEM_GET_CLASS (self)->create_filename_fallback (self);
- photos_utils_take_string (&priv->filename, filename);
-
- equipment = tracker_sparql_cursor_get_string (cursor, PHOTOS_QUERY_COLUMNS_EQUIPMENT, NULL);
- priv->equipment = g_quark_from_string (equipment);
-
- orientation = tracker_sparql_cursor_get_string (cursor, PHOTOS_QUERY_COLUMNS_ORIENTATION, NULL);
- priv->orientation = g_quark_from_string (orientation);
- if (priv->orientation != PHOTOS_ORIENTATION_BOTTOM
- && priv->orientation != PHOTOS_ORIENTATION_BOTTOM_MIRROR
- && priv->orientation != PHOTOS_ORIENTATION_LEFT
- && priv->orientation != PHOTOS_ORIENTATION_LEFT_MIRROR
- && priv->orientation != PHOTOS_ORIENTATION_RIGHT
- && priv->orientation != PHOTOS_ORIENTATION_RIGHT_MIRROR
- && priv->orientation != PHOTOS_ORIENTATION_TOP
- && priv->orientation != PHOTOS_ORIENTATION_TOP_MIRROR)
- {
- if (orientation != NULL)
- g_warning ("Unknown value for nfo:orientation: %s", orientation);
- priv->orientation = PHOTOS_ORIENTATION_TOP;
- }
-
- height = tracker_sparql_cursor_get_integer (cursor, PHOTOS_QUERY_COLUMNS_HEIGHT);
- width = tracker_sparql_cursor_get_integer (cursor, PHOTOS_QUERY_COLUMNS_WIDTH);
- if (priv->orientation == PHOTOS_ORIENTATION_BOTTOM
- || priv->orientation == PHOTOS_ORIENTATION_BOTTOM_MIRROR
- || priv->orientation == PHOTOS_ORIENTATION_TOP
- || priv->orientation == PHOTOS_ORIENTATION_TOP_MIRROR)
- {
- priv->height = height;
- priv->width = width;
- }
- else
- {
- priv->height = width;
- priv->width = height;
- }
-
- priv->exposure_time = tracker_sparql_cursor_get_double (cursor, PHOTOS_QUERY_COLUMNS_EXPOSURE_TIME);
- priv->fnumber = tracker_sparql_cursor_get_double (cursor, PHOTOS_QUERY_COLUMNS_FNUMBER);
- priv->focal_length = tracker_sparql_cursor_get_double (cursor, PHOTOS_QUERY_COLUMNS_FOCAL_LENGTH);
- priv->iso_speed = tracker_sparql_cursor_get_double (cursor, PHOTOS_QUERY_COLUMNS_ISO_SPEED);
-
- flash = tracker_sparql_cursor_get_string (cursor, PHOTOS_QUERY_COLUMNS_FLASH, NULL);
- priv->flash = g_quark_from_string (flash);
-
- name_fallback = PHOTOS_BASE_ITEM_GET_CLASS (self)->create_name_fallback (self);
- photos_utils_take_string (&priv->name_fallback, name_fallback);
-
- photos_base_item_refresh_icon (self);
-}
-
-
static void
photos_base_item_print_load (GObject *source_object, GAsyncResult *res, gpointer user_data)
{
@@ -2823,7 +2822,7 @@ photos_base_item_constructed (GObject *object)
G_OBJECT_CLASS (photos_base_item_parent_class)->constructed (object);
- photos_base_item_populate_from_cursor (self, priv->cursor);
+ PHOTOS_BASE_ITEM_GET_CLASS (self)->populate_from_cursor (self, priv->cursor);
g_clear_object (&priv->cursor); /* We will not need it any more */
}
@@ -2989,6 +2988,7 @@ photos_base_item_class_init (PhotosBaseItemClass *class)
object_class->set_property = photos_base_item_set_property;
class->metadata_add_shared = photos_base_item_default_metadata_add_shared;
class->open = photos_base_item_default_open;
+ class->populate_from_cursor = photos_base_item_default_populate_from_cursor;
class->set_favorite = photos_base_item_default_set_favorite;
class->update_type_description = photos_base_item_default_update_type_description;
diff --git a/src/photos-base-item.h b/src/photos-base-item.h
index 21d26874..4b95ede3 100644
--- a/src/photos-base-item.h
+++ b/src/photos-base-item.h
@@ -29,6 +29,7 @@
#include <gio/gio.h>
#include <glib-object.h>
#include <gtk/gtk.h>
+#include <tracker-sparql.h>
G_BEGIN_DECLS
@@ -68,6 +69,7 @@ struct _PhotosBaseItemClass
GCancellable *cancellable,
GError **error);
void (*open) (PhotosBaseItem *self, GtkWindow *parent, guint32 timestamp);
+ void (*populate_from_cursor) (PhotosBaseItem *self, TrackerSparqlCursor *cursor);
void (*set_favorite) (PhotosBaseItem *self, gboolean favorite);
void (*trash) (PhotosBaseItem *self);
void (*update_type_description) (PhotosBaseItem *self);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]