+ g_regex_unref(regex);
+ g_list_foreach(times, (GFunc)g_free, NULL);
+ g_list_free(times);
+}
+static void update_times_online_cb(char *path, gboolean updated, gpointer _self)
+{
+ GList *times = NULL;
+ gchar *data;
+ gsize length;
+ g_file_get_contents(path, &data, &length, NULL);
+ gchar **lines = g_strsplit(data, "\n", -1);
+ for (int i = 0; lines[i] && lines[i][0]; i++) {
+ char **parts = g_strsplit(lines[i], " ", 2);
+ times = g_list_prepend(times, g_strdup(parts[1]));
+ g_strfreev(parts);
+ }
+ g_strfreev(lines);
+ g_free(data);
+
+ update_times_gtk(_self, times);
+}
+static void update_times(AWeatherGui *self, GisViewer *viewer, char *site)
+{
+ g_debug("AWeatherGui: update_times - site=%s", site);
+ if (gis_viewer_get_offline(self->viewer)) {
+ GList *times = NULL;
+ gchar *path = g_build_filename(g_get_user_cache_dir(),
+ "libgis", "nexrad", "level2", site, NULL);
+ GDir *dir = g_dir_open(path, 0, NULL);
+ if (dir) {
+ const gchar *name;
+ while ((name = g_dir_read_name(dir))) {
+ times = g_list_prepend(times, g_strdup(name));
+ }
+ g_dir_close(dir);
+ }
+ g_free(path);
+ update_times_gtk(self, times);
+ } else {
+ GisHttp *http = gis_http_new("/nexrad/level2/");
+ gchar *base = gis_prefs_get_string(self->prefs, "aweather/nexrad_url", NULL);
+ gchar *local = g_strdup_printf("%s/dir.list", site);
+ gchar *uri = g_strconcat(base, "/", local, NULL);
+ gchar *path = gis_http_fetch(http, uri, local, GIS_REFRESH, NULL, NULL);
+ update_times_online_cb(path, TRUE, self);
+ gis_http_free(http);
+ /* update_times_gtk from update_times_online_cb */
+ }
+}
+/* FIXME: This is redundent with the radar plugin
+ * Make a shared wsr88d file? */
+static void on_gis_location_changed(GisViewer *viewer,
+ gdouble lat, gdouble lon, gdouble elev,
+ gpointer _self)
+{
+ AWeatherGui *self = AWEATHER_GUI(_self);
+ gdouble min_dist = EARTH_R / 5;
+ city_t *city, *min_city = NULL;
+ for (city = cities; city->type; city++) {
+ if (city->type != LOCATION_CITY)
+ continue;
+ gdouble city_loc[3] = {};
+ gdouble eye_loc[3] = {lat, lon, elev};
+ lle2xyz(city->lat, city->lon, city->elev,
+ &city_loc[0], &city_loc[1], &city_loc[2]);
+ lle2xyz(lat, lon, elev,
+ &eye_loc[0], &eye_loc[1], &eye_loc[2]);
+ gdouble dist = distd(city_loc, eye_loc);
+ if (dist < min_dist) {
+ min_dist = dist;
+ min_city = city;
+ }
+ }
+ static city_t *last_city = NULL;
+ if (min_city && min_city != last_city) {
+ update_site_widget(self->viewer, min_city->code, self);
+ update_times(self, viewer, min_city->code);
+ }
+ last_city = min_city;
+}
+static void on_gis_refresh(GisViewer *viewer, gpointer _self)
+{
+ AWeatherGui *self = AWEATHER_GUI(_self);
+ gdouble lat, lon, elev;
+ gis_viewer_get_location(self->viewer, &lat, &lon, &elev);
+ /* Hack to update times */
+ on_gis_location_changed(self->viewer, lat, lon, elev, self);