[gnome-sound-recorder/bilelmoussaoui/fixes: 2/12] recorder: switch to using actions
- From: Bilal Elmoussaoui <bilelmoussaoui src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-sound-recorder/bilelmoussaoui/fixes: 2/12] recorder: switch to using actions
- Date: Wed, 9 Sep 2020 04:44:11 +0000 (UTC)
commit bbcfa90d637d347b5404f9bfa4b401cfe8159bcf
Author: Bilal Elmoussaoui <bil elmoussaoui gmail com>
Date: Wed Sep 9 01:04:36 2020 +0200
recorder: switch to using actions
data/ui/window.ui | 10 +++++-----
src/application.js | 5 +++++
src/window.js | 42 +++++++++++++++++++++++++++++++++++++++++-
3 files changed, 51 insertions(+), 6 deletions(-)
---
diff --git a/data/ui/window.ui b/data/ui/window.ui
index d0bbd6f..a8a6dc6 100644
--- a/data/ui/window.ui
+++ b/data/ui/window.ui
@@ -37,7 +37,7 @@
<property name="valign">center</property>
<property name="halign">center</property>
<property name="receives_default">False</property>
- <signal name="clicked" handler="onRecorderStart" swapped="no"/>
+ <property name="action_name">recorder.start</property>
<child>
<object class="GtkBox">
<property name="visible">True</property>
@@ -251,7 +251,7 @@
<property name="halign">center</property>
<property name="receives_default">True</property>
<property name="tooltip_text" translatable="yes">Resume
Recording</property>
- <signal name="clicked" handler="onRecorderResume" swapped="no"/>
+ <property name="action_name">recorder.resume</property>
<child>
<object class="GtkImage" id="playIcon">
<property name="visible">True</property>
@@ -275,7 +275,7 @@
<property name="halign">center</property>
<property name="receives_default">True</property>
<property name="tooltip_text" translatable="yes">Pause
Recording</property>
- <signal name="clicked" handler="onRecorderPause" swapped="no"/>
+ <property name="action_name">recorder.pause</property>
<child>
<object class="GtkImage" id="pauseIcon">
<property name="visible">True</property>
@@ -305,7 +305,7 @@
<property name="halign">center</property>
<property name="receives_default">True</property>
<property name="tooltip_text" translatable="yes">Stop Recording</property>
- <signal name="clicked" handler="onRecorderStop" swapped="no"/>
+ <property name="action_name">recorder.stop</property>
<child>
<object class="GtkImage">
<property name="visible">True</property>
@@ -332,7 +332,7 @@
<property name="halign">center</property>
<property name="receives_default">True</property>
<property name="tooltip_text" translatable="yes">Cancel Recording</property>
- <signal name="clicked" handler="onRecorderCancel" swapped="no"/>
+ <property name="action_name">recorder.cancel</property>
<child>
<object class="GtkImage">
<property name="visible">True</property>
diff --git a/src/application.js b/src/application.js
index 1465c23..62f9087 100644
--- a/src/application.js
+++ b/src/application.js
@@ -122,6 +122,11 @@ var Application = GObject.registerClass(class Application extends Gtk.Applicatio
});
this.add_action(quitAction);
this.add_accelerator('<Primary>q', 'app.quit', null);
+ this.add_accelerator('<Primary>r', 'recorder.start', null);
+ this.add_accelerator('<Primary>p', 'recorder.pause', null);
+ this.add_accelerator('<Primary>r', 'recorder.resume', null);
+ this.add_accelerator('<Primary>c', 'recorder.cancel', null);
+ this.add_accelerator('<Primary>s', 'recorder.stop', null);
}
vfunc_startup() {
diff --git a/src/window.js b/src/window.js
index b138741..d76d812 100644
--- a/src/window.js
+++ b/src/window.js
@@ -18,7 +18,7 @@
*
*/
-const { GLib, GObject, GstPlayer, Gtk, Handy } = imports.gi;
+const { Gio, GLib, GObject, GstPlayer, Gtk, Handy } = imports.gi;
const { Recorder } = imports.recorder;
const { RecordingList } = imports.recordingList;
@@ -97,6 +97,23 @@ var Window = GObject.registerClass({
this._notificationUndoBtn.disconnect(this.cancelSignalId);
});
+ const actions = [
+ { name: 'start', callback : this.onRecorderStart.bind(this), enabled: true },
+ { name: 'pause', callback : this.onRecorderPause.bind(this), enabled: false },
+ { name: 'stop', callback : this.onRecorderStop.bind(this), enabled: false, },
+ { name: 'resume', callback : this.onRecorderResume.bind(this), enabled: false },
+ { name: 'cancel', callback : this.onRecorderCancel.bind(this), enabled: false }
+ ];
+
+ this.recorderActions = new Gio.SimpleActionGroup();
+
+ for ( let { name, callback, enabled } of actions) {
+ const action = new Gio.SimpleAction({ name: name, enabled: enabled });
+ action.connect('activate', callback);
+ this.recorderActions.add_action(action);
+ }
+
+ this.insert_action_group('recorder', this.recorderActions);
this._column.add(this._recordingListBox);
@@ -106,16 +123,25 @@ var Window = GObject.registerClass({
onRecorderPause() {
this.recorder.pause();
+ this.recorderActions.lookup('resume').set_enabled(true);
+ this.recorderActions.lookup('pause').set_enabled(false);
this._playbackStack.visible_child_name = 'recorder-start';
}
onRecorderResume() {
this.recorder.resume();
+ this.recorderActions.lookup('resume').set_enabled(false);
+ this.recorderActions.lookup('pause').set_enabled(true);
this._playbackStack.visible_child_name = 'recorder-pause';
}
onRecorderStart() {
this.player.stop();
+ this.recorderActions.lookup('start').set_enabled(false);
+ this.recorderActions.lookup('stop').set_enabled(true);
+ this.recorderActions.lookup('cancel').set_enabled(true);
+ this.recorderActions.lookup('pause').set_enabled(true);
+ this.recorderActions.lookup('resume').set_enabled(false);
const activeRow = this._recordingListBox.activeRow;
if (activeRow && activeRow.editMode)
@@ -128,6 +154,13 @@ var Window = GObject.registerClass({
onRecorderCancel() {
const recording = this.recorder.stop();
+
+ this.recorderActions.lookup('stop').set_enabled(false);
+ this.recorderActions.lookup('cancel').set_enabled(false);
+ this.recorderActions.lookup('resume').set_enabled(false);
+ this.recorderActions.lookup('pause').set_enabled(false);
+ this.recorderActions.lookup('start').set_enabled(true);
+
recording.delete();
if (this._recordingList.get_n_items() === 0)
@@ -140,6 +173,13 @@ var Window = GObject.registerClass({
onRecorderStop() {
const recording = this.recorder.stop();
+
+ this.recorderActions.lookup('stop').set_enabled(false);
+ this.recorderActions.lookup('cancel').set_enabled(false);
+ this.recorderActions.lookup('resume').set_enabled(false);
+ this.recorderActions.lookup('pause').set_enabled(false);
+ this.recorderActions.lookup('start').set_enabled(true);
+
this._recordingList.insert(0, recording);
this._recordingListBox.get_row_at_index(0).editMode = true;
this.state = WindowState.LIST;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]