[sushi] folder: notify deep size as we get new folder results



commit af3cb0181bdfce4980ee6507fdce0afaf397d730
Author: Cosimo Cecchi <cosimoc gnome org>
Date:   Wed Apr 20 16:15:12 2011 -0400

    folder: notify deep size as we get new folder results

 src/js/viewers/folder.js         |   16 +++++++++++++++-
 src/libsushi/sushi-file-loader.c |   26 +++++++++++++++++++++-----
 src/libsushi/sushi-file-loader.h |    2 ++
 3 files changed, 38 insertions(+), 6 deletions(-)
---
diff --git a/src/js/viewers/folder.js b/src/js/viewers/folder.js
index 9eac21a..0d8f05f 100644
--- a/src/js/viewers/folder.js
+++ b/src/js/viewers/folder.js
@@ -41,9 +41,17 @@ FolderRenderer.prototype = {
                                  "margin-right": 12 });
         this._box.pack_start(vbox, false, false, 0);
 
+        let hbox = new Gtk.Box({ orientation: Gtk.Orientation.HORIZONTAL,
+                                 spacing: 6 });
+        vbox.pack_start(hbox, false, false, 0);
+
         this._titleLabel = new Gtk.Label();
         this._titleLabel.set_halign(Gtk.Align.START);
-        vbox.pack_start(this._titleLabel, false, false, 0);
+        hbox.pack_start(this._titleLabel, false, false, 0);
+
+        this._spinner = new Gtk.Spinner();
+        hbox.pack_start(this._spinner, false, false, 0);
+        this._spinner.start();
 
         this._sizeLabel = new Gtk.Label();
         this._sizeLabel.set_halign(Gtk.Align.START);
@@ -83,6 +91,11 @@ FolderRenderer.prototype = {
     },
 
     _onFolderInfoChanged : function() {
+        if (!this._folderLoader.get_loading()) {
+            this._spinner.stop();
+            this._spinner.hide();
+        }
+
         this._applyLabels();
         this._image.set_from_pixbuf(this._folderLoader.icon);
         this._mainWindow.refreshSize();
@@ -94,6 +107,7 @@ FolderRenderer.prototype = {
 
     clear : function() {
         this._folderLoader.stop();
+        delete this._folderLoader;
     },
 
     getSizeForAllocation : function(allocation) {
diff --git a/src/libsushi/sushi-file-loader.c b/src/libsushi/sushi-file-loader.c
index ea2d872..ff81b93 100644
--- a/src/libsushi/sushi-file-loader.c
+++ b/src/libsushi/sushi-file-loader.c
@@ -46,6 +46,8 @@ struct _SushiFileLoaderPrivate {
   gint unreadable_items;
 
   goffset total_size;
+
+  gboolean loading;
 };
 
 #define DIRECTORY_LOAD_ITEMS_PER_CALLBACK 100
@@ -122,6 +124,8 @@ deep_count_one (DeepCountState *state,
 static void
 deep_count_state_free (DeepCountState *state)
 {
+  state->self->priv->loading = FALSE;
+  
   if (state->enumerator) {
     if (!g_file_enumerator_is_closed (state->enumerator))
       g_file_enumerator_close_async (state->enumerator,
@@ -157,9 +161,11 @@ deep_count_next_dir (DeepCountState *state)
     deep_count_load (state, new_file);
     g_object_unref (new_file);
   } else {
-    g_object_notify (G_OBJECT (self), "size");
     deep_count_state_free (state);
   }
+
+  /* notify current or last size */
+  g_object_notify (G_OBJECT (self), "size");
 }
 
 static void
@@ -191,12 +197,12 @@ deep_count_more_files_callback (GObject *source_object,
     g_file_enumerator_close_async (state->enumerator, 0, NULL, NULL, NULL);
     g_object_unref (state->enumerator);
     state->enumerator = NULL;
-		
+
     deep_count_next_dir (state);
   } else {
     g_file_enumerator_next_files_async (state->enumerator,
                                         DIRECTORY_LOAD_ITEMS_PER_CALLBACK,
-                                        G_PRIORITY_LOW,
+                                        G_PRIORITY_DEFAULT,
                                         state->self->priv->cancellable,
                                         deep_count_more_files_callback,
                                         state);
@@ -298,15 +304,19 @@ query_info_async_ready_cb (GObject *source,
   g_object_notify (G_OBJECT (self), "name");
   g_object_notify (G_OBJECT (self), "time");
 
-  if (g_file_info_get_file_type (info) != G_FILE_TYPE_DIRECTORY)
+  if (g_file_info_get_file_type (info) != G_FILE_TYPE_DIRECTORY) {
+    self->priv->loading = FALSE;
     g_object_notify (G_OBJECT (self), "size");
-  else
+  } else {
     deep_count_start (self);
+  }
 }
 
 static void
 start_loading_file (SushiFileLoader *self)
 {
+  self->priv->loading = TRUE;
+
   g_file_query_info_async (self->priv->file,
                            LOADER_ATTRS,
                            G_FILE_QUERY_INFO_NONE,
@@ -569,6 +579,12 @@ sushi_file_loader_get_size_string (SushiFileLoader *self)
   return NULL;
 }
 
+gboolean
+sushi_file_loader_get_loading (SushiFileLoader *self)
+{
+  return self->priv->loading;
+}
+
 /**
  * sushi_file_loader_get_date_string:
  * @self:
diff --git a/src/libsushi/sushi-file-loader.h b/src/libsushi/sushi-file-loader.h
index 27e9483..b2ca4be 100644
--- a/src/libsushi/sushi-file-loader.h
+++ b/src/libsushi/sushi-file-loader.h
@@ -39,6 +39,8 @@ gchar *sushi_file_loader_get_size_string  (SushiFileLoader *self);
 gchar *sushi_file_loader_get_date_string  (SushiFileLoader *self);
 GdkPixbuf *sushi_file_loader_get_icon     (SushiFileLoader *self);
 
+gboolean sushi_file_loader_get_loading (SushiFileLoader *self);
+
 void sushi_file_loader_stop (SushiFileLoader *self);
 
 G_END_DECLS



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