[gnome-sound-recorder] Add params.js so the API version check in package.js works



commit d292ddb84fbdafac61dc9986b29efe10b6630d11
Author: Meg Ford <meg387 gmail com>
Date:   Tue Oct 1 10:08:56 2013 -0500

    Add params.js so the API version check in package.js works
    
    package.js requires params.js in order to function properly

 src/Makefile.am     |    1 +
 src/audioProfile.js |    1 +
 src/fileUtil.js     |    1 +
 src/info.js         |    2 +-
 src/listview.js     |    6 ++-
 src/main.js         |    7 ++-
 src/mainWindow.js   |   45 +++++++++++-------
 src/package.js      |    4 +-
 src/params.js       |  130 +++++++++++++++++++++++++++++++++++++++++++++++++++
 src/play.js         |    1 +
 src/preferences.js  |    1 +
 src/record.js       |    1 +
 src/waveform.js     |    2 +-
 13 files changed, 176 insertions(+), 26 deletions(-)
---
diff --git a/src/Makefile.am b/src/Makefile.am
index 6e6a145..3641bc0 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -16,6 +16,7 @@ dist_js_DATA = \
     main.js \
     mainWindow.js \
     package.js \
+    params.js \
     play.js \
     preferences.js \
     record.js \
diff --git a/src/audioProfile.js b/src/audioProfile.js
index f483b34..62ca921 100644
--- a/src/audioProfile.js
+++ b/src/audioProfile.js
@@ -25,6 +25,7 @@ const _ = imports.gettext.gettext;
 const Gio = imports.gi.Gio;
 const Gst = imports.gi.Gst;
 const GstPbutils = imports.gi.GstPbutils;
+
 const Mainloop = imports.mainloop;
 
 const MainWindow = imports.mainWindow;
diff --git a/src/fileUtil.js b/src/fileUtil.js
index c2ac2e0..7b113c8 100644
--- a/src/fileUtil.js
+++ b/src/fileUtil.js
@@ -27,6 +27,7 @@ const GLib = imports.gi.GLib;
 const GObject = imports.gi.GObject; 
 const Gst = imports.gi.Gst;
 const GstPbutils = imports.gi.GstPbutils;
+
 const Signals = imports.signals;
 
 const Listview = imports.listview;
diff --git a/src/info.js b/src/info.js
index a44b6dd..35076a6 100644
--- a/src/info.js
+++ b/src/info.js
@@ -23,9 +23,9 @@
 const Gio = imports.gi.Gio;
 const GLib = imports.gi.GLib;
 const Gtk = imports.gi.Gtk;
+
 const _ = imports.gettext.gettext;
 const C_ = imports.gettext.pgettext;
-const Lang = imports.lang;
 
 const FileUtil = imports.fileUtil;
 const MainWindow = imports.mainWindow;
diff --git a/src/listview.js b/src/listview.js
index 469c201..2181dd2 100644
--- a/src/listview.js
+++ b/src/listview.js
@@ -28,6 +28,7 @@ const GLib = imports.gi.GLib;
 const GObject = imports.gi.GObject; 
 const Gst = imports.gi.Gst;
 const GstPbutils = imports.gi.GstPbutils;
+
 const Signals = imports.signals;
 
 const AudioProfile = imports.audioProfile;
@@ -239,7 +240,8 @@ const Listview = new Lang.Class({
          
         if (this.idx == this.endIdx) { 
             this._discoverer.stop();
-            
+            log(this.idx + "index");
+           log(this.endIdx + "endIndex");
             if (listType == ListType.NEW) {
                 MainWindow.view.listBoxAdd();
                 MainWindow.view.scrolledWinAdd();
@@ -248,7 +250,7 @@ const Listview = new Lang.Class({
                 MainWindow.view.scrolledWinDelete();
                 currentlyEnumerating = CurrentlyEnumerating.FALSE;
             }
-            return false; 
+            //return false; 
         }         
         this.idx++;                              
     },
diff --git a/src/main.js b/src/main.js
index 94a5919..9069d0d 100644
--- a/src/main.js
+++ b/src/main.js
@@ -33,9 +33,10 @@ pkg.require({ 'Gd': '1.0',
               'GLib': '2.0',
               'GObject': '2.0',
               'Gtk': '3.0',
-              'Lang': '1.0',
-              'Mainloop': '1.0',
-              'Params': '1.0' });
+              'Lang': '',
+              'Mainloop': '',
+              'Params': '1.0',
+              'System': '' });
               
 imports.gi.versions.Gst = '1.0';
 
diff --git a/src/mainWindow.js b/src/mainWindow.js
index 97b0361..59f0856 100644
--- a/src/mainWindow.js
+++ b/src/mainWindow.js
@@ -26,6 +26,7 @@ const Gdk = imports.gi.Gdk;
 const GdkPixbuf = imports.gi.GdkPixbuf;
 const Gio = imports.gi.Gio;
 const Gst = imports.gi.Gst;
+
 const Signals = imports.signals;
 
 const AudioProfile = imports.audioProfile;
@@ -43,6 +44,7 @@ let fileUtil = null;
 let grid = null;
 let groupGrid;
 let list = null;
+let listBox = null;
 let loadMoreButton = null;
 let offsetController = null;
 let path = null;
@@ -95,6 +97,7 @@ const MainWindow = new Lang.Class({
         fileUtil = new FileUtil.FileUtil();
         offsetController = new FileUtil.OffsetController;
         view = new MainView();
+       log(view);
         play = new Play.Play();
         
         params = Params.fill(params, { title: GLib.get_application_name(), 
@@ -163,9 +166,12 @@ const MainView = new Lang.Class({
     _addListviewPage: function(name) {
         fileUtil = new FileUtil.FileUtil();
         list = new Listview.Listview();
+       log(list);
+log(list.allFilesInfo);
         list.setListTypeNew();
         list.enumerateDirectory();
         this._record = new Record.Record(audioProfile);
+log(this._record._TENTH_SEC);
         let initialPage = new Gtk.EventBox();
         
         groupGrid = new Gtk.Grid({ orientation: Gtk.Orientation.VERTICAL,
@@ -301,7 +307,8 @@ const MainView = new Lang.Class({
         this.recordGrid.attach(this.toolbarStart, 5, 1, 1, 2);
     },
      
-    scrolledWinAdd: function() {       
+    scrolledWinAdd: function() { 
+       log("Scrolled window added");      
         this._scrolledWin = new Gtk.ScrolledWindow({ shadow_type: Gtk.ShadowType.IN,
                                                      margin_bottom: 3,
                                                      margin_top: 5,
@@ -328,21 +335,23 @@ const MainView = new Lang.Class({
         this.groupGrid.add(this._scrolledWin);
         this._scrolledWin.show();
         
-        this.listBox = Gtk.ListBox.new();
-        this._scrolledWin.add(this.listBox);
-        this.listBox.set_selection_mode(Gtk.SelectionMode.SINGLE);
-        this.listBox.set_header_func(null);
-        this.listBox.set_activate_on_single_click(true);
-        this.listBox.connect("row-selected", Lang.bind(this,
+        listBox = Gtk.ListBox.new();
+       log(listBox);
+        this._scrolledWin.add(listBox);
+        listBox.set_selection_mode(Gtk.SelectionMode.SINGLE);
+        listBox.set_header_func(null);
+        listBox.set_activate_on_single_click(true);
+        listBox.connect("row-selected", Lang.bind(this,
             function(){
-                this.rowGridCallback(this.listBox.get_selected_row())
+                this.rowGridCallback(listBox.get_selected_row())
             }));
-        this.listBox.show();
+        listBox.show();
         
         this._startIdx = 0;
         this._endIdx = offsetController.getcidx();
         this._files = [];
         this._files = list.getFilesInfoForList();
+log("this._files.length");
         
         for (let i = this._startIdx; i <= this._endIdx; i++) {
             this.rowGrid = new Gtk.Grid({ orientation: Gtk.Orientation.VERTICAL,
@@ -350,7 +359,7 @@ const MainView = new Lang.Class({
                                           width_request: 900,
                                           name: i.toString() });
             this.rowGrid.set_orientation(Gtk.Orientation.HORIZONTAL);
-            this.listBox.add(this.rowGrid);
+            listBox.add(this.rowGrid);
             this.rowGrid.show();
             
             this.widget = new Gtk.Toolbar({ show_arrow: false,
@@ -377,7 +386,7 @@ const MainView = new Lang.Class({
             this._playListButton.show();
             this._playListButton.connect('clicked', Lang.bind(this,
                 function(){
-                    let row = this.listBox.get_selected_row();
+                    let row = listBox.get_selected_row();
                     play.passSelected(row); 
                     let gridForName = row.get_child();
                     let idx = parseInt(gridForName.name);                   
@@ -409,7 +418,7 @@ const MainView = new Lang.Class({
             this._pauseListButton.show();
             this._pauseListButton.connect('clicked', Lang.bind(this,
                 function(){
-                    let row = this.listBox.get_selected_row();
+                    let row = listBox.get_selected_row();
                     this.onPause(row);
                 }));
             
@@ -489,7 +498,7 @@ const MainView = new Lang.Class({
             this._info.image = Gtk.Image.new_from_icon_name("dialog-information-symbolic", 
Gtk.IconSize.BUTTON);
             this._info.connect("clicked", Lang.bind(this,
                 function() {
-                    let row = this.listBox.get_selected_row();
+                    let row = listBox.get_selected_row();
                     let gridForName = row.get_child();
                     let idx = parseInt(gridForName.name);                    
                     let file = this._files[idx];
@@ -518,7 +527,7 @@ const MainView = new Lang.Class({
             this._delete.image = Gtk.Image.new_from_icon_name("user-trash-symbolic", Gtk.IconSize.BUTTON);
             this._delete.connect("clicked", Lang.bind(this,
                 function() {
-                    this._deleteFile(this.listBox.get_selected_row());
+                    this._deleteFile(listBox.get_selected_row());
                 }));
             this._delete.set_tooltip_text(_("Delete"));
             this._boxDelete.add(this._delete);
@@ -526,7 +535,7 @@ const MainView = new Lang.Class({
             
             this._separator = Gtk.Separator.new(Gtk.Orientation.HORIZONTAL);
             this._separator.set_sensitive(false);
-            this.listBox.add(this._separator);
+            listBox.add(this._separator);
             this.selectionRow = this._separator.get_parent();
             this.selectionRow.set_sensitive(false);
             this._separator.show();
@@ -551,14 +560,14 @@ const MainView = new Lang.Class({
     listBoxRefresh: function() {
         this.destroyLoadMoreButton();        
         previousSelRow = null;
-        this.listBox.set_selection_mode(Gtk.SelectionMode.NONE);  
+        listBox.set_selection_mode(Gtk.SelectionMode.NONE);  
         list.enumerateDirectory();         
     },
     
     listBoxLoadMore: function() {
        this.destroyLoadMoreButton();
        previousSelRow = null;
-       this.listBox.set_selection_mode(Gtk.SelectionMode.NONE);
+       listBox.set_selection_mode(Gtk.SelectionMode.NONE);
        offsetController.increaseEndIdxStep();
        list.setListTypeRefresh();
        list._setDiscover();
@@ -751,7 +760,7 @@ const RecordButton = new Lang.Class({
     _onRecord: function() {
         view.destroyLoadMoreButton();
         view.hasPreviousSelRow();
-        view.listBox.set_selection_mode(Gtk.SelectionMode.NONE);
+        listBox.set_selection_mode(Gtk.SelectionMode.NONE);
         this.set_sensitive(false);
         setVisibleID = ActiveArea.RECORD;
         view.recordGrid.show_all();
diff --git a/src/package.js b/src/package.js
index 3872695..8a9ba9c 100644
--- a/src/package.js
+++ b/src/package.js
@@ -26,9 +26,9 @@
 const GLib = imports.gi.GLib;
 const GIRepository = imports.gi.GIRepository;
 const Gio = imports.gi.Gio;
-const System = imports.system;
 
 const Gettext = imports.gettext;
+const System = imports.system;
 
 /*< public >*/
 var name;
@@ -181,6 +181,8 @@ function _checkVersion(required, current) {
 }
 
 function _isGjsModule(name, version) {
+       log(name + "name");
+       log(version + "version");
     // This is a subset of the JS modules we offer,
     // it includes only those that makes sense to use
     // standalone and in a general app.
diff --git a/src/params.js b/src/params.js
new file mode 100644
index 0000000..4074ef9
--- /dev/null
+++ b/src/params.js
@@ -0,0 +1,130 @@
+// -*- mode: js; js-indent-level: 4; indent-tabs-mode: nil -*-
+
+// Rules for versioning: bump major when making API incompatible changes,
+// bump minor when adding API
+var $API_VERSION = [1, 0];
+
+// Params:
+//
+// A set of convenience functions for dealing with pseudo-keyword
+// arguments.
+//
+// Examples:
+//
+// A function with complex arguments
+// function myFunction(params) {
+//     params = Params.parse(params, { myFlags: Flags.NONE,
+//                                     anInt: 42,
+//                                     aString: 'hello, world!',
+//                                    });
+//     ... params.anInt, params.myFlags, params.aString ...
+// }
+// myFunction({ anInt: -1 });
+//
+// Extend a method to allow more params in a subclass
+// The superclass can safely use Params.parse(), it won't see
+// the extensions.
+// const MyClass = new Lang.Class({
+//       ...
+//       method: function(params) {
+//           let mine = Params.filter(params, { anInt: 42 });
+//           this.parent(params);
+//           ... mine.anInt ...
+//       }
+// });
+
+// parse:
+// @params: caller-provided parameter object, or %null
+// @defaults: function-provided defaults object
+//
+// Examines @params and fills in default values from @defaults for
+// any properties in @defaults that don't appear in @params.
+// This function will throw a Error if @params contains a property
+// that is not recognized. Use fill() or filter() if you don't
+// want that.
+//
+// If @params is %null, this returns the values from @defaults.
+//
+// Return value: a new object, containing the merged parameters from
+// @params and @defaults
+function parse(params, defaults) {
+    let ret = {}, prop;
+    params = params || {};
+
+    for (prop in params) {
+        if (!(prop in defaults))
+            throw new Error('Unrecognized parameter "' + prop + '"');
+        ret[prop] = params[prop];
+    }
+
+    for (prop in defaults) {
+        if (!(prop in params))
+            ret[prop] = defaults[prop];
+    }
+
+    return ret;
+}
+
+// fill:
+// @params: caller-provided parameter object, or %null
+// @defaults: function-provided defaults object
+//
+// Examines @params and fills in default values from @defaults
+// for any properties in @defaults that don't appear in @params.
+//
+// Differently from parse(), this function does not throw for
+// unrecognized parameters.
+//
+// Return value: a new object, containing the merged parameters from
+// @params and @defaults
+function fill(params, defaults) {
+    let ret = {}, prop;
+    params = params || {};
+
+    for (prop in params)
+        ret[prop] = params[prop];
+
+    for (prop in defaults) {
+        if (!(prop in ret))
+            ret[prop] = defaults[prop];
+    }
+
+    return ret;
+}
+
+// filter:
+// @params: caller-provided parameter object, or %null
+// @defaults: function-provided defaults object
+//
+// Examines @params and returns an object containing the
+// same properties as @defaults, but with values taken from
+// @params where available.
+// Then it removes from @params all matched properties.
+//
+// This is similar to parse(), but it accepts unknown properties
+// and modifies @params for known ones.
+//
+// If @params is %null, this returns the values from @defaults.
+//
+// Return value: a new object, containing the merged parameters from
+// @params and @defaults
+function filter(params, defaults) {
+    let ret = {}, prop;
+    params = params || {};
+
+    for (prop in defaults) {
+        if (!(prop in params))
+            ret[prop] = defaults[prop];
+    }
+
+    for (prop in params) {
+        if (prop in defaults) {
+            ret[prop] = params[prop];
+            delete params[prop];
+        }
+    }
+
+    return ret;
+}
+
+
diff --git a/src/play.js b/src/play.js
index 2bcc36a..07d2237 100644
--- a/src/play.js
+++ b/src/play.js
@@ -26,6 +26,7 @@ const Gio = imports.gi.Gio;
 const Gst = imports.gi.Gst;
 const GstAudio = imports.gi.GstAudio;
 const GstPbutils = imports.gi.GstPbutils;
+
 const Mainloop = imports.mainloop;
 
 const MainWindow = imports.mainWindow;
diff --git a/src/preferences.js b/src/preferences.js
index 85ff204..576596d 100644
--- a/src/preferences.js
+++ b/src/preferences.js
@@ -22,6 +22,7 @@
 const Gio = imports.gi.Gio;
 const GLib = imports.gi.GLib;
 const Gtk = imports.gi.Gtk;
+
 const _ = imports.gettext.gettext;
 const C_ = imports.gettext.pgettext;
 
diff --git a/src/record.js b/src/record.js
index 3361693..cce9bd1 100644
--- a/src/record.js
+++ b/src/record.js
@@ -28,6 +28,7 @@ const GObject = imports.gi.GObject;
 const Gst = imports.gi.Gst;
 const GstAudio = imports.gi.GstAudio;
 const GstPbutils = imports.gi.GstPbutils;
+
 const Mainloop = imports.mainloop;
 const Signals = imports.signals;
 
diff --git a/src/waveform.js b/src/waveform.js
index 5a9048a..57b3bd0 100644
--- a/src/waveform.js
+++ b/src/waveform.js
@@ -28,9 +28,9 @@ const GObject = imports.gi.GObject;
 const Gst = imports.gi.Gst;
 const GstAudio = imports.gi.GstAudio;
 const Gtk = imports.gi.Gtk;
+
 const _ = imports.gettext.gettext;
 const C_ = imports.gettext.pgettext;
-const Lang = imports.lang;
 const Mainloop = imports.mainloop;
 
 const MainWindow = imports.mainWindow;


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