[gnome-photos/wip/rishi/collection: 12/51] item-manager: Add photos_item_manager_wait_for_file_async



commit bf3c71af2c76307b40cb9cfe5dc3551c72b3ecec
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 | 41 +++++++++++++++++++++++++++++++++++++++++
 src/photos-item-manager.h | 10 ++++++++++
 2 files changed, 51 insertions(+)
---
diff --git a/src/photos-item-manager.c b/src/photos-item-manager.c
index cb0abdd4..31bca5ab 100644
--- a/src/photos-item-manager.c
+++ b/src/photos-item-manager.c
@@ -1270,6 +1270,47 @@ 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_steal_pointer (&uri), tasks);
+}
+
+
+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]