Add kelvin temp

yahoo_weather
Neroth 13 years ago
parent 9f3881d812
commit cc41703670
  1. 26
      src/extension.js
  2. 1
      src/org.gnome.shell.extensions.weather.gschema.xml.in
  3. 2
      src/weather-settings.js.in

@ -63,7 +63,8 @@ const WEATHER_REFRESH_INTERVAL = 'refresh-interval';
// Keep enums in sync with GSettings schemas // Keep enums in sync with GSettings schemas
const WeatherUnits = { const WeatherUnits = {
CELSIUS: 0, CELSIUS: 0,
FAHRENHEIT: 1 FAHRENHEIT: 1,
KELVIN: 2
} }
const WeatherWindSpeedUnits = { const WeatherWindSpeedUnits = {
@ -478,7 +479,12 @@ WeatherMenuButton.prototype = {
}, },
unit_to_unicode: function() { unit_to_unicode: function() {
return this._units == WeatherUnits.FAHRENHEIT ? '\u2109' : '\u2103'; if(this._units == WeatherUnits.FAHRENHEIT)
return '\u2109';
else if(this._units == WeatherUnits.KELVIN)
return 'K';
else
return '\u2103';
}, },
get_weather_url: function() { get_weather_url: function() {
@ -704,6 +710,10 @@ WeatherMenuButton.prototype = {
} }
}, },
toKelvin: function(c) {
return String(Math.round(Number(c)+273.15));
},
parse_day: function(abr) { parse_day: function(abr) {
let yahoo_days = ['monday', 'tuesday', 'wednesday', 'thursday', 'friday', 'saturday', 'sunday']; let yahoo_days = ['monday', 'tuesday', 'wednesday', 'thursday', 'friday', 'saturday', 'sunday'];
for (var i = 0; i < yahoo_days.length; i++) { for (var i = 0; i < yahoo_days.length; i++) {
@ -813,6 +823,12 @@ WeatherMenuButton.prototype = {
let d = Math.floor((actualDate.getTime()-lastBuildDate.getTime())/86400000); let d = Math.floor((actualDate.getTime()-lastBuildDate.getTime())/86400000);
let date_string = [_('Today'), _('Tomorrow')]; let date_string = [_('Today'), _('Tomorrow')];
if(this._units == WeatherUnits.KELVIN)
{
temperature = this.toKelvin(temperature);
chill = this.toKelvin(chill);
}
if(this._clockFormat == "24h") if(this._clockFormat == "24h")
{ {
sunrise = new Date("3 Mar 1999 "+sunrise); sunrise = new Date("3 Mar 1999 "+sunrise);
@ -917,6 +933,12 @@ WeatherMenuButton.prototype = {
let t_low = forecastData.low; let t_low = forecastData.low;
let t_high = forecastData.high; let t_high = forecastData.high;
if(this._units == WeatherUnits.KELVIN)
{
t_low = this.toKelvin(t_low);
t_high = this.toKelvin(t_high);
}
let comment = forecastData.text; let comment = forecastData.text;
if (this._translate_condition) if (this._translate_condition)
comment = this.get_weather_condition(code); comment = this.get_weather_condition(code);

@ -2,6 +2,7 @@
<enum id="org.gnome.shell.extensions.weather.unit"> <enum id="org.gnome.shell.extensions.weather.unit">
<value nick="celsius" value="0" /> <value nick="celsius" value="0" />
<value nick="fahrenheit" value="1" /> <value nick="fahrenheit" value="1" />
<value nick="kelvin" value="2" />
</enum> </enum>
<enum id="org.gnome.shell.extensions.weather.wind-speed-unit"> <enum id="org.gnome.shell.extensions.weather.wind-speed-unit">
<value nick="kph" value="0" /> <value nick="kph" value="0" />

@ -606,7 +606,7 @@ WeatherSetting.prototype =
this.initConfigWidget(); this.initConfigWidget();
this.addLabel(_("Temperature Unit")); this.addLabel(_("Temperature Unit"));
this.addComboBox(["°C","°F"],"units"); this.addComboBox(["°C","°F","K"],"units");
this.addLabel(_("Wind Speed Unit")); this.addLabel(_("Wind Speed Unit"));
this.addComboBox(["km/h","mph","m/s","knots"],"wind_speed_unit"); this.addComboBox(["km/h","mph","m/s","knots"],"wind_speed_unit");
this.addLabel(_("Position in Panel")); this.addLabel(_("Position in Panel"));

Loading…
Cancel
Save