Update code for Gnome Shell coding rules
This commit is contained in:
parent
11acefa076
commit
5d64f4e8db
673
extension.js
673
extension.js
@ -42,340 +42,341 @@ const GObject = imports.gi.GObject;
|
|||||||
const Pixbuf = imports.gi.GdkPixbuf;
|
const Pixbuf = imports.gi.GdkPixbuf;
|
||||||
const Cogl = imports.gi.Cogl;
|
const Cogl = imports.gi.Cogl;
|
||||||
|
|
||||||
function hash_get(hash, key, default_value) {
|
|
||||||
if (hash.hasOwnProperty(key))
|
|
||||||
return hash[key];
|
|
||||||
|
|
||||||
return default_value;
|
function hashGet(hash, key, defaultValue) {
|
||||||
|
if (hash.hasOwnProperty(key))
|
||||||
|
return hash[key];
|
||||||
|
|
||||||
|
return defaultValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
function log(message) {
|
function log(message) {
|
||||||
global.log('[GenericMontior]', message);
|
global.log('[GenericMontior]', message);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
var MyPopupMenuItem = GObject.registerClass({
|
var MyPopupMenuItem = GObject.registerClass({
|
||||||
GTypeName: "MyPopupMenuItem"
|
GTypeName: "MyPopupMenuItem"
|
||||||
},
|
},
|
||||||
class MyPopupMenuItem extends PopupMenu.PopupBaseMenuItem {
|
class MyPopupMenuItem extends PopupMenu.PopupBaseMenuItem {
|
||||||
_init(widgets, params) {
|
_init(widgets, params) {
|
||||||
super._init(params);
|
super._init(params);
|
||||||
|
|
||||||
this.box = new St.BoxLayout({ style_class: 'popup-combobox-item' });
|
this.box = new St.BoxLayout({ style_class: 'popup-combobox-item' });
|
||||||
this.box.set_vertical(true);
|
this.box.set_vertical(true);
|
||||||
|
|
||||||
for (let widgetIndex in widgets)
|
for (let widgetIndex in widgets)
|
||||||
this.box.add(widgets[widgetIndex]);
|
this.box.add(widgets[widgetIndex]);
|
||||||
|
|
||||||
this.add_child(this.box);
|
this.add_child(this.box);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
var MonitorWidget = GObject.registerClass({
|
var MonitorWidget = GObject.registerClass({
|
||||||
GTypeName: "MonitorWidget"
|
GTypeName: "MonitorWidget"
|
||||||
},
|
},
|
||||||
class MonitorWidget extends PanelMenu.Button {
|
class MonitorWidget extends PanelMenu.Button {
|
||||||
|
|
||||||
|
_init(item, group, dbus, position) {
|
||||||
_init(item, group, dbus, position) {
|
super._init(0.0);
|
||||||
super._init(0.0);
|
|
||||||
|
|
||||||
this.name = item['name'];
|
this.name = item['name'];
|
||||||
this.group = group;
|
this.group = group;
|
||||||
this.fullname = this.name + '@' + this.group;
|
this.fullname = this.name + '@' + this.group;
|
||||||
this.dbus = dbus;
|
this.dbus = dbus;
|
||||||
this.signals = {}
|
this.signals = {}
|
||||||
|
|
||||||
if (item.hasOwnProperty('icon'))
|
if (item.hasOwnProperty('icon'))
|
||||||
{
|
{
|
||||||
if (typeof(item['icon']) === "string")
|
if (typeof(item['icon']) === "string")
|
||||||
this.icon = this._createIconOld(item);
|
this.icon = this._createIconOld(item);
|
||||||
else
|
else
|
||||||
this.icon = this._createIcon(item['icon']);
|
this.icon = this._createIcon(item['icon']);
|
||||||
if (this.icon !== null) {
|
if (this.icon !== null) {
|
||||||
this._connectWidgetSignals(this.icon);
|
this._connectWidgetSignals(this.icon);
|
||||||
this.add_child(this.icon);
|
this.add_child(this.icon);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
this.icon = null;
|
this.icon = null;
|
||||||
|
|
||||||
if (item.hasOwnProperty('text'))
|
if (item.hasOwnProperty('text'))
|
||||||
{
|
{
|
||||||
if (typeof(item['text']) === "string")
|
if (typeof(item['text']) === "string")
|
||||||
this.widget = this._createTextOld(item);
|
this.widget = this._createTextOld(item);
|
||||||
else
|
else
|
||||||
this.widget = this._createText(item['text']);
|
this.widget = this._createText(item['text']);
|
||||||
|
|
||||||
if (this.widget !== null) {
|
if (this.widget !== null) {
|
||||||
this._connectWidgetSignals(this.widget);
|
this._connectWidgetSignals(this.widget);
|
||||||
this.add_child(this.widget);
|
this.add_child(this.widget);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
this.widget = null;
|
this.widget = null;
|
||||||
|
|
||||||
if (item.hasOwnProperty('popup'))
|
if (item.hasOwnProperty('popup'))
|
||||||
this._createPopup(item['popup']);
|
this._createPopup(item['popup']);
|
||||||
|
|
||||||
this.onClick = hash_get(item, 'on-click', '');
|
this.onClick = hashGet(item, 'on-click', '');
|
||||||
this.onDblClick = hash_get(item, 'on-dblclick', '');
|
this.onDblClick = hashGet(item, 'on-dblclick', '');
|
||||||
this.onRightClick = hash_get(item, 'on-rightclick', '');
|
this.onRightClick = hashGet(item, 'on-rightclick', '');
|
||||||
this.onRightDblClick = hash_get(item, 'on-rightdblclick', '');
|
this.onRightDblClick = hashGet(item, 'on-rightdblclick', '');
|
||||||
this.onEnter = hash_get(item, 'on-enter', '');
|
this.onEnter = hashGet(item, 'on-enter', '');
|
||||||
this.onLeave = hash_get(item, 'on-leave', '');
|
this.onLeave = hashGet(item, 'on-leave', '');
|
||||||
this.onScroll = hash_get(item, 'on-scroll', '');
|
this.onScroll = hashGet(item, 'on-scroll', '');
|
||||||
|
|
||||||
let box = hash_get(item, 'box', 'center');
|
let box = hashGet(item, 'box', 'center');
|
||||||
|
|
||||||
if (box === 'right' && position == -1)
|
if (box === 'right' && position == -1)
|
||||||
position = 0;
|
position = 0;
|
||||||
|
|
||||||
this.connect('style-changed', this._onStyleChanged.bind(this));
|
this.connect('style-changed', this._onStyleChanged.bind(this));
|
||||||
|
|
||||||
// Disable click event at PanelMenu.button level
|
// Disable click event at PanelMenu.button level
|
||||||
this.setSensitive(false);
|
this.setSensitive(false);
|
||||||
|
|
||||||
this.nbClicks = 0;
|
this.nbClicks = 0;
|
||||||
this.button = -1;
|
this.button = -1;
|
||||||
|
|
||||||
Main.panel.addToStatusArea(this.fullname, this, position, box);
|
Main.panel.addToStatusArea(this.fullname, this, position, box);
|
||||||
}
|
}
|
||||||
|
|
||||||
_onStyleChanged(actor) {
|
_onStyleChanged() {
|
||||||
// Force these values to avoid big spaces between each widgets
|
// Force these values to avoid big spaces between each widgets
|
||||||
this._minHPadding = 1;
|
this._minHPadding = 1;
|
||||||
this._natHPadding = 1;
|
this._natHPadding = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
_connectWidgetSignals(widget) {
|
_connectWidgetSignals(widget) {
|
||||||
this.signals[widget] = [];
|
this.signals[widget] = [];
|
||||||
let id;
|
let id;
|
||||||
id = widget.connect('enter-event', this._onEnter.bind(this));
|
id = widget.connect('enter-event', this._onEnter.bind(this));
|
||||||
this.signals[widget].push(id);
|
this.signals[widget].push(id);
|
||||||
id = widget.connect('leave-event', this._onLeave.bind(this));
|
id = widget.connect('leave-event', this._onLeave.bind(this));
|
||||||
this.signals[widget].push(id);
|
this.signals[widget].push(id);
|
||||||
id = widget.connect('scroll-event', this._onScroll.bind(this));
|
id = widget.connect('scroll-event', this._onScroll.bind(this));
|
||||||
this.signals[widget].push(id);
|
this.signals[widget].push(id);
|
||||||
widget.set_reactive(true);
|
widget.set_reactive(true);
|
||||||
id = widget.connect('button-release-event', Lang.bind(this, this._clicked));
|
id = widget.connect('button-release-event', Lang.bind(this, this._clicked));
|
||||||
this.signals[widget].push(id);
|
this.signals[widget].push(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
_disconnectWidgetSignals(widget) {
|
_disconnectWidgetSignals(widget) {
|
||||||
for(let idx in this.signals[widget])
|
for(let idx in this.signals[widget])
|
||||||
widget.disconnect(this.signals[widget][idx]);
|
widget.disconnect(this.signals[widget][idx]);
|
||||||
this.signals[widget] = null;
|
this.signals[widget] = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
_createPopup(item) {
|
_createPopup(item) {
|
||||||
if (!item.hasOwnProperty('items')) {
|
if (!item.hasOwnProperty('items')) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
let widgets = [];
|
let widgets = [];
|
||||||
for (let itemIndex in item['items']) {
|
for (let itemIndex in item['items']) {
|
||||||
let widget = null;
|
let widget = null;
|
||||||
let widgetDict = item['items'][itemIndex];
|
let widgetDict = item['items'][itemIndex];
|
||||||
|
|
||||||
if (widgetDict.hasOwnProperty('text'))
|
if (widgetDict.hasOwnProperty('text'))
|
||||||
widget = this._createText(widgetDict['text']);
|
widget = this._createText(widgetDict['text']);
|
||||||
else if (widgetDict.hasOwnProperty('picture'))
|
else if (widgetDict.hasOwnProperty('picture'))
|
||||||
widget = this._createPicture(widgetDict['picture']);
|
widget = this._createPicture(widgetDict['picture']);
|
||||||
|
|
||||||
if (widget !== null)
|
if (widget !== null)
|
||||||
widgets.push(widget);
|
widgets.push(widget);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (widgets.length > 0) {
|
if (widgets.length > 0) {
|
||||||
this.menuItem = new MyPopupMenuItem(widgets, {});
|
this.menuItem = new MyPopupMenuItem(widgets, {});
|
||||||
this.menu.addMenuItem(this.menuItem);
|
this.menu.addMenuItem(this.menuItem);
|
||||||
this.menu.setSensitive(false);
|
this.menu.setSensitive(false);
|
||||||
return this.menuItem;
|
return this.menuItem;
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
_createTextOld(item) {
|
_createTextOld(item) {
|
||||||
var item_values = {};
|
var itemValues = {};
|
||||||
item_values = {'text':item['text']};
|
itemValues = { 'text':item['text'] };
|
||||||
if (item.hasOwnProperty('style'))
|
if (item.hasOwnProperty('style'))
|
||||||
item_values['style'] = item['style'];
|
itemValues['style'] = item['style'];
|
||||||
return this._createText(item_values);
|
return this._createText(itemValues);
|
||||||
}
|
}
|
||||||
|
|
||||||
_createText(item) {
|
_createText(item) {
|
||||||
if (!item.hasOwnProperty('text')) {
|
if (!item.hasOwnProperty('text')) {
|
||||||
log("Text must have a \'text\' value");
|
log("Text must have a 'text' value");
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
let style = hash_get(item, 'style', '');
|
let style = hashGet(item, 'style', '');
|
||||||
|
|
||||||
this.textProperties = item;
|
this.textProperties = item;
|
||||||
|
|
||||||
if (item['text'] === '') {
|
if (item['text'] === '') {
|
||||||
return null;
|
return null;
|
||||||
} else {
|
} else {
|
||||||
let widget = new St.Button({ label: item['text'] });
|
let widget = new St.Button({ label: item['text'] });
|
||||||
widget.set_style(style);
|
widget.set_style(style);
|
||||||
|
|
||||||
return widget;
|
return widget;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
_createIconOld(item) {
|
_createIconOld(item) {
|
||||||
var item_values = {};
|
var itemValues = {};
|
||||||
item_values = {'path':item['icon']};
|
itemValues = { 'path':item['icon'] };
|
||||||
if (item.hasOwnProperty('iconStyle'))
|
if (item.hasOwnProperty('iconStyle'))
|
||||||
item_values['style'] = item['iconStyle'];
|
itemValues['style'] = item['iconStyle'];
|
||||||
return this._createIcon(item_values);
|
return this._createIcon(itemValues);
|
||||||
}
|
}
|
||||||
|
|
||||||
_createIcon(item) {
|
_createIcon(item) {
|
||||||
if (!item.hasOwnProperty('path')) {
|
if (!item.hasOwnProperty('path')) {
|
||||||
log("Icon must have a \'path\' value");
|
log("Icon must have a 'path' value");
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
let style = hash_get(item, 'style', '');
|
let style = hashGet(item, 'style', '');
|
||||||
|
|
||||||
this.iconProperties = item;
|
this.iconProperties = item;
|
||||||
|
|
||||||
if (item['path'] === '') {
|
if (item['path'] === '') {
|
||||||
return null;
|
return null;
|
||||||
} else {
|
} else {
|
||||||
let gicon = Gio.icon_new_for_string(item['path']);
|
let gicon = Gio.icon_new_for_string(item['path']);
|
||||||
gicon = new St.Icon({ gicon });
|
gicon = new St.Icon({ gicon });
|
||||||
gicon.set_style(style);
|
gicon.set_style(style);
|
||||||
|
|
||||||
return gicon;
|
return gicon;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
_createPicture(item) {
|
_createPicture(item) {
|
||||||
if (!item.hasOwnProperty('path')) {
|
if (!item.hasOwnProperty('path')) {
|
||||||
log("Picture must have a \'path\' value");
|
log("Picture must have a 'path' value");
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
let width = hash_get(item, 'width', -1);
|
let width = hashGet(item, 'width', -1);
|
||||||
let height = hash_get(item, 'height', -1);
|
let height = hashGet(item, 'height', -1);
|
||||||
|
|
||||||
if (typeof(width) === "string")
|
if (typeof(width) === "string")
|
||||||
width = parseInt(width, 10);
|
width = parseInt(width, 10);
|
||||||
|
|
||||||
if (typeof(heigth) === "string")
|
if (typeof(height) === "string")
|
||||||
heigth = parseInt(heigth, 10);
|
height = parseInt(height, 10);
|
||||||
|
|
||||||
let img = new Clutter.Image();
|
let img = new Clutter.Image();
|
||||||
let initial_pixbuf = Pixbuf.Pixbuf.new_from_file(item['path']);
|
let initialPixbuf = Pixbuf.Pixbuf.new_from_file(item['path']);
|
||||||
img.set_data(initial_pixbuf.get_pixels(),
|
img.set_data(initialPixbuf.get_pixels(),
|
||||||
initial_pixbuf.get_has_alpha() ? Cogl.PixelFormat.RGBA_8888
|
initialPixbuf.get_has_alpha() ? Cogl.PixelFormat.RGBA_8888
|
||||||
: Cogl.PixelFormat.RGB_888,
|
: Cogl.PixelFormat.RGB_888,
|
||||||
initial_pixbuf.get_width(),
|
initialPixbuf.get_width(),
|
||||||
initial_pixbuf.get_height(),
|
initialPixbuf.get_height(),
|
||||||
initial_pixbuf.get_rowstride());
|
initialPixbuf.get_rowstride());
|
||||||
let picture = new Clutter.Actor();
|
let picture = new Clutter.Actor();
|
||||||
picture.set_content(img);
|
picture.set_content(img);
|
||||||
picture.set_size((width != -1)?width:initial_pixbuf.get_width(),
|
picture.set_size((width != -1)?width:initialPixbuf.get_width(),
|
||||||
(height != -1)?height:initial_pixbuf.get_height());
|
(height != -1)?height:initialPixbuf.get_height());
|
||||||
|
|
||||||
// Pack it in a box to avoid picture resize
|
// Pack it in a box to avoid picture resize
|
||||||
let box = new St.BoxLayout({});
|
let box = new St.BoxLayout({});
|
||||||
box.add_child(picture);
|
box.add_child(picture);
|
||||||
|
|
||||||
return box;
|
return box;
|
||||||
}
|
}
|
||||||
|
|
||||||
_manageEventAction(action) {
|
_manageEventAction(action) {
|
||||||
if (action === 'open-popup')
|
if (action === 'open-popup')
|
||||||
this.menu.open(true);
|
this.menu.open(true);
|
||||||
else if (action === 'close-popup')
|
else if (action === 'close-popup')
|
||||||
this.menu.close();
|
this.menu.close();
|
||||||
else if (action === 'toggle-popup')
|
else if (action === 'toggle-popup')
|
||||||
this.menu.toggle();
|
this.menu.toggle();
|
||||||
else if (action == 'delete')
|
else if (action == 'delete')
|
||||||
this.dbus.deleteItem(this, this.group);
|
this.dbus.deleteItem(this, this.group);
|
||||||
|
|
||||||
return Clutter.EVENT_PROPAGATE;
|
return Clutter.EVENT_PROPAGATE;
|
||||||
}
|
}
|
||||||
|
|
||||||
_manageLeaveEvent() {
|
_manageLeaveEvent() {
|
||||||
this._manageEventAction(this.onLeave);
|
this._manageEventAction(this.onLeave);
|
||||||
}
|
}
|
||||||
|
|
||||||
_doClickCallback() {
|
_doClickCallback() {
|
||||||
let right = '';
|
let right = '';
|
||||||
let nbClicks = '';
|
let nbClicks = '';
|
||||||
if (this.button == 3)
|
if (this.button == 3)
|
||||||
right = 'Right';
|
right = 'Right';
|
||||||
if (this.nbClicks > 1)
|
if (this.nbClicks > 1)
|
||||||
nbClicks = 'Dbl';
|
nbClicks = 'Dbl';
|
||||||
let signalName = 'on' + right + nbClicks + 'Click';
|
let signalName = 'on' + right + nbClicks + 'Click';
|
||||||
|
|
||||||
let action = 'signal';
|
let action = 'signal';
|
||||||
switch(signalName) {
|
switch(signalName) {
|
||||||
case 'onClick': action = this.onClick; break;
|
case 'onClick': action = this.onClick; break;
|
||||||
case 'onDblClick': action = this.onDblClick; break;
|
case 'onDblClick': action = this.onDblClick; break;
|
||||||
case 'onRightClick': action = this.onRightClick; break;
|
case 'onRightClick': action = this.onRightClick; break;
|
||||||
case 'onRightDblClick': action = this.onRightDblClick; break;
|
case 'onRightDblClick': action = this.onRightDblClick; break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (action === 'signal')
|
if (action === 'signal')
|
||||||
this.dbus.emit_signal(signalName, this.fullname);
|
this.dbus.emitSignal(signalName, this.fullname);
|
||||||
else
|
else
|
||||||
this._manageEventAction(action);
|
this._manageEventAction(action);
|
||||||
this.nbClicks = 0;
|
this.nbClicks = 0;
|
||||||
this.button = -1;
|
this.button = -1;
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
_clicked(actor, event) {
|
_clicked(actor, event) {
|
||||||
if (event.get_button() == this.button) {
|
if (event.get_button() == this.button) {
|
||||||
this.nbClicks++;
|
this.nbClicks++;
|
||||||
} else {
|
} else {
|
||||||
this.button = event.get_button();
|
this.button = event.get_button();
|
||||||
this.nbClicks = 1;
|
this.nbClicks = 1;
|
||||||
|
|
||||||
Mainloop.timeout_add(this.dbus.ClutterSettings['double-click-time'],
|
Mainloop.timeout_add(this.dbus.ClutterSettings['double-click-time'],
|
||||||
Lang.bind(this, this._doClickCallback));
|
Lang.bind(this, this._doClickCallback));
|
||||||
}
|
}
|
||||||
|
|
||||||
return Clutter.EVENT_PROPAGATE;
|
return Clutter.EVENT_PROPAGATE;
|
||||||
}
|
}
|
||||||
|
|
||||||
_onEnter(actor, event) {
|
_onEnter(/*actor, event*/) {
|
||||||
if (this.onEnter === 'signal')
|
if (this.onEnter === 'signal')
|
||||||
this.dbus.emit_signal('onEnter', this.fullname);
|
this.dbus.emitSignal('onEnter', this.fullname);
|
||||||
else
|
else
|
||||||
return this._manageEventAction(this.onEnter);
|
return this._manageEventAction(this.onEnter);
|
||||||
|
|
||||||
return Clutter.EVENT_PROPAGATE;
|
return Clutter.EVENT_PROPAGATE;
|
||||||
}
|
}
|
||||||
|
|
||||||
_onLeave(actor, event) {
|
_onLeave(/*actor, event*/) {
|
||||||
if (this.onLeave === 'signal')
|
if (this.onLeave === 'signal')
|
||||||
this.dbus.emit_signal('onLeave', this.fullname);
|
this.dbus.emitSignal('onLeave', this.fullname);
|
||||||
else
|
else
|
||||||
return this._manageEventAction(this.onEnter);
|
return this._manageEventAction(this.onEnter);
|
||||||
|
|
||||||
return Clutter.EVENT_PROPAGATE;
|
return Clutter.EVENT_PROPAGATE;
|
||||||
}
|
}
|
||||||
|
|
||||||
_onScroll(actor, event) {
|
_onScroll(/*actor, event*/) {
|
||||||
if (this.onScroll === 'signal') {
|
if (this.onScroll === 'signal') {
|
||||||
let direction = event.get_scroll_direction ();
|
let direction = event.get_scroll_direction ();
|
||||||
if (direction == Clutter.ScrollDirection.UP)
|
if (direction == Clutter.ScrollDirection.UP)
|
||||||
this.dbus.emit_signal('onScrollUp', this.fullname);
|
this.dbus.emitSignal('onScrollUp', this.fullname);
|
||||||
else if (direction == Clutter.ScrollDirection.DOWN)
|
else if (direction == Clutter.ScrollDirection.DOWN)
|
||||||
this.dbus.emit_signal('onScrollDown', this.fullname);
|
this.dbus.emitSignal('onScrollDown', this.fullname);
|
||||||
} else
|
} else
|
||||||
return this._manageEventAction(this.onEnter);
|
return this._manageEventAction(this.onEnter);
|
||||||
|
|
||||||
return Clutter.EVENT_PROPAGATE;
|
return Clutter.EVENT_PROPAGATE;
|
||||||
}
|
}
|
||||||
|
|
||||||
update(item) {
|
update(item) {
|
||||||
@ -383,107 +384,107 @@ class MonitorWidget extends PanelMenu.Button {
|
|||||||
let prevIcon = this.icon;
|
let prevIcon = this.icon;
|
||||||
|
|
||||||
if (item.hasOwnProperty('text'))
|
if (item.hasOwnProperty('text'))
|
||||||
{
|
{
|
||||||
let text = '';
|
let text = '';
|
||||||
let style = '';
|
let style = '';
|
||||||
if (typeof(item['text']) === "string") {
|
if (typeof(item['text']) === "string") {
|
||||||
text = hash_get(item, 'text', '');
|
text = hashGet(item, 'text', '');
|
||||||
style = hash_get(item, 'style', '');
|
style = hashGet(item, 'style', '');
|
||||||
} else {
|
} else {
|
||||||
let textValues = item['text'];
|
let textValues = item['text'];
|
||||||
text = hash_get(textValues, 'text', '');
|
text = hashGet(textValues, 'text', '');
|
||||||
style = hash_get(textValues, 'style', '');
|
style = hashGet(textValues, 'style', '');
|
||||||
}
|
}
|
||||||
|
|
||||||
if (text !== '') {
|
if (text !== '') {
|
||||||
if (!this.widget) {
|
if (!this.widget) {
|
||||||
if (typeof(item['text']) === "string")
|
if (typeof(item['text']) === "string")
|
||||||
this.widget = this._createTextOld(item);
|
this.widget = this._createTextOld(item);
|
||||||
else
|
else
|
||||||
this.widget = this._createText(item['text']);
|
this.widget = this._createText(item['text']);
|
||||||
this.insert_child_above(this.widget, this.icon);
|
this.insert_child_above(this.widget, this.icon);
|
||||||
} else {
|
} else {
|
||||||
this.widget.label = text;
|
this.widget.label = text;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (style !== '' && this.widget) {
|
if (style !== '' && this.widget) {
|
||||||
this.widget.set_style(style);
|
this.widget.set_style(style);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (item.hasOwnProperty('icon'))
|
if (item.hasOwnProperty('icon'))
|
||||||
{
|
{
|
||||||
let icon = '';
|
let icon = '';
|
||||||
let style = '';
|
let style = '';
|
||||||
if (typeof(item['icon']) === "string") {
|
if (typeof(item['icon']) === "string") {
|
||||||
icon = hash_get(item, 'icon', '');
|
icon = hashGet(item, 'icon', '');
|
||||||
style = hash_get(item, 'iconStyle', '');
|
style = hashGet(item, 'iconStyle', '');
|
||||||
} else {
|
} else {
|
||||||
let iconValues = item['icon'];
|
let iconValues = item['icon'];
|
||||||
icon = hash_get(iconValues, 'path', '');
|
icon = hashGet(iconValues, 'path', '');
|
||||||
style = hash_get(textValues, 'style', '');
|
style = hashGet(iconValues, 'style', '');
|
||||||
}
|
}
|
||||||
|
|
||||||
if (icon !== '') {
|
if (icon !== '') {
|
||||||
if (typeof(item['icon']) === "string")
|
if (typeof(item['icon']) === "string")
|
||||||
this.icon = this._createIconOld(item);
|
this.icon = this._createIconOld(item);
|
||||||
else
|
else
|
||||||
this.icon = this._createIcon(item['icon']);
|
this.icon = this._createIcon(item['icon']);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (prevIcon) {
|
if (prevIcon) {
|
||||||
this._disconnectWidgetSignals(prevIcon);
|
this._disconnectWidgetSignals(prevIcon);
|
||||||
this.insert_child_above(this.icon, prevIcon);
|
this.insert_child_above(this.icon, prevIcon);
|
||||||
this.remove_child(prevIcon);
|
this.remove_child(prevIcon);
|
||||||
//delete prevIcon;
|
//delete prevIcon;
|
||||||
} else
|
} else
|
||||||
this.insert_child_before(this.icon, prevWidget);
|
this.insert_child_before(this.icon, prevWidget);
|
||||||
|
|
||||||
if (style !== '' && this.icon) {
|
if (style !== '' && this.icon) {
|
||||||
this.icon.set_style(style);
|
this.icon.set_style(style);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (item.hasOwnProperty('popup'))
|
if (item.hasOwnProperty('popup'))
|
||||||
{
|
{
|
||||||
let menuOpen = this.menu.isOpen;
|
let menuOpen = this.menu.isOpen;
|
||||||
if (this.menuItem) {
|
if (this.menuItem) {
|
||||||
if (menuOpen)
|
if (menuOpen)
|
||||||
this.menu.close();
|
this.menu.close();
|
||||||
this.menu.removeAll();
|
this.menu.removeAll();
|
||||||
//delete this.menuItem;
|
//delete this.menuItem;
|
||||||
}
|
}
|
||||||
|
|
||||||
let popup = this._createPopup(item['popup']);
|
let popup = this._createPopup(item['popup']);
|
||||||
if (popup !== null && menuOpen)
|
if (popup !== null && menuOpen)
|
||||||
this.menu.open(true);
|
this.menu.open(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
this.onClick = hash_get(item, 'on-click', this.onClick);
|
this.onClick = hashGet(item, 'on-click', this.onClick);
|
||||||
this.onDblClick = hash_get(item, 'on-dblclick', this.onDblClick);
|
this.onDblClick = hashGet(item, 'on-dblclick', this.onDblClick);
|
||||||
this.onRightClick = hash_get(item, 'on-rightclick', this.onRightClick);
|
this.onRightClick = hashGet(item, 'on-rightclick', this.onRightClick);
|
||||||
this.onRightDblClick = hash_get(item, 'on-rightdblclick', this.onRightDblClick);
|
this.onRightDblClick = hashGet(item, 'on-rightdblclick', this.onRightDblClick);
|
||||||
this.onEnter = hash_get(item, 'on-enter', this.onEnter);
|
this.onEnter = hashGet(item, 'on-enter', this.onEnter);
|
||||||
this.onLeave = hash_get(item, 'on-leave', this.onLeave);
|
this.onLeave = hashGet(item, 'on-leave', this.onLeave);
|
||||||
this.onScroll = hash_get(item, 'on-scroll', this.onScroll);
|
this.onScroll = hashGet(item, 'on-scroll', this.onScroll);
|
||||||
}
|
}
|
||||||
|
|
||||||
openPopup() {
|
openPopup() {
|
||||||
this.menu.open(true);
|
this.menu.open(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
closePopup() {
|
closePopup() {
|
||||||
this.menu.close();
|
this.menu.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
togglePopup() {
|
togglePopup() {
|
||||||
this.menu.toggle();
|
this.menu.toggle();
|
||||||
}
|
}
|
||||||
|
|
||||||
destroy() {
|
destroy() {
|
||||||
this.menu.close();
|
this.menu.close();
|
||||||
super.destroy();
|
super.destroy();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -523,30 +524,30 @@ class GenericMonitorDBUS {
|
|||||||
this._dbusImpl.emit_signal('onActivate', null);
|
this._dbusImpl.emit_signal('onActivate', null);
|
||||||
}
|
}
|
||||||
|
|
||||||
emit_signal(name, value) {
|
emitSignal(name, value) {
|
||||||
this._dbusImpl.emit_signal(name, GLib.Variant.new('(s)',[value]));
|
this._dbusImpl.emit_signal(name, GLib.Variant.new('(s)',[value]));
|
||||||
}
|
}
|
||||||
|
|
||||||
_checkParameters(parameters) {
|
_checkParameters(parameters) {
|
||||||
if (!parameters.hasOwnProperty('group')) {
|
if (!parameters.hasOwnProperty('group')) {
|
||||||
log('No group defined');
|
log('No group defined');
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!parameters.hasOwnProperty('items')) {
|
if (!parameters.hasOwnProperty('items')) {
|
||||||
log('No items defined');
|
log('No items defined');
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (let itemIndex in parameters['items']) {
|
for (let itemIndex in parameters['items']) {
|
||||||
let item = parameters['items'][itemIndex];
|
let item = parameters['items'][itemIndex];
|
||||||
if (!item.hasOwnProperty('name')) {
|
if (!item.hasOwnProperty('name')) {
|
||||||
log('No name defined for item');
|
log('No name defined for item');
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
_getItemFromGroup(group, name) {
|
_getItemFromGroup(group, name) {
|
||||||
@ -560,14 +561,14 @@ class GenericMonitorDBUS {
|
|||||||
}
|
}
|
||||||
|
|
||||||
_getItemFromFullName(fullname) {
|
_getItemFromFullName(fullname) {
|
||||||
let splitName = fullname.split('@');
|
let splitName = fullname.split('@');
|
||||||
if (splitName.length !== 2) {
|
if (splitName.length !== 2) {
|
||||||
log(`Invalid name ${item}`);
|
log(`Invalid name ${fullname}`);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
if (!this.monitor_groups.hasOwnProperty(splitName[1]))
|
if (!this.monitor_groups.hasOwnProperty(splitName[1]))
|
||||||
return null;
|
return null;
|
||||||
return this._getItemFromGroup(this.monitor_groups[splitName[1]], splitName[0]);
|
return this._getItemFromGroup(this.monitor_groups[splitName[1]], splitName[0]);
|
||||||
}
|
}
|
||||||
|
|
||||||
_removeFromArray(array, value) {
|
_removeFromArray(array, value) {
|
||||||
@ -585,7 +586,7 @@ class GenericMonitorDBUS {
|
|||||||
notify(str) {
|
notify(str) {
|
||||||
let parameters = JSON.parse(str);
|
let parameters = JSON.parse(str);
|
||||||
if (!this._checkParameters(parameters))
|
if (!this._checkParameters(parameters))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
let groupName = parameters['group'];
|
let groupName = parameters['group'];
|
||||||
let group;
|
let group;
|
||||||
@ -602,21 +603,21 @@ class GenericMonitorDBUS {
|
|||||||
|
|
||||||
// New widget
|
// New widget
|
||||||
if (monitorWidget === null) {
|
if (monitorWidget === null) {
|
||||||
let position = group.length - 1;
|
let position = group.length - 1;
|
||||||
// Find real position
|
// Find real position
|
||||||
if (position != -1) {
|
if (position != -1) {
|
||||||
let lastWidget = group[position].container;
|
let lastWidget = group[position].container;
|
||||||
let childrens = lastWidget.get_parent().get_children();
|
let childrens = lastWidget.get_parent().get_children();
|
||||||
for(;position < childrens.length; position++)
|
for(;position < childrens.length; position++)
|
||||||
{
|
{
|
||||||
if (childrens[position] == lastWidget) {
|
if (childrens[position] == lastWidget) {
|
||||||
position++;
|
position++;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (position >= childrens.length)
|
if (position >= childrens.length)
|
||||||
position = -1;
|
position = -1;
|
||||||
}
|
}
|
||||||
monitorWidget = new MonitorWidget(item, groupName, this, position);
|
monitorWidget = new MonitorWidget(item, groupName, this, position);
|
||||||
group.push(monitorWidget);
|
group.push(monitorWidget);
|
||||||
} else {
|
} else {
|
||||||
@ -628,7 +629,7 @@ class GenericMonitorDBUS {
|
|||||||
deleteItem(item, groupName) {
|
deleteItem(item, groupName) {
|
||||||
let group = this.monitor_groups[groupName];
|
let group = this.monitor_groups[groupName];
|
||||||
group = this._removeFromArray(group, item);
|
group = this._removeFromArray(group, item);
|
||||||
item.destroy();
|
item.destroy();
|
||||||
if (group.length === 0)
|
if (group.length === 0)
|
||||||
delete this.monitor_groups[groupName];
|
delete this.monitor_groups[groupName];
|
||||||
else
|
else
|
||||||
@ -639,17 +640,17 @@ class GenericMonitorDBUS {
|
|||||||
let parameters = JSON.parse(str);
|
let parameters = JSON.parse(str);
|
||||||
|
|
||||||
if (!parameters.hasOwnProperty('items')) {
|
if (!parameters.hasOwnProperty('items')) {
|
||||||
log('No items defined');
|
log('No items defined');
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (let itemIndex in parameters['items']) {
|
for (let itemIndex in parameters['items']) {
|
||||||
let itemName = parameters['items'][itemIndex];
|
let itemName = parameters['items'][itemIndex];
|
||||||
let splitName = itemName.split('@');
|
let splitName = itemName.split('@');
|
||||||
if (splitName.length !== 2) {
|
if (splitName.length !== 2) {
|
||||||
log(`Invalid name ${itemName}`);
|
log(`Invalid name ${itemName}`);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
itemName = splitName[0];
|
itemName = splitName[0];
|
||||||
let groupName = splitName[1];
|
let groupName = splitName[1];
|
||||||
if (!this.monitor_groups.hasOwnProperty(groupName))
|
if (!this.monitor_groups.hasOwnProperty(groupName))
|
||||||
@ -666,9 +667,9 @@ class GenericMonitorDBUS {
|
|||||||
let parameters = JSON.parse(str);
|
let parameters = JSON.parse(str);
|
||||||
|
|
||||||
if (!parameters.hasOwnProperty('groups')) {
|
if (!parameters.hasOwnProperty('groups')) {
|
||||||
log('No groups defined');
|
log('No groups defined');
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
let groupsToDelete = [];
|
let groupsToDelete = [];
|
||||||
for (let groupIndex in parameters['groups']) {
|
for (let groupIndex in parameters['groups']) {
|
||||||
@ -677,7 +678,7 @@ class GenericMonitorDBUS {
|
|||||||
continue;
|
continue;
|
||||||
let group = this.monitor_groups[groupName];
|
let group = this.monitor_groups[groupName];
|
||||||
for (let itemIndex in group)
|
for (let itemIndex in group)
|
||||||
group[itemIndex].destroy();
|
group[itemIndex].destroy();
|
||||||
groupsToDelete.push(groupName);
|
groupsToDelete.push(groupName);
|
||||||
}
|
}
|
||||||
for (let groupDeleteIndex in groupsToDelete) {
|
for (let groupDeleteIndex in groupsToDelete) {
|
||||||
@ -690,35 +691,35 @@ class GenericMonitorDBUS {
|
|||||||
let parameters = JSON.parse(str);
|
let parameters = JSON.parse(str);
|
||||||
|
|
||||||
if (!parameters.hasOwnProperty('item')) {
|
if (!parameters.hasOwnProperty('item')) {
|
||||||
log('No item defined');
|
log('No item defined');
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
let monitorWidget = this._getItemFromFullName(parameters['item']);
|
let monitorWidget = this._getItemFromFullName(parameters['item']);
|
||||||
if (monitorWidget !== null)
|
if (monitorWidget !== null)
|
||||||
return monitorWidget;
|
return monitorWidget;
|
||||||
else
|
else
|
||||||
log(`Item ${str} not found`);
|
log(`Item ${str} not found`);
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
openPopup(str) {
|
openPopup(str) {
|
||||||
let monitorWidget = this._popupFunction(str)
|
let monitorWidget = this._popupFunction(str)
|
||||||
if (monitorWidget !== null)
|
if (monitorWidget !== null)
|
||||||
monitorWidget.openPopup();
|
monitorWidget.openPopup();
|
||||||
}
|
}
|
||||||
|
|
||||||
closePopup(str) {
|
closePopup(str) {
|
||||||
let monitorWidget = this._popupFunction(str)
|
let monitorWidget = this._popupFunction(str)
|
||||||
if (monitorWidget !== null)
|
if (monitorWidget !== null)
|
||||||
monitorWidget.closePopup();
|
monitorWidget.closePopup();
|
||||||
}
|
}
|
||||||
|
|
||||||
togglePopup(str) {
|
togglePopup(str) {
|
||||||
let monitorWidget = this._popupFunction(str)
|
let monitorWidget = this._popupFunction(str)
|
||||||
if (monitorWidget !== null)
|
if (monitorWidget !== null)
|
||||||
monitorWidget.togglePopup();
|
monitorWidget.togglePopup();
|
||||||
}
|
}
|
||||||
|
|
||||||
destructor() {
|
destructor() {
|
||||||
@ -726,7 +727,7 @@ class GenericMonitorDBUS {
|
|||||||
for (let groupIndex in this.monitor_groups) {
|
for (let groupIndex in this.monitor_groups) {
|
||||||
let group = this.monitor_groups[groupIndex];
|
let group = this.monitor_groups[groupIndex];
|
||||||
for (let itemIndex in group)
|
for (let itemIndex in group)
|
||||||
group[itemIndex].destroy();
|
group[itemIndex].destroy();
|
||||||
}
|
}
|
||||||
this.monitor_groups = {};
|
this.monitor_groups = {};
|
||||||
this._dbusImpl.unexport();
|
this._dbusImpl.unexport();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user