-
-
Notifications
You must be signed in to change notification settings - Fork 17
/
prefs.js
1625 lines (1348 loc) · 44.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
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
imports.gi.versions.Gtk = '3.0';
imports.gi.versions.Gdk = '3.0';
const { Gio, Gtk, GLib, Gdk, Vte, Pango, GObject } = imports.gi;
const Local = imports.misc.extensionUtils.getCurrentExtension();
const { SettingLabel, addToGrid } = Local.imports.prefs_shared;
const Soup = Local.imports.soup;
const Helper = Local.imports.helper;
const Settings = Helper.getSettings(Local.path);
const shared = Local.imports.shared.module.exports;
const Gettext = imports.gettext.domain(Local.metadata['gettext-domain']);
const _ = Gettext.gettext;
const HOME_DIR = GLib.get_home_dir();
const NODE_PATH = (GLib.find_program_in_path('nodejs') || GLib.find_program_in_path('node'));
const NPM_PATH = GLib.find_program_in_path('npm');
const FILE_MANAGERS = ['nautilus', 'nemo'];
let nodeDir;
let nodeBin;
let soupClient;
function init()
{
Helper.initTranslations(Local.path);
}
let CastMissingAppInfoBox = GObject.registerClass(
class CastMissingAppInfoBox extends Gtk.VBox
{
_init(dependName)
{
super._init({
height_request: 380,
spacing: 10,
margin: 20
});
let label = null;
label = new Gtk.Label({
/* TRANSLATORS: Will contain dependency name at the beginning (e.g. Node.js is not installed) */
label: '<span font="16"><b>' + dependName + " " + _("is not installed") + '</b></span>',
use_markup: true,
vexpand: true,
valign: Gtk.Align.CENTER
});
this.pack_start(label, true, true, 0);
this.show_all();
}
});
let CastIsStreamingInfoBox = GObject.registerClass(
class CastIsStreamingInfoBox extends Gtk.VBox
{
_init()
{
super._init({
height_request: 380,
spacing: 10,
margin: 10
});
let label = null;
label = new Gtk.Label({
label: '<span font="16"><b>' + _("Streaming in progress") + '</b></span>',
use_markup: true,
vexpand: true,
valign: Gtk.Align.END,
margin_top: 10
});
this.pack_start(label, true, true, 0);
label = new Gtk.Label({
/* TRANSLATORS: Keep line this short (otherwise extension prefs will strech) */
label: '<span font="13">' + _("Stop media transfer before accessing extension settings") + '</span>',
use_markup: true,
vexpand: true,
valign: Gtk.Align.START,
margin_bottom: 0
});
this.pack_start(label, true, true, 0);
let remoteWidget = new CastRemoteSettingsGrid();
this.pack_start(remoteWidget, true, true, 0);
}
});
let CastMainSettingsBox = GObject.registerClass(
class CastMainSettingsBox extends Gtk.VBox
{
_init()
{
super._init();
let label = null;
let widget = null;
let button = null;
let box = null;
let grid = new Gtk.Grid({
margin: 20,
row_spacing: 6
});
this.pack_start(grid, false, false, 0);
/* Label: Main Options */
label = new SettingLabel(_("Main Options"), true);
addToGrid(grid, label, null, true);
/* Receiver Type */
label = new SettingLabel(_("Receiver type"));
widget = new Gtk.ComboBoxText({width_request: 230, halign:Gtk.Align.END});
widget.append('chromecast', "Chromecast");
/* TRANSLATORS: "Playercast" is a name of an app, so do not change it */
widget.append('playercast', _("Playercast app"));
/* TRANSLATORS: Web browser or Media player app selection.
This should be as short as possible e.g. "Browser | Player". */
widget.append('other', _("Web browser | Media player"));
Settings.bind('receiver-type', widget, 'active-id', Gio.SettingsBindFlags.DEFAULT);
addToGrid(grid, label, widget);
/* FFmpeg Path */
label = new SettingLabel(_("FFmpeg path"));
widget = new Gtk.Entry({width_request: 230, halign:Gtk.Align.END});
widget.set_placeholder_text("/usr/bin/ffmpeg");
Settings.bind('ffmpeg-path', widget, 'text', Gio.SettingsBindFlags.DEFAULT);
addToGrid(grid, label, widget);
/* FFprobe Path */
label = new SettingLabel(_("FFprobe path"));
widget = new Gtk.Entry({width_request: 230, halign:Gtk.Align.END});
widget.set_placeholder_text("/usr/bin/ffprobe");
Settings.bind('ffprobe-path', widget, 'text', Gio.SettingsBindFlags.DEFAULT);
addToGrid(grid, label, widget);
/* Listening Port */
label = new SettingLabel(_("Listening port"));
this.portWidget = new Gtk.SpinButton({halign:Gtk.Align.END});
this.portWidget.set_sensitive(true);
this.portWidget.set_range(1024, 65535);
this.portWidget.set_value(Settings.get_int('listening-port'));
this.portWidget.set_increments(1, 2);
Settings.bind('listening-port', this.portWidget, 'value', Gio.SettingsBindFlags.DEFAULT);
addToGrid(grid, label, this.portWidget);
/* Internal Port */
label = new SettingLabel(_("Internal communication port"));
this.intPortWidget = new Gtk.SpinButton({halign:Gtk.Align.END});
this.intPortWidget.set_sensitive(true);
this.intPortWidget.set_range(1024, 65535);
this.intPortWidget.set_value(Settings.get_int('internal-port'));
this.intPortWidget.set_increments(1, 2);
Settings.bind('internal-port', this.intPortWidget, 'value', Gio.SettingsBindFlags.DEFAULT);
addToGrid(grid, label, this.intPortWidget);
/* Web player link */
this.linkButton = new Gtk.LinkButton({
expand: false,
halign:Gtk.Align.CENTER
});
box = new Gtk.VBox({
margin: 5,
hexpand: true,
valign:Gtk.Align.END,
halign:Gtk.Align.CENTER
});
this.infoLabel = new Gtk.Label();
box.pack_start(this.infoLabel, false, false, 0);
box.pack_start(this.linkButton, false, false, 0);
this.pack_end(box, false, false, 0);
this.linkSignal = this.portWidget.connect('value-changed', () => this.updateLink());
getHostIpAsync(hostIp =>
{
this.hostIp = hostIp;
if(this.hostIp)
{
this.infoLabel.label = _("Access web player from devices on local network");
this.updateLink();
this.checkService();
}
});
}
updateLink()
{
let link = 'http://' + this.hostIp + ':' + this.portWidget.value;
this.linkButton.uri = link;
this.linkButton.label = link;
}
checkService()
{
soupClient.getIsServiceEnabled(data =>
{
if(data && data.isEnabled)
this.setDisplayInfo(true);
else
this.setDisplayInfo(false);
});
}
setDisplayInfo(isEnabled)
{
/* No point in displaying without host IP */
if(isEnabled && this.hostIp)
{
this.infoLabel.show();
this.linkButton.show();
}
else
{
this.infoLabel.hide();
this.linkButton.hide();
}
}
destroy()
{
this.portWidget.disconnect(this.linkSignal);
super.destroy();
}
});
let CastRemoteSettingsGrid = GObject.registerClass(
class CastRemoteSettingsGrid extends Gtk.Grid
{
_init()
{
super._init({
margin: 20,
row_spacing: 6
});
let label = null;
let widget = null;
/* Label: Remote Controller */
label = new SettingLabel(_("Remote Controller"), true);
addToGrid(this, label, null, true);
/* Remote Position */
label = new SettingLabel(_("Remote position"));
widget = new Gtk.ComboBoxText({halign:Gtk.Align.END});
widget.append('left', _("Left"));
widget.append('center-left', _("Center (left side)"));
widget.append('center-right', _("Center (right side)"));
widget.append('right', _("Right"));
Settings.bind('remote-position', widget, 'active-id', Gio.SettingsBindFlags.DEFAULT);
addToGrid(this, label, widget);
/* Seek Backward/Forward */
label = new SettingLabel(_("Seek backward/forward (seconds)"));
widget = new Gtk.SpinButton({halign:Gtk.Align.END});
widget.set_sensitive(true);
widget.set_range(1, 120);
widget.set_value(Settings.get_int('seek-time'));
widget.set_increments(1, 2);
Settings.bind('seek-time', widget, 'value', Gio.SettingsBindFlags.DEFAULT);
addToGrid(this, label, widget);
/* Slideshow Timer */
label = new SettingLabel(_("Slideshow time per picture (seconds)"));
widget = new Gtk.SpinButton({halign:Gtk.Align.END});
widget.set_sensitive(true);
widget.set_range(5, 999);
widget.set_value(Settings.get_int('slideshow-time'));
widget.set_increments(1, 2);
Settings.bind('slideshow-time', widget, 'value', Gio.SettingsBindFlags.DEFAULT);
addToGrid(this, label, widget);
/* Media Buttons Size */
label = new SettingLabel(_("Media control buttons size"));
widget = new Gtk.SpinButton({halign:Gtk.Align.END});
widget.set_sensitive(true);
widget.set_range(8, 32);
widget.set_value(Settings.get_int('media-buttons-size'));
widget.set_increments(1, 2);
Settings.bind('media-buttons-size', widget, 'value', Gio.SettingsBindFlags.DEFAULT);
addToGrid(this, label, widget);
/* Slider Icon Size */
label = new SettingLabel(_("Slider icon size"));
widget = new Gtk.SpinButton({halign:Gtk.Align.END});
widget.set_sensitive(true);
widget.set_range(8, 32);
widget.set_value(Settings.get_int('slider-icon-size'));
widget.set_increments(1, 2);
Settings.bind('slider-icon-size', widget, 'value', Gio.SettingsBindFlags.DEFAULT);
addToGrid(this, label, widget);
/* Volume Slider */
label = new SettingLabel(_("Unify sliders"));
widget = new Gtk.Switch({halign:Gtk.Align.END});
widget.set_sensitive(true);
widget.set_active(Settings.get_boolean('unified-slider'));
Settings.bind('unified-slider', widget, 'active', Gio.SettingsBindFlags.DEFAULT);
addToGrid(this, label, widget);
/* Remote Label */
label = new SettingLabel(_("Show remote label"));
this.remoteSwitch = new Gtk.Switch({halign:Gtk.Align.END});
this.remoteSwitch.set_sensitive(true);
this.remoteSwitch.set_active(Settings.get_boolean('remote-label'));
Settings.bind('remote-label', this.remoteSwitch, 'active', Gio.SettingsBindFlags.DEFAULT);
addToGrid(this, label, this.remoteSwitch);
/* Remote Label */
label = new SettingLabel(_("Receiver name as label"));
this.nameSwitch = new Gtk.Switch({halign:Gtk.Align.END});
this.nameSwitch.set_sensitive(true);
this.nameSwitch.set_active(Settings.get_boolean('remote-label-fn'));
Settings.bind('remote-label-fn', this.nameSwitch, 'active', Gio.SettingsBindFlags.DEFAULT);
addToGrid(this, label, this.nameSwitch);
this.remoteSwitchSignal = this.remoteSwitch.connect('notify::active', () =>
{
this.nameSwitch.set_sensitive(this.remoteSwitch.active);
});
}
destroy()
{
this.remoteSwitch.disconnect(this.remoteSwitchSignal);
super.destroy();
}
});
let CastChromecastSettingsGrid = GObject.registerClass(
class CastChromecastSettingsGrid extends Gtk.Grid
{
_init()
{
super._init({
margin: 20,
row_spacing: 6
});
this.subsConfig = {};
let label = null;
let widget = null;
let box = null;
let button = null;
let rgba = new Gdk.RGBA();
/* Restore default subtitles values if someone messed them externally */
try { this.subsConfig = JSON.parse(Settings.get_string('chromecast-subtitles')); }
catch(err) { Settings.set_string('chromecast-subtitles', "{}"); }
/* Label: Chromecast Options */
label = new SettingLabel(_("Chromecast Options"), true);
addToGrid(this, label, null, true);
/* Chromecast device name */
label = new SettingLabel(_("Device selection"));
box = new Gtk.HBox({halign:Gtk.Align.END});
widget = new Gtk.ComboBoxText();
this.scanButton = Gtk.Button.new_from_icon_name('view-refresh-symbolic', 4);
this.ipConfButton = Gtk.Button.new_from_icon_name('emblem-system-symbolic', 4);
box.pack_end(this.ipConfButton, false, false, 0);
box.pack_end(this.scanButton, false, false, 4);
box.pack_end(widget, false, false, 0);
setDevices(widget);
this.devChangeSignal = Settings.connect('changed::chromecast-devices', this.onDevEdit.bind(this, widget));
this.scanSignal = this.scanButton.connect('clicked',
scanDevices.bind(this, widget, [this.scanButton, this.ipConfButton], 'googlecast')
);
this.ipConfSignal = this.ipConfButton.connect('clicked', () => {
let castIp = new CastChromecastIpDialog(this);
});
Settings.bind('chromecast-name', widget, 'active-id', Gio.SettingsBindFlags.DEFAULT);
addToGrid(this, label, box);
/* Label: Subtitles */
label = new SettingLabel(_("Subtitles"), true, true);
addToGrid(this, label);
/* Font Family */
label = new SettingLabel(_("Font family"));
this.fontFamily = new Gtk.ComboBoxText({width_request: 180, halign:Gtk.Align.END});
this.fontFamily.append('SANS_SERIF', "Droid Sans");
this.fontFamily.append('MONOSPACED_SANS_SERIF', "Droid Sans Mono");
this.fontFamily.append('SERIF', "Droid Serif Regular");
this.fontFamily.append('MONOSPACED_SERIF', "Cutive Mono");
this.fontFamily.append('CASUAL', "Short Stack");
this.fontFamily.append('CURSIVE', "Quintessential");
this.fontFamily.append('SMALL_CAPITALS', "Alegreya Sans SC");
this.fontFamily.active_id = this.getSubsConfig('fontGenericFamily');
this.familySignal = this.fontFamily.connect('changed', () =>
{
this.subsConfig.fontFamily = this.fontFamily.get_active_text();
this.subsConfig.fontGenericFamily = this.fontFamily.active_id;
this.setSubsConfig();
});
addToGrid(this, label, this.fontFamily);
/* Font Style */
label = new SettingLabel(_("Font style"));
this.fontStyle = new Gtk.ComboBoxText({width_request: 180, halign:Gtk.Align.END});
this.fontStyle.append('NORMAL', _("Normal"));
this.fontStyle.append('BOLD', _("Bold"));
this.fontStyle.append('ITALIC', _("Italic"));
this.fontStyle.append('BOLD_ITALIC', _("Bold italic"));
this.fontStyle.active_id = this.getSubsConfig('fontStyle');
this.styleSignal = this.fontStyle.connect('changed', () =>
{
this.subsConfig.fontStyle = this.fontStyle.active_id;
this.setSubsConfig();
});
addToGrid(this, label, this.fontStyle);
/* Subtitles Scale */
label = new SettingLabel(_("Scale factor"));
this.scaleButton = new Gtk.SpinButton({halign:Gtk.Align.END, digits:1});
this.scaleButton.set_sensitive(true);
this.scaleButton.set_range(0.1, 5.0);
this.scaleButton.set_value(this.getSubsConfig('fontScale'));
this.scaleButton.set_increments(0.1, 0.2);
this.scaleSignal = this.scaleButton.connect('value-changed', () =>
{
this.subsConfig.fontScale = this.scaleButton.value.toFixed(1);
this.setSubsConfig();
});
addToGrid(this, label, this.scaleButton);
/* Font Color */
label = new SettingLabel(_("Font color"));
rgba.parse(hashToColor(this.getSubsConfig('foregroundColor')));
this.fontColor = new Gtk.ColorButton({halign:Gtk.Align.END, rgba: rgba, show_editor: true});
this.fontColor.set_sensitive(true);
this.fontColorSignal = this.fontColor.connect('color-set', () =>
{
this.subsConfig.foregroundColor = colorToHash(this.fontColor.rgba.to_string());
this.setSubsConfig();
});
addToGrid(this, label, this.fontColor);
/* Font Outline */
label = new SettingLabel(_("Font outline"));
box = new Gtk.HBox({halign:Gtk.Align.END});
this.outlineSwitch = new Gtk.Switch({halign:Gtk.Align.END, valign:Gtk.Align.CENTER});
this.outlineSwitch.set_sensitive(true);
this.checkActive = () =>
{
return (this.getSubsConfig('edgeType') === "OUTLINE") ? true : false;
}
this.outlineSwitch.set_active(this.checkActive());
this.outlineSignal = this.outlineSwitch.connect('notify::active', () =>
{
if(this.outlineSwitch.active)
this.subsConfig.edgeType = "OUTLINE";
else
this.subsConfig.edgeType = "NONE";
this.setSubsConfig();
});
rgba.parse(hashToColor(this.getSubsConfig('edgeColor')));
this.edgeColor = new Gtk.ColorButton({halign:Gtk.Align.END, rgba: rgba, show_editor: true});
this.edgeColor.set_sensitive(true);
this.edgeSignal = this.edgeColor.connect('color-set', () =>
{
this.subsConfig.edgeColor = colorToHash(this.edgeColor.rgba.to_string());
this.setSubsConfig();
});
box.pack_end(this.edgeColor, false, false, 0);
box.pack_end(this.outlineSwitch, false, false, 8);
addToGrid(this, label, box);
/* Background color */
label = new SettingLabel(_("Background color"));
rgba.parse(hashToColor(this.getSubsConfig('backgroundColor')));
this.bgColor = new Gtk.ColorButton({halign:Gtk.Align.END, rgba: rgba, show_editor: true, use_alpha: true});
this.bgColor.set_sensitive(true);
this.bgSignal = this.bgColor.connect('color-set', () =>
{
this.subsConfig.backgroundColor = colorToHash(this.bgColor.rgba.to_string());
this.setSubsConfig();
});
addToGrid(this, label, this.bgColor);
}
getSubsConfig(confName)
{
return this.subsConfig[confName] || shared.chromecast.subsStyle[confName];
}
setSubsConfig()
{
Settings.set_string('chromecast-subtitles', JSON.stringify(this.subsConfig));
}
onDevEdit(widget)
{
let activeText = widget.get_active_text();
setDevices(widget, false, activeText);
}
destroy()
{
Settings.disconnect(this.devChangeSignal);
this.scanButton.disconnect(this.scanSignal);
this.ipConfButton.disconnect(this.ipConfSignal);
this.fontFamily.disconnect(this.familySignal);
this.fontStyle.disconnect(this.styleSignal);
this.scaleButton.disconnect(this.scaleSignal);
this.fontColor.disconnect(this.fontColorSignal);
this.outlineSwitch.disconnect(this.outlineSignal);
this.edgeColor.disconnect(this.edgeSignal);
this.bgColor.disconnect(this.bgSignal);
super.destroy();
}
});
let CastOtherSettingsNotebook = GObject.registerClass(
class CastOtherSettingsNotebook extends Gtk.Notebook
{
_init()
{
super._init();
let widget = null;
this.createdWidgets = [];
let otherWidgets = [
CastEncoderSettingsGrid,
CastExtractorSettingsGrid,
CastMiscSettingsGrid
];
otherWidgets.forEach(OtherWidget =>
{
widget = new OtherWidget();
this.append_page(widget, widget.title);
this.createdWidgets.push(widget);
});
}
destroy()
{
this.createdWidgets.forEach(createdWidget =>
{
createdWidget.destroy();
});
super.destroy();
}
});
let CastEncoderSettingsGrid = GObject.registerClass(
class CastEncoderSettingsGrid extends Gtk.Grid
{
_init()
{
super._init({
margin: 20,
row_spacing: 6
});
this.title = new Gtk.Label({ label: _("Encoder") });
let label = null;
let widget = null;
/* Label: Media Encoding */
label = new SettingLabel(_("Media Encoding"), true);
addToGrid(this, label, null, true);
/* Hardware Acceleration */
label = new SettingLabel(_("Hardware acceleration"));
widget = new Gtk.ComboBoxText({halign:Gtk.Align.END});
widget.append('none', _("None"));
widget.append('vaapi', "VAAPI");
widget.append('nvenc', "NVENC");
widget.append('amf', "AMF");
Settings.bind('video-acceleration', widget, 'active-id', Gio.SettingsBindFlags.DEFAULT);
addToGrid(this, label, widget);
/* Video Bitrate */
label = new SettingLabel(_("Bitrate (Mbps)"));
widget = new Gtk.SpinButton({halign:Gtk.Align.END, digits:1});
widget.set_sensitive(true);
widget.set_range(2.0, 10.0);
widget.set_value(Settings.get_double('video-bitrate'));
widget.set_increments(0.1, 0.2);
Settings.bind('video-bitrate', widget, 'value', Gio.SettingsBindFlags.DEFAULT);
addToGrid(this, label, widget);
/* Burn Subtitles */
label = new SettingLabel(_("Burn subtitles when transcoding video"));
widget = new Gtk.Switch({halign:Gtk.Align.END});
widget.set_sensitive(true);
widget.set_active(Settings.get_boolean('burn-subtitles'));
Settings.bind('burn-subtitles', widget, 'active', Gio.SettingsBindFlags.DEFAULT);
addToGrid(this, label, widget);
}
});
let CastExtractorSettingsGrid = GObject.registerClass(
class CastExtractorSettingsGrid extends Gtk.Grid
{
_init()
{
super._init({
margin: 20,
row_spacing: 6
});
/* TRANSLATORS: "Players" as video players */
this.title = new Gtk.Label({ label: _("Extractor") });
let label = null;
let widget = null;
/* Label: Extractor Settings */
label = new SettingLabel(_("Subtitles Extraction"), true);
addToGrid(this, label);
/* Add vttextract */
/* TRANSLATORS: "vttextract" is the name of executable, do not change */
label = new SettingLabel(_("Add vttextract executable"));
this.installExtractor = new Gtk.Switch({halign:Gtk.Align.END});
this.installExtractor.set_sensitive(true);
this.installExtractor.set_active(
GLib.file_test(HOME_DIR + '/.local/bin/vttextract', GLib.FileTest.EXISTS)
);
addToGrid(this, label, this.installExtractor);
/* Reuse Extracted Subtitles */
label = new SettingLabel(_("Reuse extracted subtitles"));
this.extractorSave = new Gtk.Switch({halign:Gtk.Align.END});
this.extractorSave.set_sensitive(true);
this.extractorSave.set_active(Settings.get_boolean('extractor-reuse'));
Settings.bind('extractor-reuse', this.extractorSave, 'active', Gio.SettingsBindFlags.DEFAULT);
addToGrid(this, label, this.extractorSave);
/* Preferred Subtitles Language */
label = new SettingLabel(_("Preferred language"));
widget = new Gtk.Entry({halign:Gtk.Align.END});
widget.set_placeholder_text("eng/English");
Settings.bind('subs-preferred', widget, 'text', Gio.SettingsBindFlags.DEFAULT);
addToGrid(this, label, widget);
/* Fallback Subtitles Language */
label = new SettingLabel(_("Fallback language"));
widget = new Gtk.Entry({halign:Gtk.Align.END});
widget.set_placeholder_text(_("none"));
Settings.bind('subs-fallback', widget, 'text', Gio.SettingsBindFlags.DEFAULT);
addToGrid(this, label, widget);
/* Save Folder */
/* TRANSLATORS: Destination folder to save subtitles */
label = new SettingLabel(_("Save folder"));
this.extractorChooser = Gtk.FileChooserButton.new(
_("Select folder"), Gtk.FileChooserAction.SELECT_FOLDER
);
let startupDir = Settings.get_string('extractor-dir');
this.extractorChooser.set_filename(startupDir);
this.extractorChooser.set_sensitive(this.extractorSave.active);
addToGrid(this, label, this.extractorChooser);
this.chooserSignal = this.extractorChooser.connect('file-set', () =>
{
let filename = this.extractorChooser.get_filename();
if(filename && filename.length > 1)
Settings.set_string('extractor-dir', filename);
});
this.installExtractorSignal = this.installExtractor.connect('notify::active', () =>
{
enableCmdTool(this.installExtractor.active, 'vttextract');
});
this.enableExtractorSignal = this.extractorSave.connect('notify::active', () =>
{
this.extractorChooser.set_sensitive(this.extractorSave.active);
});
}
destroy()
{
this.extractorChooser.disconnect(this.chooserSignal);
this.installExtractor.disconnect(this.installExtractorSignal);
this.extractorSave.disconnect(this.enableExtractorSignal);
super.destroy();
}
});
let CastMiscSettingsGrid = GObject.registerClass(
class CastMiscSettingsGrid extends Gtk.Grid
{
_init()
{
super._init({
margin: 20,
row_spacing: 6
});
this.title = new Gtk.Label({ label: _("Misc") });
let label = null;
let widget = null;
let box = null;
/* Label: Playercast */
label = new SettingLabel(_("Playercast app"), true);
addToGrid(this, label);
/* Playercast device name */
label = new SettingLabel(_("Device selection"));
box = new Gtk.HBox({halign:Gtk.Align.END});
this.playercastSelect = new Gtk.ComboBoxText();
this.playercastScanButton = Gtk.Button.new_from_icon_name('view-refresh-symbolic', 4);
box.pack_end(this.playercastScanButton, false, false, 4);
box.pack_end(this.playercastSelect, false, false, 0);
setDevices(this.playercastSelect, true).then(() => {
Settings.bind('playercast-name', this.playercastSelect, 'active-id', Gio.SettingsBindFlags.DEFAULT);
/* Set to Automatic instead of empty box */
if(!this.playercastSelect.get_active_text())
this.playercastSelect.set_active(0);
});
this.playercastChangeSignal = Settings.connect(
'changed::playercast-devices', this.onPlayercastEdit.bind(this, this.playercastSelect)
);
this.playercastScanSignal = this.playercastScanButton.connect('clicked',
scanDevices.bind(this, this.playercastSelect, [this.playercastScanButton], 'playercast')
);
addToGrid(this, label, box);
/* Label: Web Player */
label = new SettingLabel(_("Web Player"), true, true);
addToGrid(this, label);
/* Subtitles Scale */
label = new SettingLabel(_("Subtitles scale factor"));
widget = new Gtk.SpinButton({halign:Gtk.Align.END, digits:1});
widget.set_sensitive(true);
widget.set_range(0.1, 5.0);
widget.set_value(Settings.get_double('webplayer-subs'));
widget.set_increments(0.1, 0.2);
Settings.bind('webplayer-subs', widget, 'value', Gio.SettingsBindFlags.DEFAULT);
addToGrid(this, label, widget);
/* Label: Miscellaneous */
/* TRANSLATORS: The rest of extension settings */
label = new SettingLabel(_("Miscellaneous"), true, true);
addToGrid(this, label);
/* Music Visualizer */
label = new SettingLabel(_("Music visualizer"));
widget = new Gtk.Switch({halign:Gtk.Align.END});
widget.set_sensitive(true);
widget.set_active(Settings.get_boolean('music-visualizer'));
Settings.bind('music-visualizer', widget, 'active', Gio.SettingsBindFlags.DEFAULT);
addToGrid(this, label, widget);
if(Local.metadata['custom-install'])
return;
/* Nautilus/Nemo Integration */
label = new SettingLabel(_("Nautilus/Nemo integration"));
this.nautilusSwitch = new Gtk.Switch({halign:Gtk.Align.END});
this.nautilusSwitch.set_sensitive(true);
this.nautilusSwitch.set_active(this.getIsFmEnabled());
this.nautilusSignal = this.nautilusSwitch.connect('notify::active', () =>
{
enableNautilusExtension(this.nautilusSwitch.active);
});
addToGrid(this, label, this.nautilusSwitch);
}
getIsFmEnabled()
{
if(!HOME_DIR) return false;
for(let fm of FILE_MANAGERS)
{
if(
GLib.file_test(HOME_DIR + '/.local/share/' + fm +
'-python/extensions/nautilus-cast-to-tv.py', GLib.FileTest.EXISTS)
) {
return true;
}
}
return false;
}
onPlayercastEdit(widget)
{
let activeText = widget.get_active_text();
setDevices(widget, true, activeText);
}
destroy()
{
Settings.disconnect(this.playercastChangeSignal);
this.playercastScanButton.disconnect(this.playercastScanSignal);
if(this.nautilusSwitch)
this.nautilusSwitch.disconnect(this.nautilusSignal);
super.destroy();
}
});
let CastAddonsSettingsNotebook = GObject.registerClass(
class CastAddonsSettingsNotebook extends Gtk.Notebook
{
_init()
{
super._init();
let label = null;
let extPath = Local.path.substring(0, Local.path.lastIndexOf('/'));
let extDir = Gio.File.new_for_path(extPath);
let dirEnum = extDir.enumerate_children('standard::name,standard::type', 0, null);
let addons = [];
let info;
while((info = dirEnum.next_file(null)))
{
let dirName = info.get_name();
if(dirName.startsWith('cast-to-tv') && dirName.includes('addon@'))
{
addons.push(dirName);
}
}
addons.sort();
addons.forEach(addonDir =>
{
let addonPath = extPath + '/' + addonDir;
let addonName = addonDir.substring(11, addonDir.lastIndexOf('-'));
let isPrefs = GLib.file_test(addonPath + '/' + addonName + '_prefs.js', GLib.FileTest.EXISTS);
if(isPrefs)
{
imports.searchPath.unshift(addonPath);
let addonPrefs = imports[addonName + '_prefs'];
imports.searchPath.shift();
addonPrefs.init();
let widget = addonPrefs.buildPrefsWidget();
this.append_page(widget, widget.title);
if(!widget.visible && !widget.get_realized())
widget.realize();
}
});
}
});
let CastModulesSettingsBox = GObject.registerClass(
class CastModulesSettingsBox extends Gtk.VBox
{
_init()
{
super._init({ margin: 10 });
let installLabel = _("Install npm modules");
this.installButton = new Gtk.Button({
label: _(installLabel),
expand: false,
halign: Gtk.Align.CENTER
});
let installCallback = () =>
{
if(Settings.get_boolean('service-wanted'))
GLib.spawn_async(Local.path, ['/usr/bin/gjs', Local.path + '/server-monitor.js'], null, 0, null);
this.installButton.label = _(installLabel);
this.installButton.set_sensitive(true);
}
let ptyCallback = (pty, spawnRes) =>
{
let [res, pid] = pty.spawn_finish(spawnRes);
this.termWidget.watch_child(pid);
}
let installModules = () =>
{
if(!this.termWidget)
return;
this.termWidget.reset(true, true);
/* Stops both server and monitor service */
GLib.spawn_command_line_sync('pkill -SIGINT -f ' + Local.path);
this.installButton.set_sensitive(false);
this.installButton.label = _("Installing...");
let pty = Vte.Pty.new_sync(Vte.PtyFlags.DEFAULT, null);
this.termWidget.set_pty(pty);
try {
pty.spawn_async(
Local.path, [NPM_PATH, 'install'], null,
GLib.SpawnFlags.DO_NOT_REAP_CHILD, null, 120000, null,
(self, res) => ptyCallback(self, res)
);
}
catch(err) {
let errMsg = [
'Error: Could not spawn VTE terminal',
'Reason: ' + err.message,
'',
'Try installing from terminal with:',
'cd ' + Local.path,
'npm install',
'\0'
].join('\n');
this.termWidget.feed_child(errMsg, -1);
this.installButton.label = _(installLabel);
this.installButton.set_sensitive(true);
}
}
/*
Creating new Vte.Terminal on prefs init causes weird misbehaviour
of prefs window. Adding it after small delay makes it work.
*/
GLib.timeout_add(GLib.PRIORITY_DEFAULT, 100, () =>
{
this.termWidget = new Vte.Terminal({
scroll_on_output: true,
margin_bottom: 10
});
let background = new Gdk.RGBA({red: 0.96, green: 0.96, blue: 0.96, alpha: 1});
let foreground = new Gdk.RGBA({red: 0, green: 0, blue: 0, alpha: 1});
this.termWidget.set_color_background(background);
this.termWidget.set_color_foreground(foreground);
this.termWidget.set_color_cursor(background);
this.termWidget.set_cursor_shape(Vte.CursorShape.IBEAM);
this.termWidget.set_cursor_blink_mode(Vte.CursorBlinkMode.OFF);
this.termWidget.set_sensitive(false);
this.installFinishSignal = this.termWidget.connect('child-exited', installCallback.bind(this));
this.pack_start(this.termWidget, true, true, 0);
this.pack_start(this.installButton, false, false, 0);
this.show_all();
return GLib.SOURCE_REMOVE;
});
this.installSignal = this.installButton.connect('clicked', installModules.bind(this));
}
destroy()
{
this.installButton.disconnect(this.installSignal);
if(this.termWidget && this.installFinishSignal)
this.termWidget.disconnect(this.installFinishSignal);
super.destroy();
}
});
let CastAboutPageBox = GObject.registerClass(
class CastAboutPageBox extends Gtk.VBox
{
_init()
{
super._init({
valign: Gtk.Align.CENTER,
halign: Gtk.Align.CENTER
});
let label = null;
let linkButton = null;
/* Image */
let image = new Gtk.Image({
file: Local.path + '/appIcon/prefs.png',
margin: 5,
margin_top: 25