[the-board: 4/8] [things] Show recording time in SoundThing



commit d32ad294ff040c1e7fb63c4579a367cc77a2ad53
Author: Lucas Rocha <lucasr gnome org>
Date:   Thu Jan 27 00:49:03 2011 +0000

    [things] Show recording time in SoundThing
    
    https://bugzilla.gnome.org/show_bug.cgi?id=639207

 src/js/ui/things/sound.js |   68 +++++++++++++++++++++++++++++++++------------
 1 files changed, 50 insertions(+), 18 deletions(-)
---
diff --git a/src/js/ui/things/sound.js b/src/js/ui/things/sound.js
index 007d5c8..f615a76 100644
--- a/src/js/ui/things/sound.js
+++ b/src/js/ui/things/sound.js
@@ -125,8 +125,6 @@ SoundThing.prototype = {
             new Tb.Box({ orientation: Tb.BoxOrientation.VERTICAL,
                          xAlign: Tb.BoxAlignment.FILL,
                          yAlign: Tb.BoxAlignment.START,
-                         opacity: 0,
-                         visible: false,
                          name: "sound-thing-controls-box" });
 
         this._controlsBox.set_style(this._style);
@@ -147,6 +145,8 @@ SoundThing.prototype = {
             new Tb.Box({ orientation: Tb.BoxOrientation.HORIZONTAL,
                          xAlign: Tb.BoxAlignment.FILL,
                          yAlign: Tb.BoxAlignment.CENTER,
+                         visible: false,
+                         opacity: 0,
                          name: "sound-thing-playback-box" });
 
         this._playbackBox.set_style(this._style);
@@ -200,11 +200,13 @@ SoundThing.prototype = {
             new Mx.Label({ yAlign: Mx.Align.MIDDLE,
                            text: "00:12:00",
                            anchorY: -2,
+                           visible: false,
+                           opacity: 0,
                            name: "sound-thing-time-label" });
 
         this._timeLabel.set_style(this._style);
 
-        this._updateTimeLabel();
+        this._updateTimeLabel(0);
 
         this._controlsBox.append(this._timeLabel,
                                  Tb.BoxPackFlags.NONE);
@@ -308,8 +310,8 @@ SoundThing.prototype = {
         }
     },
 
-    _showSoundControlsBox : function() {
-        Tweener.addTween(this._controlsBox,
+    _showSoundControlActors : function(actors) {
+        Tweener.addTween(actors,
                          { opacity: 255,
                            time: _SHOW_BUTTON_BOX_TIME,
                            onStart: function() {
@@ -317,8 +319,8 @@ SoundThing.prototype = {
                            }});
     },
 
-    _hideSoundControlsBox : function() {
-        Tweener.addTween(this._controlsBox,
+    _hideSoundControlActors : function(actors) {
+        Tweener.addTween(actors,
                          { opacity: 0,
                            time: _SHOW_BUTTON_BOX_TIME,
                            onComplete: function() {
@@ -407,6 +409,10 @@ SoundThing.prototype = {
         this._recorder =
             new Tb.SoundRecorder({ filename: filename });
 
+        this._recorder.connect("notify::duration",
+                               Lang.bind(this,
+                                         this._onRecorderDurationChanged));
+
         this._stopButton =
             new Mx.Button({ label: Gettext.gettext("Stop"),
                             y: _STOP_BUTTON_Y,
@@ -506,10 +512,7 @@ SoundThing.prototype = {
         return (n >= 10 ? n : "0" + n);
     },
 
-    _updateTimeLabel : function() {
-        let currentTime =
-            Math.floor(this._player.duration * this._player.progress);
-
+    _updateTimeLabel : function(currentTime) {
         let hours = Math.floor(currentTime / 3600);
         currentTime -= hours * 3600;
 
@@ -524,15 +527,32 @@ SoundThing.prototype = {
     },
 
     _updateSoundControlsVisibility : function() {
-        let visible = !this._recorder &&
-                      this._soundFilename &&
-                      (this.hover || this.active);
+        let hoverOrActive = this.hover || this.active;
+
+        let actorsToShow = [];
+        let actorsToHide = [];
+
+        let showTimeLabel =
+            (this._recorder || this._soundFilename) &&
+            (hoverOrActive || this._player.playing);
 
-        if (visible) {
-            this._showSoundControlsBox();
+        if (showTimeLabel) {
+            actorsToShow.push(this._timeLabel);
         } else {
-            this._hideSoundControlsBox();
+            actorsToHide.push(this._timeLabel);
         }
+
+        let showPlaybackBox =
+            !this._recorder && this._soundFilename && hoverOrActive;
+
+        if (showPlaybackBox) {
+            actorsToShow.push(this._playbackBox);
+        } else {
+            actorsToHide.push(this._playbackBox);
+        }
+
+        this._showSoundControlActors(actorsToShow);
+        this._hideSoundControlActors(actorsToHide);
     },
 
     _setSpoolsAnimating : function(animating) {
@@ -570,6 +590,11 @@ SoundThing.prototype = {
     _onPlayButtonToggled : function() {
         this._player.playing = this._playButton.toggled;
         this._setSpoolsAnimating(this._playButton.toggled);
+        this._updateSoundControlsVisibility();
+    },
+
+    _onRecorderDurationChanged : function() {
+        this._updateTimeLabel(this._recorder.duration);
     },
 
     _onStopButtonClicked : function() {
@@ -588,8 +613,15 @@ SoundThing.prototype = {
     },
 
     _onPlayerProgressChanged : function() {
+        if (this._recorder) {
+            return;
+        }
+
+        let currentTime =
+            Math.floor(this._player.duration * this._player.progress);
+
         this._updateProgressBar();
-        this._updateTimeLabel();
+        this._updateTimeLabel(currentTime);
     },
 
     _onPlayerStateChanged : function() {



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