Control for the wind speed unit

yahoo_weather
Neroth 13 years ago
parent 9112020065
commit 04df3eede6
  1. 4
      po/fr.po
  2. 66
      src/extension.js
  3. 13
      src/org.gnome.shell.extensions.weather.gschema.xml.in
  4. 17
      src/weather-settings.js.in

@ -291,6 +291,10 @@ msgstr "Traduire les conditions"
msgid "Temperature Unit"
msgstr "Unité de température"
#: weather-settings.js
msgid "Wind Speed Unit"
msgstr "Unité de vitesse du vent"
#: weather-settings.js
msgid "Position in Panel"
msgstr "Position sur le panel"

@ -49,6 +49,7 @@ const PopupMenu = imports.ui.popupMenu;
// Settings
const WEATHER_SETTINGS_SCHEMA = 'org.gnome.shell.extensions.weather';
const WEATHER_UNIT_KEY = 'unit';
const WEATHER_WIND_SPEED_UNIT_KEY = 'wind-speed-unit';
const WEATHER_CITY_KEY = 'city';
const WEATHER_ACTUAL_CITY_KEY = 'actual-city';
const WEATHER_TRANSLATE_CONDITION_KEY = 'translate-condition';
@ -63,12 +64,24 @@ const WeatherUnits = {
CELSIUS: 0,
FAHRENHEIT: 1
}
const WeatherWindSpeedUnits = {
KPH: 0,
MPH: 1,
MPS: 2,
KNOTS: 3
}
const WeatherPosition = {
CENTER: 0,
RIGHT: 1,
LEFT: 2
}
const WEATHER_CONV_MPH_IN_MPS = 2.23693629;
const WEATHER_CONV_KPH_IN_MPS = 3.6;
const WEATHER_CONV_KNOTS_IN_MPS = 1.94384449;
// Soup session (see https://bugzilla.gnome.org/show_bug.cgi?id=661323#c64) (Simon Legner)
const _httpSession = new Soup.SessionAsync();
Soup.Session.prototype.add_feature.call(_httpSession, new Soup.ProxyResolverDefault());
@ -221,6 +234,20 @@ WeatherMenuButton.prototype = {
this._settings.set_enum(WEATHER_UNIT_KEY,v);
},
get _wind_speed_units()
{
if(!this._settings)
this.loadConfig();
return this._settings.get_enum(WEATHER_WIND_SPEED_UNIT_KEY);
},
set _wind_speed_units(v)
{
if(!this._settings)
this.loadConfig();
this._settings.set_enum(WEATHER_WIND_SPEED_UNIT_KEY,v);
},
get _cities()
{
if(!this._settings)
@ -739,10 +766,47 @@ global.log(a);
this._currentWeatherTemperature.text = temperature + ' ' + this.unit_to_unicode();
this._currentWeatherHumidity.text = humidity;
this._currentWeatherPressure.text = pressure + ' ' + pressure_unit;
this._currentWeatherWind.text = (wind_direction && wind > 0 ? wind_direction + ' ' : '') + wind + ' ' + wind_unit;
this._currentWeatherSunrise.text = sunrise;
this._currentWeatherSunset.text = sunset;
// Override wind units with our preference
// Need to consider what units the Yahoo API has returned it in
switch (this._wind_speed_units) {
case WeatherWindSpeedUnits.KPH:
// Round to whole units
if (this._units == WeatherUnits.FAHRENHEIT) {
wind = Math.round (wind / WEATHER_CONV_MPH_IN_MPS * WEATHER_CONV_KPH_IN_MPS);
wind_unit = 'km/h';
}
// Otherwise no conversion needed - already in correct units
break;
case WeatherWindSpeedUnits.MPH:
// Round to whole units
if (this._units == WeatherUnits.CELSIUS) {
wind = Math.round (wind / WEATHER_CONV_KPH_IN_MPS * WEATHER_CONV_MPH_IN_MPS);
wind_unit = 'mph';
}
// Otherwise no conversion needed - already in correct units
break;
case WeatherWindSpeedUnits.MPS:
// Precision to one decimal place as 1 m/s is quite a large unit
if (this._units == WeatherUnits.CELSIUS)
wind = Math.round ((wind / WEATHER_CONV_KPH_IN_MPS) * 10)/ 10;
else
wind = Math.round ((wind / WEATHER_CONV_MPH_IN_MPS) * 10)/ 10;
wind_unit = 'm/s';
break;
case WeatherWindSpeedUnits.KNOTS:
// Round to whole units
if (this._units == WeatherUnits.CELSIUS)
wind = Math.round (wind / WEATHER_CONV_KPH_IN_MPS * WEATHER_CONV_KNOTS_IN_MPS);
else
wind = Math.round (wind / WEATHER_CONV_MPH_IN_MPS * WEATHER_CONV_KNOTS_IN_MPS);
wind_unit = 'knots';
break;
}
this._currentWeatherWind.text = (wind_direction && wind > 0 ? wind_direction + ' ' : '') + wind + ' ' + wind_unit;
// Refresh forecast
let date_string = [_('Today'), _('Tomorrow')];
for (let i = 0; i <= 1; i++) {

@ -3,6 +3,12 @@
<value nick="celsius" value="0" />
<value nick="fahrenheit" value="1" />
</enum>
<enum id="org.gnome.shell.extensions.weather.wind-speed-unit">
<value nick="kph" value="0" />
<value nick="mph" value="1" />
<value nick="m/s" value="2" />
<value nick="knots" value="3" />
</enum>
<enum id="org.gnome.shell.extensions.weather.position">
<value nick="center" value="0" />
<value nick="right" value="1" />
@ -10,9 +16,14 @@
</enum>
<schema id="org.gnome.shell.extensions.weather" path="/org/gnome/shell/extensions/weather/">
<key name="unit" enum="org.gnome.shell.extensions.weather.unit">
<default>'celsius'</default>
<default>'fahrenheit'</default>
<_summary>Temperature Unit</_summary>
</key>
<key name="wind-speed-unit" enum="org.gnome.shell.extensions.weather.wind-speed-unit">
<default>'mph'</default>
<_summary>Wind Speed Units</_summary>
<_description>Choose the units used for wind speed. Allowed values are 'kph', 'mph', 'm/s' or 'knots'.</_description>
</key>
<key name="city" type="s">
<default>'Cambridge, MA'</default>
<_summary>City to be displayed</_summary>

@ -33,6 +33,7 @@ const _ = Gettext.gettext;
const WEATHER_SETTINGS_SCHEMA = 'org.gnome.shell.extensions.weather';
const WEATHER_UNIT_KEY = 'unit';
const WEATHER_WIND_SPEED_UNIT_KEY = 'wind-speed-unit';
const WEATHER_CITY_KEY = 'city';
const WEATHER_ACTUAL_CITY_KEY = 'actual-city';
const WEATHER_TRANSLATE_CONDITION_KEY = 'translate-condition';
@ -180,6 +181,20 @@ WeatherSetting.prototype =
this.Settings.set_enum(WEATHER_UNIT_KEY,arguments[0]);
},
get wind_speed_unit()
{
if(!this.Settings)
this.loadConfig();
return this.Settings.get_enum(WEATHER_WIND_SPEED_UNIT_KEY);
},
set wind_speed_unit(v)
{
if(!this.Settings)
this.loadConfig();
this.Settings.set_enum(WEATHER_WIND_SPEED_UNIT_KEY,v);
},
get city()
{
if(!this.Settings)
@ -471,6 +486,8 @@ WeatherSetting.prototype =
this.initConfigWidget();
this.addLabel(_("Temperature Unit"));
this.addComboBox(["°C","°F"],"units");
this.addLabel(_("Wind Speed Unit"));
this.addComboBox(["km/h","mph","m/s","knots"],"wind_speed_unit");
this.addLabel(_("Position in Panel"));
this.addComboBox([_("Center"),_("Right"),_("Left")],"position_in_panel");
this.addLabel(_("Translate Conditions"));

Loading…
Cancel
Save