Add GSettings configuration

No more code editing. This extension now uses gsettings to configure everything.
Documention updated according to this functionnality
Under the woods, we added gsettings schemas that need to be installed in the system
so you need admin rights to install this extension.
yahoo_weather
ecyrbe 14 years ago
parent 5c0e32a848
commit 3b75e6a9f0
  1. 17
      .gitignore
  2. 40
      README
  3. 40
      README.md
  4. 2
      configure.ac
  5. 11
      src/Makefile.am
  6. 54
      src/extension.js
  7. 23
      src/org.gnome.shell.extensions.weather.gschema.xml.in

17
.gitignore vendored

@ -0,0 +1,17 @@
Makefile
Makefile.in
Makefile.in.in
configure
config.log
config.status
aclocal.m4
autom4te.cache/
po/POTFILES
po/stamp-it
staging/
*~
*.gmo
metadata.json
*.gschema.xml
*.gschema.valid

@ -10,14 +10,38 @@ Currently, the weather report including forecast for today and tomorrow is fetch
### Installation
1. Change `YAHOO_ID` to your location in extension.js (cf. [WOEID](http://developer.yahoo.com/geo/geoplanet/guide/concepts.html))
2. chage the 'CITY_DIPLAYED' to the real name of your location as the WOEID doesn't always match your tiny town
3. from command line run the following commands :
> ./autogen.sh --prefix="/usr"
> make
> sudo make install
3. Restart Gnome Shell (`[Alt]+[F2]`, `r`)
4. Enjoy, contribute, ...
From the command line
1. ./autogen.sh --prefix="/usr"
2. make
3. sudo make install
that's it!
### Configuration
Gnome extension weather use gsettings to save your configuration
You can modify the temperature unit with the following command
. gsettings set org.gnome.shell.extensions.weather unit 'celsius'
or
. gsettings set org.gnome.shell.extensions.weather unit 'fahrenheit'
You can specify your location buy using this command, (cf. [WOEID](http://developer.yahoo.com/geo/geoplanet/guide/concepts.html))
. gsettings set org.gnome.shell.extensions.weather woeid 'your location'
Sometimes your woeid location isn't quite right. it's the next major city around. to customise the displayed city you can type :
. gsettings set org.gnome.shell.extensions.weather city 'your city'
### Restart Gnome-Shell
Don't forget to restart Gnome-Shell
1. Restart Gnome Shell (`[Alt]+[F2]`, `r`)
2. Fork this project as you like
### Licence

@ -10,14 +10,38 @@ Currently, the weather report including forecast for today and tomorrow is fetch
### Installation
1. Change `YAHOO_ID` to your location in extension.js (cf. [WOEID](http://developer.yahoo.com/geo/geoplanet/guide/concepts.html))
2. chage the 'CITY_DIPLAYED' to the real name of your location as the WOEID doesn't always match your tiny town
3. from command line run the following commands :
> ./autogen.sh --prefix="/usr"
> make
> sudo make install
3. Restart Gnome Shell (`[Alt]+[F2]`, `r`)
4. Enjoy, contribute, ...
From the command line
1. ./autogen.sh --prefix="/usr"
2. make
3. sudo make install
that's it!
### Configuration
Gnome extension weather use gsettings to save your configuration
You can modify the temperature unit with the following command
. gsettings set org.gnome.shell.extensions.weather unit 'celsius'
or
. gsettings set org.gnome.shell.extensions.weather unit 'fahrenheit'
You can specify your location buy using this command, (cf. [WOEID](http://developer.yahoo.com/geo/geoplanet/guide/concepts.html))
. gsettings set org.gnome.shell.extensions.weather woeid 'your location'
Sometimes your woeid location isn't quite right. it's the next major city around. to customise the displayed city you can type :
. gsettings set org.gnome.shell.extensions.weather city 'your city'
### Restart Gnome-Shell
Don't forget to restart Gnome-Shell
1. Restart Gnome Shell (`[Alt]+[F2]`, `r`)
2. Fork this project as you like
### Licence

@ -1,6 +1,6 @@
AC_PREREQ(2.63)
dnl be carefull, the version needs to be in sync with your gnome shell version
AC_INIT([gnome-shell-extension-weather],[3.0.1],[https://github.com/ecyrbe/gnome-shell-extension-weather/issues])
AC_INIT([gnome-shell-extension-weather],[3.0],[https://github.com/ecyrbe/gnome-shell-extension-weather/issues])
AC_CONFIG_MACRO_DIR([m4])
AC_CONFIG_AUX_DIR([config])

@ -19,3 +19,14 @@ metadata.json: metadata.json.in $(top_builddir)/config.status
-e "s|[@]url@|$(extensionurl)|" $< > $@
CLEANFILES = metadata.json
gschemas_in = org.gnome.shell.extensions.weather.gschema.xml.in
@INTLTOOL_XML_NOMERGE_RULE@
gsettings_SCHEMAS = $(gschemas_in:.xml.in=.xml)
@GSETTINGS_RULES@
CLEANFILES += $(gschemas_in:.xml.in=.valid) $(gsettings_SCHEMAS)
EXTRA_DIST += $(gschemas_in)

@ -45,12 +45,17 @@ const PopupMenu = imports.ui.popupMenu;
const Soup = imports.gi.Soup;
const Util = imports.misc.util;
const UNITS = 'c'; // Units for temperature (case sensitive). f: Fahrenheit. c: Celsius
const CITY_DISPLAYED = 'your city';
const YAHOO_ID = 'your yahoo woeid';
const WEATHER_URL = 'http://weather.yahooapis.com/forecastjson?u=' + UNITS + '&p=' + YAHOO_ID;
const FORECAST_URL = 'http://query.yahooapis.com/v1/public/yql?format=json&q=select%20item.forecast%20from%20weather.forecast%20where%20location%3D%22' + YAHOO_ID + '%22%20%20and%20u="' + UNITS + '"';
// Settings
const WEATHER_SETTINGS_SCHEMA = 'org.gnome.shell.extensions.weather';
const WEATHER_UNIT_KEY = 'unit';
const WEATHER_CITY_KEY = 'city';
const WEATHER_WOEID_KEY = 'woeid';
// Keep enums in sync with GSettings schemas
const WeatherUnits = {
CELSIUS: 0,
FAHRENHEIT: 1
};
function WeatherMenuButton() {
this._init();
@ -60,6 +65,15 @@ WeatherMenuButton.prototype = {
__proto__: PanelMenu.Button.prototype,
_init: function() {
// Load Settings
this._settings = new Gio.Settings({ schema: WEATHER_SETTINGS_SCHEMA });
if(this._settings==null){
global.log('xml weather schemas not installed');
return;
}
this._units = this._settings.get_enum(WEATHER_UNIT_KEY);
this._city = this._settings.get_string(WEATHER_CITY_KEY);
this._woeid = this._settings.get_string(WEATHER_WOEID_KEY);
// Panel icon
this._weatherIcon = new St.Icon({
@ -118,6 +132,22 @@ WeatherMenuButton.prototype = {
},
unit_to_string: function(unit) {
if(unit == WeatherUnits.FAHRENHEIT){
return 'f';
}else {
return 'c';
}
},
get_weather_url: function() {
return 'http://weather.yahooapis.com/forecastjson?u=' + this.unit_to_string(this._units) + '&p=' + this._woeid;
},
get_forecast_url: function() {
return 'http://query.yahooapis.com/v1/public/yql?format=json&q=select%20item.forecast%20from%20weather.forecast%20where%20location%3D%22' + this._woeid + '%22%20%20and%20u="' + this.unit_to_string(this._units) + '"';
},
get_weather_icon: function(code) {
switch (parseInt(code, 10)){
/* see http://developer.yahoo.com/weather/#codetable */
@ -358,11 +388,13 @@ WeatherMenuButton.prototype = {
},
refreshWeather: function() {
// Refresh current weather
this.load_json_async(WEATHER_URL, function(weather) {
this.load_json_async(this.get_weather_url(), function(weather) {
let location = CITY_DISPLAYED;
let location = weather.get_object_member('location').get_string_member('city');
if(this._city!=null && this._city.length>0) {
location = this._city;
}
let comment = this.get_weather_condition(weather.get_object_member('condition').get_string_member('code'));
let temperature = weather.get_object_member('condition').get_double_member('temperature');
let temperature_unit = '\u00b0' + weather.get_object_member('units').get_string_member('temperature');
@ -387,7 +419,7 @@ WeatherMenuButton.prototype = {
});
// Refresh forecast
this.load_json_async(FORECAST_URL, function(forecast) {
this.load_json_async(this.get_forecast_url(), function(forecast) {
date_string = [_('Today'), _('Tomorrow')];
forecast2 = forecast.get_object_member('query').get_object_member('results').get_array_member('channel').get_elements();
@ -401,7 +433,7 @@ WeatherMenuButton.prototype = {
let t_high = forecastData.get_string_member('high');
forecastUi.Day.text = date_string[i] + ' (' + this.get_locale_day(forecastData.get_string_member('day')) + ')';
forecastUi.Temperature.text = t_low + '\u2013' + t_high + ' \u00b0' + UNITS.toUpperCase();
forecastUi.Temperature.text = t_low + '\u2013' + t_high + ' \u00b0' + this.unit_to_string(this._units).toUpperCase();
forecastUi.Summary.text = comment;
forecastUi.Icon.icon_name = this.get_weather_icon(code);
}

@ -0,0 +1,23 @@
<schemalist gettext-domain="gnome-shell-extension-weather">
<enum id="org.gnome.shell.extensions.weather.unit">
<value nick="celsius" value="0" />
<value nick="fahrenheit" value="1" />
</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>
<_summary>display units</_summary>
<_description>Choose the units you want the temperatures. Allowed values are 'celsius' or 'fahrenheit'</_description>
</key>
<key name="woeid" type="s">
<default>'FRXX6724'</default>
<_summary>Forecast Yahoo WOEID</_summary>
<_description>Set Yahoo id location to retrieve the corresponding forecast informations</_description>
</key>
<key name="city" type="s">
<default>''</default>
<_summary>City to be displayed</_summary>
<_description>Optional, you can override the displayed city provided by the woeid location</_description>
</key>
</schema>
</schemalist>
Loading…
Cancel
Save