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



commit 1dadc8daf0171737714b2a86a37c5896f116d78d
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 |   67 +++++++++++++++++++++++++++++++++++---------------------
 2 files changed, 71 insertions(+), 42 deletions(-)
---
diff --git a/src/play.js b/src/play.js
index dafa099..8b8ba2e 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:
@@ -218,23 +228,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 7b54c8c..ad5b0ba 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 )
@@ -155,6 +168,7 @@ const Record = new Lang.Class({
         
         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(); 
@@ -180,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,9 +219,8 @@ const Record = new Lang.Class({
                 let description = GstPbutils.missing_plugin_message_get_description(this.localMsg);
                    
                 if (description != null)
-                    errorTwo = description; 
-                this.pipeline.set_state(Gst.State.NULL);      
-                log(errorOne, errorTwo);                       
+                    errorTwo = description;      
+                log(errorOne + '\n' + errorTwo);                       
             }
                 
             let s = message.get_structure();
@@ -252,7 +267,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;
         }
     },
@@ -264,25 +279,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]