Merge branch 'udisks'

This commit is contained in:
Marcel Metz
2013-10-31 13:49:29 +01:00
3 changed files with 99 additions and 1 deletions

View File

@@ -74,6 +74,12 @@ const SensorsMenuButton = new Lang.Class({
this.hddtempArgv = Utilities.detectHDDTemp();
}
this.udisksProxies = [];
Utilities.UDisks.get_drive_ata_proxies((function(proxies) {
this.udisksProxies = proxies;
this._updateDisplay(this._sensorsOutput, this._hddtempOutput);
}).bind(this));
this._settingsChanged = settings.connect("changed", Lang.bind(this,function(){ this._querySensors(false); }));
this._querySensors(true);
@@ -128,6 +134,8 @@ const SensorsMenuButton = new Lang.Class({
if(this.hddtempArgv)
tempInfo = tempInfo.concat(Utilities.parseHddTempOutput(hddtemp_output, !(/nc$/.exec(this.hddtempArgv[0])) ? ': ' : '|'));
tempInfo = tempInfo.concat(Utilities.UDisks.create_list_from_proxies(this.udisksProxies));
tempInfo.sort(function(a,b) { return a['label'].localeCompare(b['label']) });
fanInfo.sort(function(a,b) { return a['label'].localeCompare(b['label']) });
voltageInfo.sort(function(a,b) { return a['label'].localeCompare(b['label']) });

View File

@@ -96,7 +96,7 @@ const SensorsPrefsWidget = new GObject.Class({
}
//List of items of the ComboBox
//List of items of the ComboBox
this._model = new Gtk.ListStore();
this._model.set_column_types([GObject.TYPE_STRING, GObject.TYPE_BOOLEAN]);
this._appendItem(_("Average"));
@@ -110,6 +110,7 @@ const SensorsPrefsWidget = new GObject.Class({
//Fill the list
this._getSensorsLabels();
this._getUdisksLabels();
if(this._display_hdd_temp) {
this._appendSeparator();
@@ -192,6 +193,14 @@ const SensorsPrefsWidget = new GObject.Class({
}
},
_getUdisksLabels: function() {
Utilities.UDisks.get_drive_ata_proxies((function(proxies) {
let list = Utilities.UDisks.create_list_from_proxies(proxies);
this._appendMultipleItems(list);
}).bind(this));
},
_getActiveSensorIter: function() {
/* Get the first iter in the list */
[success, iter] = this._model.get_iter_first();

View File

@@ -6,6 +6,16 @@ const Me = imports.misc.extensionUtils.getCurrentExtension();
const Gettext = imports.gettext.domain(Me.metadata['gettext-domain']);
const _ = Gettext.gettext;
const UDisksDriveProxy = Gio.DBusProxy.makeProxyWrapper(
<interface name="org.freedesktop.UDisks2.Drive">
<property type="s" name="Model" access="read"/>
</interface>);
const UDisksDriveAtaProxy = Gio.DBusProxy.makeProxyWrapper(
<interface name="org.freedesktop.UDisks2.Drive.Ata">
<property type="d" name="SmartTemperature" access="read"/>
</interface>);
function detectSensors() {
let path = GLib.find_program_in_path('sensors');
return path ? [path] : undefined;
@@ -231,7 +241,78 @@ const Future = new Lang.Class({
}
});
// Poor man's async.js
const Async = {
// mapping will be done in parallel
map: function(arr, mapClb /* function(in, successClb)) */, resClb /* function(result) */) {
let counter = arr.length;
let result = [];
for (let i = 0; i < arr.length; ++i) {
mapClb(arr[i], (function(i, newVal) {
result[i] = newVal;
if (--counter == 0) resClb(result);
}).bind(null, i)); // i needs to be bound since it will be changed during the next iteration
}
}
}
function debug(str){
//tail -f -n100 ~/.cache/gdm/session.log | grep temperature
print ('LOG temperature@xtranophilist: ' + str);
}
// routines for handling of udisks2
const UDisks = {
// creates a list of sensor objects from the list of proxies given
create_list_from_proxies: function(proxies) {
return proxies.filter(function(proxy) {
// 0K means no data available
return proxy.ata.SmartTemperature > 0;
}).map(function(proxy) {
return {
label: proxy.drive.Model,
temp: proxy.ata.SmartTemperature - 272.15
};
});
},
// calls callback with [{ drive: UDisksDriveProxy, ata: UDisksDriveAtaProxy }, ... ] for every drive that implements both interfaces
get_drive_ata_proxies: function(callback) {
Gio.DBusObjectManagerClient.new(Gio.DBus.system, 0, "org.freedesktop.UDisks2", "/org/freedesktop/UDisks2", null, null, function(src, res) {
try {
let objMgr = Gio.DBusObjectManagerClient.new_finish(res); //might throw
let objPaths = objMgr.get_objects().filter(function(o) {
return o.get_interface("org.freedesktop.UDisks2.Drive") != null
&& o.get_interface("org.freedesktop.UDisks2.Drive.Ata") != null;
}).map(function(o) { return o.get_object_path() });
// now create the proxy objects, log and ignore every failure
Async.map(objPaths, function(obj, callback) {
// create the proxies object
let driveProxy = new UDisksDriveProxy(Gio.DBus.system, "org.freedesktop.UDisks2", obj, function(res, error) {
if (error) { //very unlikely - we even checked the interfaces before!
debug("Could not create proxy on "+obj+":"+error);
callback(null);
return;
}
let ataProxy = new UDisksDriveAtaProxy(Gio.DBus.system, "org.freedesktop.UDisks2", obj, function(res, error) {
if (error) {
debug("Could not create proxy on "+obj+":"+error);
callback(null);
return;
}
callback({ drive: driveProxy, ata: ataProxy });
});
});
}, function(proxies) {
// filter out failed attempts == null values
callback(proxies.filter(function(a) { return a != null; }));
});
} catch (e) {
debug("Could not find UDisks objects: "+e);
}
});
}
};