[sushi] all: port all the new renderers to the new prepare() + render() API



commit 485b2f96b26498ff080ed6dbf6473fd2c4a53ea0
Author: Cosimo Cecchi <cosimoc gnome org>
Date:   Fri May 13 17:25:46 2011 -0400

    all: port all the new renderers to the new prepare() + render() API

 src/js/ui/fallbackRenderer.js |    6 +++-
 src/js/viewers/audio.js       |    9 ++++-
 src/js/viewers/evince.js      |   52 +++++++---------------------
 src/js/viewers/folder.js      |    9 ++++-
 src/js/viewers/font.js        |   26 +++++++-------
 src/js/viewers/gst.js         |   14 ++++----
 src/js/viewers/html.js        |    7 +++-
 src/js/viewers/image.js       |   77 +++++++++--------------------------------
 src/js/viewers/text.js        |   40 ++++-----------------
 9 files changed, 84 insertions(+), 156 deletions(-)
---
diff --git a/src/js/ui/fallbackRenderer.js b/src/js/ui/fallbackRenderer.js
index dee6099..163c19c 100644
--- a/src/js/ui/fallbackRenderer.js
+++ b/src/js/ui/fallbackRenderer.js
@@ -17,7 +17,7 @@ FallbackRenderer.prototype = {
         this.canFullScreen = false;
     },
 
-    render : function(file, mainWindow) {
+    prepare : function(file, mainWindow, callback) {
         this._mainWindow = mainWindow;
         this.lastWidth = 0;
         this.lastHeight = 0;
@@ -76,6 +76,10 @@ FallbackRenderer.prototype = {
         this._box.show_all();
         this._actor = new GtkClutter.Actor({ contents: this._box });
 
+        callback();
+    },
+
+    render : function() {
         return this._actor;
     },
 
diff --git a/src/js/viewers/audio.js b/src/js/viewers/audio.js
index e66a787..f2144ff 100644
--- a/src/js/viewers/audio.js
+++ b/src/js/viewers/audio.js
@@ -19,8 +19,11 @@ AudioRenderer.prototype = {
         this.canFullScreen = false;
     },
 
-    render : function(file, mainWindow) {
+    prepare : function(file, mainWindow, callback) {
         this._mainWindow = mainWindow;
+        this._file = file;
+        this._callback = callback;
+
         this._createPlayer(file);
 
         this._box = new Gtk.Box({ orientation: Gtk.Orientation.HORIZONTAL,
@@ -51,6 +54,10 @@ AudioRenderer.prototype = {
         this._box.show_all();
         this._actor = new GtkClutter.Actor({ contents: this._box });
 
+        this._callback();
+    },
+
+    render : function(file, mainWindow) {
         return this._actor;
     },
 
diff --git a/src/js/viewers/evince.js b/src/js/viewers/evince.js
index 937b1b5..3d94539 100644
--- a/src/js/viewers/evince.js
+++ b/src/js/viewers/evince.js
@@ -10,8 +10,6 @@ let _ = Gettext.gettext;
 let Utils = imports.ui.utils;
 let Features = imports.util.features;
 
-let SPINNER_SIZE = 48;
-
 function EvinceRenderer(args) {
     this._init(args);
 }
@@ -23,32 +21,18 @@ EvinceRenderer.prototype = {
         this.canFullScreen = true;
     },
 
-    render : function(file, mainWindow) {
+    prepare : function(file, mainWindow, callback) {
         this._mainWindow = mainWindow;
+        this._file = file;
+        this._callback = callback;
 
         this._pdfLoader = new Sushi.PdfLoader();
         this._pdfLoader.connect("notify::document",
                                 Lang.bind(this, this._onDocumentLoaded));
         this._pdfLoader.uri = file.get_uri();
+    },
 
-        this._spinnerBox = Gtk.Box.new(Gtk.Orientation.VERTICAL, 12);
-        this._spinnerBox.show();
-
-        let spinner = Gtk.Spinner.new();
-        spinner.show();
-        spinner.start();
-        spinner.set_size_request(SPINNER_SIZE, SPINNER_SIZE);
-        
-        this._spinnerBox.pack_start(spinner, true, true, 0);
-
-        let label = new Gtk.Label();
-        label.set_text(_("Loading..."));
-        label.show();
-        this._spinnerBox.pack_start(label, true, true, 0);
-
-        this._actor = new GtkClutter.Actor({ contents: this._spinnerBox });
-        this._actor.set_reactive(true);
-
+    render : function(file, mainWindow) {
         return this._actor;
     },
 
@@ -65,8 +49,6 @@ EvinceRenderer.prototype = {
     },
 
     _onDocumentLoaded : function() {
-        this._spinnerBox.destroy();
-
         this._document = this._pdfLoader.document;
         this._model = EvView.DocumentModel.new_with_document(this._document);
 
@@ -77,7 +59,6 @@ EvinceRenderer.prototype = {
                             Lang.bind(this, function() {
                                 this._updatePageLabel();
                             }));
-        this._updatePageLabel();
 
         this._view = EvView.View.new();
         this._view.show();
@@ -90,23 +71,15 @@ EvinceRenderer.prototype = {
         this._view.set_model(this._model);
         this._scrolledWin.add(this._view);
 
-        this._actor.get_widget().add(this._scrolledWin);
-        this._mainWindow.refreshSize();
+        this._actor = new GtkClutter.Actor({ contents: this._scrolledWin });
+        this._actor.set_reactive(true);
 
-        /* let the toolbar fade on motion now */
-        this._toolbarActor.show();
+        this._callback();
     },
 
     getSizeForAllocation : function(allocation) {
-        if (!this._document) {
-            [ width, height ] = [ this._spinnerBox.get_preferred_size()[0].width,
-                                  this._spinnerBox.get_preferred_size()[0].height ];
-        } else {
-            /* always give the view the maximum possible allocation */
-            [ width, height ] = allocation;
-        }
-
-        return [ width, height ];
+        /* always give the view the maximum possible allocation */
+        return allocation;
     },
 
     _createLabelItem : function() {
@@ -128,8 +101,7 @@ EvinceRenderer.prototype = {
         this._mainToolbar.set_show_arrow(false);
         this._mainToolbar.show();
 
-        this._toolbarActor = new GtkClutter.Actor({ contents: this._mainToolbar,
-                                                    "show-on-set-parent": false });
+        this._toolbarActor = new GtkClutter.Actor({ contents: this._mainToolbar });
 
         this._toolbarZoom = Utils.createFullScreenButton(this._mainWindow);
         this._mainToolbar.insert(this._toolbarZoom, 0);
@@ -161,6 +133,8 @@ EvinceRenderer.prototype = {
                                          this._view.next_page();
                                      }));
 
+        this._updatePageLabel();
+
         return this._toolbarActor;
     },
 
diff --git a/src/js/viewers/folder.js b/src/js/viewers/folder.js
index 42101f5..d70e6f6 100644
--- a/src/js/viewers/folder.js
+++ b/src/js/viewers/folder.js
@@ -18,8 +18,11 @@ FolderRenderer.prototype = {
         this.canFullScreen = false;
     },
 
-    render : function(file, mainWindow) {
+    prepare : function(file, mainWindow, callback) {
         this._mainWindow = mainWindow;
+        this._file = file;
+        this._callback = callback;
+
         this.lastWidth = 0;
         this.lastHeight = 0;
 
@@ -73,6 +76,10 @@ FolderRenderer.prototype = {
         this._box.show_all();
         this._actor = new GtkClutter.Actor({ contents: this._box });
 
+        this._callback();
+    },
+
+    render : function() {
         return this._actor;
     },
 
diff --git a/src/js/viewers/font.js b/src/js/viewers/font.js
index 11ad24b..f3fafcf 100644
--- a/src/js/viewers/font.js
+++ b/src/js/viewers/font.js
@@ -15,24 +15,24 @@ FontRenderer.prototype = {
         this.canFullScreen = false;
     },
 
-    render : function(file, mainWindow) {
+    prepare : function(file, mainWindow, callback) {
+        this._mainWindow = mainWindow;
+        this._file = file;
+        this._callback = callback;
+
         this._fontWidget = new Sushi.FontWidget({ uri: file.get_uri() });
         this._fontWidget.show();
-
-        this._fontWidget.connect
-        ("loaded",
-         Lang.bind (this,
-                    function() {
-                        if (this._fontWidget.get_realized())
-                            mainWindow.refreshSize();
-                        else
-                            this._fontWidget.connect("realize",
-                                                     function() {
-                                                         mainWindow.refreshSize();
-                                                     })}));
+        this._fontWidget.connect("loaded",
+                                 Lang.bind(this, this._onFontLoaded));
 
         this._fontActor = new GtkClutter.Actor({ contents: this._fontWidget });
+    },
 
+    _onFontLoaded : function() {
+        this._callback();
+    },
+
+    render : function(file, mainWindow) {
         return this._fontActor;
     },
 
diff --git a/src/js/viewers/gst.js b/src/js/viewers/gst.js
index 68f0215..c6f398e 100644
--- a/src/js/viewers/gst.js
+++ b/src/js/viewers/gst.js
@@ -19,10 +19,16 @@ GstRenderer.prototype = {
         this.canFullScreen = true;
     },
 
-    render : function(file, mainWindow) {
+    prepare : function(file, mainWindow, callback) {
         this._mainWindow = mainWindow;
+        this._file = file;
+        this._callback = callback;
+
         this._createVideo(file);
+        this._callback();
+    },
 
+    render : function() {
         return this._video;
     },
 
@@ -61,12 +67,6 @@ GstRenderer.prototype = {
         this._isSettingValue = false;
     },
 
-    _formatTimeComponent : function(n) {
-        // FIXME: we need a sprinf equivalent to do
-        // proper formatting here.
-        return (n >= 10 ? n : "0" + n);
-    },
-
     _updateCurrentLabel : function() {
         if (!this._mainToolbar)
             return;
diff --git a/src/js/viewers/html.js b/src/js/viewers/html.js
index 2ee1024..765e8d5 100644
--- a/src/js/viewers/html.js
+++ b/src/js/viewers/html.js
@@ -18,9 +18,10 @@ HTMLRenderer.prototype = {
         this.canFullScreen = true;
     },
 
-    render : function(file, mainWindow) {
+    prepare : function(file, mainWindow, callback) {
         this._mainWindow = mainWindow;
         this._file = file;
+        this._callback = callback;
 
         this._webView = WebKit.WebView.new();
         this._scrolledWin = Gtk.ScrolledWindow.new (null, null);
@@ -36,6 +37,10 @@ HTMLRenderer.prototype = {
         this._actor = new GtkClutter.Actor({ contents: this._scrolledWin });
         this._actor.set_reactive(true);
 
+        this._callback();
+    },
+
+    render : function() {
         return this._actor;
     },
 
diff --git a/src/js/viewers/image.js b/src/js/viewers/image.js
index 71977b6..60b7fab 100644
--- a/src/js/viewers/image.js
+++ b/src/js/viewers/image.js
@@ -9,8 +9,6 @@ let _ = Gettext.gettext;
 
 let Utils = imports.ui.utils;
 
-let SPINNER_SIZE = 48;
-
 function ImageRenderer(args) {
     this._init(args);
 }
@@ -21,41 +19,16 @@ ImageRenderer.prototype = {
         this.canFullScreen = true;
     },
 
-    render : function(file, mainWindow) {
+    prepare : function(file, mainWindow, callback) {
         this._mainWindow = mainWindow;
-
-        this._spinnerBox = Gtk.Box.new(Gtk.Orientation.VERTICAL, 12);
-        this._spinnerBox.show();
-
-        let spinner = Gtk.Spinner.new();
-        spinner.show();
-        spinner.start();
-        spinner.set_size_request(SPINNER_SIZE, SPINNER_SIZE);
-
-        this._spinnerBox.pack_start(spinner, true, true, 0);
-
-        let label = new Gtk.Label();
-        label.set_text(_("Loading..."));
-        label.show();
-        this._spinnerBox.pack_start(label, true, true, 0);
-
-        this._spinnerActor = new GtkClutter.Actor({ contents: this._spinnerBox });
-
-        this._group = new Clutter.Group({ clipToAllocation: true });
-        this._group.add_actor(this._spinnerActor);
-
-        this._spinnerActor.add_constraint(
-            new Clutter.AlignConstraint({ source: this._group,
-                                          "align-axis": Clutter.AlignAxis.Y_AXIS,
-                                          factor: 0.5 }));
-        this._spinnerActor.add_constraint(
-            new Clutter.AlignConstraint({ source: this._group,
-                                          "align-axis": Clutter.AlignAxis.X_AXIS,
-                                          factor: 0.5 }));
+        this._file = file;
+        this._callback = callback;
 
         this._createImageTexture(file);
+    },
 
-        return this._group;
+    render : function() {
+        return this._texture;
     },
 
     _createImageTexture : function(file) {
@@ -75,37 +48,22 @@ ImageRenderer.prototype = {
         GdkPixbuf.Pixbuf.new_from_stream_async
         (stream, null,
          Lang.bind(this, function(obj, res) {
-             try {
-                 let pix = GdkPixbuf.Pixbuf.new_from_stream_finish(res);
-
-                 this._texture = new GtkClutter.Texture({ "keep-aspect-ratio": true });
-                 this._texture.set_from_pixbuf(pix);
+             let pix = GdkPixbuf.Pixbuf.new_from_stream_finish(res);
 
-                 this._texture.add_constraint(
-                     new Clutter.BindConstraint({ source: this._group,
-                                                  coordinate: Clutter.BindCoordinate.SIZE }));
+             this._texture = new GtkClutter.Texture({ "keep-aspect-ratio": true });
+             this._texture.set_from_pixbuf(pix);
 
-                 this._mainWindow.refreshSize();
+             /* we're ready now */
+             this._callback();
 
-                 this._group.add_actor(this._texture);
-                 this._spinnerActor.destroy();
-
-                 this._toolbarActor.show();
-             } catch(e) {
-             }}));
+             stream.close_async(GLib.PRIORITY_DEFAULT,
+                                null, null, null);
+         }));
     },
 
     getSizeForAllocation : function(allocation, fullScreen) {
-        if (!this._texture) {
-            [ width, height ] = [ this._spinnerBox.get_preferred_size()[0].width,
-                                  this._spinnerBox.get_preferred_size()[0].height ];
-        } else {
-            let baseSize = this._texture.get_base_size();
-
-            [ width, height ] = Utils.getScaledSize(baseSize, allocation, fullScreen);
-        }
-
-        return [ width, height ];
+        let baseSize = this._texture.get_base_size();
+        return Utils.getScaledSize(baseSize, allocation, fullScreen);
     },
 
     createToolbar : function() {
@@ -114,8 +72,7 @@ ImageRenderer.prototype = {
         this._mainToolbar.set_show_arrow(false);
         this._mainToolbar.show();
 
-        this._toolbarActor = new GtkClutter.Actor({ contents: this._mainToolbar,
-                                                    "show-on-set-parent": false });
+        this._toolbarActor = new GtkClutter.Actor({ contents: this._mainToolbar });
 
         this._toolbarZoom = Utils.createFullScreenButton(this._mainWindow);
         this._mainToolbar.insert(this._toolbarZoom, 0);
diff --git a/src/js/viewers/text.js b/src/js/viewers/text.js
index e79afea..4790786 100644
--- a/src/js/viewers/text.js
+++ b/src/js/viewers/text.js
@@ -18,39 +18,22 @@ TextRenderer.prototype = {
         this.canFullScreen = true;
     },
 
-    render : function(file, mainWindow) {
+    prepare : function(file, mainWindow, callback) {
         this._mainWindow = mainWindow;
         this._file = file;
+        this._callback = callback;
 
         this._textLoader = new Sushi.TextLoader();
         this._textLoader.connect("loaded",
                                  Lang.bind(this, this._onBufferLoaded));
         this._textLoader.uri = file.get_uri();
+    },
 
-        this._spinnerBox = Gtk.Box.new(Gtk.Orientation.VERTICAL, 12);
-        this._spinnerBox.show();
-
-        let spinner = Gtk.Spinner.new();
-        spinner.show();
-        spinner.start();
-        spinner.set_size_request(SPINNER_SIZE, SPINNER_SIZE);
-        
-        this._spinnerBox.pack_start(spinner, true, true, 0);
-
-        let label = new Gtk.Label();
-        label.set_text(_("Loading..."));
-        label.show();
-        this._spinnerBox.pack_start(label, true, true, 0);
-
-        this._actor = new GtkClutter.Actor({ contents: this._spinnerBox });
-        this._actor.set_reactive(true);
-
+    render : function() {
         return this._actor;
     },
 
     _onBufferLoaded : function(loader, buffer) {
-        this._spinnerBox.destroy();
-
         this._buffer = buffer;
         this._buffer["highlight-syntax"] = true;
 
@@ -84,21 +67,12 @@ TextRenderer.prototype = {
         this._scrolledWin.add(this._view);
         this._scrolledWin.show_all();    
 
-        this._actor.get_widget().add(this._scrolledWin);
-        this._mainWindow.refreshSize();    
+        this._actor = new GtkClutter.Actor({ contents: this._scrolledWin });
+        this._callback();
     },
 
     getSizeForAllocation : function(allocation) {
-        let baseSize = [];
-
-        if (!this._view) {
-            baseSize = [ this._spinnerBox.get_preferred_size()[0].width,
-                         this._spinnerBox.get_preferred_size()[0].height ];
-        } else {
-            baseSize = allocation;
-        }
-
-        return baseSize;
+        return allocation;
     }
 }
 



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