Add openPopup(), closePopup() and togglePopup() functions to DBUS interface

This commit is contained in:
Grégory Soutadé 2020-11-12 10:42:11 +01:00
parent d3eb13994a
commit 6b1fe1dd2d
3 changed files with 79 additions and 4 deletions

View File

@ -58,6 +58,8 @@ extension emit one of the following signals :
* onRightClick * onRightClick
* onDblClick * onDblClick
* onRightDblClick * onRightDblClick
* onEnter
* onLeave
Other signals are available when extension is activated/deactivated : Other signals are available when extension is activated/deactivated :

View File

@ -9,6 +9,15 @@
<method name="deleteGroups"> <method name="deleteGroups">
<arg type="s" direction="in" /> <arg type="s" direction="in" />
</method> </method>
<method name="openPopup">
<arg type="s" direction="in" />
</method>
<method name="closePopup">
<arg type="s" direction="in" />
</method>
<method name="togglePopup">
<arg type="s" direction="in" />
</method>
<!-- Click events --> <!-- Click events -->
<signal name="onClick"> <signal name="onClick">
<arg type="s" direction="out" /> <arg type="s" direction="out" />
@ -22,6 +31,12 @@
<signal name="onRightDblClick"> <signal name="onRightDblClick">
<arg type="s" direction="out" /> <arg type="s" direction="out" />
</signal> </signal>
<signal name="onEnter">
<arg type="s" direction="out" />
</signal>
<signal name="onLeave">
<arg type="s" direction="out" />
</signal>
<!-- Activate/Deactivate signals --> <!-- Activate/Deactivate signals -->
<signal name="onActivate"> <signal name="onActivate">
</signal> </signal>

View File

@ -420,6 +420,18 @@ class MonitorWidget extends PanelMenu.Button {
this.onLeave = hash_get(item, 'on-leave', this.onLeave); this.onLeave = hash_get(item, 'on-leave', this.onLeave);
} }
openPopup() {
this.menu.open(true);
}
closePopup() {
this.menu.close();
}
togglePopup() {
this.menu.toggle();
}
destroy() { destroy() {
this.menu.close(); this.menu.close();
super.destroy(); super.destroy();
@ -498,6 +510,17 @@ class GenericMonitorDBUS {
return null; return null;
} }
_getItemFromFullName(fullname) {
let splitName = fullname.split('@');
if (splitName.length !== 2) {
log(`Invalid name ${item}`);
return null;
}
if (!this.monitor_groups.hasOwnProperty(splitName[1]))
return null;
return this._getItemFromGroup(this.monitor_groups[splitName[1]], splitName[0]);
}
_removeFromArray(array, value) { _removeFromArray(array, value) {
for(let i=0; i<array.length; i++) { for(let i=0; i<array.length; i++) {
if (array[i] === value) { if (array[i] === value) {
@ -573,13 +596,13 @@ class GenericMonitorDBUS {
for (let itemIndex in parameters['items']) { for (let itemIndex in parameters['items']) {
let itemName = parameters['items'][itemIndex]; let itemName = parameters['items'][itemIndex];
let fullName = itemName.split('@'); let splitName = itemName.split('@');
if (fullName.length !== 2) { if (splitName.length !== 2) {
log(`Invalid name ${itemName}`); log(`Invalid name ${itemName}`);
return false; return false;
} }
itemName = fullName[0]; itemName = splitName[0];
let groupName = fullName[1]; let groupName = splitName[1];
if (!this.monitor_groups.hasOwnProperty(groupName)) if (!this.monitor_groups.hasOwnProperty(groupName))
continue; continue;
let group = this.monitor_groups[groupName]; let group = this.monitor_groups[groupName];
@ -614,6 +637,41 @@ class GenericMonitorDBUS {
} }
} }
_popupFunction(str) {
let parameters = JSON.parse(str);
if (!parameters.hasOwnProperty('item')) {
log('No item defined');
return false;
}
let monitorWidget = this._getItemFromFullName(parameters['item']);
if (monitorWidget !== null)
return monitorWidget;
else
log(`Item ${str} not found`);
return null;
}
openPopup(str) {
let monitorWidget = this._popupFunction(str)
if (monitorWidget !== null)
monitorWidget.openPopup();
}
closePopup(str) {
let monitorWidget = this._popupFunction(str)
if (monitorWidget !== null)
monitorWidget.closePopup();
}
togglePopup(str) {
let monitorWidget = this._popupFunction(str)
if (monitorWidget !== null)
monitorWidget.togglePopup();
}
destructor() { destructor() {
this._dbusImpl.emit_signal('onDeactivate', null); this._dbusImpl.emit_signal('onDeactivate', null);
for (let groupIndex in this.monitor_groups) { for (let groupIndex in this.monitor_groups) {