Add default API-key for openweathermap.org, because it was added to there FOSS-whitelist.

Fixes #84.
Thanks to the team of openweathermap.org .
merge-requests/218/head
Jens Lody 9 years ago
parent ae12283ada
commit 54a6c497f8
  1. 4
      data/org.gnome.shell.extensions.openweather.gschema.xml.in
  2. 42
      data/weather-settings.ui
  3. 24
      src/extension.js
  4. 13
      src/prefs.js

@ -134,6 +134,10 @@
<default>''</default>
<_summary>Your personal API key from openweathermap.org</_summary>
</key>
<key name="use-default-owm-key" type="b">
<default>true</default>
<_summary>Use the extensions default API key from openweathermap.org</_summary>
</key>
<key name="appid-fc" type="s">
<default>''</default>
<_summary>Your personal API key from forecast.io</_summary>

@ -495,7 +495,7 @@
</object>
<packing>
<property name="left_attach">0</property>
<property name="top_attach">1</property>
<property name="top_attach">2</property>
</packing>
</child>
<child>
@ -521,7 +521,7 @@
</object>
<packing>
<property name="left_attach">1</property>
<property name="top_attach">1</property>
<property name="top_attach">2</property>
</packing>
</child>
<child>
@ -533,7 +533,7 @@
</object>
<packing>
<property name="left_attach">1</property>
<property name="top_attach">2</property>
<property name="top_attach">3</property>
</packing>
</child>
<child>
@ -546,7 +546,7 @@
</object>
<packing>
<property name="left_attach">0</property>
<property name="top_attach">2</property>
<property name="top_attach">3</property>
</packing>
</child>
<child>
@ -560,7 +560,7 @@
</object>
<packing>
<property name="left_attach">0</property>
<property name="top_attach">4</property>
<property name="top_attach">5</property>
</packing>
</child>
<child>
@ -574,7 +574,7 @@
</object>
<packing>
<property name="left_attach">0</property>
<property name="top_attach">5</property>
<property name="top_attach">6</property>
</packing>
</child>
<child>
@ -590,7 +590,7 @@
</object>
<packing>
<property name="left_attach">1</property>
<property name="top_attach">4</property>
<property name="top_attach">5</property>
</packing>
</child>
<child>
@ -606,7 +606,7 @@
</object>
<packing>
<property name="left_attach">1</property>
<property name="top_attach">5</property>
<property name="top_attach">6</property>
</packing>
</child>
<child>
@ -616,10 +616,34 @@
</object>
<packing>
<property name="left_attach">0</property>
<property name="top_attach">3</property>
<property name="top_attach">4</property>
<property name="width">2</property>
</packing>
</child>
<child>
<object class="GtkLabel" id="label-use-default-owm-appid">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="halign">start</property>
<property name="label" translatable="yes">Use extensions api-key for openweathermap.org</property>
</object>
<packing>
<property name="left_attach">0</property>
<property name="top_attach">1</property>
</packing>
</child>
<child>
<object class="GtkSwitch" id="use_default_owm_key">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="tooltip_text" translatable="yes">Switch off, if you have your own api-key for openweathermap.org and put it into the text-box below.</property>
<property name="halign">center</property>
</object>
<packing>
<property name="left_attach">1</property>
<property name="top_attach">1</property>
</packing>
</child>
</object>
<packing>
<property name="position">1</property>

@ -81,7 +81,9 @@ const OPENWEATHER_REFRESH_INTERVAL_FORECAST = 'refresh-interval-forecast';
const OPENWEATHER_CENTER_FORECAST_KEY = 'center-forecast';
const OPENWEATHER_DAYS_FORECAST = 'days-forecast';
const OPENWEATHER_DECIMAL_PLACES = 'decimal-places';
const OPENWEATHER_USE_DEFAULT_OWM_API_KEY = 'use-default-owm-key';
const OPENWEATHER_OWM_API_KEY = 'appid';
const OPENWEATHER_OWM_DEFAULT_API_KEY = 'c93b4a667c8c9d1d1eb941621f899bb8';
const OPENWEATHER_FC_API_KEY = 'appid-fc';
// Keep enums in sync with GSettings schemas
@ -157,6 +159,7 @@ const OpenweatherMenuButton = new Lang.Class({
this.user_agent += ' ';
this.oldProvider = this._weather_provider;
this.oldUseDefaultOwmKey = this._use_default_owm_key;
this.oldTranslateCondition = this._translate_condition;
this.switchProvider();
@ -364,7 +367,7 @@ const OpenweatherMenuButton = new Lang.Class({
this.weatherProvider = "https://openweathermap.org/";
if (this._appid.toString().trim() === '')
Main.notify("Openweather", _("Openweathermap.org does not work without an api-key.\nPlease register at http://openweathermap.org/appid and paste your personal key into the preferences dialog."));
Main.notify("Openweather", _("Openweathermap.org does not work without an api-key.\nEither set the swith to use the extensions default key in the preferences dialog to on or register at http://openweathermap.org/appid and paste your personal key into the preferences dialog."));
},
@ -519,6 +522,13 @@ const OpenweatherMenuButton = new Lang.Class({
this.oldProvider = provider;
return true;
}
if (provider == WeatherProvider.OPENWEATHERMAP) {
let useDefaultOwmKey = this._use_default_owm_key;
if (this.oldUseDefaultOwmKey != useDefaultOwmKey) {
this.oldUseDefaultOwmKey = useDefaultOwmKey;
return true;
}
}
if (provider == WeatherProvider.FORECAST_IO) {
let translateCondition = this._translate_condition;
if (this.oldTranslateCondition != translateCondition) {
@ -717,10 +727,20 @@ const OpenweatherMenuButton = new Lang.Class({
get _appid() {
if (!this._settings)
this.loadConfig();
let key = this._settings.get_string(OPENWEATHER_OWM_API_KEY);
let key = '';
if (this._use_default_owm_key)
key = OPENWEATHER_OWM_DEFAULT_API_KEY;
else
key = this._settings.get_string(OPENWEATHER_OWM_API_KEY);
return (key.length == 32) ? key : '';
},
get _use_default_owm_key() {
if (!this._settings)
this.loadConfig();
return this._settings.get_boolean(OPENWEATHER_USE_DEFAULT_OWM_API_KEY);
},
get _appid_fc() {
if (!this._settings)
this.loadConfig();

@ -65,6 +65,7 @@ const OPENWEATHER_REFRESH_INTERVAL_FORECAST = 'refresh-interval-forecast';
const OPENWEATHER_CENTER_FORECAST_KEY = 'center-forecast';
const OPENWEATHER_DAYS_FORECAST = 'days-forecast';
const OPENWEATHER_DECIMAL_PLACES = 'decimal-places';
const OPENWEATHER_USE_DEFAULT_OWM_API_KEY = 'use-default-owm-key';
const OPENWEATHER_OWM_API_KEY = 'appid';
const OPENWEATHER_FC_API_KEY = 'appid-fc';
const OPENWEATHER_GC_APP_KEY = 'geolocation-appid-mapquest';
@ -976,6 +977,18 @@ const WeatherPrefsWidget = new GObject.Class({
this.Settings.set_string(OPENWEATHER_OWM_API_KEY, v);
},
get use_default_owm_key() {
if (!this.Settings)
this.loadConfig();
return this.Settings.get_boolean(OPENWEATHER_USE_DEFAULT_OWM_API_KEY);
},
set use_default_owm_key(v) {
if (!this.Settings)
this.loadConfig();
this.Settings.set_boolean(OPENWEATHER_USE_DEFAULT_OWM_API_KEY, v);
},
get appid_fc() {
if (!this.Settings)
this.loadConfig();

Loading…
Cancel
Save