mirror of
https://github.com/Rafostar/clapper.git
synced 2025-08-30 07:42:23 +02:00
Reuse old redio buttons
When a media is changed, normally one would expect to create new radio buttons with video/audio/subtitle tracks names corresponding to current video, but this is inefficient. Destroying objects just to create similiar ones again does take a long time and might lead to memory leaks. That is why a better and faster approach is to simply edit already available objects to match our expectations instead. This commit does just that for tracks radio buttons.
This commit is contained in:
56
clapper_src/controls.js
vendored
56
clapper_src/controls.js
vendored
@@ -1,8 +1,11 @@
|
||||
const { GObject, Gtk } = imports.gi;
|
||||
const Debug = imports.clapper_src.debug;
|
||||
|
||||
const CONTROLS_MARGIN = 4;
|
||||
const CONTROLS_SPACING = 4;
|
||||
|
||||
let { debug } = Debug;
|
||||
|
||||
var Controls = GObject.registerClass({
|
||||
Signals: {
|
||||
'position-seeking-changed': {
|
||||
@@ -116,6 +119,7 @@ var Controls = GObject.registerClass({
|
||||
button.osd = this.fullscreenMode;
|
||||
button.popover.add(button.popoverBox);
|
||||
button.connect('clicked', this._onPopoverButtonClicked.bind(this, button));
|
||||
button.popoverBox.show();
|
||||
|
||||
return button;
|
||||
}
|
||||
@@ -123,27 +127,53 @@ var Controls = GObject.registerClass({
|
||||
addRadioButtons(box, array, activeId)
|
||||
{
|
||||
let group = null;
|
||||
let children = box.get_children();
|
||||
let lastEl = (children.length > array.length)
|
||||
? children.length
|
||||
: array.length;
|
||||
|
||||
for(let el of array) {
|
||||
let radioButton = new Gtk.RadioButton({
|
||||
label: el.label,
|
||||
for(let i = 0; i < lastEl; i++) {
|
||||
if(i >= array.length) {
|
||||
children[i].hide();
|
||||
debug(`hiding unused ${children[i].trackType} radioButton nr: ${i}`);
|
||||
continue;
|
||||
}
|
||||
|
||||
let el = array[i];
|
||||
let radioButton;
|
||||
|
||||
if(i < children.length) {
|
||||
radioButton = children[i];
|
||||
debug(`reusing ${el.type} radioButton nr: ${i}`);
|
||||
}
|
||||
else {
|
||||
debug(`creating new ${el.type} radioButton nr: ${i}`);
|
||||
radioButton = new Gtk.RadioButton({
|
||||
group: group,
|
||||
});
|
||||
radioButton.trackType = el.type;
|
||||
radioButton.trackId = el.value;
|
||||
|
||||
if(radioButton.trackId === activeId)
|
||||
radioButton.set_active(true);
|
||||
if(!group)
|
||||
group = radioButton;
|
||||
|
||||
radioButton.connect(
|
||||
'toggled', this._onTrackRadioButtonToggled.bind(this, radioButton)
|
||||
'toggled',
|
||||
this._onTrackRadioButtonToggled.bind(this, radioButton)
|
||||
);
|
||||
this.setDefaultWidgetBehaviour(radioButton);
|
||||
box.add(radioButton);
|
||||
}
|
||||
box.show_all();
|
||||
radioButton.label = el.label;
|
||||
debug(`radioButton label: ${radioButton.label}`);
|
||||
radioButton.trackType = el.type;
|
||||
debug(`radioButton type: ${radioButton.trackType}`);
|
||||
radioButton.trackId = el.value;
|
||||
debug(`radioButton track id: ${radioButton.trackId}`);
|
||||
|
||||
if(radioButton.trackId === activeId) {
|
||||
radioButton.set_active(true);
|
||||
debug(`activated ${el.type} radioButton nr: ${i}`);
|
||||
}
|
||||
if(!group)
|
||||
group = radioButton;
|
||||
|
||||
radioButton.show();
|
||||
}
|
||||
}
|
||||
|
||||
setDefaultWidgetBehaviour(widget)
|
||||
|
Reference in New Issue
Block a user