[gnome-sound-recorder] preferences: migrate to use glade Part of #65



commit f8e535e2543f4c6e4f567e5a809a69473755d199
Author: Kavan Mevada <kavanmevada gmail com>
Date:   Sun Mar 29 05:14:36 2020 +0530

    preferences: migrate to use glade
    Part of #65

 data/org.gnome.SoundRecorder.data.gresource.xml |   1 +
 data/ui/preferences.ui                          | 184 ++++++++++++++++++++++++
 po/POTFILES.in                                  |   1 +
 src/application.js                              |  50 +------
 src/fileUtil.js                                 |   1 +
 src/info.js                                     |   2 -
 src/mainWindow.js                               |  60 +-------
 src/preferences.js                              | 147 +++++++++----------
 src/record.js                                   |   3 +-
 9 files changed, 264 insertions(+), 185 deletions(-)
---
diff --git a/data/org.gnome.SoundRecorder.data.gresource.xml b/data/org.gnome.SoundRecorder.data.gresource.xml
index 7794c0e..490ea27 100644
--- a/data/org.gnome.SoundRecorder.data.gresource.xml
+++ b/data/org.gnome.SoundRecorder.data.gresource.xml
@@ -3,6 +3,7 @@
   <gresource prefix="/org/gnome/SoundRecorder">
     <file>application.css</file>
     <file>ui/window.ui</file>
+    <file>ui/preferences.ui</file>
   </gresource>
 </gresources>
 
diff --git a/data/ui/preferences.ui b/data/ui/preferences.ui
new file mode 100644
index 0000000..45a60ba
--- /dev/null
+++ b/data/ui/preferences.ui
@@ -0,0 +1,184 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!-- Generated with glade 3.22.0 -->
+<interface>
+  <requires lib="gtk+" version="3.20"/>
+  <object class="GtkAdjustment" id="microphone-adjustment">
+    <property name="upper">1</property>
+    <property name="step_increment">0.05</property>
+  </object>
+  <object class="GtkAdjustment" id="volume-adjustment">
+    <property name="upper">1</property>
+    <property name="step_increment">0.05</property>
+  </object>
+  <template class="Gjs_SettingsDialog" parent="GtkDialog">
+    <property name="can_focus">False</property>
+    <property name="margin_top">5</property>
+    <property name="hexpand">True</property>
+    <property name="title" translatable="yes">Preferences</property>
+    <property name="modal">True</property>
+    <property name="window_position">center-on-parent</property>
+    <property name="default_width">400</property>
+    <property name="destroy_with_parent">True</property>
+    <property name="type_hint">dialog</property>
+    <property name="use_header_bar">1</property>
+    <child internal-child="vbox">
+      <object class="GtkBox">
+        <property name="can_focus">False</property>
+        <property name="orientation">vertical</property>
+        <property name="spacing">2</property>
+        <child internal-child="action_area">
+          <object class="GtkButtonBox">
+            <property name="can_focus">False</property>
+            <property name="layout_style">end</property>
+            <child>
+              <placeholder/>
+            </child>
+          </object>
+          <packing>
+            <property name="expand">False</property>
+            <property name="fill">False</property>
+            <property name="position">0</property>
+          </packing>
+        </child>
+        <child>
+          <object class="GtkGrid">
+            <property name="visible">True</property>
+            <property name="can_focus">False</property>
+            <property name="halign">center</property>
+            <property name="margin_start">24</property>
+            <property name="margin_end">24</property>
+            <property name="margin_top">12</property>
+            <property name="margin_bottom">12</property>
+            <property name="row_spacing">8</property>
+            <property name="column_spacing">24</property>
+            <property name="row_homogeneous">True</property>
+            <property name="column_homogeneous">True</property>
+            <child>
+              <object class="GtkLabel" id="formate-label">
+                <property name="visible">True</property>
+                <property name="can_focus">False</property>
+                <property name="halign">end</property>
+                <property name="valign">center</property>
+                <property name="label" translatable="yes">Preferred format</property>
+              </object>
+              <packing>
+                <property name="left_attach">0</property>
+                <property name="top_attach">0</property>
+              </packing>
+            </child>
+            <child>
+              <object class="GtkComboBoxText" id="formateComboBox">
+                <property name="visible">True</property>
+                <property name="can_focus">False</property>
+                <property name="halign">start</property>
+                <property name="valign">center</property>
+                <property name="active">0</property>
+                <items>
+                  <item translatable="yes">Ogg Vorbis</item>
+                  <item translatable="yes">Opus</item>
+                  <item translatable="yes">FLAC</item>
+                  <item translatable="yes">MP3</item>
+                  <item translatable="yes">MOV</item>
+                </items>
+              </object>
+              <packing>
+                <property name="left_attach">1</property>
+                <property name="top_attach">0</property>
+              </packing>
+            </child>
+            <child>
+              <object class="GtkLabel" id="mode-label">
+                <property name="visible">True</property>
+                <property name="can_focus">False</property>
+                <property name="halign">end</property>
+                <property name="valign">center</property>
+                <property name="label" translatable="yes">Default mode</property>
+              </object>
+              <packing>
+                <property name="left_attach">0</property>
+                <property name="top_attach">1</property>
+              </packing>
+            </child>
+            <child>
+              <object class="GtkComboBoxText" id="channelsComboBox">
+                <property name="visible">True</property>
+                <property name="can_focus">False</property>
+                <property name="halign">start</property>
+                <property name="valign">center</property>
+                <property name="active">0</property>
+                <items>
+                  <item translatable="yes">Stereo</item>
+                  <item translatable="yes">Mono</item>
+                </items>
+              </object>
+              <packing>
+                <property name="left_attach">1</property>
+                <property name="top_attach">1</property>
+              </packing>
+            </child>
+            <child>
+              <object class="GtkLabel" id="volume-label">
+                <property name="visible">True</property>
+                <property name="can_focus">False</property>
+                <property name="halign">end</property>
+                <property name="valign">center</property>
+                <property name="label" translatable="yes">Volume</property>
+              </object>
+              <packing>
+                <property name="left_attach">0</property>
+                <property name="top_attach">2</property>
+              </packing>
+            </child>
+            <child>
+              <object class="GtkLabel" id="microhone-label">
+                <property name="visible">True</property>
+                <property name="can_focus">False</property>
+                <property name="halign">end</property>
+                <property name="valign">center</property>
+                <property name="label" translatable="yes">Microphone</property>
+              </object>
+              <packing>
+                <property name="left_attach">0</property>
+                <property name="top_attach">3</property>
+              </packing>
+            </child>
+            <child>
+              <object class="GtkScale" id="volumeScale">
+                <property name="visible">True</property>
+                <property name="can_focus">True</property>
+                <property name="adjustment">microphone-adjustment</property>
+                <property name="fill_level">1</property>
+                <property name="round_digits">1</property>
+              </object>
+              <packing>
+                <property name="left_attach">1</property>
+                <property name="top_attach">2</property>
+              </packing>
+            </child>
+            <child>
+              <object class="GtkScale" id="microphoneScale">
+                <property name="visible">True</property>
+                <property name="can_focus">True</property>
+                <property name="adjustment">volume-adjustment</property>
+                <property name="fill_level">1</property>
+                <property name="round_digits">1</property>
+              </object>
+              <packing>
+                <property name="left_attach">1</property>
+                <property name="top_attach">3</property>
+              </packing>
+            </child>
+          </object>
+          <packing>
+            <property name="expand">False</property>
+            <property name="fill">True</property>
+            <property name="position">1</property>
+          </packing>
+        </child>
+      </object>
+    </child>
+    <child type="titlebar">
+      <placeholder/>
+    </child>
+  </template>
+</interface>
diff --git a/po/POTFILES.in b/po/POTFILES.in
index 1b2f521..439556f 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -2,6 +2,7 @@ data/appdata/org.gnome.SoundRecorder.appdata.xml.in.in
 data/org.gnome.SoundRecorder.gschema.xml.in
 data/org.gnome.SoundRecorder.desktop.in.in
 data/ui/window.ui
+data/ui/preferences.ui
 src/audioProfile.js
 src/application.js
 src/fileUtil.js
diff --git a/src/application.js b/src/application.js
index f4c713e..50c20ac 100644
--- a/src/application.js
+++ b/src/application.js
@@ -26,13 +26,12 @@ const Gtk = imports.gi.Gtk;
 const Gdk = imports.gi.Gdk;
 
 const MainWindow = imports.mainWindow;
-const Preferences = imports.preferences;
+const Settings = imports.preferences;
 
 var SIGINT = 2;
 var SIGTERM = 15;
 
 var application = null;
-let settings = null;
 
 var Application = GObject.registerClass(class Application extends Gtk.Application {
     _init() {
@@ -58,7 +57,7 @@ var Application = GObject.registerClass(class Application extends Gtk.Applicatio
     _initAppMenu() {
         let preferences = new Gio.SimpleAction({ name: 'preferences' });
         preferences.connect('activate', () => {
-            this._showPreferences();
+            (new Settings.SettingsDialog()).show();
         });
         this.add_action(preferences);
 
@@ -84,7 +83,6 @@ var Application = GObject.registerClass(class Application extends Gtk.Applicatio
         Gst.init(null);
         this._initAppMenu();
         application = this;
-        settings = new Gio.Settings({ schema: pkg.name });
         this.ensureDirectory();
     }
 
@@ -113,50 +111,6 @@ var Application = GObject.registerClass(class Application extends Gtk.Applicatio
             MainWindow.play.play.set_state(Gst.State.NULL);
     }
 
-    _showPreferences() {
-        let preferencesDialog = new Preferences.Preferences();
-
-        preferencesDialog.widget.connect('response', () => {
-            preferencesDialog.widget.destroy();
-        });
-    }
-
-    getPreferences() {
-        let set = settings.get_int('media-type-preset');
-        return set;
-    }
-
-    setPreferences(profileName) {
-        settings.set_int('media-type-preset', profileName);
-    }
-
-    getChannelsPreferences() {
-        let set = settings.get_int('channel');
-        return set;
-    }
-
-    setChannelsPreferences(channel) {
-        settings.set_int('channel', channel);
-    }
-
-    getMicVolume() {
-        let micVolLevel = settings.get_double('mic-volume');
-        return micVolLevel;
-    }
-
-    setMicVolume(level) {
-        settings.set_double('mic-volume', level);
-    }
-
-    getSpeakerVolume() {
-        let speakerVolLevel = settings.get_double('speaker-volume');
-        return speakerVolLevel;
-    }
-
-    setSpeakerVolume(level) {
-        settings.set_double('speaker-volume', level);
-    }
-
     _loadStyleSheet() {
         let provider = new Gtk.CssProvider();
         provider.load_from_resource('/org/gnome/SoundRecorder/application.css');
diff --git a/src/fileUtil.js b/src/fileUtil.js
index e77e9be..c3daefe 100644
--- a/src/fileUtil.js
+++ b/src/fileUtil.js
@@ -21,6 +21,7 @@
 const Gettext = imports.gettext;
 const GLib = imports.gi.GLib;
 
+
 var DisplayTime = class DisplayTime {
     getDisplayTime(mtime) {
         let text = '';
diff --git a/src/info.js b/src/info.js
index bec7039..f4bbe65 100644
--- a/src/info.js
+++ b/src/info.js
@@ -24,8 +24,6 @@ const GLib = imports.gi.GLib;
 const Gtk = imports.gi.Gtk;
 
 
-
-
 var InfoDialog = class InfoDialog {
     constructor(fileNav) {
         let fileName = fileNav;
diff --git a/src/mainWindow.js b/src/mainWindow.js
index 2a2d16f..388df2b 100644
--- a/src/mainWindow.js
+++ b/src/mainWindow.js
@@ -28,7 +28,7 @@ const Gst = imports.gi.Gst;
 const Gtk = imports.gi.Gtk;
 const Pango = imports.gi.Pango;
 
-const Application = imports.application;
+const Settings = imports.preferences.settings;
 const AudioProfile = imports.audioProfile;
 const FileUtil = imports.fileUtil;
 const Info = imports.info;
@@ -197,16 +197,6 @@ var MainWindow = GObject.registerClass({
         return true;
     }
 
-    presetVolume(source, vol) {
-        if (source === ActiveArea.PLAY) {
-            volumeValue[0].play = vol;
-            Application.application.setSpeakerVolume(vol);
-        } else {
-            volumeValue[0].record = vol;
-            Application.application.setMicVolume(vol);
-        }
-    }
-
     setVolume() {
         if (setVisibleID === ActiveArea.PLAY)
             play.setVolume(volumeValue[0].play);
@@ -220,10 +210,10 @@ var MainWindow = GObject.registerClass({
     }
 
     listBoxAdd() {
-        let playVolume = Application.application.getSpeakerVolume();
-        let micVolume = Application.application.getMicVolume();
+        let playVolume = Settings.speakerVolume;
+        let micVolume = Settings.micVolume;
         volumeValue.push({ record: micVolume, play: playVolume });
-        activeProfile = Application.application.getPreferences();
+        activeProfile = Settings.mediaCodec;
 
         this.recordGrid = new Gtk.Grid({ name: 'recordGrid',
             orientation: Gtk.Orientation.HORIZONTAL });
@@ -653,45 +643,3 @@ var MainWindow = GObject.registerClass({
         }
     }
 });
-
-var EncoderComboBox = GObject.registerClass(class EncoderComboBox extends Gtk.ComboBoxText {
-    // encoding setting labels in combobox
-    _init() {
-        super._init();
-        let combo = [_('Ogg Vorbis'), _('Opus'), _('FLAC'), _('MP3'), _('MOV')];
-
-        for (let i = 0; i < combo.length; i++)
-            this.append_text(combo[i]);
-        this.set_property('valign', Gtk.Align.CENTER);
-        this.set_sensitive(true);
-        activeProfile = Application.application.getPreferences();
-        this.set_active(activeProfile);
-        this.connect('changed', () => this._onComboBoxTextChanged());
-    }
-
-    _onComboBoxTextChanged() {
-        activeProfile = this.get_active();
-        Application.application.setPreferences(activeProfile);
-    }
-});
-
-var ChannelsComboBox = GObject.registerClass(class ChannelsComboBox extends Gtk.ComboBoxText {
-    // channel setting labels in combobox
-    _init() {
-        super._init();
-        let combo = [_('Mono'), _('Stereo')];
-
-        for (let i = 0; i < combo.length; i++)
-            this.append_text(combo[i]);
-        this.set_property('valign', Gtk.Align.CENTER);
-        this.set_sensitive(true);
-        let chanProfile = Application.application.getChannelsPreferences();
-        this.set_active(chanProfile);
-        this.connect('changed', () => this._onChannelComboBoxTextChanged());
-    }
-
-    _onChannelComboBoxTextChanged() {
-        let channelProfile = this.get_active();
-        Application.application.setChannelsPreferences(channelProfile);
-    }
-});
diff --git a/src/preferences.js b/src/preferences.js
index ca58b7e..9fccedf 100644
--- a/src/preferences.js
+++ b/src/preferences.js
@@ -20,89 +20,80 @@
 
 const Gio = imports.gi.Gio;
 const Gtk = imports.gi.Gtk;
-
+const GObject = imports.gi.GObject;
 
 const MainWindow = imports.mainWindow;
 
-let formatComboBoxText = null;
-let channelsComboBoxText = null;
-let recordVolume = null;
-let playVolume = null;
-
-var Preferences = class Preferences {
-    constructor() {
-        this.widget = new Gtk.Dialog({ title: _('Preferences'),
-            resizable: false,
-            modal: true,
-            destroy_with_parent: true,
-            default_width: 400,
-            margin_top: 5,
-            use_header_bar: 1,
-            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,
-            halign: Gtk.Align.CENTER,
-            row_spacing: 6,
-            column_spacing: 24,
-            margin_bottom: 12,
-            margin_end: 24,
-            margin_start: 24,
-            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');
-        grid.attach(channelsLabel, 0, 1, 2, 1);
-
-        channelsComboBoxText = new MainWindow.ChannelsComboBox();
-        grid.attach(channelsComboBoxText, 2, 1, 2, 1);
-
-        let volumeLabel = new Gtk.Label({ label: _('Volume'),
-            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);
-        playVolume.set_sensitive(true);
-        playVolume.connect('value-changed', () => {
-            MainWindow.view.presetVolume(MainWindow.ActiveArea.PLAY, playVolume.get_value());
+let _settings = new Gio.Settings({ schema: pkg.name });
+
+var settings = {
+    get mediaCodec() {
+        return _settings.get_int('media-type-preset');
+    },
+
+    set mediaCodec(profileName) {
+        _settings.set_int('media-type-preset', profileName);
+    },
+
+    get channel() {
+        return _settings.get_int('channel');
+    },
+
+    set channel(channel) {
+        _settings.set_int('channel', channel);
+    },
+
+    get micVolume() {
+        return _settings.get_double('mic-volume');
+    },
+
+    set micVolume(level) {
+        _settings.set_double('mic-volume', level);
+    },
+
+    get speakerVolume() {
+        return _settings.get_double('speaker-volume');
+    },
+
+    set speakerVolume(level) {
+        _settings.set_double('speaker-volume', level);
+    },
+};
+
+var SettingsDialog = GObject.registerClass({ // eslint-disable-line no-unused-vars
+    Template: 'resource:///org/gnome/SoundRecorder/ui/preferences.ui',
+    InternalChildren: ['formateComboBox', 'channelsComboBox', 'volumeScale', 'microphoneScale'],
+}, class SettingsDialog extends Gtk.Dialog {
+    _init() {
+        super._init({ transient_for: Gio.Application.get_default().get_active_window() });
+
+        this.connect('response', () => {
+            this.destroy();
         });
-        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);
-        recordVolume.set_sensitive(true);
-        recordVolume.connect('value-changed', () => {
-            MainWindow.view.presetVolume(MainWindow.ActiveArea.RECORD, recordVolume.get_value());
+
+        this._formateComboBox.set_active(settings.mediaCodec);
+        this._formateComboBox.connect('changed', () => {
+            settings.mediaCodec = this._formateComboBox.get_active();
         });
-        grid.attach(recordVolume, 2, 3, 2, 1);
 
-        this.widget.show_all();
-    }
+        this._channelsComboBox.set_active(settings.channel);
+        this._channelsComboBox.connect('changed', () => {
+            settings.channel = this._channelsComboBox.get_active();
+        });
 
-    onDoneClicked() {
-        this.widget.destroy();
+        let volumeValue = MainWindow.volumeValue[0];
+        this._volumeScale.set_value(volumeValue.play);
+        this._volumeScale.connect('value-changed', () => {
+            let vol = this._volumeScale.get_value();
+            volumeValue.play = vol;
+            settings.speakerVolume = vol;
+        });
+
+        this._microphoneScale.set_value(volumeValue.record);
+        this._microphoneScale.connect('value-changed', () => {
+            let vol = this._microphoneScale.get_value();
+            volumeValue.record = vol;
+            settings.micVolume = vol;
+        });
     }
-};
+});
diff --git a/src/record.js b/src/record.js
index b6a561f..d9fc1ea 100644
--- a/src/record.js
+++ b/src/record.js
@@ -26,6 +26,7 @@ const GstPbutils = imports.gi.GstPbutils;
 const Gtk = imports.gi.Gtk;
 
 const Application = imports.application;
+const Settings = imports.preferences.settings;
 const MainWindow = imports.mainWindow;
 
 const PipelineStates = {
@@ -296,7 +297,7 @@ var Record = class Record {
     _getChannels() {
 
         let channels = null;
-        let channelsPref = Application.application.getChannelsPreferences();
+        let channelsPref = Settings.channel;
 
         switch (channelsPref) {
         case Channels.MONO:


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