[gnome-documents] documents: don't load thumbnail pixbufs synchronously



commit f5479c51bfd36f1a5b65177aa169f0e1b572530a
Author: Cosimo Cecchi <cosimoc gnome org>
Date:   Mon Oct 31 17:45:04 2011 -0400

    documents: don't load thumbnail pixbufs synchronously
    
    Use gdk_pixbuf_new_from_stream_at_scale_async() instead of loading the
    pixbuf from file in the main thread.

 src/documents.js |   29 +++++++++++++++++++++++------
 1 files changed, 23 insertions(+), 6 deletions(-)
---
diff --git a/src/documents.js b/src/documents.js
index f2f5aef..afe1a05 100644
--- a/src/documents.js
+++ b/src/documents.js
@@ -24,6 +24,7 @@ const Gio = imports.gi.Gio;
 const Gd = imports.gi.Gd;
 const Gdk = imports.gi.Gdk;
 const GData = imports.gi.GData;
+const GLib = imports.gi.GLib;
 const GObject = imports.gi.GObject;
 const Gtk = imports.gi.Gtk;
 const _ = imports.gettext.gettext;
@@ -273,12 +274,28 @@ LocalDocument.prototype = {
     },
 
     _refreshThumbPath: function() {
-        this.pixbuf = GdkPixbuf.Pixbuf.new_from_file_at_size(this._thumbPath,
-                                                             Utils.getIconSize(),
-                                                             Utils.getIconSize());
-        this.thumbnailed = true;
-        this.checkEffectsAndUpdateInfo();
-        return;
+        let thumbFile = Gio.file_new_for_path(this._thumbPath);
+
+        thumbFile.read_async(GLib.PRIORITY_DEFAULT, null, Lang.bind(this,
+            function(object, res) {
+                try {
+                    let stream = object.read_finish(res);
+                    GdkPixbuf.Pixbuf.new_from_stream_at_scale_async(stream,
+                        Utils.getIconSize(), Utils.getIconSize(),
+                        true, null, Lang.bind(this,
+                            function(object, res) {
+                                try {
+                                    this.pixbuf = GdkPixbuf.Pixbuf.new_from_stream_finish(res);
+                                    this.thumbnailed = true;
+                                    this.checkEffectsAndUpdateInfo();
+                                } catch (e) {
+                                    this._failedThumbnailing = true;
+                                }
+                            }));
+                } catch (e) {
+                    this._failedThumbnailing = true;
+                }
+            }));
     },
 
     refreshIcon: function() {



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