Added 'Average' and 'Maximum' as sensor entries

Removed specific setting to show average or maximum temperature in
panel, just treat them as a sensor.
Selected sensor to show in panel is now called 'main-sensor' in the
settings and it's also highlighted in bold in the menu list.
This commit is contained in:
Alessandro Casale
2013-04-15 15:11:20 +02:00
parent 47dbb81ae1
commit b9977941bb
3 changed files with 54 additions and 64 deletions

View File

@@ -20,8 +20,7 @@ const SensorsItem = new Lang.Class({
_init: function(label, value) {
this.parent();
this.connect('activate', function () {
settings.set_string('show-in-panel', 'sensor');
settings.set_string('sensor', label);
settings.set_string('main-sensor', label);
});
this._label = label;
this._value = value;
@@ -36,6 +35,15 @@ const SensorsItem = new Lang.Class({
else
return this._value;
},
setMainSensor: function() {
//this.setShowDot(true);
this.actor.add_style_class_name('popup-subtitle-menu-item'); //bold
},
getLabel: function() {
return this._label;
},
});
const SensorsMenuButton = new Lang.Class({
@@ -126,59 +134,51 @@ const SensorsMenuButton = new Lang.Class({
});
let section = new PopupMenu.PopupMenuSection("Temperature");
if (tempInfo.length > 0){
let item;
let sensorsList = new Array();
let sum = 0; //sum
let max = 0; //max temp
let sel = 'N/A'; //selected sensor temp
for each (let temp in tempInfo){
sum += temp['temp'];
if (temp['temp'] > max)
max = temp['temp'];
item = new SensorsItem(temp['label'], this._formatTemp(temp['temp']));
if (temp['label'] == settings.get_string('sensor'))
sel = item;
section.addMenuItem(item);
sensorsList.push(new SensorsItem(temp['label'], this._formatTemp(temp['temp'])));
}
if (tempInfo.length > 0 && (fanInfo.length > 0 || voltageInfo.length > 0)){
section.addMenuItem(new PopupMenu.PopupSeparatorMenuItem());
if (tempInfo.length > 0){
sensorsList.push(new PopupMenu.PopupSeparatorMenuItem());
// Add average and maximum entries
sensorsList.push(new SensorsItem('Average', this._formatTemp(sum/tempInfo.length)));
sensorsList.push(new SensorsItem('Maximum', this._formatTemp(max)));
if(fanInfo.length > 0 || voltageInfo.length > 0)
sensorsList.push(new PopupMenu.PopupSeparatorMenuItem());
}
for each (let fan in fanInfo){
item = new SensorsItem(fan['label'], '%drpm'.format(fan['rpm']));
if (settings.get_string('sensor') == fan['label'])
sel = item;
section.addMenuItem(item);
sensorsList.push(new SensorsItem(fan['label'], '%drpm'.format(fan['rpm'])));
}
if (fanInfo.length > 0 && voltageInfo.length > 0){
section.addMenuItem(new PopupMenu.PopupSeparatorMenuItem());
sensorsList.push(new PopupMenu.PopupSeparatorMenuItem());
}
for each (let voltage in voltageInfo){
item = new SensorsItem(voltage['label'], '%s%.2fV'.format(((voltage['volt'] >= 0) ? '+' : '-'), voltage['volt']));
if (settings.get_string('sensor') == voltage['label'])
sel = item;
sensorsList.push(new SensorsItem(voltage['label'], '%s%.2fV'.format(((voltage['volt'] >= 0) ? '+' : '-'), voltage['volt'])));
}
this.statusLabel.set_text('N/A'); // Just in case
for each (let item in sensorsList) {
if(item instanceof SensorsItem) {
if (settings.get_string('main-sensor') == item.getLabel()) {
// Configure as main sensor and set panel string
item.setMainSensor();
this.statusLabel.set_text(item.getPanelString());
}
}
section.addMenuItem(item);
}
let mainSensor = '';
switch (settings.get_string('show-in-panel')) {
case 'maximum':
if(settings.get_boolean('display-label'))
mainSensor = "Maximum: %s".format(this._formatTemp(max));
else
mainSensor = this._formatTemp(max);//or the maximum temp
break;
case 'sensor':
mainSensor = sel.getPanelString();//or temperature from a selected sensor
break;
case 'average':
default:
if(settings.get_boolean('display-label'))
mainSensor = "Average: %s".format(this._formatTemp(sum/tempInfo.length));
else
mainSensor = this._formatTemp(sum/tempInfo.length);//average as default
break;
}
this.statusLabel.set_text(mainSensor);
}else{
this.statusLabel.set_text('Error');

View File

@@ -14,8 +14,7 @@ const Utilities = Me.imports.utilities;
const modelColumn = {
label: 0,
method: 1,
separator: 2
separator: 1
}
function init() {
@@ -104,9 +103,9 @@ const SensorsPrefsWidget = new GObject.Class({
//List of items of the ComboBox
this._model = new Gtk.ListStore();
this._model.set_column_types([GObject.TYPE_STRING, GObject.TYPE_STRING, GObject.TYPE_BOOLEAN]);
this._appendItem('Average temperature', 'average');
this._appendItem('Maximum temperature', 'maximum');
this._model.set_column_types([GObject.TYPE_STRING, GObject.TYPE_BOOLEAN]);
this._appendItem('Average');
this._appendItem('Maximum');
this._appendSeparator();
//Get current options
@@ -148,13 +147,13 @@ const SensorsPrefsWidget = new GObject.Class({
return model.get_value(iter, modelColumn.separator);
},
_appendItem: function(label, type) {
this._model.set(this._model.append(), [modelColumn.label, modelColumn.method], [label, type]);
_appendItem: function(label) {
this._model.set(this._model.append(), [modelColumn.label], [label]);
},
_appendMultipleItems: function(sensorInfo, type) {
_appendMultipleItems: function(sensorInfo) {
for each (let sensor in sensorInfo) {
this._model.set(this._model.append(), [modelColumn.label, modelColumn.method], [sensor['label'], type]);
this._model.set(this._model.append(), [modelColumn.label], [sensor['label']]);
}
},
@@ -171,16 +170,16 @@ const SensorsPrefsWidget = new GObject.Class({
let output = sensors_output[1].toString();
let tempInfo = Utilities.parseSensorsOutput(output,Utilities.parseSensorsTemperatureLine);
tempInfo = tempInfo.filter(Utilities.filterTemperature);
this._appendMultipleItems(tempInfo, 'sensor');
this._appendMultipleItems(tempInfo);
if (this._display_fan_rpm){
let fanInfo = Utilities.parseSensorsOutput(output,Utilities.parseFanRPMLine);
fanInfo = fanInfo.filter(Utilities.filterFan);
this._appendMultipleItems(fanInfo, 'sensor');
this._appendMultipleItems(fanInfo);
}
if (this._display_voltage){
let voltageInfo = Utilities.parseSensorsOutput(output,Utilities.parseVoltageLine);
this._appendMultipleItems(voltageInfo, 'sensor');
this._appendMultipleItems(voltageInfo);
}
}
}
@@ -193,7 +192,7 @@ const SensorsPrefsWidget = new GObject.Class({
if(hddtemp_output[0]){
let hddTempInfo = Utilities.parseHddTempOutput(hddtemp_output[1].toString(),
!(/nc$/.exec(hddtemp_cmd[0])) ? ': ' : '|');
this._appendMultipleItems(hddTempInfo, 'sensor');
this._appendMultipleItems(hddTempInfo);
}
}
},
@@ -206,7 +205,7 @@ const SensorsPrefsWidget = new GObject.Class({
while (success) {
/* Walk through the list, reading each row */
let sensorLabel = this._model.get_value(iter, 0);
if(sensorLabel == this._settings.get_string('sensor'))
if(sensorLabel == this._settings.get_string('main-sensor'))
break;
success = this._model.iter_next(iter);
@@ -230,10 +229,7 @@ const SensorsPrefsWidget = new GObject.Class({
return;
let label = this._model.get_value(iter, modelColumn.label);
let method = this._model.get_value(iter, modelColumn.method);
this._settings.set_string('show-in-panel', method);
this._settings.set_string('sensor', label);
this._settings.set_string('main-sensor', label);
},
});

View File

@@ -15,19 +15,13 @@
<description>The unit ('centigrade' or 'fahrenheit', without quotes) the extension should display the temperature in.</description>
</key>
<key type="s" name="show-in-panel">
<default>"average"</default>
<summary>Average, maximum or specific sensor in panel</summary>
<description>Select if "average", "maximum" or a specific sensor temperature has to be shown in the panel</description>
</key>
<key type="b" name="display-label">
<default>false</default>
<summary>Display label</summary>
<description>Display also the label of the sensor in the panel</description>
</key>
<key type="s" name="sensor">
<key type="s" name="main-sensor">
<default>""</default>
<summary>Sensor temperature to show in panel</summary>
<description>Select the sensor whose temperature has to be shown in the panel</description>