forked from EasyScreenCast/EasyScreenCast
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprefs.js
546 lines (460 loc) · 20.6 KB
/
prefs.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
/* -*- mode: js; js-basic-offset: 4; indent-tabs-mode: nil -*- */
/*
Copyright (C) 2013 Borsato Ivano
The JavaScript code in this page is free software: you can
redistribute it and/or modify it under the terms of the GNU
General Public License (GNU GPL) as published by the Free Software
Foundation, either version 3 of the License, or (at your option)
any later version. The code is distributed WITHOUT ANY WARRANTY;
without even the implied warranty of MERCHANTABILITY or FITNESS
FOR A PARTICULAR PURPOSE. See the GNU GPL for more details.
*/
const GLib = imports.gi.GLib;
const GObject = imports.gi.GObject;
const Gio = imports.gi.Gio;
const Gtk = imports.gi.Gtk;
const Lang = imports.lang;
const Gettext = imports.gettext.domain(
'EasyScreenCast@iacopodeenosee.gmail.com');
const _ = Gettext.gettext;
const ExtensionUtils = imports.misc.extensionUtils;
const Me = ExtensionUtils.getCurrentExtension();
const Lib = Me.imports.convenience;
// setting keys - own
const ACTIVE_DELAY_SETTING_KEY = 'active-delay-time';
const ACTIVE_AUDIO_REC_SETTING_KEY = 'active-audio-rec';
const INPUT_AUDIO_SOURCE_SETTING_KEY = 'input-audio-source';
const LIST_INPUT_AUDIO_SETTING_KEY = 'list-input-audio';
const ACTIVE_CUSTOM_GSP_SETTING_KEY = 'active-custom-gsp';
const ACTIVE_SHORTCUT_SETTING_KEY = 'active-shortcut';
const SHORTCUT_KEY_SETTING_KEY = 'shortcut-key';
const TIME_DELAY_SETTING_KEY = 'delay-time';
const SHOW_TIMER_REC_SETTING_KEY = 'show-timer-rec';
const SHOW_AREA_REC_SETTING_KEY = 'show-area-rec';
const VERBOSE_DEBUG_SETTING_KEY = 'verbose-debug';
const PIPELINE_REC_SETTING_KEY = 'pipeline';
const FPS_SETTING_KEY = 'fps';
const REPLACE_INDICATOR_SETTING_KEY = 'replace-indicator';
const X_POS_SETTING_KEY = 'x-pos';
const Y_POS_SETTING_KEY = 'y-pos';
const WIDTH_SETTING_KEY = 'width-rec';
const HEIGHT_SETTING_KEY = 'height-rec';
const DRAW_CURSOR_SETTING_KEY = 'draw-cursor';
const AREA_SCREEN_SETTING_KEY = 'area-screen';
const FILE_NAME_SETTING_KEY = 'file-name';
const FILE_FOLDER_SETTING_KEY = 'file-folder';
// setting key - recorder
const MAX_DURATION_SETTING_KEY = 'max-screencast-length';
// shortcut tree view columns
const SHORTCUT_COLUMN_KEY = 0;
const SHORTCUT_COLUMN_MODS = 1;
let settings = null;
function init() {
Lib.initTranslationsGtkBuilder('EasyScreenCast@iacopodeenosee.gmail.com');
}
const EasyScreenCastSettingsWidget = new GObject.Class({
Name: 'EasyScreenCast.Prefs.Widget',
GTypeName: 'EasyScreenCastSettingsWidget',
Extends: Gtk.Box,
_init: function (params) {
this.parent(params);
// creates the settings
checkSettings();
this.RecorderSettings = new Gio.Settings({
schema: 'org.gnome.settings-daemon.plugins.media-keys'
});
// creates the ui builder and add the main resource file
let uiFilePath = Me.path + '/EasyScreenCast.gtkbuilder';
let builder = new Gtk.Builder();
builder.set_translation_domain(
'EasyScreenCast@iacopodeenosee.gmail.com');
if (builder.add_from_file(uiFilePath) == 0) {
Lib.TalkativeLog('could not load the ui file: ' + format(uiFilePath));
let label = new Gtk.Label({
label: _('Could not load the preferences UI file'),
vexpand: true
});
this.pack_start(label, true, true, 0);
} else {
Lib.TalkativeLog('UI file receive and load: ' + uiFilePath);
// gets the interesting builder objects
let Ref_box_MainContainer = builder.get_object('Main_Container');
// packs the main table
this.pack_start(Ref_box_MainContainer, true, true, 0);
//disable grid coordinates
this.Ref_GridArea_AreaRec = builder.get_object(
'grd_coordinatearea');
this.Ref_GridArea_AreaRec.set_sensitive(false);
//implements show timer option
this.Ref_switch_ShowTimerRec = builder.get_object(
'swt_ShowTimerRec');
settings.bind(
SHOW_TIMER_REC_SETTING_KEY, this.Ref_switch_ShowTimerRec,
'active', Gio.SettingsBindFlags.DEFAULT);
//implements show area option
this.Ref_switch_ShowAreaRec = builder.get_object('swt_ShowAreaRec');
settings.bind(
SHOW_AREA_REC_SETTING_KEY, this.Ref_switch_ShowAreaRec,
'active', Gio.SettingsBindFlags.DEFAULT);
//implements show indicator option
this.Ref_switch_ShowIndicatorRec = builder.get_object(
'swt_ShowIndicatorRec');
settings.bind(
REPLACE_INDICATOR_SETTING_KEY, this.Ref_switch_ShowIndicatorRec,
'active', Gio.SettingsBindFlags.DEFAULT);
//implements draw cursor option
this.Ref_switch_DrawCursorRec = builder.get_object(
'swt_DrawCursorRec');
settings.bind(
DRAW_CURSOR_SETTING_KEY, this.Ref_switch_DrawCursorRec,
'active', Gio.SettingsBindFlags.DEFAULT);
//implements enable keybinding option
this.Ref_switch_EnableShortcut = builder.get_object(
'swt_KeyShortcut');
settings.bind(
ACTIVE_SHORTCUT_SETTING_KEY, this.Ref_switch_EnableShortcut,
'active', Gio.SettingsBindFlags.DEFAULT);
//implements selecting alternative key combo
this.Ref_treeview_Shortcut = builder.get_object(
"treeview_KeyShortcut");
this.Ref_treeview_Shortcut.set_sensitive(true);
this.Ref_liststore_Shortcut = builder.get_object(
"liststore_KeyShortcut");
this.Iter_ShortcutRow = this.Ref_liststore_Shortcut.append();
let renderer = new Gtk.CellRendererAccel({
editable: true
});
renderer.connect(
"accel-edited", Lang.bind(this,
function (renderer, path, key, mods, hwCode) {
Lib.TalkativeLog('edited key accel');
let accel = Gtk.accelerator_name(key, mods);
this._updateRowShortcut(accel);
setOption(SHORTCUT_KEY_SETTING_KEY, [accel]);
}));
renderer.connect(
"accel-cleared", Lang.bind(this,
function (renderer, path) {
Lib.TalkativeLog('cleared key accel');
this._updateRowShortcut(null);
setOption(SHORTCUT_KEY_SETTING_KEY, []);
}
));
let column = new Gtk.TreeViewColumn();
column.pack_start(renderer, true);
column.add_attribute(renderer, "accel-key", SHORTCUT_COLUMN_KEY);
column.add_attribute(renderer, "accel-mods", SHORTCUT_COLUMN_MODS);
this.Ref_treeview_Shortcut.append_column(column);
//implements area recording option
this.Ref_LabelInfo_AreaRec = builder.get_object('lbl_infoarearec');
this.Ref_ComboBox_AreaRec = builder.get_object('cbt_arearec');
settings.bind(
AREA_SCREEN_SETTING_KEY, this.Ref_ComboBox_AreaRec, 'active',
Gio.SettingsBindFlags.DEFAULT);
this.Ref_ComboBox_AreaRec.connect(
'changed', Lang.bind(this, function () {
this._setLabelGridsettings(
this.Ref_ComboBox_AreaRec.get_active());
}));
//implements image of screen
this.Ref_Image_Screen = builder.get_object('img_screen');
this.Ref_Image_Screen.set_from_file(Lib.ESCimgScreen);
//implements FPS option
this.Ref_spinner_FrameRateRec = builder.get_object(
'spb_FrameRateRec');
// Create an adjustment to use for the second spinbutton
let adjustment1 = new Gtk.Adjustment({
value: 30,
lower: 1,
upper: 666,
step_increment: 1,
page_increment: 10
});
this.Ref_spinner_FrameRateRec.configure(adjustment1, 10, 0);
settings.bind(
FPS_SETTING_KEY, this.Ref_spinner_FrameRateRec, 'value',
Gio.SettingsBindFlags.DEFAULT);
//implements max duration option
this.Ref_spinner_MaxDurationRec = builder.get_object(
'spb_MaxDurationRec');
// Create an adjustment to use for the second spinbutton
let adjustment2 = new Gtk.Adjustment({
value: 0,
lower: 0,
upper: 3600,
step_increment: 1,
page_increment: 10
});
this.Ref_spinner_MaxDurationRec.configure(adjustment2, 10, 0);
this.RecorderSettings.bind(
MAX_DURATION_SETTING_KEY, this.Ref_spinner_MaxDurationRec,
'value', Gio.SettingsBindFlags.DEFAULT);
//implements specific area options [ X , Y , width , height]
this.Ref_spinner_X = builder.get_object('spb_XposRec');
this.Ref_spinner_Y = builder.get_object('spb_YposRec');
this.Ref_spinner_Width = builder.get_object('spb_WidthRec');
this.Ref_spinner_Height = builder.get_object('spb_HeigthRec');
// Create an adjustment to use for the second spinbutton
let adjustment3 = new Gtk.Adjustment({
value: 0,
lower: 0,
upper: 20000,
step_increment: 1,
page_increment: 10
});
this.Ref_spinner_X.configure(adjustment3, 10, 0);
let adjustment4 = new Gtk.Adjustment({
value: 0,
lower: 0,
upper: 20000,
step_increment: 1,
page_increment: 10
});
this.Ref_spinner_Y.configure(adjustment4, 10, 0);
let adjustment6 = new Gtk.Adjustment({
value: 600,
lower: 0,
upper: 20000,
step_increment: 1,
page_increment: 10
});
this.Ref_spinner_Width.configure(adjustment6, 10, 0);
let adjustment5 = new Gtk.Adjustment({
value: 400,
lower: 0,
upper: 20000,
step_increment: 1,
page_increment: 10
});
this.Ref_spinner_Height.configure(adjustment5, 10, 0);
settings.bind(X_POS_SETTING_KEY, this.Ref_spinner_X, 'value',
Gio.SettingsBindFlags.DEFAULT);
settings.bind(Y_POS_SETTING_KEY, this.Ref_spinner_Y, 'value',
Gio.SettingsBindFlags.DEFAULT);
settings.bind(WIDTH_SETTING_KEY, this.Ref_spinner_Width, 'value',
Gio.SettingsBindFlags.DEFAULT);
settings.bind(HEIGHT_SETTING_KEY, this.Ref_spinner_Height, 'value',
Gio.SettingsBindFlags.DEFAULT);
//implements command string rec option
this.Ref_textedit_Pipeline = builder.get_object(
'txe_CommandStringRec');
this.Ref_buffer_Pipeline = this.Ref_textedit_Pipeline.get_buffer();
settings.bind(
PIPELINE_REC_SETTING_KEY, this.Ref_buffer_Pipeline, 'text',
Gio.SettingsBindFlags.DEFAULT);
//implements custom GSPipeline option
this.Ref_checkbox_CustomGSP = builder.get_object(
'ckb_EnableCustomGSP');
settings.bind(
ACTIVE_CUSTOM_GSP_SETTING_KEY, this.Ref_checkbox_CustomGSP,
'active', Gio.SettingsBindFlags.DEFAULT);
this.Ref_checkbox_CustomGSP.connect(
'clicked', Lang.bind(this, function () {
//update GSP text area
this._setStateGSP();
}));
//implements audio input option
this.Ref_ComboBox_InputAudio = builder.get_object('cbt_inputaudio');
settings.bind(
INPUT_AUDIO_SOURCE_SETTING_KEY, this.Ref_ComboBox_InputAudio,
'active', Gio.SettingsBindFlags.DEFAULT);
this.Ref_ComboBox_InputAudio.connect(
'changed', Lang.bind(this, function () {
this._setLabelGridsettings(
this.Ref_ComboBox_InputAudio.get_active());
}));
//implements file name string rec option
this.Ref_textedit_FileName = builder.get_object('txe_FileNameRec');
settings.bind(
FILE_NAME_SETTING_KEY, this.Ref_textedit_FileName, 'text',
Gio.SettingsBindFlags.DEFAULT);
//implements file folder option
this.Ref_label_FileFolderRec = builder.get_object(
'lbl_FileFolderRec');
settings.bind(
FILE_FOLDER_SETTING_KEY, this.Ref_label_FileFolderRec, 'label',
Gio.SettingsBindFlags.DEFAULT);
//implements file folder string rec option
this.Ref_filechooser_FileFolder = builder.get_object(
'fcs_FilePathRec');
this.Ref_filechooser_FileFolder.set_can_focus(false);
this.Ref_filechooser_FileFolder.connect(
'selection_changed', Lang.bind(this,
function (self) {
Lib.TalkativeLog('file path get from widget : ' + self.get_filename());
if (self.get_filename() !== null)
setOption(FILE_FOLDER_SETTING_KEY, self.get_filename());
}));
//update GSP text area and input source
this._setStateGSP();
this._refreshInputAudio();
//update label and grid
this._setLabelGridsettings(getOption('i', AREA_SCREEN_SETTING_KEY));
//implements default button action
this.Ref_button_SetDeafaultSettings = builder.get_object(
'btn_DefaultOption');
this.Ref_button_SetDeafaultSettings.connect(
'clicked', Lang.bind(this, this._setDefaultsettings));
//implements verbose debug option
this.Ref_switch_VerboseDebug = builder.get_object(
'swt_VerboseDebug');
settings.bind(
VERBOSE_DEBUG_SETTING_KEY, this.Ref_switch_VerboseDebug,
'active', Gio.SettingsBindFlags.DEFAULT);
//update list view
this._updateRowShortcut(
getOption('as', SHORTCUT_KEY_SETTING_KEY)[0]);
}
},
_updateRowShortcut: function (accel) {
Lib.TalkativeLog('update row combo key accel');
let [key, mods] =
(accel !== null) ? Gtk.accelerator_parse(accel): [0, 0];
Lib.TalkativeLog('key ' + key + ' mods ' + mods);
this.Ref_liststore_Shortcut.set(
this.Iter_ShortcutRow, [SHORTCUT_COLUMN_KEY, SHORTCUT_COLUMN_MODS], [key, mods]);
},
//set label and grid enable
_setLabelGridsettings: function (choice) {
Lib.TalkativeLog('set label and grid enable');
switch (choice) {
case 0:
Lib.TalkativeLog('select all area');
this.Ref_LabelInfo_AreaRec.set_label(
_('The registration covers the entire area'));
this.Ref_GridArea_AreaRec.set_sensitive(false);
break;
case 1:
Lib.TalkativeLog('select specific area from coordinates');
this.Ref_LabelInfo_AreaRec.set_label(
_('Fill box below with the values of the coordinates in pixels'));
this.Ref_GridArea_AreaRec.set_sensitive(true);
break;
case 2:
Lib.TalkativeLog('select specific area');
this.Ref_LabelInfo_AreaRec.set_label(
_('At the start of the recording you can select the recording area'));
this.Ref_GridArea_AreaRec.set_sensitive(false);
break;
case 3:
Lib.TalkativeLog('select specific window');
this.Ref_LabelInfo_AreaRec.set_label(
_('At the start of the recording you can select the window you want to record'));
this.Ref_GridArea_AreaRec.set_sensitive(false);
break;
case 4:
Lib.TalkativeLog('select specific desktop');
this.Ref_LabelInfo_AreaRec.set_label(
_('At the start of the recording you can select the desktop you want to record'));
this.Ref_GridArea_AreaRec.set_sensitive(false);
break;
}
},
_refreshInputAudio: function () {
//setup list of input audio
Lib.TalkativeLog('create list of input audio');
var inputaudio = getOption('as', LIST_INPUT_AUDIO_SETTING_KEY);
Lib.TalkativeLog('from settings audio: ' + inputaudio);
for (var x in inputaudio) {
this.Ref_ComboBox_InputAudio.append_text(inputaudio[x]);
};
},
_setStateGSP: function () {
//update GSP text area
if (getOption('b', ACTIVE_CUSTOM_GSP_SETTING_KEY)) {
Lib.TalkativeLog('custom GSP');
this.Ref_textedit_Pipeline.set_editable(true);
this.Ref_textedit_Pipeline.set_cursor_visible(true);
this.Ref_textedit_Pipeline.set_sensitive(true);
} else {
Lib.TalkativeLog('NOT custom GSP');
this.Ref_textedit_Pipeline.set_editable(false);
this.Ref_textedit_Pipeline.set_cursor_visible(false);
this.Ref_textedit_Pipeline.set_sensitive(false);
if (getOption('b', ACTIVE_AUDIO_REC_SETTING_KEY)) {
setOption(PIPELINE_REC_SETTING_KEY, 'queue ! videorate ! vp8enc min_quantizer=13 max_quantizer=13 cpu-used=5 deadline=1000000 threads=%T ! queue ! mux. pulsesrc ! queue ! audioconvert ! vorbisenc ! queue ! mux. webmmux name=mux ');
} else {
setOption(PIPELINE_REC_SETTING_KEY, 'vp8enc min_quantizer=13 max_quantizer=13 cpu-used=5 deadline=1000000 threads=%T ! queue ! webmmux');
}
}
},
//function to restore default value of the settings
_setDefaultsettings: function () {
Lib.TalkativeLog('restore default option');
setOption(SHOW_TIMER_REC_SETTING_KEY, true);
setOption(SHOW_AREA_REC_SETTING_KEY, false);
setOption(REPLACE_INDICATOR_SETTING_KEY, false);
setOption(DRAW_CURSOR_SETTING_KEY, true);
setOption(VERBOSE_DEBUG_SETTING_KEY, false);
setOption(FPS_SETTING_KEY, 30);
this.RecorderSettings.set_int(MAX_DURATION_SETTING_KEY, 0);
setOption(X_POS_SETTING_KEY, 0);
setOption(Y_POS_SETTING_KEY, 0);
setOption(WIDTH_SETTING_KEY, 600);
setOption(HEIGHT_SETTING_KEY, 400);
setOption(PIPELINE_REC_SETTING_KEY, 'vp8enc min_quantizer=13 max_quantizer=13 cpu-used=5 deadline=1000000 threads=%T ! queue ! webmmux');
//TO-DO queue ! videorate ! vp8enc min_quantizer=13 max_quantizer=13 cpu-used=5 deadline=1000000 threads=%T ! queue ! mux. pulsesrc ! queue ! audioconvert ! vorbisenc ! queue ! mux. webmmux name=mux
//pacmd list-source-outputs
//pacmd list-sources | grep name:
//pacmd list-sources | grep index:
//pacmd list-sink-inputs
//pacmd list-source-outputs
//pacmd move-sink-input 206 1
// 206 = index sink input - 1 = index source out
setOption(FILE_NAME_SETTING_KEY, 'Screencast_%d_%t.webm');
setOption(FILE_FOLDER_SETTING_KEY, '');
}
});
//getter option
function getOption(type, key) {
checkSettings();
switch (type) {
case 'b':
return settings.get_boolean(key);
break;
case 'i':
return settings.get_int(key);
break;
case 's':
return settings.get_string(key);
break;
case 'as':
return settings.get_strv(key);
break;
default:
return 'ERROR';
};
return '';
}
//setter option
function setOption(key, option) {
checkSettings();
switch (typeof (option)) {
case 'boolean':
settings.set_boolean(key, option);
break;
case 'number':
settings.set_int(key, option);
break;
case 'string':
settings.set_string(key, option);
break;
case 'object':
settings.set_strv(key, option);
break;
default:
return 'ERROR';
};
return '';
}
function checkSettings() {
if (settings === null) {
settings = Lib.getSettings('org.gnome.shell.extensions.EasyScreenCast');
}
}
function buildPrefsWidget() {
Lib.TalkativeLog('Init pref widget');
var widget = new EasyScreenCastSettingsWidget();
widget.show_all();
return widget;
};