[gnome-sound-recorder] play.js, record.js: Use an enum to keep track of the error messages



commit 3d3ddb5f997b4f031800e79b06189b659c07fa49
Author: Meg Ford <megford gnome org>
Date:   Mon Jun 2 21:28:01 2014 -0500

    play.js, record.js: Use an enum to keep track of the error messages
    
    The pipeline was sending too many error messages on the bus,
    causing multiple dialogs to be launched. Only launch one dialog,
    and reset the enum after the pipeline is set to null after eos.

 src/play.js   |   46 ++++++++++++++++++++++++--------------
 src/record.js |   68 ++++++++++++++++++++++++++++++++++++--------------------
 2 files changed, 73 insertions(+), 41 deletions(-)
---
diff --git a/src/play.js b/src/play.js
index 24bab2b..6fa7d7f 100644
--- a/src/play.js
+++ b/src/play.js
@@ -38,12 +38,20 @@ const PipelineStates = {
     NULL: 3
 }; 
 
+const ErrState = {
+    OFF: 0,
+    ON: 1
+}
+
+let errorDialogState;
+
 const _TENTH_SEC = 100000000;
  
  const Play = new Lang.Class({
     Name: "Play",
 
     _playPipeline: function() {
+        errorDialogState = ErrState.OFF;
         let uri = this._fileToPlay.get_uri();
         this.play = Gst.ElementFactory.make("playbin", "play");
         this.play.set_property("uri", uri);
@@ -79,7 +87,7 @@ const _TENTH_SEC = 100000000;
                 
         if (this.ret == Gst.StateChangeReturn.FAILURE) {
             this._showErrorDialog(_('Unable to play recording'));
-            this.play.set_state(Gst.State.NULL); 
+            errorDialogState = ErrState.ON;
         } else if (this.ret == Gst.StateChangeReturn.SUCCESS) {        
             MainWindow.view.setVolume(); 
         }
@@ -116,6 +124,8 @@ const _TENTH_SEC = 100000000;
         
         if (MainWindow.wave != null)
             MainWindow.wave.endDrawing();
+            
+        errorDialogState = ErrState.OFF;
     },
     
     onEndOfStream: function() {
@@ -139,7 +149,7 @@ const _TENTH_SEC = 100000000;
         case Gst.MessageType.ERROR:
             let errorMessage = message.parse_error()[0];
             this._showErrorDialog(errorMessage.toString());              
-            this.play.set_state(Gst.State.NULL);       
+            errorDialogState = ErrState.ON;       
             break;
             
         case Gst.MessageType.ASYNC_DONE:
@@ -219,23 +229,25 @@ const _TENTH_SEC = 100000000;
     },
     
     _showErrorDialog: function(errorStrOne, errorStrTwo) {
-        let errorDialog = new Gtk.MessageDialog ({ destroy_with_parent: true,
-                                                   buttons: Gtk.ButtonsType.OK,
-                                                   message_type: Gtk.MessageType.WARNING });
+        if (errorDialogState == ErrState.OFF) {
+            let errorDialog = new Gtk.MessageDialog ({ destroy_with_parent: true,
+                                                       buttons: Gtk.ButtonsType.OK,
+                                                       message_type: Gtk.MessageType.WARNING });
 
-        if (errorStrOne != null)
-            errorDialog.set_property('text', errorStrOne);
-         
-        if (errorStrTwo != null)
-            errorDialog.set_property('secondary-text', errorStrTwo);
+            if (errorStrOne != null)
+                errorDialog.set_property('text', errorStrOne);
+             
+            if (errorStrTwo != null)
+                errorDialog.set_property('secondary-text', errorStrTwo);
 
-        errorDialog.set_transient_for(Gio.Application.get_default().get_active_window());
-        errorDialog.connect ('response', Lang.bind(this,
-            function() {
-                errorDialog.destroy();
-                this.onEndOfStream();
-            }));
-        errorDialog.show();
+            errorDialog.set_transient_for(Gio.Application.get_default().get_active_window());
+            errorDialog.connect ('response', Lang.bind(this,
+                function() {
+                    errorDialog.destroy();
+                    this.onEndOfStream();
+                }));
+            errorDialog.show();
+        }
     }
 });
    
diff --git a/src/record.js b/src/record.js
index 6c9329e..b69ec41 100644
--- a/src/record.js
+++ b/src/record.js
@@ -42,12 +42,20 @@ const PipelineStates = {
     STOPPED: 2
 };
 
+const ErrState = {
+    OFF: 0,
+    ON: 1
+}
+
 const _TENTH_SEC = 100000000;
+
+let errorDialogState;
    
 const Record = new Lang.Class({
     Name: "Record",
     
     _recordPipeline: function() {
+        errorDialogState = ErrState.OFF;
         this.baseTime = 0;
         this._view = MainWindow.view; 
         this._buildFileName = new BuildFileName();
@@ -57,6 +65,7 @@ const Record = new Lang.Class({
         
         if (this.initialFileName == -1) {
             this._showErrorDialog(_('Unable to create Recordings directory.'));
+            errorDialogState = ErrState.ON;
             this.onEndOfStream();
         }
                       
@@ -65,6 +74,7 @@ const Record = new Lang.Class({
         
         if(this.srcElement == null) {
           this._showErrorDialog(_('Your audio capture settings are invalid.'));
+          errorDialogState = ErrState.ON;
           this.onEndOfStream();
           return;
         }
@@ -111,6 +121,7 @@ const Record = new Lang.Class({
         
         if (!this.pipeline || !this.filesink) {
             this._showErrorDialog(_('Not all elements could be created.'));
+            errorDialogState = ErrState.ON;
             this.onEndOfStream();
         }
             
@@ -121,6 +132,7 @@ const Record = new Lang.Class({
         
         if (!srcLink || !levelLink || !ebinLink) {
             this._showErrorDialog(_('Not all of the elements were linked'));
+            errorDialogState = ErrState.ON;
             this.onEndOfStream();
         }
         
@@ -145,6 +157,7 @@ const Record = new Lang.Class({
         
         if (this._mediaProfile == -1) {
             this._showErrorDialog(_('No Media Profile was set.'));
+            errorDialogState = ErrState.ON;
         }
         
         if (!this.pipeline || this.pipeState == PipelineStates.STOPPED )
@@ -154,6 +167,8 @@ const Record = new Lang.Class({
         this.pipeState = PipelineStates.PLAYING;
         
         if (ret == Gst.StateChangeReturn.FAILURE) {
+            this._showErrorDialog(_('Unable to set the pipeline \n to the recording state'));
+            errorDialogState = ErrState.ON;
             this._buildFileName.getTitle().delete_async(GLib.PRIORITY_DEFAULT, null, null); 
         } else {        
             MainWindow.view.setVolume(); 
@@ -179,10 +194,12 @@ const Record = new Lang.Class({
     onEndOfStream: function() { 
         this.pipeline.set_state(Gst.State.NULL);
         this.pipeState = PipelineStates.STOPPED;
-        if (this.recordBus) {
+        
+        if (this.recordBus) 
                this.recordBus.remove_signal_watch();
-        }
+               
         this._updateTime(); 
+        errorDialogState = ErrState.OFF;
     },
         
     _onMessageReceived: function(message) {
@@ -203,8 +220,9 @@ const Record = new Lang.Class({
                    
                 if (description != null)
                     errorTwo = description; 
-                this.pipeline.set_state(Gst.State.NULL);      
-                this._showErrorDialog(errorOne, errorTwo);                       
+    
+                this._showErrorDialog(errorOne, errorTwo); 
+                errorDialogState = ErrState.ON;                          
             }
                 
             let s = message.get_structure();
@@ -251,7 +269,7 @@ const Record = new Lang.Class({
         case Gst.MessageType.ERROR:
             let errorMessage = message.parse_error();
             this._showErrorDialog(errorMessage.toString()); 
-            this.pipeline.set_state(Gst.State.NULL);               
+            errorDialogState = ErrState.ON;               
             break;
         }
     },
@@ -263,25 +281,27 @@ const Record = new Lang.Class({
     },
     
     _showErrorDialog: function(errorStrOne, errorStrTwo) {
-        let errorDialog = new Gtk.MessageDialog ({ modal: true,
-                                                   destroy_with_parent: true,
-                                                   buttons: Gtk.ButtonsType.OK,
-                                                   message_type: Gtk.MessageType.WARNING });
-        if (errorStrOne != null) {
-            errorDialog.set_property('text', errorStrOne);
-        }
-         
-        if (errorStrTwo != null)
-            errorDialog.set_property('secondary-text', errorStrTwo);
-            
-        errorDialog.set_transient_for(Gio.Application.get_default().get_active_window());
-        errorDialog.connect('response', Lang.bind(this,
-            function() {
-                errorDialog.destroy();
-                MainWindow.view.onRecordStopClicked();
-                this.onEndOfStream();
-            }));
-        errorDialog.show();
+        if (errorDialogState == ErrState.OFF) {
+            let errorDialog = new Gtk.MessageDialog ({ modal: true,
+                                                       destroy_with_parent: true,
+                                                       buttons: Gtk.ButtonsType.OK,
+                                                       message_type: Gtk.MessageType.WARNING });
+            if (errorStrOne != null) {
+                errorDialog.set_property('text', errorStrOne);
+            }
+             
+            if (errorStrTwo != null)
+                errorDialog.set_property('secondary-text', errorStrTwo);
+                
+            errorDialog.set_transient_for(Gio.Application.get_default().get_active_window());
+            errorDialog.connect('response', Lang.bind(this,
+                function() {
+                    errorDialog.destroy();
+                    MainWindow.view.onRecordStopClicked();
+                    this.onEndOfStream();
+                }));
+            errorDialog.show();
+        } 
     } 
 });
 


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