From cc41703670feb3b2306a6eb11962d7cd148f9e8f Mon Sep 17 00:00:00 2001 From: Neroth Date: Tue, 5 Jun 2012 01:11:42 +0200 Subject: [PATCH] Add kelvin temp --- src/extension.js | 26 +++++++++++++++++-- ...me.shell.extensions.weather.gschema.xml.in | 1 + src/weather-settings.js.in | 2 +- 3 files changed, 26 insertions(+), 3 deletions(-) diff --git a/src/extension.js b/src/extension.js index 9c37ee9..cdc17cb 100644 --- a/src/extension.js +++ b/src/extension.js @@ -63,7 +63,8 @@ const WEATHER_REFRESH_INTERVAL = 'refresh-interval'; // Keep enums in sync with GSettings schemas const WeatherUnits = { CELSIUS: 0, - FAHRENHEIT: 1 + FAHRENHEIT: 1, + KELVIN: 2 } const WeatherWindSpeedUnits = { @@ -478,7 +479,12 @@ WeatherMenuButton.prototype = { }, 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() { @@ -704,6 +710,10 @@ WeatherMenuButton.prototype = { } }, + toKelvin: function(c) { + return String(Math.round(Number(c)+273.15)); + }, + parse_day: function(abr) { let yahoo_days = ['monday', 'tuesday', 'wednesday', 'thursday', 'friday', 'saturday', 'sunday']; 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 date_string = [_('Today'), _('Tomorrow')]; + if(this._units == WeatherUnits.KELVIN) + { + temperature = this.toKelvin(temperature); + chill = this.toKelvin(chill); + } + if(this._clockFormat == "24h") { sunrise = new Date("3 Mar 1999 "+sunrise); @@ -917,6 +933,12 @@ WeatherMenuButton.prototype = { let t_low = forecastData.low; 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; if (this._translate_condition) comment = this.get_weather_condition(code); diff --git a/src/org.gnome.shell.extensions.weather.gschema.xml.in b/src/org.gnome.shell.extensions.weather.gschema.xml.in index 58a0a1c..e341533 100644 --- a/src/org.gnome.shell.extensions.weather.gschema.xml.in +++ b/src/org.gnome.shell.extensions.weather.gschema.xml.in @@ -2,6 +2,7 @@ + diff --git a/src/weather-settings.js.in b/src/weather-settings.js.in index c5e8503..6f7f5ba 100644 --- a/src/weather-settings.js.in +++ b/src/weather-settings.js.in @@ -606,7 +606,7 @@ WeatherSetting.prototype = this.initConfigWidget(); this.addLabel(_("Temperature Unit")); - this.addComboBox(["°C","°F"],"units"); + this.addComboBox(["°C","°F","K"],"units"); this.addLabel(_("Wind Speed Unit")); this.addComboBox(["km/h","mph","m/s","knots"],"wind_speed_unit"); this.addLabel(_("Position in Panel"));