[gnome-sound-recorder/wip/jtojnar/es6: 11/12] Port to ES6 classes



commit 0ec10bf08e8ec327fe6378a77f3929929d63d388
Author: Jan Tojnar <jtojnar gmail com>
Date:   Fri Jan 18 06:39:01 2019 +0100

    Port to ES6 classes

 src/application.js  |  73 ++++++++++-----------
 src/audioProfile.js |  23 ++++---
 src/fileUtil.js     |  35 ++++------
 src/info.js         |  17 ++---
 src/listview.js     |  81 +++++++++++------------
 src/mainWindow.js   | 180 +++++++++++++++++++++++-----------------------------
 src/params.js       |   8 +--
 src/play.js         |  61 +++++++++---------
 src/preferences.js  |  39 ++++++------
 src/record.js       |  61 ++++++++----------
 src/waveform.js     |  47 +++++++-------
 11 files changed, 286 insertions(+), 339 deletions(-)
---
diff --git a/src/application.js b/src/application.js
index 723eae8..3f383fc 100644
--- a/src/application.js
+++ b/src/application.js
@@ -20,9 +20,9 @@
 
 const Gio = imports.gi.Gio;
 const GLib = imports.gi.GLib;
+const GObject = imports.gi.GObject;
 const Gst = imports.gi.Gst;
 const Gtk = imports.gi.Gtk;
-const Lang = imports.lang;
 
 const MainWindow = imports.mainWindow;
 const Preferences = imports.preferences;
@@ -34,16 +34,13 @@ var SIGTERM = 15;
 var application = null;
 let settings = null;
 
-var Application = new Lang.Class({
-    Name: 'Application',
-    Extends: Gtk.Application,
-
-    _init: function() {
-        this.parent({ application_id: pkg.name });
+var Application = GObject.registerClass(class Application extends Gtk.Application {
+    _init() {
+        super._init({ application_id: pkg.name });
         GLib.set_application_name(_("SoundRecorder"));
-    },
+    }
 
-    _initAppMenu: function() {
+    _initAppMenu() {
         let preferences = new Gio.SimpleAction({ name: 'preferences' });
         preferences.connect('activate', () => {
             this._showPreferences();
@@ -62,10 +59,10 @@ var Application = new Lang.Class({
         });
         this.add_action(quitAction);
         this.add_accelerator('<Primary>q', 'app.quit', null);
-    },
+    }
 
-    vfunc_startup: function() {
-        this.parent();
+    vfunc_startup() {
+        super.vfunc_startup();
 
         Util.loadStyleSheet();
         log(_("Sound Recorder started"));
@@ -74,22 +71,22 @@ var Application = new Lang.Class({
         application = this;
         settings = new Gio.Settings({ schema: 'org.gnome.gnome-sound-recorder' });
         this.ensure_directory();
-    },
+    }
 
-    ensure_directory: function() {
+    ensure_directory() {
         /* Translators: "Recordings" here refers to the name of the directory where the application places 
files */
         let path = GLib.build_filenamev([GLib.get_home_dir(), _("Recordings")]);
 
         // Ensure Recordings directory
         GLib.mkdir_with_parents(path, parseInt("0755", 8));
         this.saveDir = Gio.file_new_for_path(path);
-    },
+    }
 
-    vfunc_activate: function() {
+    vfunc_activate() {
         (this.window = new MainWindow.MainWindow({ application: this })).show();
-    },
+    }
 
-    onWindowDestroy: function() {
+    onWindowDestroy() {
         if (MainWindow.wave.pipeline)
             MainWindow.wave.pipeline.set_state(Gst.State.NULL);
         if (MainWindow._record.pipeline)
@@ -97,53 +94,53 @@ var Application = new Lang.Class({
 
         if (MainWindow.play.play)
             MainWindow.play.play.set_state(Gst.State.NULL);
-    },
+    }
 
-    _showPreferences: function() {
+    _showPreferences() {
         let preferencesDialog = new Preferences.Preferences();
 
         preferencesDialog.widget.connect('response', (widget, response) => {
             preferencesDialog.widget.destroy();
         });
-    },
+    }
 
-    getPreferences: function() {
+    getPreferences() {
         let set = settings.get_int("media-type-preset");
         return set;
-     },
+    }
 
-    setPreferences: function(profileName) {
+    setPreferences(profileName) {
         settings.set_int("media-type-preset", profileName);
-    },
+    }
 
-    getChannelsPreferences: function() {
+    getChannelsPreferences() {
         let set = settings.get_int("channel");
         return set;
-    },
+    }
 
-    setChannelsPreferences: function(channel) {
+    setChannelsPreferences(channel) {
         settings.set_int("channel", channel);
-    },
+    }
 
-    getMicVolume: function() {
+    getMicVolume() {
         let micVolLevel = settings.get_double("mic-volume");
         return micVolLevel;
-    },
+    }
 
-    setMicVolume: function(level) {
+    setMicVolume(level) {
          settings.set_double("mic-volume", level);
-    },
+    }
 
-    getSpeakerVolume: function() {
+    getSpeakerVolume() {
         let speakerVolLevel = settings.get_double("speaker-volume");
         return speakerVolLevel;
-    },
+    }
 
-    setSpeakerVolume: function(level) {
+    setSpeakerVolume(level) {
          settings.set_double("speaker-volume", level);
-    },
+    }
 
-    _showAbout: function() {
+    _showAbout() {
         let aboutDialog = new Gtk.AboutDialog();
         aboutDialog.artists = [ 'Reda Lazri <the red shortcut gmail com>',
                                 'Garrett LeSage <garrettl gmail com>',
diff --git a/src/audioProfile.js b/src/audioProfile.js
index ffec841..6ec5c55 100644
--- a/src/audioProfile.js
+++ b/src/audioProfile.js
@@ -20,9 +20,9 @@
 
 const _ = imports.gettext.gettext;
 const Gio = imports.gi.Gio;
+const GObject = imports.gi.GObject;
 const Gst = imports.gi.Gst;
 const GstPbutils = imports.gi.GstPbutils;
-const Lang = imports.lang;
 const Mainloop = imports.mainloop;
 
 const MainWindow = imports.mainWindow;
@@ -52,14 +52,13 @@ var audioCodecMap = {
     VORBIS: "audio/x-vorbis"
 };
 
-var AudioProfile = new Lang.Class({
-    Name: 'AudioProfile',
-
-    profile: function(profileName){
-        if (profileName)
+var AudioProfile = class AudioProfile {
+    profile(profileName){
+        if (profileName) {
             this._profileName = profileName;
-       else
+        } else {
             this._profileName = comboBoxMap.OGG_VORBIS;
+        }
 
         switch(this._profileName) {
 
@@ -86,9 +85,9 @@ var AudioProfile = new Lang.Class({
         default:
             break;
         }
-    },
+    }
 
-    mediaProfile: function(){
+    mediaProfile(){
         let audioCaps;
         this._containerProfile = null;
         if (this._values.audio && this._values.container) {
@@ -105,9 +104,9 @@ var AudioProfile = new Lang.Class({
         } else {
             return -1;
         }
-    },
+    }
 
-    fileExtensionReturner: function() {
+    fileExtensionReturner() {
         let suffixName;
 
         if (this._values.audio) {
@@ -121,4 +120,4 @@ var AudioProfile = new Lang.Class({
         this.audioSuffix = ("." + suffixName);
         return this.audioSuffix;
     }
-});
+}
diff --git a/src/fileUtil.js b/src/fileUtil.js
index d015474..c21f1e0 100644
--- a/src/fileUtil.js
+++ b/src/fileUtil.js
@@ -25,7 +25,6 @@ const GLib = imports.gi.GLib;
 const GObject = imports.gi.GObject;
 const Gst = imports.gi.Gst;
 const GstPbutils = imports.gi.GstPbutils;
-const Lang = imports.lang;
 const Signals = imports.signals;
 
 const Listview = imports.listview;
@@ -36,21 +35,19 @@ const _OFFSET_STEP = 20;
 let CurrentEndIdx;
 let totItems;
 
-var OffsetController = new Lang.Class({
-    Name: 'OffsetController',
-
-    _init: function(context) {
+var OffsetController = class OffsetController {
+    constructor(context) {
         this._offset = 0;
         this._itemCount = 0;
         this._context = context;
         CurrentEndIdx = _OFFSET_STEP;
-    },
+    }
 
-    getOffset: function() {
+    getOffset() {
         return this._offset;
-    },
+    }
 
-    getEndIdx: function() {
+    getEndIdx() {
         totItems = MainWindow.list.getItemCount();
         if (CurrentEndIdx < totItems) {
             this.endIdx = CurrentEndIdx -1;
@@ -59,21 +56,19 @@ var OffsetController = new Lang.Class({
         }
 
         return this.endIdx;
-    },
+    }
 
-    increaseEndIdxStep: function() {
+    increaseEndIdxStep() {
         CurrentEndIdx += _OFFSET_STEP;
-    },
+    }
 
-    getcidx: function() {
+    getcidx() {
         return CurrentEndIdx;
     }
-});
-
-var DisplayTime = new Lang.Class({
-    Name: 'DisplayTime',
+}
 
-    getDisplayTime: function(mtime) {
+var DisplayTime = class DisplayTime {
+    getDisplayTime(mtime) {
         let text = "";
         let DAY = 86400000000;
         let now = GLib.DateTime.new_now_local();
@@ -112,6 +107,4 @@ var DisplayTime = new Lang.Class({
         }
         return text;
     }
-});
-
-
+}
diff --git a/src/info.js b/src/info.js
index 70f7374..4dc867e 100644
--- a/src/info.js
+++ b/src/info.js
@@ -22,17 +22,14 @@
 const Gio = imports.gi.Gio;
 const GLib = imports.gi.GLib;
 const Gtk = imports.gi.Gtk;
-const Lang = imports.lang;
 
 const _ = imports.gettext.gettext;
 const C_ = imports.gettext.pgettext;
 
 const MainWindow = imports.mainWindow;
 
-var InfoDialog = new Lang.Class({
-    Name: 'InfoDialog',
-
-    _init: function(fileNav) {
+var InfoDialog = class InfoDialog {
+    constructor(fileNav) {
         let fileName = fileNav;
 
         this._file = Gio.File.new_for_uri(fileNav.uri);
@@ -156,15 +153,15 @@ var InfoDialog = new Lang.Class({
         grid.attach_next_to(this._mediaTypeData, this._mediaType, Gtk.PositionType.RIGHT, 2, 1);
 
         this.widget.show_all();
-    },
+    }
 
-    onDoneClicked: function() {
+    onDoneClicked() {
         let newFileName = this._fileNameEntry.get_text();
         this._file.set_display_name_async(newFileName, GLib.PRIORITY_DEFAULT, null, null);
         this.widget.destroy();
-    },
+    }
 
-    onCancelClicked: function() {
+    onCancelClicked() {
         this.widget.destroy();
     }
-});
+}
diff --git a/src/listview.js b/src/listview.js
index 875e323..fe8f901 100644
--- a/src/listview.js
+++ b/src/listview.js
@@ -25,7 +25,6 @@ const GLib = imports.gi.GLib;
 const GObject = imports.gi.GObject;
 const Gst = imports.gi.Gst;
 const GstPbutils = imports.gi.GstPbutils;
-const Lang = imports.lang;
 const Signals = imports.signals;
 
 const AudioProfile = imports.audioProfile;
@@ -63,40 +62,38 @@ let startRecording = false;
 let stopVal = null;
 var trackNumber = 0;
 
-var Listview = new Lang.Class({
-    Name: "Listview",
-
-    _init: function() {
+var Listview = class Listview {
+    constructor() {
         stopVal = EnumeratorState.ACTIVE;
         allFilesInfo = [];
 
         // Save a reference to the savedir to quickly access it
         this._saveDir = Gio.Application.get_default().saveDir;
-    },
+    }
 
-    monitorListview: function() {
+    monitorListview() {
         this.dirMonitor = this._saveDir.monitor_directory(Gio.FileMonitorFlags.WATCH_MOVES, null);
-        this.dirMonitor.connect('changed', this._onDirChanged);
-    },
+        this.dirMonitor.connect('changed', (dirMonitor, file1, file2, eventType) => 
this._onDirChanged(dirMonitor, file1, file2, eventType));
+    }
 
-    enumerateDirectory: function() {
+    enumerateDirectory() {
         this._saveDir.enumerate_children_async('standard::display-name,time::created,time::modified',
                                      Gio.FileQueryInfoFlags.NONE,
                                      GLib.PRIORITY_LOW,
                                      null,
                                      (obj, res) => this._onEnumerator(obj, res));
-    },
+    }
 
-    _onEnumerator: function(obj, res) {
+    _onEnumerator(obj, res) {
         this._enumerator = obj.enumerate_children_finish(res);
 
         if (this._enumerator == null)
             log("The contents of the Recordings directory were not indexed.");
         else
             this._onNextFileComplete();
-    },
+    }
 
-    _onNextFileComplete: function () {
+    _onNextFileComplete () {
         fileInfo = [];
         try{
             this._enumerator.next_files_async(20, GLib.PRIORITY_DEFAULT, null, (obj, res) => {
@@ -166,9 +163,9 @@ var Listview = new Lang.Class({
         } catch(e) {
             log(e);
         }
-    },
+    }
 
-    _sortItems: function(fileArr) {
+    _sortItems(fileArr) {
         allFilesInfo = allFilesInfo.concat(fileArr);
         allFilesInfo.sort(function(a, b) {
             return b.dateForSort - a.dateForSort;
@@ -177,13 +174,13 @@ var Listview = new Lang.Class({
         if (stopVal == EnumeratorState.ACTIVE) {
             this._onNextFileComplete();
         }
-    },
+    }
 
-    getItemCount: function() {
+    getItemCount() {
         return allFilesInfo.length;
-    },
+    }
 
-    _setDiscover: function() {
+    _setDiscover() {
         this._controller = MainWindow.offsetController;
         this.endIdx = this._controller.getEndIdx();
         this.idx = 0;
@@ -195,16 +192,16 @@ var Listview = new Lang.Class({
             this._discoverer.discover_uri_async(uri);
         }
         this._runDiscover();
-     },
+    }
 
-     _runDiscover: function() {
+     _runDiscover() {
         this._discoverer.connect('discovered', (_discoverer, info, error) => {
             let result = info.get_result();
             this._onDiscovererFinished(result, info, error);
         });
-    },
+    }
 
-    _onDiscovererFinished: function(res, info, err) {
+    _onDiscovererFinished(res, info, err) {
         this.result = res;
         if (this.result == GstPbutils.DiscovererResult.OK && allFilesInfo[this.idx]) {
             this.tagInfo = info.get_tags();
@@ -248,17 +245,17 @@ var Listview = new Lang.Class({
             //return false;
         }
         this.idx++;
-    },
+    }
 
-    setListTypeNew: function() {
+    setListTypeNew() {
         listType = ListType.NEW;
-    },
+    }
 
-    setListTypeRefresh: function() {
+    setListTypeRefresh() {
         listType = ListType.REFRESH;
-    },
+    }
 
-    _onDirChanged: function(dirMonitor, file1, file2, eventType) {
+    _onDirChanged(dirMonitor, file1, file2, eventType) {
         if (eventType == Gio.FileMonitorEvent.DELETED && Gio.Application.get_default().saveDir.equal(file1)) 
{
             Gio.Application.get_default().ensure_directory();
             this._saveDir = Gio.Application.get_default().saveDir;
@@ -281,9 +278,9 @@ var Listview = new Lang.Class({
         else if (eventType == Gio.FileMonitorEvent.CREATED) {
             startRecording = true;
         }
-    },
+    }
 
-    _onDirChangedDeb: function(dirMonitor, file1, file2, eventType) {
+    _onDirChangedDeb(dirMonitor, file1, file2, eventType) {
         /* Workaround for Debian and Tails not recognizing Gio.FileMointor.WATCH_MOVES */
         if (eventType == Gio.FileMonitorEvent.DELETED && Gio.Application.get_default().saveDir.equal(file1)) 
{
             Gio.Application.get_default().ensure_directory();
@@ -306,9 +303,9 @@ var Listview = new Lang.Class({
         else if (eventType == Gio.FileMonitorEvent.CREATED) {
             startRecording = true;
         }
-    },
+    }
 
-    _getCapsForList: function(info) {
+    _getCapsForList(info) {
         let discovererStreamInfo = null;
         discovererStreamInfo = info.get_stream_info();
         let containerStreams = info.get_container_streams()[0];
@@ -342,16 +339,14 @@ var Listview = new Lang.Class({
                 // Remove the file from the array if we don't recognize it
                 allFilesInfo.splice(this.idx, 1);
         }
-    },
+    }
 
-    capTypes: function(capString) {
-       let caps = Gst.Caps.from_string(capString);
-       return caps;
-    },
+    capTypes(capString) {
+        let caps = Gst.Caps.from_string(capString);
+        return caps;
+    }
 
-    getFilesInfoForList: function() {
+    getFilesInfoForList() {
         return allFilesInfo;
     }
-});
-
-
+}
diff --git a/src/mainWindow.js b/src/mainWindow.js
index 2879994..f90ef5b 100644
--- a/src/mainWindow.js
+++ b/src/mainWindow.js
@@ -27,9 +27,9 @@ const Gdk = imports.gi.Gdk;
 const GdkPixbuf = imports.gi.GdkPixbuf;
 const Gio = imports.gi.Gio;
 const GLib = imports.gi.GLib;
+const GObject = imports.gi.GObject;
 const Gst = imports.gi.Gst;
 const Gtk = imports.gi.Gtk;
-const Lang = imports.lang;
 const Pango = imports.gi.Pango;
 
 const Application = imports.application;
@@ -89,11 +89,8 @@ var RecordPipelineStates = {
 const _TIME_DIVISOR = 60;
 var _SEC_TIMEOUT = 100;
 
-var MainWindow = new Lang.Class({
-    Name: 'MainWindow',
-    Extends: Gtk.ApplicationWindow,
-
-     _init: function(params) {
+var MainWindow = GObject.registerClass(class MainWindow extends Gtk.ApplicationWindow {
+     _init(params) {
         audioProfile = new AudioProfile.AudioProfile();
         offsetController = new FileUtil.OffsetController;
         displayTime = new FileUtil.DisplayTime;
@@ -108,7 +105,7 @@ var MainWindow = new Lang.Class({
                                        hexpand: true,
                                        vexpand: true,
                                        icon_name: "org.gnome.SoundRecorder" });
-        this.parent(params);
+        super._init(params);
 
         header = new Gtk.HeaderBar({ hexpand: true,
                                      show_close_button: true });
@@ -123,9 +120,9 @@ var MainWindow = new Lang.Class({
 
         this.add(view);
         this.show_all();
-    },
+    }
 
-    _addAppMenu: function() {
+    _addAppMenu() {
         let menu = new Gio.Menu();
         menu.append(_("Preferences"), 'app.preferences');
         menu.append(_("About Sound Recorder"), 'app.about');
@@ -138,22 +135,19 @@ var MainWindow = new Lang.Class({
     }
 });
 
-const MainView = new Lang.Class({
-    Name: 'MainView',
-    Extends: Gtk.Stack,
-
-    _init: function(params) {
+const MainView = GObject.registerClass(class MainView extends Gtk.Stack {
+    _init(params) {
         params = Params.fill(params, { vexpand: true,
                                        transition_type: Gtk.StackTransitionType.CROSSFADE,
                                        transition_duration: 100,
                                        visible: true });
-        this.parent(params);
+        super._init(params);
 
         this._addListviewPage('listviewPage');
         this.labelID = null;
-    },
+    }
 
-    _addEmptyPage: function() {
+    _addEmptyPage() {
         this.emptyGrid = new Gtk.Grid({ orientation: Gtk.Orientation.VERTICAL,
                                         hexpand: true,
                                         vexpand: true,
@@ -178,9 +172,9 @@ const MainView = new Lang.Class({
         emptyPageDirections.get_style_context().add_class('dim-label');
         this.emptyGrid.add(emptyPageDirections);
         this.emptyGrid.show_all();
-    },
+    }
 
-    _addListviewPage: function(name) {
+    _addListviewPage(name) {
         list = new Listview.Listview();
         list.setListTypeNew();
         list.enumerateDirectory();
@@ -190,9 +184,9 @@ const MainView = new Lang.Class({
                                    hexpand: true,
                                    vexpand: true });
         this.add_titled(groupGrid, name, "View");
-    },
+    }
 
-    onPlayStopClicked: function() {
+    onPlayStopClicked() {
         if (play.getPipeStates() == PipelineStates.PLAYING) {
             play.stopPlaying();
             let listRow = this.listBox.get_selected_row();
@@ -220,18 +214,18 @@ const MainView = new Lang.Class({
                 }
             });
         }
-    },
+    }
 
-    onRecordStopClicked: function() {
+    onRecordStopClicked() {
         this._record.stopRecording();
         this.recordGrid.hide();
         recordPipeline = RecordPipelineStates.STOPPED;
         recordButton.set_sensitive(true);
         if (this.listBox != null)
             this.listBox.set_selection_mode(Gtk.SelectionMode.SINGLE);
-    },
+    }
 
-    _formatTime: function(unformattedTime) {
+    _formatTime(unformattedTime) {
         this.unformattedTime = unformattedTime;
         let seconds = Math.floor(this.unformattedTime);
         let hours = parseInt(seconds / Math.pow(_TIME_DIVISOR, 2));
@@ -251,18 +245,18 @@ const MainView = new Lang.Class({
             (secondString < 10 ? "0" + secondString : secondString);
 
         return timeString;
-    },
+    }
 
-    _updatePositionCallback: function() {
+    _updatePositionCallback() {
         let position = MainWindow.play.queryPosition();
 
         if (position >= 0) {
             this.progressScale.set_value(position);
         }
         return true;
-    },
+    }
 
-    presetVolume: function(source, vol) {
+    presetVolume(source, vol) {
         if (source == ActiveArea.PLAY) {
             volumeValue[0].play = vol;
             Application.application.setSpeakerVolume(vol);
@@ -270,23 +264,23 @@ const MainView = new Lang.Class({
             volumeValue[0].record = vol;
             Application.application.setMicVolume(vol);
         }
-    },
+    }
 
-    setVolume: function() {
+    setVolume() {
         if (setVisibleID == ActiveArea.PLAY) {
             play.setVolume(volumeValue[0].play);
         } else if (setVisibleID == ActiveArea.RECORD) {
            this._record.setVolume(volumeValue[0].record);
         }
-    },
+    }
 
-    getVolume: function() {
+    getVolume() {
         let volumeValue = this.playVolume.get_value();
 
         return volumeValue;
-    },
+    }
 
-    listBoxAdd: function() {
+    listBoxAdd() {
         selectable = true;
         this.groupGrid = groupGrid;
         let playVolume = Application.application.getSpeakerVolume();
@@ -339,9 +333,9 @@ const MainView = new Lang.Class({
         stopRecord.connect("clicked", () => this.onRecordStopClicked());
         this.toolbarStart.pack_start(stopRecord, true, true, 0);
         this.recordGrid.attach(this.toolbarStart, 5, 1, 2, 2);
-    },
+    }
 
-    scrolledWinAdd: function() {
+    scrolledWinAdd() {
         this._scrolledWin = new Gtk.ScrolledWindow({ vexpand: true });
         this._scrolledWin.set_policy(Gtk.PolicyType.NEVER, Gtk.PolicyType.AUTOMATIC);
         this.scrollbar = this._scrolledWin.get_vadjustment();
@@ -540,23 +534,23 @@ const MainView = new Lang.Class({
             }
         }
         list.monitorListview();
-    },
+    }
 
-    addLoadMoreButton: function() {
+    addLoadMoreButton() {
        loadMoreButton = new LoadMoreButton();
        loadMoreButton.connect('clicked', () => loadMoreButton.onLoadMore());
        this.groupGrid.add(loadMoreButton);
        loadMoreButton.show();
-    },
+    }
 
-    destroyLoadMoreButton: function() {
+    destroyLoadMoreButton() {
         if (loadMoreButton != null) {
             loadMoreButton.destroy();
             loadMoreButton = null;
         }
-    },
+    }
 
-    listBoxRefresh: function() {
+    listBoxRefresh() {
         this.destroyLoadMoreButton();
         previousSelRow = null;
 
@@ -566,23 +560,23 @@ const MainView = new Lang.Class({
 
         list.setListTypeRefresh();
         list.enumerateDirectory();
-    },
+    }
 
-    listBoxLoadMore: function() {
+    listBoxLoadMore() {
        this.destroyLoadMoreButton();
        previousSelRow = null;
        this.listBox.set_selection_mode(Gtk.SelectionMode.NONE);
        offsetController.increaseEndIdxStep();
        list.setListTypeRefresh();
        list._setDiscover();
-    },
+    }
 
-    scrolledWinDelete: function() {
+    scrolledWinDelete() {
         this._scrolledWin.destroy();
         this.scrolledWinAdd();
-    },
+    }
 
-    hasPreviousSelRow: function() {
+    hasPreviousSelRow() {
         this.destroyLoadMoreButton();
         if (previousSelRow != null) {
             let rowGrid = previousSelRow.get_child();
@@ -620,9 +614,9 @@ const MainView = new Lang.Class({
             }
         }
         previousSelRow = null;
-    },
+    }
 
-    rowGridCallback: function() {
+    rowGridCallback() {
         let selectedRow = this.listBox.get_selected_row();
         this.destroyLoadMoreButton();
 
@@ -648,9 +642,9 @@ const MainView = new Lang.Class({
             if (child.name == "WaveFormGrid")
                 child.sensitive = true;
         });
-    }    },
+    }    }
 
-    _getFileFromRow: function(selected) {
+    _getFileFromRow(selected) {
 
         let fileForAction = null;
         let rowGrid = selected.get_child();
@@ -663,28 +657,28 @@ const MainView = new Lang.Class({
         });
 
         return fileForAction;
-    },
+    }
 
-    _deleteFile: function(selected) {
+    _deleteFile(selected) {
         let fileToDelete = this._getFileFromRow(selected);
         fileToDelete.trash_async(GLib.PRIORITY_DEFAULT, null, null);
-    },
+    }
 
-    loadPlay: function(selected) {
+    loadPlay(selected) {
         let fileToPlay = this._getFileFromRow(selected);
 
         return fileToPlay;
-    },
+    }
 
-    _onInfoButton: function(selected) {
+    _onInfoButton(selected) {
         let infoDialog = new Info.InfoDialog(selected);
 
         infoDialog.widget.connect('response', (widget, response) => {
             infoDialog.widget.destroy();
         });
-    },
+    }
 
-    setLabel: function(time) {
+    setLabel(time) {
         this.time = time
 
         this.timeLabelString = this._formatTime(time);
@@ -695,9 +689,9 @@ const MainView = new Lang.Class({
         } else if (setVisibleID == ActiveArea.PLAY) {
             this.playTimeLabel.label = this.timeLabelString;
         }
-    },
+    }
 
-    setNameLabel: function(newName, oldName, index) {
+    setNameLabel(newName, oldName, index) {
 
         let selected = this.listBox.get_row_at_index(index);
         let rowGrid = selected.get_child();
@@ -709,9 +703,9 @@ const MainView = new Lang.Class({
             }
         });
         rowGrid.set_name(newName);
-    },
+    }
 
-    onPause: function(listRow) {
+    onPause(listRow) {
         let activeState = play.getPipeStates();
 
         if (activeState == PipelineStates.PLAYING) {
@@ -730,9 +724,9 @@ const MainView = new Lang.Class({
                 }
             });
         }
-    },
+    }
 
-    onPlayPauseToggled: function(listRow, selFile) {
+    onPlayPauseToggled(listRow, selFile) {
         setVisibleID = ActiveArea.PLAY;
         let activeState = play.getPipeStates();
 
@@ -778,21 +772,18 @@ const MainView = new Lang.Class({
     }
 });
 
-const RecordButton = new Lang.Class({
-    Name: "RecordButton",
-    Extends: Gtk.Button,
-
-    _init: function(activeProfile) {
-        this.parent();
+const RecordButton = GObject.registerClass(class RecordButton extends Gtk.Button {
+    _init(activeProfile) {
+        super._init();
         this.image = Gtk.Image.new_from_icon_name('media-record-symbolic', Gtk.IconSize.BUTTON);
         this.set_always_show_image(true);
         this.set_valign(Gtk.Align.CENTER);
         this.set_label(_("Record"));
         this.get_style_context().add_class('text-button');
         this.connect("clicked", () => this._onRecord());
-    },
+    }
 
-    _onRecord: function() {
+    _onRecord() {
         view.destroyLoadMoreButton();
         view.hasPreviousSelRow();
 
@@ -815,13 +806,10 @@ const RecordButton = new Lang.Class({
     }
 });
 
-var EncoderComboBox = new Lang.Class({
-    Name: "EncoderComboBox",
-    Extends: Gtk.ComboBoxText,
-
+var EncoderComboBox = GObject.registerClass(class EncoderComboBox extends Gtk.ComboBoxText {
     // encoding setting labels in combobox
-    _init: function() {
-        this.parent();
+    _init() {
+        super._init();
         let combo = [_("Ogg Vorbis"), _("Opus"), _("FLAC"), _("MP3"), _("MOV")];
 
         for (let i = 0; i < combo.length; i++)
@@ -831,21 +819,18 @@ var EncoderComboBox = new Lang.Class({
         activeProfile = Application.application.getPreferences();
         this.set_active(activeProfile);
         this.connect("changed", () => this._onComboBoxTextChanged());
-    },
+    }
 
-    _onComboBoxTextChanged: function() {
+    _onComboBoxTextChanged() {
         activeProfile = this.get_active();
         Application.application.setPreferences(activeProfile);
     }
 });
 
-var ChannelsComboBox = new Lang.Class({
-    Name: "ChannelsComboBox",
-    Extends: Gtk.ComboBoxText,
-
+var ChannelsComboBox = GObject.registerClass(class ChannelsComboBox extends Gtk.ComboBoxText {
     // channel setting labels in combobox
-    _init: function() {
-        this.parent();
+    _init() {
+        super._init();
         let combo = [_("Mono"), _("Stereo")];
 
         for (let i = 0; i < combo.length; i++)
@@ -855,26 +840,23 @@ var ChannelsComboBox = new Lang.Class({
         let chanProfile = Application.application.getChannelsPreferences();
         this.set_active(chanProfile);
         this.connect("changed", () => this._onChannelComboBoxTextChanged());
-    },
+    }
 
-    _onChannelComboBoxTextChanged: function() {
+    _onChannelComboBoxTextChanged() {
         let channelProfile = this.get_active();
         Application.application.setChannelsPreferences(channelProfile);
     }
 });
 
-const LoadMoreButton = new Lang.Class({
-    Name: 'LoadMoreButton',
-    Extends: Gtk.Button,
-
-    _init: function() {
-        this.parent();
+const LoadMoreButton = GObject.registerClass(class LoadMoreButton extends Gtk.Button {
+    _init() {
+        super._init();
         this._block = false;
         this.label = _("Load More");
         this.get_style_context().add_class('documents-load-more');
-    },
+    }
 
-    onLoadMore: function() {
+    onLoadMore() {
         view.listBoxLoadMore();
     }
 });
diff --git a/src/params.js b/src/params.js
index 4074ef9..cd862cf 100644
--- a/src/params.js
+++ b/src/params.js
@@ -24,14 +24,14 @@ var $API_VERSION = [1, 0];
 // 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({
+// class MyClass {
 //       ...
 //       method: function(params) {
 //           let mine = Params.filter(params, { anInt: 42 });
-//           this.parent(params);
+//           super(params);
 //           ... mine.anInt ...
 //       }
-// });
+// }
 
 // parse:
 // @params: caller-provided parameter object, or %null
@@ -126,5 +126,3 @@ function filter(params, defaults) {
 
     return ret;
 }
-
-
diff --git a/src/play.js b/src/play.js
index 233a34c..0d2bcd4 100644
--- a/src/play.js
+++ b/src/play.js
@@ -25,7 +25,6 @@ const Gst = imports.gi.Gst;
 const GstAudio = imports.gi.GstAudio;
 const GstPbutils = imports.gi.GstPbutils;
 const Gtk = imports.gi.Gtk;
-const Lang = imports.lang;
 const Mainloop = imports.mainloop;
 
 const Application = imports.application;
@@ -48,10 +47,8 @@ let errorDialogState;
 
 const _TENTH_SEC = 100000000;
 
-var Play = new Lang.Class({
-    Name: "Play",
-
-    _playPipeline: function() {
+var Play = class Play {
+    _playPipeline() {
         errorDialogState = ErrState.OFF;
         let uri = this._fileToPlay.get_uri();
         this.play = Gst.ElementFactory.make("playbin", "play");
@@ -66,9 +63,9 @@ var Play = new Lang.Class({
                 this._onMessageReceived(message);
             }
         });
-    },
+    }
 
-    startPlaying: function() {
+    startPlaying() {
         this.baseTime = 0;
 
         if (!this.play || this.playState == PipelineStates.STOPPED ) {
@@ -92,9 +89,9 @@ var Play = new Lang.Class({
         }
         GLib.unix_signal_add(GLib.PRIORITY_DEFAULT, Application.SIGINT, 
Application.application.onWindowDestroy);
         GLib.unix_signal_add(GLib.PRIORITY_DEFAULT, Application.SIGTERM, 
Application.application.onWindowDestroy);
-    },
+    }
 
-    pausePlaying: function() {
+    pausePlaying() {
         this.play.set_state(Gst.State.PAUSED);
         this.playState = PipelineStates.PAUSED;
 
@@ -102,15 +99,15 @@ var Play = new Lang.Class({
             GLib.source_remove(this.timeout);
             this.timeout = null;
         }
-    },
+    }
 
-    stopPlaying: function() {
+    stopPlaying() {
         if (this.playState != PipelineStates.STOPPED) {
             this.onEnd();
         }
-    },
+    }
 
-    onEnd: function() {
+    onEnd() {
         this.play.set_state(Gst.State.NULL);
         this.playState = PipelineStates.STOPPED;
         this.playBus.remove_signal_watch();
@@ -125,13 +122,13 @@ var Play = new Lang.Class({
             MainWindow.wave.endDrawing();
 
         errorDialogState = ErrState.OFF;
-    },
+    }
 
-    onEndOfStream: function() {
+    onEndOfStream() {
         MainWindow.view.onPlayStopClicked();
-    },
+    }
 
-    _onMessageReceived: function(message) {
+    _onMessageReceived(message) {
         this.localMsg = message;
         let msg = message.type;
         switch(msg) {
@@ -170,13 +167,13 @@ var Play = new Lang.Class({
             }
             break;
         }
-    },
+    }
 
-    getPipeStates: function() {
+    getPipeStates() {
         return this.playState;
-    },
+    }
 
-    _updateTime: function() {
+    _updateTime() {
         let time = this.play.query_position(Gst.Format.TIME)[1]/Gst.SECOND;
         this.trackDuration = this.play.query_duration(Gst.Format.TIME)[1];
         this.trackDurationSecs = this.trackDuration/Gst.SECOND;
@@ -209,34 +206,34 @@ var Play = new Lang.Class({
         }
 
         return true;
-    },
+    }
 
-    queryPosition: function() {
+    queryPosition() {
         let position = 0;
         while (position == 0) {
             position = this.play.query_position(Gst.Format.TIME)[1]/Gst.SECOND;
         }
 
         return position;
-    },
+    }
 
-    updatePosition: function() {
+    updatePosition() {
         if (!this.timeout) {
             this.timeout = GLib.timeout_add(GLib.PRIORITY_DEFAULT, 10, () =>
                 this._updateTime());
         }
-    },
+    }
 
-    setVolume: function(value) {
+    setVolume(value) {
         this.play.set_volume(GstAudio.StreamVolumeFormat.CUBIC, value);
-    },
+    }
 
-    passSelected: function(selected) {
+    passSelected(selected) {
         this._selected = selected;
         this._fileToPlay = MainWindow.view.loadPlay(this._selected);
-    },
+    }
 
-    _showErrorDialog: function(errorStrOne, errorStrTwo) {
+    _showErrorDialog(errorStrOne, errorStrTwo) {
         if (errorDialogState == ErrState.OFF) {
             let errorDialog = new Gtk.MessageDialog ({ destroy_with_parent: true,
                                                        buttons: Gtk.ButtonsType.OK,
@@ -256,4 +253,4 @@ var Play = new Lang.Class({
             errorDialog.show();
         }
     }
-});
+}
diff --git a/src/preferences.js b/src/preferences.js
index ead0ac9..7209f19 100644
--- a/src/preferences.js
+++ b/src/preferences.js
@@ -21,7 +21,6 @@
 const Gio = imports.gi.Gio;
 const GLib = imports.gi.GLib;
 const Gtk = imports.gi.Gtk;
-const Lang = imports.lang;
 
 const _ = imports.gettext.gettext;
 const C_ = imports.gettext.pgettext;
@@ -34,10 +33,8 @@ let channelsComboBoxText = null;
 let recordVolume= null;
 let playVolume = null;
 
-var Preferences = new Lang.Class({
-    Name: 'Preferences',
-    
-     _init: function() {    
+var Preferences = class Preferences {
+    constructor() {
         this.widget = new Gtk.Dialog ({ title: _("Preferences"),
                                         resizable: false,
                                         modal: true,
@@ -45,10 +42,10 @@ var Preferences = new Lang.Class({
                                         default_width: 400,
                                         margin_top: 5,
                                         use_header_bar: 1,
-                                        hexpand: true }); 
-                                        
+                                        hexpand: true });
+
         this.widget.set_transient_for(Gio.Application.get_default().get_active_window());
-        
+
         let grid = new Gtk.Grid ({ orientation: Gtk.Orientation.VERTICAL,
                                    row_homogeneous: true,
                                    column_homogeneous: true,
@@ -61,15 +58,15 @@ var Preferences = new Lang.Class({
                                    margin_top: 12 });
         let contentArea = this.widget.get_content_area();
         contentArea.pack_start(grid, true, true, 2);
-        
+
         let formatLabel = new Gtk.Label({ label: _("Preferred format"),
                                           halign: Gtk.Align.END });
         formatLabel.get_style_context().add_class('dim-label');
         grid.attach(formatLabel, 0, 0, 2, 1);
-        
+
         formatComboBoxText = new MainWindow.EncoderComboBox();
         grid.attach(formatComboBoxText, 2, 0, 2, 1);
-        
+
         let channelsLabel = new Gtk.Label({ label: _("Default mode"),
                                             halign: Gtk.Align.END });
         channelsLabel.get_style_context().add_class('dim-label');
@@ -82,7 +79,7 @@ var Preferences = new Lang.Class({
                                           halign: Gtk.Align.END });
         volumeLabel.get_style_context().add_class('dim-label');
         grid.attach(volumeLabel, 0, 2, 2, 1);
-        
+
         playVolume = new Gtk.Scale({ orientation: Gtk.Orientation.HORIZONTAL });
         this.playRange = Gtk.Adjustment.new(MainWindow.volumeValue[0].play, 0, 1.0, 0.05, 0.0, 0.0);
         playVolume.set_adjustment(this.playRange);
@@ -91,12 +88,12 @@ var Preferences = new Lang.Class({
             MainWindow.view.presetVolume(MainWindow.ActiveArea.PLAY, playVolume.get_value());
         });
         grid.attach(playVolume, 2, 2, 2, 1);
-        
+
         let micVolLabel = new Gtk.Label({ label: _("Microphone"),
                                           halign: Gtk.Align.END });
         micVolLabel.get_style_context().add_class('dim-label');
         grid.attach(micVolLabel, 0, 3, 2, 1);
-        
+
         recordVolume = new Gtk.Scale({ orientation: Gtk.Orientation.HORIZONTAL });
         this.recordRange = Gtk.Adjustment.new(MainWindow.volumeValue[0].record, 0, 1.0, 0.05, 0.0, 0.0);
         recordVolume.set_adjustment(this.recordRange);
@@ -105,11 +102,11 @@ var Preferences = new Lang.Class({
             MainWindow.view.presetVolume(MainWindow.ActiveArea.RECORD, recordVolume.get_value());
         });
         grid.attach(recordVolume, 2, 3, 2, 1);
-        
+
         this.widget.show_all();
-      },
-      
-      onDoneClicked: function() {
-        this.widget.destroy(); 
-      }  
-});
+    }
+
+    onDoneClicked() {
+        this.widget.destroy();
+    }
+}
diff --git a/src/record.js b/src/record.js
index b0f3a9d..00405c5 100644
--- a/src/record.js
+++ b/src/record.js
@@ -27,7 +27,6 @@ const GstAudio = imports.gi.GstAudio;
 const GstPbutils = imports.gi.GstPbutils;
 const Gtk = imports.gi.Gtk;
 const Pango = imports.gi.Pango;
-const Lang = imports.lang;
 const Mainloop = imports.mainloop;
 const Signals = imports.signals;
 
@@ -45,21 +44,19 @@ const PipelineStates = {
 const ErrState = {
     OFF: 0,
     ON: 1
-}
+};
 
 const Channels = {
     MONO: 0,
     STEREO: 1
-}
+};
 
 const _TENTH_SEC = 100000000;
 
 let errorDialogState;
 
-var Record = new Lang.Class({
-    Name: "Record",
-
-    _recordPipeline: function() {
+var Record = class Record {
+    _recordPipeline() {
         errorDialogState = ErrState.OFF;
         this.baseTime = 0;
         this._view = MainWindow.view;
@@ -151,9 +148,9 @@ var Record = new Lang.Class({
 
         GLib.unix_signal_add(GLib.PRIORITY_DEFAULT, Application.SIGINT, 
Application.application.onWindowDestroy);
         GLib.unix_signal_add(GLib.PRIORITY_DEFAULT, Application.SIGTERM, 
Application.application.onWindowDestroy);
-    },
+    }
 
-    _updateTime: function() {
+    _updateTime() {
         let time = this.pipeline.query_position(Gst.Format.TIME)[1]/Gst.SECOND;
 
         if (time >= 0) {
@@ -161,9 +158,9 @@ var Record = new Lang.Class({
         }
 
         return true;
-    },
+    }
 
-    startRecording: function(profile) {
+    startRecording(profile) {
         this.profile = profile;
         this._audioProfile = MainWindow.audioProfile;
         this._mediaProfile = this._audioProfile.mediaProfile();
@@ -190,9 +187,9 @@ var Record = new Lang.Class({
         if (!this.timeout) {
             this.timeout = GLib.timeout_add(GLib.PRIORITY_DEFAULT, MainWindow._SEC_TIMEOUT, () => 
this._updateTime());
         }
-    },
+    }
 
-    stopRecording: function() {
+    stopRecording() {
         let sent = this.pipeline.send_event(Gst.Event.new_eos());
 
         if (this.timeout) {
@@ -202,9 +199,9 @@ var Record = new Lang.Class({
 
         if (MainWindow.wave != null)
             MainWindow.wave.endDrawing();
-    },
+    }
 
-    onEndOfStream: function() {
+    onEndOfStream() {
         this.pipeline.set_state(Gst.State.NULL);
         this.pipeState = PipelineStates.STOPPED;
 
@@ -213,9 +210,9 @@ var Record = new Lang.Class({
 
         this._updateTime();
         errorDialogState = ErrState.OFF;
-    },
+    }
 
-    _onMessageReceived: function(message) {
+    _onMessageReceived(message) {
         this.localMsg = message;
         let msg = message.type;
         switch(msg) {
@@ -295,15 +292,15 @@ var Record = new Lang.Class({
             errorDialogState = ErrState.ON;
             break;
         }
-    },
+    }
 
-    setVolume: function(value) {
+    setVolume(value) {
         if (this.volume) {
             this.volume.set_volume(GstAudio.StreamVolumeFormat.CUBIC, value);
         }
-    },
+    }
 
-    _getChannels: function() {
+    _getChannels() {
 
         let channels = null;
         let channelsPref = Application.application.getChannelsPreferences();
@@ -322,9 +319,9 @@ var Record = new Lang.Class({
         }
 
         return channels;
-    },
+    }
 
-    _showErrorDialog: function(errorStrOne, errorStrTwo) {
+    _showErrorDialog(errorStrOne, errorStrTwo) {
         if (errorDialogState == ErrState.OFF) {
             let errorDialog = new Gtk.MessageDialog ({ modal: true,
                                                        destroy_with_parent: true,
@@ -346,12 +343,10 @@ var Record = new Lang.Class({
             errorDialog.show();
         }
     }
-});
-
-const BuildFileName = new Lang.Class({
-    Name: "BuildFileName",
+}
 
-    buildInitialFilename: function() {
+const BuildFileName = class BuildFileName {
+    buildInitialFilename() {
         var fileExtensionName = MainWindow.audioProfile.fileExtensionReturner();
         var dir = Gio.Application.get_default().saveDir;
         this.dateTime = GLib.DateTime.new_now_local();
@@ -362,13 +357,13 @@ const BuildFileName = new Lang.Class({
         this.clip = dir.get_child_for_display_name(clipName);
         var file = this.clip.get_path();
         return file;
-    },
+    }
 
-    getTitle: function() {
+    getTitle() {
         return this.clip;
-    },
+    }
 
-    getOrigin: function() {
+    getOrigin() {
         return this.dateTime;
     }
-});
+}
diff --git a/src/waveform.js b/src/waveform.js
index 1959841..6813884 100644
--- a/src/waveform.js
+++ b/src/waveform.js
@@ -27,7 +27,6 @@ const GObject = imports.gi.GObject;
 const Gst = imports.gi.Gst;
 const GstAudio = imports.gi.GstAudio;
 const Gtk = imports.gi.Gtk;
-const Lang = imports.lang;
 const Mainloop = imports.mainloop;
 
 const _ = imports.gettext.gettext;
@@ -46,10 +45,8 @@ const WaveType = {
     PLAY: 1
 };
 
-var WaveForm = new Lang.Class({
-    Name: 'WaveForm',
-
-    _init: function(grid, file) {
+var WaveForm = class WaveForm {
+    constructor(grid, file) {
         this._grid = grid;
 
         let placeHolder = -100;
@@ -87,9 +84,9 @@ var WaveForm = new Lang.Class({
             this._launchPipeline();
             this.startGeneration();
         }
-    },
+    }
 
-    _launchPipeline: function() {
+    _launchPipeline() {
         this.pipeline =
             Gst.parse_launch("uridecodebin name=decode uri=" + this._uri + " ! audioconvert ! 
audio/x-raw,channels=2 ! level name=level interval=100000000 post-messages=true ! fakesink qos=false");
         this._level = this.pipeline.get_by_name("level");
@@ -106,9 +103,9 @@ var WaveForm = new Lang.Class({
                 this._messageCb(message);
             }
         });
-    },
+    }
 
-    _messageCb: function(message) {
+    _messageCb(message) {
         let msg = message.type;
 
         switch(msg) {
@@ -149,17 +146,17 @@ var WaveForm = new Lang.Class({
             this.stopGeneration();
             break;
         }
-    },
+    }
 
-    startGeneration: function() {
+    startGeneration() {
         this.pipeline.set_state(Gst.State.PLAYING);
-    },
+    }
 
-    stopGeneration: function() {
+    stopGeneration() {
         this.pipeline.set_state(Gst.State.NULL);
-    },
+    }
 
-    fillSurface: function(drawing, cr) {
+    fillSurface(drawing, cr) {
         let start = 0;
 
         if (this.waveType == WaveType.PLAY) {
@@ -169,9 +166,9 @@ var WaveForm = new Lang.Class({
             }
             start = Math.floor(this.playTime);
         } else {
-
-            if (this.recordTime >= 0)
-            start = this.recordTime;
+            if (this.recordTime >= 0) {
+                start = this.recordTime;
+            }
         }
 
         let i = 0;
@@ -218,11 +215,11 @@ var WaveForm = new Lang.Class({
         cr.closePath();
         cr.strokePreserve();
         cr.setSource(gradient);
-           cr.fillPreserve();
-           cr.$dispose();
-    },
+        cr.fillPreserve();
+        cr.$dispose();
+    }
 
-    _drawEvent: function(playTime, recPeaks) {
+    _drawEvent(playTime, recPeaks) {
         let lastTime;
 
         if (this.waveType == WaveType.PLAY) {
@@ -250,9 +247,9 @@ var WaveForm = new Lang.Class({
                 this.drawing.queue_draw();
         }
         return true;
-    },
+    }
 
-    endDrawing: function() {
+    endDrawing() {
         if (this.pipeline)
             this.stopGeneration();
 
@@ -264,4 +261,4 @@ var WaveForm = new Lang.Class({
             log(e);
         }
     }
-});
+}



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