Update code for Gnome Shell coding rules
This commit is contained in:
parent
11acefa076
commit
5d64f4e8db
125
extension.js
125
extension.js
|
@ -42,17 +42,19 @@ const GObject = imports.gi.GObject;
|
|||
const Pixbuf = imports.gi.GdkPixbuf;
|
||||
const Cogl = imports.gi.Cogl;
|
||||
|
||||
function hash_get(hash, key, default_value) {
|
||||
|
||||
function hashGet(hash, key, defaultValue) {
|
||||
if (hash.hasOwnProperty(key))
|
||||
return hash[key];
|
||||
|
||||
return default_value;
|
||||
return defaultValue;
|
||||
}
|
||||
|
||||
function log(message) {
|
||||
global.log('[GenericMontior]', message);
|
||||
}
|
||||
|
||||
|
||||
var MyPopupMenuItem = GObject.registerClass({
|
||||
GTypeName: "MyPopupMenuItem"
|
||||
},
|
||||
|
@ -76,7 +78,6 @@ var MonitorWidget = GObject.registerClass({
|
|||
},
|
||||
class MonitorWidget extends PanelMenu.Button {
|
||||
|
||||
|
||||
_init(item, group, dbus, position) {
|
||||
super._init(0.0);
|
||||
|
||||
|
@ -118,15 +119,15 @@ class MonitorWidget extends PanelMenu.Button {
|
|||
if (item.hasOwnProperty('popup'))
|
||||
this._createPopup(item['popup']);
|
||||
|
||||
this.onClick = hash_get(item, 'on-click', '');
|
||||
this.onDblClick = hash_get(item, 'on-dblclick', '');
|
||||
this.onRightClick = hash_get(item, 'on-rightclick', '');
|
||||
this.onRightDblClick = hash_get(item, 'on-rightdblclick', '');
|
||||
this.onEnter = hash_get(item, 'on-enter', '');
|
||||
this.onLeave = hash_get(item, 'on-leave', '');
|
||||
this.onScroll = hash_get(item, 'on-scroll', '');
|
||||
this.onClick = hashGet(item, 'on-click', '');
|
||||
this.onDblClick = hashGet(item, 'on-dblclick', '');
|
||||
this.onRightClick = hashGet(item, 'on-rightclick', '');
|
||||
this.onRightDblClick = hashGet(item, 'on-rightdblclick', '');
|
||||
this.onEnter = hashGet(item, 'on-enter', '');
|
||||
this.onLeave = hashGet(item, 'on-leave', '');
|
||||
this.onScroll = hashGet(item, 'on-scroll', '');
|
||||
|
||||
let box = hash_get(item, 'box', 'center');
|
||||
let box = hashGet(item, 'box', 'center');
|
||||
|
||||
if (box === 'right' && position == -1)
|
||||
position = 0;
|
||||
|
@ -142,7 +143,7 @@ class MonitorWidget extends PanelMenu.Button {
|
|||
Main.panel.addToStatusArea(this.fullname, this, position, box);
|
||||
}
|
||||
|
||||
_onStyleChanged(actor) {
|
||||
_onStyleChanged() {
|
||||
// Force these values to avoid big spaces between each widgets
|
||||
this._minHPadding = 1;
|
||||
this._natHPadding = 1;
|
||||
|
@ -198,20 +199,20 @@ class MonitorWidget extends PanelMenu.Button {
|
|||
}
|
||||
|
||||
_createTextOld(item) {
|
||||
var item_values = {};
|
||||
item_values = {'text':item['text']};
|
||||
var itemValues = {};
|
||||
itemValues = { 'text':item['text'] };
|
||||
if (item.hasOwnProperty('style'))
|
||||
item_values['style'] = item['style'];
|
||||
return this._createText(item_values);
|
||||
itemValues['style'] = item['style'];
|
||||
return this._createText(itemValues);
|
||||
}
|
||||
|
||||
_createText(item) {
|
||||
if (!item.hasOwnProperty('text')) {
|
||||
log("Text must have a \'text\' value");
|
||||
log("Text must have a 'text' value");
|
||||
return null;
|
||||
}
|
||||
|
||||
let style = hash_get(item, 'style', '');
|
||||
let style = hashGet(item, 'style', '');
|
||||
|
||||
this.textProperties = item;
|
||||
|
||||
|
@ -226,20 +227,20 @@ class MonitorWidget extends PanelMenu.Button {
|
|||
}
|
||||
|
||||
_createIconOld(item) {
|
||||
var item_values = {};
|
||||
item_values = {'path':item['icon']};
|
||||
var itemValues = {};
|
||||
itemValues = { 'path':item['icon'] };
|
||||
if (item.hasOwnProperty('iconStyle'))
|
||||
item_values['style'] = item['iconStyle'];
|
||||
return this._createIcon(item_values);
|
||||
itemValues['style'] = item['iconStyle'];
|
||||
return this._createIcon(itemValues);
|
||||
}
|
||||
|
||||
_createIcon(item) {
|
||||
if (!item.hasOwnProperty('path')) {
|
||||
log("Icon must have a \'path\' value");
|
||||
log("Icon must have a 'path' value");
|
||||
return null;
|
||||
}
|
||||
|
||||
let style = hash_get(item, 'style', '');
|
||||
let style = hashGet(item, 'style', '');
|
||||
|
||||
this.iconProperties = item;
|
||||
|
||||
|
@ -256,31 +257,31 @@ class MonitorWidget extends PanelMenu.Button {
|
|||
|
||||
_createPicture(item) {
|
||||
if (!item.hasOwnProperty('path')) {
|
||||
log("Picture must have a \'path\' value");
|
||||
log("Picture must have a 'path' value");
|
||||
return null;
|
||||
}
|
||||
|
||||
let width = hash_get(item, 'width', -1);
|
||||
let height = hash_get(item, 'height', -1);
|
||||
let width = hashGet(item, 'width', -1);
|
||||
let height = hashGet(item, 'height', -1);
|
||||
|
||||
if (typeof(width) === "string")
|
||||
width = parseInt(width, 10);
|
||||
|
||||
if (typeof(heigth) === "string")
|
||||
heigth = parseInt(heigth, 10);
|
||||
if (typeof(height) === "string")
|
||||
height = parseInt(height, 10);
|
||||
|
||||
let img = new Clutter.Image();
|
||||
let initial_pixbuf = Pixbuf.Pixbuf.new_from_file(item['path']);
|
||||
img.set_data(initial_pixbuf.get_pixels(),
|
||||
initial_pixbuf.get_has_alpha() ? Cogl.PixelFormat.RGBA_8888
|
||||
let initialPixbuf = Pixbuf.Pixbuf.new_from_file(item['path']);
|
||||
img.set_data(initialPixbuf.get_pixels(),
|
||||
initialPixbuf.get_has_alpha() ? Cogl.PixelFormat.RGBA_8888
|
||||
: Cogl.PixelFormat.RGB_888,
|
||||
initial_pixbuf.get_width(),
|
||||
initial_pixbuf.get_height(),
|
||||
initial_pixbuf.get_rowstride());
|
||||
initialPixbuf.get_width(),
|
||||
initialPixbuf.get_height(),
|
||||
initialPixbuf.get_rowstride());
|
||||
let picture = new Clutter.Actor();
|
||||
picture.set_content(img);
|
||||
picture.set_size((width != -1)?width:initial_pixbuf.get_width(),
|
||||
(height != -1)?height:initial_pixbuf.get_height());
|
||||
picture.set_size((width != -1)?width:initialPixbuf.get_width(),
|
||||
(height != -1)?height:initialPixbuf.get_height());
|
||||
|
||||
// Pack it in a box to avoid picture resize
|
||||
let box = new St.BoxLayout({});
|
||||
|
@ -324,7 +325,7 @@ class MonitorWidget extends PanelMenu.Button {
|
|||
}
|
||||
|
||||
if (action === 'signal')
|
||||
this.dbus.emit_signal(signalName, this.fullname);
|
||||
this.dbus.emitSignal(signalName, this.fullname);
|
||||
else
|
||||
this._manageEventAction(action);
|
||||
this.nbClicks = 0;
|
||||
|
@ -347,31 +348,31 @@ class MonitorWidget extends PanelMenu.Button {
|
|||
return Clutter.EVENT_PROPAGATE;
|
||||
}
|
||||
|
||||
_onEnter(actor, event) {
|
||||
_onEnter(/*actor, event*/) {
|
||||
if (this.onEnter === 'signal')
|
||||
this.dbus.emit_signal('onEnter', this.fullname);
|
||||
this.dbus.emitSignal('onEnter', this.fullname);
|
||||
else
|
||||
return this._manageEventAction(this.onEnter);
|
||||
|
||||
return Clutter.EVENT_PROPAGATE;
|
||||
}
|
||||
|
||||
_onLeave(actor, event) {
|
||||
_onLeave(/*actor, event*/) {
|
||||
if (this.onLeave === 'signal')
|
||||
this.dbus.emit_signal('onLeave', this.fullname);
|
||||
this.dbus.emitSignal('onLeave', this.fullname);
|
||||
else
|
||||
return this._manageEventAction(this.onEnter);
|
||||
|
||||
return Clutter.EVENT_PROPAGATE;
|
||||
}
|
||||
|
||||
_onScroll(actor, event) {
|
||||
_onScroll(/*actor, event*/) {
|
||||
if (this.onScroll === 'signal') {
|
||||
let direction = event.get_scroll_direction ();
|
||||
if (direction == Clutter.ScrollDirection.UP)
|
||||
this.dbus.emit_signal('onScrollUp', this.fullname);
|
||||
this.dbus.emitSignal('onScrollUp', this.fullname);
|
||||
else if (direction == Clutter.ScrollDirection.DOWN)
|
||||
this.dbus.emit_signal('onScrollDown', this.fullname);
|
||||
this.dbus.emitSignal('onScrollDown', this.fullname);
|
||||
} else
|
||||
return this._manageEventAction(this.onEnter);
|
||||
|
||||
|
@ -387,12 +388,12 @@ class MonitorWidget extends PanelMenu.Button {
|
|||
let text = '';
|
||||
let style = '';
|
||||
if (typeof(item['text']) === "string") {
|
||||
text = hash_get(item, 'text', '');
|
||||
style = hash_get(item, 'style', '');
|
||||
text = hashGet(item, 'text', '');
|
||||
style = hashGet(item, 'style', '');
|
||||
} else {
|
||||
let textValues = item['text'];
|
||||
text = hash_get(textValues, 'text', '');
|
||||
style = hash_get(textValues, 'style', '');
|
||||
text = hashGet(textValues, 'text', '');
|
||||
style = hashGet(textValues, 'style', '');
|
||||
}
|
||||
|
||||
if (text !== '') {
|
||||
|
@ -417,12 +418,12 @@ class MonitorWidget extends PanelMenu.Button {
|
|||
let icon = '';
|
||||
let style = '';
|
||||
if (typeof(item['icon']) === "string") {
|
||||
icon = hash_get(item, 'icon', '');
|
||||
style = hash_get(item, 'iconStyle', '');
|
||||
icon = hashGet(item, 'icon', '');
|
||||
style = hashGet(item, 'iconStyle', '');
|
||||
} else {
|
||||
let iconValues = item['icon'];
|
||||
icon = hash_get(iconValues, 'path', '');
|
||||
style = hash_get(textValues, 'style', '');
|
||||
icon = hashGet(iconValues, 'path', '');
|
||||
style = hashGet(iconValues, 'style', '');
|
||||
}
|
||||
|
||||
if (icon !== '') {
|
||||
|
@ -460,13 +461,13 @@ class MonitorWidget extends PanelMenu.Button {
|
|||
this.menu.open(true);
|
||||
}
|
||||
|
||||
this.onClick = hash_get(item, 'on-click', this.onClick);
|
||||
this.onDblClick = hash_get(item, 'on-dblclick', this.onDblClick);
|
||||
this.onRightClick = hash_get(item, 'on-rightclick', this.onRightClick);
|
||||
this.onRightDblClick = hash_get(item, 'on-rightdblclick', this.onRightDblClick);
|
||||
this.onEnter = hash_get(item, 'on-enter', this.onEnter);
|
||||
this.onLeave = hash_get(item, 'on-leave', this.onLeave);
|
||||
this.onScroll = hash_get(item, 'on-scroll', this.onScroll);
|
||||
this.onClick = hashGet(item, 'on-click', this.onClick);
|
||||
this.onDblClick = hashGet(item, 'on-dblclick', this.onDblClick);
|
||||
this.onRightClick = hashGet(item, 'on-rightclick', this.onRightClick);
|
||||
this.onRightDblClick = hashGet(item, 'on-rightdblclick', this.onRightDblClick);
|
||||
this.onEnter = hashGet(item, 'on-enter', this.onEnter);
|
||||
this.onLeave = hashGet(item, 'on-leave', this.onLeave);
|
||||
this.onScroll = hashGet(item, 'on-scroll', this.onScroll);
|
||||
}
|
||||
|
||||
openPopup() {
|
||||
|
@ -523,7 +524,7 @@ class GenericMonitorDBUS {
|
|||
this._dbusImpl.emit_signal('onActivate', null);
|
||||
}
|
||||
|
||||
emit_signal(name, value) {
|
||||
emitSignal(name, value) {
|
||||
this._dbusImpl.emit_signal(name, GLib.Variant.new('(s)',[value]));
|
||||
}
|
||||
|
||||
|
@ -562,7 +563,7 @@ class GenericMonitorDBUS {
|
|||
_getItemFromFullName(fullname) {
|
||||
let splitName = fullname.split('@');
|
||||
if (splitName.length !== 2) {
|
||||
log(`Invalid name ${item}`);
|
||||
log(`Invalid name ${fullname}`);
|
||||
return null;
|
||||
}
|
||||
if (!this.monitor_groups.hasOwnProperty(splitName[1]))
|
||||
|
|
Loading…
Reference in New Issue
Block a user