Add startup fullscreen and volume preferences

This commit is contained in:
Rafostar
2020-10-26 11:07:01 +01:00
parent 9354042379
commit 31f208006f
6 changed files with 157 additions and 60 deletions

View File

@@ -1,10 +1,10 @@
const { GObject, Gst, Gtk } = imports.gi;
const Misc = imports.clapper_src.misc;
const { Prefs } = imports.clapper_src.prefs;
const Prefs = imports.clapper_src.prefs;
var actions = [
prefs,
about
about,
];
var accels = [
@@ -13,14 +13,14 @@ var accels = [
function prefs(window, appName)
{
let prefs = new Prefs();
let prefsWidget = Prefs.buildPrefsWidget();
let prefsDialog = new Gtk.Dialog({
title: 'Preferences',
modal: true,
transient_for: window,
child: prefs,
default_width: 400,
default_height: 320,
child: prefsWidget,
default_width: 460,
default_height: 400,
});
prefsDialog.connect('close-request', () => prefsDialog.run_dispose());
prefsDialog.present();

View File

@@ -17,6 +17,7 @@ class ClapperPlayer extends PlayerBase
this.is_local_file = false;
this.seek_done = true;
this.dragAllowed = false;
this.doneStartup = false;
this.posX = 0;
this.posY = 0;
@@ -342,18 +343,32 @@ class ClapperPlayer extends PlayerBase
this.stop();
}
_onUriLoaded(self, uri)
_onUriLoaded(player, uri)
{
if(!this.doneStartup) {
if(this.settings.get_boolean('fullscreen-auto')) {
let root = player.widget.get_root();
if(root) {
let clapperWidget = root.get_child();
if(!clapperWidget.fullscreenMode)
root.fullscreen();
}
}
if(this.settings.get_string('volume-initial') === 'custom')
this.set_volume(this.settings.get_int('volume-value') / 100);
}
this.doneStartup = true;
this.play();
debug(`URI loaded: ${uri}`);
}
_onPlayerWarning(self, error)
_onPlayerWarning(player, error)
{
debug(error.message, 'LEVEL_WARNING');
}
_onPlayerError(self, error)
_onPlayerError(player, error)
{
debug(error);
}

View File

@@ -8,32 +8,46 @@ class ClapperGeneralPage extends PrefsBase.Grid
{
super._init();
let label;
let widget;
this.addTitle('Startup');
this.addCheckButton('Auto enter fullscreen', 'fullscreen-auto');
label = this.getLabel('Seeking', true);
this.addToGrid(label);
this.addTitle('Volume');
let comboBox = this.addComboBoxText('Initial value', [
['restore', "Restore"],
['custom', "Custom"],
], 'volume-initial');
let spinButton = this.addSpinButton('Value (percentage)', 0, 200, 'volume-value');
this._onVolumeInitialChanged(spinButton, comboBox);
comboBox.connect('changed', this._onVolumeInitialChanged.bind(this, spinButton));
}
label = this.getLabel('Mode:');
widget = this.getComboBoxText([
_onVolumeInitialChanged(spinButton, comboBox)
{
let value = comboBox.get_active_id();
spinButton.set_visible(value === 'custom');
}
});
let BehaviourPage = GObject.registerClass(
class ClapperBehaviourPage extends PrefsBase.Grid
{
_init()
{
super._init();
this.addTitle('Seeking');
this.addComboBoxText('Mode', [
['normal', "Normal"],
['accurate', "Accurate"],
/* Needs gstplayer pipeline ref count fix */
//['fast', "Fast"],
], 'seeking-mode');
this.addToGrid(label, widget);
label = this.getLabel('Value:');
widget = this.getSpinButton(1, 99, 'seeking-value');
this.addToGrid(label, widget);
label = this.getLabel('Unit:');
widget = this.getComboBoxText([
this.addComboBoxText('Unit', [
['second', "Second"],
['minute', "Minute"],
['percentage', "Percentage"],
], 'seeking-unit');
this.addToGrid(label, widget);
this.addSpinButton('Value', 1, 99, 'seeking-value');
}
});
@@ -52,38 +66,37 @@ class ClapperGStreamerPage extends PrefsBase.Grid
}
});
var Prefs = GObject.registerClass(
class ClapperPrefs extends Gtk.Box
function buildPrefsWidget()
{
_init()
{
super._init({
orientation: Gtk.Orientation.VERTICAL,
});
this.add_css_class('prefsbox');
let pages = [
{
title: 'General',
widget: GeneralPage,
},
let pages = [
{
title: 'Player',
pages: [
{
title: 'General',
widget: GeneralPage,
},
{
title: 'Behaviour',
widget: BehaviourPage,
}
]
},
/*
{
title: 'Advanced',
pages: [
{
title: 'GStreamer',
widget: GStreamerPage,
}
]
}
{
title: 'Advanced',
pages: [
{
title: 'GStreamer',
widget: GStreamerPage,
}
]
}
*/
];
];
let prefsNotebook = new PrefsBase.Notebook(pages);
prefsNotebook.add_css_class('prefsnotebook');
let prefsNotebook = new PrefsBase.Notebook(pages);
prefsNotebook.add_css_class('prefsnotebook');
this.append(prefsNotebook);
}
});
return prefsNotebook;
}

View File

@@ -3,13 +3,19 @@ const { Gio, GObject, Gtk } = imports.gi;
var Notebook = GObject.registerClass(
class ClapperPrefsNotebook extends Gtk.Notebook
{
_init(pages)
_init(pages, isSubpage)
{
super._init({
show_border: false,
vexpand: true,
hexpand: true,
});
if(isSubpage) {
this.set_tab_pos(Gtk.PositionType.LEFT);
this.add_css_class('prefssubpage');
}
this.addArrayPages(pages);
}
@@ -22,7 +28,7 @@ class ClapperPrefsNotebook extends Gtk.Notebook
addObjectPages(item)
{
let widget = (item.pages)
? new Notebook(item.pages)
? new Notebook(item.pages, true)
: new item.widget();
this.addToNotebook(widget, item.title);
@@ -66,16 +72,52 @@ class ClapperPrefsGrid extends Gtk.Grid
if(rightWidget) {
spanWidth = 1;
rightWidget.bind_property('visible', leftWidget, 'visible',
GObject.BindingFlags.SYNC_CREATE
);
this.attach(rightWidget, 1, this.gridIndex, 1, 1);
}
this.attach(leftWidget, 0, this.gridIndex, spanWidth, 1);
this.gridIndex++;
return rightWidget || leftWidget;
}
addTitle(text)
{
let label = this.getLabel(text, true);
return this.addToGrid(label);
}
addComboBoxText(text, entries, setting)
{
let label = this.getLabel(text + ':');
let widget = this.getComboBoxText(entries, setting);
return this.addToGrid(label, widget);
}
addSpinButton(text, min, max, setting)
{
let label = this.getLabel(text + ':');
let widget = this.getSpinButton(min, max, setting);
return this.addToGrid(label, widget);
}
addCheckButton(text, setting)
{
let widget = this.getCheckButton(text, setting);
return this.addToGrid(widget);
}
getLabel(text, isTitle)
{
let marginLR = 0;
let marginTop = (isTitle && this.gridIndex > 0) ? 16 : 0;
let marginBottom = (isTitle) ? 2 : 0;
if(isTitle)
@@ -88,6 +130,7 @@ class ClapperPrefsGrid extends Gtk.Grid
use_markup: true,
hexpand: true,
halign: Gtk.Align.START,
margin_top: marginTop,
margin_bottom: marginBottom,
margin_start: marginLR,
margin_end: marginLR,
@@ -115,4 +158,14 @@ class ClapperPrefsGrid extends Gtk.Grid
return spinButton;
}
getCheckButton(text, setting)
{
let checkButton = new Gtk.CheckButton({
label: text || null,
});
this.settings.bind(setting, checkButton, 'active', this.flag);
return checkButton;
}
});

View File

@@ -99,10 +99,9 @@ scale marks {
}
/* Preferences */
.prefsbox {
margin: 5px;
}
.prefsnotebook grid {
margin: 10px;
}
.prefssubpage header {
background: transparent;
}

View File

@@ -1,6 +1,21 @@
<?xml version="1.0" encoding="UTF-8"?>
<schemalist gettext-domain="com.github.rafostar.Clapper">
<schema id="com.github.rafostar.Clapper" path="/com/github/rafostar/Clapper/">
<!-- General -->
<key name="fullscreen-auto" type="b">
<default>false</default>
<summary>Automatically enter fullscreen when first file is loaded</summary>
</key>
<key name="volume-initial" type="s">
<default>"restore"</default>
<summary>Mode used for startup volume value</summary>
</key>
<key name="volume-value" type="i">
<default>100</default>
<summary>Custom initial volume value after startup</summary>
</key>
<!-- Behaviour -->
<key name="seeking-mode" type="s">
<default>"normal"</default>
<summary>Mode used for seeking</summary>
@@ -13,6 +28,8 @@
<default>"second"</default>
<summary>Unit to use with seeking value</summary>
</key>
<!-- GStreamer -->
<key name="plugin-ranking" type="s">
<default>"{}"</default>
<summary>Custom values for GStreamer plugin ranking</summary>