From 3b75e6a9f013d4e1dfb1207bc16da58b1cbbf82b Mon Sep 17 00:00:00 2001 From: ecyrbe Date: Fri, 27 May 2011 08:07:02 +0200 Subject: [PATCH] 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. --- .gitignore | 17 ++++++ README | 40 ++++++++++--- README.md | 40 ++++++++++--- configure.ac | 2 +- src/Makefile.am | 11 ++++ src/extension.js | 56 +++++++++++++++---- ...me.shell.extensions.weather.gschema.xml.in | 23 ++++++++ 7 files changed, 160 insertions(+), 29 deletions(-) create mode 100644 .gitignore create mode 100644 src/org.gnome.shell.extensions.weather.gschema.xml.in diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..c0ba1fe --- /dev/null +++ b/.gitignore @@ -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 diff --git a/README b/README index 4909757..2c0702b 100644 --- a/README +++ b/README @@ -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 diff --git a/README.md b/README.md index 4909757..2c0702b 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/configure.ac b/configure.ac index 38057c8..f1810d5 100644 --- a/configure.ac +++ b/configure.ac @@ -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]) diff --git a/src/Makefile.am b/src/Makefile.am index d6d06cd..0ac631b 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -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) diff --git a/src/extension.js b/src/extension.js index 173ef5d..a7150cd 100644 --- a/src/extension.js +++ b/src/extension.js @@ -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,7 +65,16 @@ 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({ icon_type: St.IconType.SYMBOLIC, @@ -117,6 +131,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)){ @@ -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); } diff --git a/src/org.gnome.shell.extensions.weather.gschema.xml.in b/src/org.gnome.shell.extensions.weather.gschema.xml.in new file mode 100644 index 0000000..9014094 --- /dev/null +++ b/src/org.gnome.shell.extensions.weather.gschema.xml.in @@ -0,0 +1,23 @@ + + + + + + + + 'celsius' + <_summary>display units + <_description>Choose the units you want the temperatures. Allowed values are 'celsius' or 'fahrenheit' + + + 'FRXX6724' + <_summary>Forecast Yahoo WOEID + <_description>Set Yahoo id location to retrieve the corresponding forecast informations + + + '' + <_summary>City to be displayed + <_description>Optional, you can override the displayed city provided by the woeid location + + +