[gnome-photos/wip/rishi/collection: 11/45] item-manager: Add photos_item_manager_wait_for_file_async



commit f905886aa800821a21b439e74d28416f5f8b27d7
Author: Debarshi Ray <debarshir gnome org>
Date:   Wed Feb 7 00:24:01 2018 +0100

    item-manager: Add photos_item_manager_wait_for_file_async
    
    This is meant to wait for a newly created native GFile to be indexed
    and entered into Tracker's database, and will return the corresponding
    new URN. It should be used before the final write to the file.
    
    https://gitlab.gnome.org/GNOME/gnome-photos/issues/29

 src/photos-item-manager.c | 48 +++++++++++++++++++++++++++++++++++++++++++++++
 src/photos-item-manager.h | 10 ++++++++++
 2 files changed, 58 insertions(+)
---
diff --git a/src/photos-item-manager.c b/src/photos-item-manager.c
index fd163bd1..0239cdc9 100644
--- a/src/photos-item-manager.c
+++ b/src/photos-item-manager.c
@@ -1420,6 +1420,54 @@ photos_item_manager_unhide_item (PhotosItemManager *self, PhotosBaseItem *item)
 }
 
 
+void
+photos_item_manager_wait_for_file_async (PhotosItemManager *self,
+                                         GFile *file,
+                                         GCancellable *cancellable,
+                                         GAsyncReadyCallback callback,
+                                         gpointer user_data)
+{
+  GList *tasks;
+  g_autoptr (GTask) task = NULL;
+  g_autofree gchar *uri = NULL;
+
+  g_return_if_fail (PHOTOS_IS_ITEM_MANAGER (self));
+  g_return_if_fail (G_IS_FILE (file));
+  g_return_if_fail (g_file_is_native (file));
+  g_return_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable));
+
+  task = g_task_new (self, cancellable, callback, user_data);
+  g_task_set_source_tag (task, photos_item_manager_wait_for_file_async);
+
+  uri = g_file_get_uri (file);
+  tasks = (GList *) g_hash_table_lookup (self->wait_for_changes_table, uri);
+  tasks = g_list_copy_deep (tasks, (GCopyFunc) g_object_ref, NULL);
+  tasks = g_list_prepend (tasks, g_object_ref (task));
+  g_hash_table_insert (self->wait_for_changes_table, g_strdup (uri), tasks);
+
+  photos_item_manager_remove_timeout (self);
+  self->wait_for_changes_id = g_timeout_add_seconds (WAIT_FOR_CHANGES_TIMEOUT,
+                                                     photos_item_manager_wait_for_changes_timeout,
+                                                     self);
+
+  photos_debug (PHOTOS_DEBUG_TRACKER, "Waiting for %s", uri);
+}
+
+
+gchar *
+photos_item_manager_wait_for_file_finish (PhotosItemManager *self, GAsyncResult *res, GError **error)
+{
+  GTask *task = G_TASK (res);
+
+  g_return_val_if_fail (PHOTOS_IS_ITEM_MANAGER (self), NULL);
+  g_return_val_if_fail (g_task_is_valid (res, self), NULL);
+  g_return_val_if_fail (g_task_get_source_tag (task) == photos_item_manager_wait_for_file_async, NULL);
+  g_return_val_if_fail (error == NULL || *error == NULL, NULL);
+
+  return g_task_propagate_pointer (task, error);
+}
+
+
 void
 photos_item_manager_wait_for_changes_async (PhotosItemManager *self,
                                             PhotosBaseItem *item,
diff --git a/src/photos-item-manager.h b/src/photos-item-manager.h
index fe203c02..0e7f279d 100644
--- a/src/photos-item-manager.h
+++ b/src/photos-item-manager.h
@@ -100,6 +100,16 @@ void                      photos_item_manager_set_constraints_for_mode     (Phot
                                                                             gboolean constrain,
                                                                             PhotosWindowMode mode);
 
+void                      photos_item_manager_wait_for_file_async          (PhotosItemManager *self,
+                                                                            GFile *file,
+                                                                            GCancellable *cancellable,
+                                                                            GAsyncReadyCallback callback,
+                                                                            gpointer user_data);
+
+gchar                    *photos_item_manager_wait_for_file_finish         (PhotosItemManager *self,
+                                                                            GAsyncResult *res,
+                                                                            GError **error);
+
 void                      photos_item_manager_wait_for_changes_async       (PhotosItemManager *self,
                                                                             PhotosBaseItem *item,
                                                                             GCancellable *cancellable,


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