diff options
author | Siegfried-Angel Gevatter Pujals <rainct@ubuntu.com> | 2009-06-22 14:23:52 +0200 |
---|---|---|
committer | Dan Winship <danw@gnome.org> | 2009-06-22 09:41:06 -0400 |
commit | f215935d2dc115c848882c7805f82832a1a269ea (patch) | |
tree | 4b4e5719f543a832577314585844d9e5fd73df94 | |
parent | b8af0c1b8b85af36d8abecaee23e117a7d58cc21 (diff) | |
download | gnome-shell-f215935d2dc115c848882c7805f82832a1a269ea.tar.gz |
Speed up initialization of DocInfo objects
We achieve this with two changes:
- Move the Shell.get_thumbnail call in DocInfo from _init
to getIcon, so that it isn't executed until it's actually
needed.
(If caching the output of said call permanently is desired
we could still do it on the first getIcon invocation, but
I don't believe this is necessary given that looking up an
already generated icon is pretty fast and this also gives
us an updated icon in case the file changes.)
- More importantly, we ommit the get_thumbnail call in case
the URI doesn't start with file://. Looking up, for example,
an http:// URI is very slow, and doesn't give us an icon anyway.
http://bugzilla.gnome.org/show_bug.cgi?id=586539
-rw-r--r-- | js/misc/docInfo.js | 16 |
1 files changed, 9 insertions, 7 deletions
diff --git a/js/misc/docInfo.js b/js/misc/docInfo.js index dfae4a72b..8ac02f6bf 100644 --- a/js/misc/docInfo.js +++ b/js/misc/docInfo.js @@ -19,14 +19,16 @@ DocInfo.prototype = { this.name = recentInfo.get_display_name(); this.uri = recentInfo.get_uri(); this.mimeType = recentInfo.get_mime_type(); - - this._iconPixbuf = Shell.get_thumbnail(this.uri, this.mimeType); }, getIcon : function(size) { let icon = new Clutter.Texture(); + let iconPixbuf; + + if (this.uri.match("^file://")) + iconPixbuf = Shell.get_thumbnail(this.uri, this.mimeType); - if (this._iconPixbuf) { + if (iconPixbuf) { // We calculate the width and height of the texture so as // to preserve the aspect ratio of the thumbnail. Because // the images generated based on thumbnails don't have an @@ -34,10 +36,10 @@ DocInfo.prototype = { // slightly smaller texture and then create a group around // it for padding purposes - let scalingFactor = (size - THUMBNAIL_ICON_MARGIN * 2) / Math.max(this._iconPixbuf.get_width(), this._iconPixbuf.get_height()); - icon.set_width(Math.ceil(this._iconPixbuf.get_width() * scalingFactor)); - icon.set_height(Math.ceil(this._iconPixbuf.get_height() * scalingFactor)); - Shell.clutter_texture_set_from_pixbuf(icon, this._iconPixbuf); + let scalingFactor = (size - THUMBNAIL_ICON_MARGIN * 2) / Math.max(iconPixbuf.get_width(), iconPixbuf.get_height()); + icon.set_width(Math.ceil(iconPixbuf.get_width() * scalingFactor)); + icon.set_height(Math.ceil(iconPixbuf.get_height() * scalingFactor)); + Shell.clutter_texture_set_from_pixbuf(icon, iconPixbuf); let group = new Clutter.Group({ width: size, height: size }); |