[gnome-photos/wip/rishi/collection: 11/21] Allow adding an optional ID to the nao:identifier of local collections



commit 75d86ebb5cc1b7e5ffcd7b9eabe87e2975ddc33a
Author: Debarshi Ray <debarshir gnome org>
Date:   Tue Feb 13 22:50:41 2018 +0100

    Allow adding an optional ID to the nao:identifier of local collections
    
    This will be necessary to "tag" the default suggested collection to
    which imported items are added, so that one may detect whether it
    already exists.
    
    The default collection during import is named based on the timestamp
    of the items being imported. The user-visible representation of the
    timestamp depends on the locale, and can't be relied upon for
    identification. Therefore, the raw timestamp is added to the
    nao:identifier as:
      photos:collection:local:<timestamp>
    
    https://gitlab.gnome.org/GNOME/gnome-photos/issues/29

 src/photos-create-collection-job.c    | 22 +++++++++++++++++++---
 src/photos-create-collection-job.h    |  3 ++-
 src/photos-organize-collection-view.c |  2 +-
 src/photos-query-builder.c            | 14 ++++++++++----
 src/photos-query-builder.h            |  4 +++-
 5 files changed, 35 insertions(+), 10 deletions(-)
---
diff --git a/src/photos-create-collection-job.c b/src/photos-create-collection-job.c
index 52ccadff..c4cd54d2 100644
--- a/src/photos-create-collection-job.c
+++ b/src/photos-create-collection-job.c
@@ -41,12 +41,14 @@ struct _PhotosCreateCollectionJob
   GObject parent_instance;
   GError *queue_error;
   PhotosTrackerQueue *queue;
+  gchar *identifier_tag;
   gchar *name;
 };
 
 enum
 {
   PROP_0,
+  PROP_IDENTIFIER_TAG,
   PROP_NAME
 };
 
@@ -122,6 +124,7 @@ photos_create_collection_job_finalize (GObject *object)
   PhotosCreateCollectionJob *self = PHOTOS_CREATE_COLLECTION_JOB (object);
 
   g_clear_error (&self->queue_error);
+  g_free (self->identifier_tag);
   g_free (self->name);
 
   G_OBJECT_CLASS (photos_create_collection_job_parent_class)->finalize (object);
@@ -135,6 +138,10 @@ photos_create_collection_job_set_property (GObject *object, guint prop_id, const
 
   switch (prop_id)
     {
+    case PROP_IDENTIFIER_TAG:
+      self->identifier_tag = g_value_dup_string (value);
+      break;
+
     case PROP_NAME:
       self->name = g_value_dup_string (value);
       break;
@@ -162,6 +169,14 @@ photos_create_collection_job_class_init (PhotosCreateCollectionJobClass *class)
   object_class->finalize = photos_create_collection_job_finalize;
   object_class->set_property = photos_create_collection_job_set_property;
 
+  g_object_class_install_property (object_class,
+                                   PROP_IDENTIFIER_TAG,
+                                   g_param_spec_string ("identifier-tag",
+                                                        "Identfier tag",
+                                                        "An optional ID that will be added to the 
nao:identifier",
+                                                        NULL,
+                                                        G_PARAM_CONSTRUCT_ONLY | G_PARAM_WRITABLE));
+
   g_object_class_install_property (object_class,
                                    PROP_NAME,
                                    g_param_spec_string ("name",
@@ -173,11 +188,12 @@ photos_create_collection_job_class_init (PhotosCreateCollectionJobClass *class)
 
 
 PhotosCreateCollectionJob *
-photos_create_collection_job_new (const gchar *name)
+photos_create_collection_job_new (const gchar *name, const gchar *identifier_tag)
 {
   g_return_val_if_fail (name != NULL && name[0] != '\0', NULL);
+  g_return_val_if_fail (identifier_tag == NULL || identifier_tag[0] != '\0', NULL);
 
-  return g_object_new (PHOTOS_TYPE_CREATE_COLLECTION_JOB, "name", name, NULL);
+  return g_object_new (PHOTOS_TYPE_CREATE_COLLECTION_JOB, "identifier-tag", identifier_tag, "name", name, 
NULL);
 }
 
 
@@ -221,7 +237,7 @@ photos_create_collection_job_run (PhotosCreateCollectionJob *self,
   app = g_application_get_default ();
   state = photos_search_context_get_state (PHOTOS_SEARCH_CONTEXT (app));
 
-  query = photos_query_builder_create_collection_query (state, self->name);
+  query = photos_query_builder_create_collection_query (state, self->name, self->identifier_tag);
   photos_tracker_queue_update_blank (self->queue,
                                      query,
                                      cancellable,
diff --git a/src/photos-create-collection-job.h b/src/photos-create-collection-job.h
index ce9de2a6..9c26db2b 100644
--- a/src/photos-create-collection-job.h
+++ b/src/photos-create-collection-job.h
@@ -34,7 +34,8 @@ G_DECLARE_FINAL_TYPE (PhotosCreateCollectionJob,
                       CREATE_COLLECTION_JOB,
                       GObject);
 
-PhotosCreateCollectionJob  *photos_create_collection_job_new         (const gchar *name);
+PhotosCreateCollectionJob  *photos_create_collection_job_new         (const gchar *name,
+                                                                      const gchar *identifier_tag);
 
 void                        photos_create_collection_job_run         (PhotosCreateCollectionJob *self,
                                                                       GCancellable *cancellable,
diff --git a/src/photos-organize-collection-view.c b/src/photos-organize-collection-view.c
index 73508193..59a50351 100644
--- a/src/photos-organize-collection-view.c
+++ b/src/photos-organize-collection-view.c
@@ -265,7 +265,7 @@ photos_organize_collection_view_text_edited_real (PhotosOrganizeCollectionView *
   gtk_tree_model_get_iter (GTK_TREE_MODEL (self->model), &iter, path);
   gtk_list_store_set (self->model, &iter, PHOTOS_ORGANIZE_MODEL_NAME, new_text, -1);
 
-  job = photos_create_collection_job_new (new_text);
+  job = photos_create_collection_job_new (new_text, NULL);
   photos_create_collection_job_run (job,
                                     self->cancellable,
                                     photos_organize_collection_view_create_collection_executed,
diff --git a/src/photos-query-builder.c b/src/photos-query-builder.c
index 56fb017b..46b03425 100644
--- a/src/photos-query-builder.c
+++ b/src/photos-query-builder.c
@@ -179,14 +179,21 @@ photos_query_builder_query (PhotosSearchContextState *state,
 
 
 PhotosQuery *
-photos_query_builder_create_collection_query (PhotosSearchContextState *state, const gchar *name)
+photos_query_builder_create_collection_query (PhotosSearchContextState *state,
+                                              const gchar *name,
+                                              const gchar *identifier_tag)
 {
   GTimeVal tv;
   PhotosQuery *query;
+  g_autofree gchar *identifier = NULL;
   g_autofree gchar *sparql = NULL;
   g_autofree gchar *time = NULL;
   gint64 timestamp;
 
+  identifier = g_strdup_printf ("%s%s",
+                                PHOTOS_QUERY_LOCAL_COLLECTIONS_IDENTIFIER,
+                                identifier_tag == NULL ? name : identifier_tag);
+
   timestamp = g_get_real_time () / G_USEC_PER_SEC;
   tv.tv_sec = timestamp;
   tv.tv_usec = 0;
@@ -195,11 +202,10 @@ photos_query_builder_create_collection_query (PhotosSearchContextState *state, c
   sparql = g_strdup_printf ("INSERT { _:res a nfo:DataContainer ; a nie:DataObject ; "
                             "nie:contentLastModified '%s' ; "
                             "nie:title '%s' ; "
-                            "nao:identifier '%s%s' }",
+                            "nao:identifier '%s' }",
                             time,
                             name,
-                            PHOTOS_QUERY_LOCAL_COLLECTIONS_IDENTIFIER,
-                            name);
+                            identifier);
 
   query = photos_query_new (state, sparql);
 
diff --git a/src/photos-query-builder.h b/src/photos-query-builder.h
index c21b1932..56ce5682 100644
--- a/src/photos-query-builder.h
+++ b/src/photos-query-builder.h
@@ -31,7 +31,9 @@
 
 G_BEGIN_DECLS
 
-PhotosQuery  *photos_query_builder_create_collection_query (PhotosSearchContextState *state, const gchar 
*name);
+PhotosQuery  *photos_query_builder_create_collection_query (PhotosSearchContextState *state,
+                                                            const gchar *name,
+                                                            const gchar *identifier_tag);
 
 PhotosQuery  *photos_query_builder_collection_icon_query (PhotosSearchContextState *state, const gchar 
*resource);
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]