power: Remove other devices
Simply have one section. This is a part of the new system status design, see https://wiki.gnome.org/GnomeShell/Design/Guidelines/SystemStatus/ for design details. https://bugzilla.gnome.org/show_bug.cgi?id=704368
This commit is contained in:
parent
040bb9354a
commit
8cce1b4f6c
@ -65,35 +65,26 @@ const Indicator = new Lang.Class({
|
|||||||
this._devicesChanged();
|
this._devicesChanged();
|
||||||
}));
|
}));
|
||||||
|
|
||||||
this._deviceItems = [ ];
|
this.item = new PopupMenu.PopupMenuItem('', { reactive: false });
|
||||||
this._hasPrimary = false;
|
|
||||||
this._primaryDeviceId = null;
|
|
||||||
|
|
||||||
this._batteryItem = new PopupMenu.PopupMenuItem('', { reactive: false });
|
|
||||||
this._primaryPercentage = new St.Label({ style_class: 'popup-battery-percentage' });
|
this._primaryPercentage = new St.Label({ style_class: 'popup-battery-percentage' });
|
||||||
this._batteryItem.addActor(this._primaryPercentage, { align: St.Align.END });
|
this.item.addActor(this._primaryPercentage, { align: St.Align.END });
|
||||||
this.menu.addMenuItem(this._batteryItem);
|
this.menu.addMenuItem(this.item);
|
||||||
|
|
||||||
this.menu.addMenuItem(new PopupMenu.PopupSeparatorMenuItem());
|
|
||||||
this._otherDevicePosition = 2;
|
|
||||||
},
|
},
|
||||||
|
|
||||||
_readPrimaryDevice: function() {
|
_readPrimaryDevice: function() {
|
||||||
this._proxy.GetPrimaryDeviceRemote(Lang.bind(this, function(result, error) {
|
this._proxy.GetPrimaryDeviceRemote(Lang.bind(this, function(result, error) {
|
||||||
if (error) {
|
if (error) {
|
||||||
this._hasPrimary = false;
|
this.item.actor.hide();
|
||||||
this._primaryDeviceId = null;
|
|
||||||
this._batteryItem.actor.hide();
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
let [[device_id, device_type, icon, percentage, state, seconds]] = result;
|
let [[device_id, device_type, icon, percentage, state, seconds]] = result;
|
||||||
if (device_type == UPDeviceType.BATTERY) {
|
if (device_type == UPDeviceType.BATTERY) {
|
||||||
this._hasPrimary = true;
|
|
||||||
let time = Math.round(seconds / 60);
|
let time = Math.round(seconds / 60);
|
||||||
if (time == 0) {
|
if (time == 0) {
|
||||||
// 0 is reported when UPower does not have enough data
|
// 0 is reported when UPower does not have enough data
|
||||||
// to estimate battery life
|
// to estimate battery life
|
||||||
this._batteryItem.label.text = _("Estimating…");
|
this.item.label.text = _("Estimating…");
|
||||||
} else {
|
} else {
|
||||||
let minutes = time % 60;
|
let minutes = time % 60;
|
||||||
let hours = Math.floor(time / 60);
|
let hours = Math.floor(time / 60);
|
||||||
@ -109,39 +100,12 @@ const Indicator = new Lang.Class({
|
|||||||
}
|
}
|
||||||
} else
|
} else
|
||||||
timestring = ngettext("%d minute remaining", "%d minutes remaining", minutes).format(minutes);
|
timestring = ngettext("%d minute remaining", "%d minutes remaining", minutes).format(minutes);
|
||||||
this._batteryItem.label.text = timestring;
|
this.item.label.text = timestring;
|
||||||
}
|
}
|
||||||
this._primaryPercentage.text = C_("percent of battery remaining", "%d%%").format(Math.round(percentage));
|
this._primaryPercentage.text = C_("percent of battery remaining", "%d%%").format(Math.round(percentage));
|
||||||
this._batteryItem.actor.show();
|
this.item.actor.show();
|
||||||
} else {
|
} else {
|
||||||
this._hasPrimary = false;
|
this.item.actor.hide();
|
||||||
this._batteryItem.actor.hide();
|
|
||||||
}
|
|
||||||
|
|
||||||
this._primaryDeviceId = device_id;
|
|
||||||
}));
|
|
||||||
},
|
|
||||||
|
|
||||||
_readOtherDevices: function() {
|
|
||||||
this._proxy.GetDevicesRemote(Lang.bind(this, function(result, error) {
|
|
||||||
this._deviceItems.forEach(function(i) { i.destroy(); });
|
|
||||||
this._deviceItems = [];
|
|
||||||
|
|
||||||
if (error) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
let position = 0;
|
|
||||||
let [devices] = result;
|
|
||||||
for (let i = 0; i < devices.length; i++) {
|
|
||||||
let [device_id, device_type] = devices[i];
|
|
||||||
if (device_type == UPDeviceType.AC_POWER || device_id == this._primaryDeviceId)
|
|
||||||
continue;
|
|
||||||
|
|
||||||
let item = new DeviceItem (devices[i]);
|
|
||||||
this._deviceItems.push(item);
|
|
||||||
this.menu.addMenuItem(item, this._otherDevicePosition + position);
|
|
||||||
position++;
|
|
||||||
}
|
}
|
||||||
}));
|
}));
|
||||||
},
|
},
|
||||||
@ -162,55 +126,5 @@ const Indicator = new Lang.Class({
|
|||||||
_devicesChanged: function() {
|
_devicesChanged: function() {
|
||||||
this._syncIcon();
|
this._syncIcon();
|
||||||
this._readPrimaryDevice();
|
this._readPrimaryDevice();
|
||||||
this._readOtherDevices();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
const DeviceItem = new Lang.Class({
|
|
||||||
Name: 'DeviceItem',
|
|
||||||
Extends: PopupMenu.PopupBaseMenuItem,
|
|
||||||
|
|
||||||
_init: function(device) {
|
|
||||||
this.parent({ reactive: false });
|
|
||||||
|
|
||||||
let [device_id, device_type, icon, percentage, state, time] = device;
|
|
||||||
|
|
||||||
this._label = new St.Label({ text: this._deviceTypeToString(device_type) });
|
|
||||||
this.addActor(this._label);
|
|
||||||
|
|
||||||
let percentLabel = new St.Label({ text: C_("percent of battery remaining", "%d%%").format(Math.round(percentage)),
|
|
||||||
style_class: 'popup-status-menu-item popup-battery-percentage' });
|
|
||||||
this.addActor(percentLabel, { align: St.Align.END });
|
|
||||||
//FIXME: ideally we would like to expose this._label and percentLabel
|
|
||||||
this.actor.label_actor = percentLabel;
|
|
||||||
},
|
|
||||||
|
|
||||||
_deviceTypeToString: function(type) {
|
|
||||||
switch (type) {
|
|
||||||
case UPDeviceType.AC_POWER:
|
|
||||||
return _("AC Adapter");
|
|
||||||
case UPDeviceType.BATTERY:
|
|
||||||
return _("Laptop Battery");
|
|
||||||
case UPDeviceType.UPS:
|
|
||||||
return _("UPS");
|
|
||||||
case UPDeviceType.MONITOR:
|
|
||||||
return _("Monitor");
|
|
||||||
case UPDeviceType.MOUSE:
|
|
||||||
return _("Mouse");
|
|
||||||
case UPDeviceType.KEYBOARD:
|
|
||||||
return _("Keyboard");
|
|
||||||
case UPDeviceType.PDA:
|
|
||||||
return _("PDA");
|
|
||||||
case UPDeviceType.PHONE:
|
|
||||||
return _("Cell Phone");
|
|
||||||
case UPDeviceType.MEDIA_PLAYER:
|
|
||||||
return _("Media Player");
|
|
||||||
case UPDeviceType.TABLET:
|
|
||||||
return _("Tablet");
|
|
||||||
case UPDeviceType.COMPUTER:
|
|
||||||
return _("Computer");
|
|
||||||
default:
|
|
||||||
return C_("device", "Unknown");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user