[sushi] file-loader: queue size notifications in a timeout



commit e485983ec22bffdd59002aa952e54b2dbaef18be
Author: Cosimo Cecchi <cosimoc gnome org>
Date:   Thu Apr 28 10:18:13 2011 -0400

    file-loader: queue size notifications in a timeout
    
    It's much faster this way.

 src/libsushi/sushi-file-loader.c |   36 ++++++++++++++++++++++++++++++++++--
 1 files changed, 34 insertions(+), 2 deletions(-)
---
diff --git a/src/libsushi/sushi-file-loader.c b/src/libsushi/sushi-file-loader.c
index f734c05..db06a9c 100644
--- a/src/libsushi/sushi-file-loader.c
+++ b/src/libsushi/sushi-file-loader.c
@@ -19,6 +19,8 @@
   G_FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE ","  \
   G_FILE_ATTRIBUTE_UNIX_INODE
 
+#define NOTIFICATION_TIMEOUT 300
+
 G_DEFINE_TYPE (SushiFileLoader, sushi_file_loader, G_TYPE_OBJECT);
 
 enum {
@@ -53,6 +55,8 @@ struct _SushiFileLoaderPrivate {
   goffset total_size;
 
   gboolean loading;
+
+  guint size_notify_timeout_id;
 };
 
 #define DIRECTORY_LOAD_ITEMS_PER_CALLBACK 100
@@ -60,6 +64,29 @@ struct _SushiFileLoaderPrivate {
 static void deep_count_load (DeepCountState *state,
                              GFile *file);
 
+static gboolean
+size_notify_timeout_cb (gpointer user_data)
+{
+  SushiFileLoader *self = user_data;
+
+  self->priv->size_notify_timeout_id = 0;
+
+  g_object_notify (G_OBJECT (self), "size");
+
+  return FALSE;
+}
+
+static void
+queue_size_notify (SushiFileLoader *self)
+{
+  if (self->priv->size_notify_timeout_id != 0)
+    return;
+
+  self->priv->size_notify_timeout_id =
+    g_timeout_add (NOTIFICATION_TIMEOUT,
+                   size_notify_timeout_cb, self);
+}
+
 /* adapted from nautilus/libnautilus-private/nautilus-directory-async.c */
 
 static inline gboolean
@@ -164,8 +191,8 @@ deep_count_next_dir (DeepCountState *state)
     deep_count_state_free (state);
   }
 
-  /* notify current or last size */
-  g_object_notify (G_OBJECT (self), "size");
+  /* queue notify */
+  queue_size_notify (self);
 }
 
 static void
@@ -352,6 +379,11 @@ sushi_file_loader_dispose (GObject *object)
     g_clear_object (&self->priv->cancellable);
   }
 
+  if (self->priv->size_notify_timeout_id != 0) {
+    g_source_remove (self->priv->size_notify_timeout_id);
+    self->priv->size_notify_timeout_id = 0;
+  }
+
   G_OBJECT_CLASS (sushi_file_loader_parent_class)->dispose (object);
 }
 



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