[gnome-photos/wip/rishi/collection: 2/31] base-item: Support sporting a busy state through the "pulse" property



commit 4774caf9ae867ade74be5b364a647aee884c981e
Author: Debarshi Ray <debarshir gnome org>
Date:   Thu Feb 8 04:12:14 2018 +0100

    base-item: Support sporting a busy state through the "pulse" property
    
    This is necessary to show a spinner while content gets imported and
    added to a collection.
    
    https://gitlab.gnome.org/GNOME/gnome-photos/issues/29

 src/photos-base-item.c | 39 +++++++++++++++++++++++++++++++++++++--
 src/photos-base-item.h |  4 ++++
 2 files changed, 41 insertions(+), 2 deletions(-)
---
diff --git a/src/photos-base-item.c b/src/photos-base-item.c
index 0f39805e..a8d58794 100644
--- a/src/photos-base-item.c
+++ b/src/photos-base-item.c
@@ -101,6 +101,7 @@ struct _PhotosBaseItemPrivate
   gint64 height;
   gint64 mtime;
   gint64 width;
+  guint busy_count;
 };
 
 enum
@@ -2920,8 +2921,12 @@ photos_base_item_get_property (GObject *object, guint prop_id, GValue *value, GP
       }
 
     case PROP_PULSE:
-      g_value_set_boolean (value, FALSE);
-      break;
+      {
+        gboolean pulse = priv->busy_count > 0;
+
+        g_value_set_boolean (value, pulse);
+        break;
+      }
 
     case PROP_SECONDARY_TEXT:
       g_value_set_string (value, priv->author);
@@ -3781,6 +3786,20 @@ photos_base_item_load_finish (PhotosBaseItem *self, GAsyncResult *res, GError **
 }
 
 
+void
+photos_base_item_mark_busy (PhotosBaseItem *self)
+{
+  PhotosBaseItemPrivate *priv;
+
+  g_return_if_fail (PHOTOS_IS_BASE_ITEM (self));
+  priv = photos_base_item_get_instance_private (self);
+
+  priv->busy_count++;
+  if (priv->busy_count == 1)
+    g_object_notify (G_OBJECT (self), "pulse");
+}
+
+
 void
 photos_base_item_metadata_add_shared_async (PhotosBaseItem *self,
                                             const gchar *provider_type,
@@ -4415,3 +4434,19 @@ photos_base_item_trash (PhotosBaseItem *self)
   job = photos_delete_item_job_new (priv->id);
   photos_delete_item_job_run (job, NULL, NULL, NULL);
 }
+
+
+void
+photos_base_item_unmark_busy (PhotosBaseItem *self)
+{
+  PhotosBaseItemPrivate *priv;
+
+  g_return_if_fail (PHOTOS_IS_BASE_ITEM (self));
+  priv = photos_base_item_get_instance_private (self);
+
+  g_return_if_fail (priv->busy_count > 0);
+
+  priv->busy_count--;
+  if (priv->busy_count == 0)
+    g_object_notify (G_OBJECT (self), "pulse");
+}
diff --git a/src/photos-base-item.h b/src/photos-base-item.h
index 21d26874..9383a921 100644
--- a/src/photos-base-item.h
+++ b/src/photos-base-item.h
@@ -182,6 +182,8 @@ GeglNode           *photos_base_item_load_finish             (PhotosBaseItem *se
                                                               GAsyncResult *res,
                                                               GError **error);
 
+void                photos_base_item_mark_busy               (PhotosBaseItem *self);
+
 void                photos_base_item_metadata_add_shared_async  (PhotosBaseItem *self,
                                                                  const gchar *provider_type,
                                                                  const gchar *account_identity,
@@ -309,6 +311,8 @@ void                photos_base_item_set_favorite            (PhotosBaseItem *se
 
 void                photos_base_item_trash                   (PhotosBaseItem *self);
 
+void                photos_base_item_unmark_busy             (PhotosBaseItem *self);
+
 G_END_DECLS
 
 #endif /* PHOTOS_BASE_ITEM_H */


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