Use geocode.farm as default geolocation-data provider.

Add the possibility to chose either geocode.farm or openmapquest as geolocation-provider.
Note: openmapquest needs an AppKey since 15. September 2015; see: https://open.mapquestapi.com/nominatim/ .
merge-requests/218/head
Jens Lody 9 years ago
parent 98b46113f9
commit 7ec1b05cec
  1. 12
      data/org.gnome.shell.extensions.openweather.gschema.xml.in
  2. 87
      data/weather-settings.ui
  3. 171
      src/prefs.js

@ -3,6 +3,10 @@
<value nick="openweathermap" value="0" />
<value nick="forecast.io" value="1" />
</enum>
<enum id="org.gnome.shell.extensions.openweather.geolocation-provider">
<value nick="geocode" value="0" />
<value nick="mapquest" value="1" />
</enum>
<enum id="org.gnome.shell.extensions.openweather.unit">
<value nick="celsius" value="0" />
<value nick="fahrenheit" value="1" />
@ -47,6 +51,10 @@
<default>'openweathermap'</default>
<_summary>Weather Provider</_summary>
</key>
<key name="geolocation-provider" enum="org.gnome.shell.extensions.openweather.geolocation-provider">
<default>'geocode'</default>
<_summary>Geolocation Provider</_summary>
</key>
<key name="unit" enum="org.gnome.shell.extensions.openweather.unit">
<default>'fahrenheit'</default>
<_summary>Temperature Unit</_summary>
@ -129,5 +137,9 @@
<default>''</default>
<_summary>Your personal API key from forecast.io</_summary>
</key>
<key name="geolocation-appid-mapquest" type="s">
<default>''</default>
<_summary>Your personal AppKey from developer.geocode.farm</_summary>
</key>
</schema>
</schemalist>

@ -511,6 +511,7 @@
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="has_tooltip">True</property>
<property name="max_length">32</property>
<property name="width_chars">32</property>
</object>
<packing>
@ -545,6 +546,80 @@
<property name="tab_fill">False</property>
</packing>
</child>
<child>
<object class="GtkGrid" id="geolocation-grid">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="hexpand">True</property>
<property name="vexpand">True</property>
<property name="border_width">10</property>
<property name="row_spacing">5</property>
<property name="column_spacing">5</property>
<child>
<object class="GtkLabel" id="label-geolocation-provider">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label" translatable="yes">Chose geolocation provider</property>
</object>
<packing>
<property name="left_attach">0</property>
<property name="top_attach">0</property>
</packing>
</child>
<child>
<object class="GtkComboBoxText" id="geolocation_provider">
<property name="visible">True</property>
<property name="can_focus">False</property>
<items>
<item>https://geocode.farm/</item>
<item>https://open.mapquestapi.com/nominatim/</item>
</items>
</object>
<packing>
<property name="left_attach">1</property>
<property name="top_attach">0</property>
</packing>
</child>
<child>
<object class="GtkLabel" id="label-geolocation-appid-mapquest">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label" translatable="yes">Personal AppKey from developer.mapquest.com</property>
</object>
<packing>
<property name="left_attach">0</property>
<property name="top_attach">1</property>
</packing>
</child>
<child>
<object class="GtkEntry" id="geolocation_appid_mapquest">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="has_tooltip">True</property>
<property name="max_length">32</property>
<property name="width_chars">32</property>
</object>
<packing>
<property name="left_attach">1</property>
<property name="top_attach">1</property>
</packing>
</child>
</object>
<packing>
<property name="position">2</property>
</packing>
</child>
<child type="tab">
<object class="GtkLabel" id="geolocation-provider-label">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label" translatable="yes">Geolocation provider</property>
</object>
<packing>
<property name="position">2</property>
<property name="tab_fill">False</property>
</packing>
</child>
<child>
<object class="GtkGrid" id="units-grid">
<property name="visible">True</property>
@ -649,7 +724,7 @@
</child>
</object>
<packing>
<property name="position">2</property>
<property name="position">3</property>
</packing>
</child>
<child type="tab">
@ -659,7 +734,7 @@
<property name="label" translatable="yes">Units</property>
</object>
<packing>
<property name="position">2</property>
<property name="position">3</property>
<property name="tab_fill">False</property>
</packing>
</child>
@ -935,7 +1010,7 @@
</child>
</object>
<packing>
<property name="position">3</property>
<property name="position">4</property>
</packing>
</child>
<child type="tab">
@ -945,7 +1020,7 @@
<property name="label" translatable="yes">Layout</property>
</object>
<packing>
<property name="position">3</property>
<property name="position">4</property>
<property name="tab_fill">False</property>
</packing>
</child>
@ -1116,7 +1191,7 @@ See the &lt;a href="https://www.gnu.org/licenses/old-licenses/gpl-2.0.html"&gt;G
</child>
</object>
<packing>
<property name="position">4</property>
<property name="position">5</property>
</packing>
</child>
<child type="tab">
@ -1126,7 +1201,7 @@ See the &lt;a href="https://www.gnu.org/licenses/old-licenses/gpl-2.0.html"&gt;G
<property name="label" translatable="yes">About</property>
</object>
<packing>
<property name="position">4</property>
<property name="position">5</property>
<property name="tab_fill">False</property>
</packing>
</child>

@ -45,6 +45,7 @@ const EXTENSIONDIR = Me.dir.get_path();
const OPENWEATHER_SETTINGS_SCHEMA = 'org.gnome.shell.extensions.openweather';
const OPENWEATHER_PROVIDER_KEY = 'weather-provider';
const OPENWEATHER_GEOLOCATION_PROVIDER_KEY = 'geolocation-provider';
const OPENWEATHER_UNIT_KEY = 'unit';
const OPENWEATHER_PRESSURE_UNIT_KEY = 'pressure-unit';
const OPENWEATHER_WIND_SPEED_UNIT_KEY = 'wind-speed-unit';
@ -65,18 +66,26 @@ const OPENWEATHER_DAYS_FORECAST = 'days-forecast';
const OPENWEATHER_DECIMAL_PLACES = 'decimal-places';
const OPENWEATHER_OWM_API_KEY = 'appid';
const OPENWEATHER_FC_API_KEY = 'appid-fc';
const OPENWEATHER_GC_APP_KEY = 'geolocation-appid-mapquest';
//URL
const OPENWEATHER_URL_BASE = 'https://open.mapquestapi.com/nominatim/v1/';
const OPENWEATHER_URL_FIND = OPENWEATHER_URL_BASE + 'search.php';
const OPENWEATHER_URL_REVERSE = OPENWEATHER_URL_BASE + 'reverse.php';
const OPENWEATHER_URL_MAPQUEST_BASE = 'https://open.mapquestapi.com/nominatim/v1/';
const OPENWEATHER_URL_MAPQUEST_FIND = OPENWEATHER_URL_MAPQUEST_BASE + 'search.php';
const OPENWEATHER_URL_GEOCODE_BASE = 'https://www.geocode.farm/v3/';
const OPENWEATHER_URL_GEOCODE_FIND = OPENWEATHER_URL_GEOCODE_BASE + 'json/forward';
// Keep enums in sync with GSettings schemas
const WeatherProvider = {
DEFAULT: -1,
OPENWEATHERMAP: 0,
FORECAST_IO: 1
};
const GeolocationProvider = {
GEOCODE: 0,
MAPQUEST: 1
};
let _httpSession;
let mCities = null;
@ -169,11 +178,6 @@ const WeatherPrefsWidget = new GObject.Class({
let location = this.searchName.get_text().trim();
if (location === "")
return 0;
let params = {
format: 'json',
addressdetails: '1',
q: location
};
let item = new Gtk.MenuItem();
if (this.spinner.get_parent())
@ -183,37 +187,120 @@ const WeatherPrefsWidget = new GObject.Class({
this.searchMenu.show_all();
this.searchMenu.popup(null, null, Lang.bind(this, this.placeSearchMenu), 0, this.searchName);
this.loadJsonAsync(OPENWEATHER_URL_FIND, params, Lang.bind(this, function() {
if (!arguments[0])
return 0;
this.clearSearchMenu();
let newCity = arguments[0];
if (Number(newCity.length) < 1) {
if (this.geolocation_provider == GeolocationProvider.MAPQUEST) {
if (this.geolocation_appid_mapquest === '') {
this.clearSearchMenu();
let item = new Gtk.MenuItem({
label: _("\"%s\" not found").format(location)
label: "You need an AppKey to search on openmapquest."
});
this.searchMenu.append(item);
item = new Gtk.MenuItem({
label: "Please visit https://developer.mapquest.com/ ."
});
this.searchMenu.append(item);
} else {
var m = {};
for (var i in newCity) {
this.searchMenu.show_all();
this.searchMenu.popup(null, null, Lang.bind(this, this.placeSearchMenu), 0, this.searchName);
return 0;
}
let params = {
key: this.geolocation_appid_mapquest,
format: 'json',
addressdetails: '1',
q: location
};
this.loadJsonAsync(OPENWEATHER_URL_MAPQUEST_FIND, params, Lang.bind(this, function() {
this.clearSearchMenu();
if (!arguments[0]) {
let item = new Gtk.MenuItem({
label: _("Invalid data when searching for\"%s\"").format(location)
});
this.searchMenu.append(item);
item = new Gtk.MenuItem({
label: "Do you use a valid AppKey to search on openmapquest ?"
});
this.searchMenu.append(item);
item = new Gtk.MenuItem({
label: "If not, please visit https://developer.mapquest.com/ ."
});
this.searchMenu.append(item);
} else {
let newCity = arguments[0];
if (Number(newCity.length) < 1) {
let item = new Gtk.MenuItem({
label: _("\"%s\" not found").format(location)
});
this.searchMenu.append(item);
} else {
var m = {};
for (var i in newCity) {
let cityText = newCity[i].display_name;
let cityCoord = "[" + newCity[i].lat + "," + newCity[i].lon + "]";
let item = new Gtk.MenuItem({
label: cityText + " " + cityCoord
});
item.connect("activate", Lang.bind(this, this.onActivateItem));
this.searchMenu.append(item);
}
}
}
this.searchMenu.show_all();
this.searchMenu.popup(null, null, Lang.bind(this, this.placeSearchMenu), 0, this.searchName);
return 0;
}));
} else if (this.geolocation_provider == GeolocationProvider.GEOCODE) {
let params = {
addr: location
};
let cityText = newCity[i].display_name;
let cityCoord = "[" + newCity[i].lat + "," + newCity[i].lon + "]";
this.loadJsonAsync(OPENWEATHER_URL_GEOCODE_FIND, params, Lang.bind(this, function() {
this.clearSearchMenu();
if (!arguments[0]) {
let item = new Gtk.MenuItem({
label: cityText + " " + cityCoord
label: _("Invalid data when searching for\"%s\"").format(location)
});
item.connect("activate", Lang.bind(this, this.onActivateItem));
this.searchMenu.append(item);
} else {
let newCity = arguments[0].geocoding_results;
if (Number(newCity.length) < 1) {
let item = new Gtk.MenuItem({
label: _("Invalid data when searching for\"%s\"").format(location)
});
this.searchMenu.append(item);
} else {
if (Number(newCity.STATUS.result_count) < 1) {
let item = new Gtk.MenuItem({
label: _("\"%s\" not found").format(location)
});
this.searchMenu.append(item);
} else {
var m = {};
newCity = newCity.RESULTS;
for (var i in newCity) {
let cityText = newCity[i].formatted_address;
let cityCoord = "[" + newCity[i].COORDINATES.latitude + "," + newCity[i].COORDINATES.longitude + "]";
let item = new Gtk.MenuItem({
label: cityText + " " + cityCoord
});
item.connect("activate", Lang.bind(this, this.onActivateItem));
this.searchMenu.append(item);
}
}
}
}
}
this.searchMenu.show_all();
this.searchMenu.popup(null, null, Lang.bind(this, this.placeSearchMenu), 0, this.searchName);
return 0;
}));
this.searchMenu.show_all();
this.searchMenu.popup(null, null, Lang.bind(this, this.placeSearchMenu), 0, this.searchName);
return 0;
}));
}
return 0;
}));
@ -529,6 +616,18 @@ const WeatherPrefsWidget = new GObject.Class({
this.Settings.set_enum(OPENWEATHER_PROVIDER_KEY, v);
},
get geolocation_provider() {
if (!this.Settings)
this.loadConfig();
return this.Settings.get_enum(OPENWEATHER_GEOLOCATION_PROVIDER_KEY);
},
set geolocation_provider(v) {
if (!this.Settings)
this.loadConfig();
this.Settings.set_enum(OPENWEATHER_GEOLOCATION_PROVIDER_KEY, v);
},
get units() {
if (!this.Settings)
this.loadConfig();
@ -804,6 +903,18 @@ const WeatherPrefsWidget = new GObject.Class({
this.Settings.set_string(OPENWEATHER_FC_API_KEY, v);
},
get geolocation_appid_mapquest() {
if (!this.Settings)
this.loadConfig();
return this.Settings.get_string(OPENWEATHER_GC_APP_KEY);
},
set geolocation_appid_mapquest(v) {
if (!this.Settings)
this.loadConfig();
this.Settings.set_string(OPENWEATHER_GC_APP_KEY, v);
},
extractLocation: function() {
if (!arguments[0])
return "";

Loading…
Cancel
Save