void a_geonames_wikipedia_box(VikWindow *vw, VikTrwLayer *vtl, VikLayersPanel *vlp, struct LatLon maxmin[2]) { gchar *uri; gchar *tmpname; GList *wiki_places; GList *selected; GList *wp_runner; VikWaypoint *wiki_wp; found_geoname *wiki_geoname; /* encode doubles in a C locale */ gchar *north = a_coords_dtostr(maxmin[0].lat); gchar *south = a_coords_dtostr(maxmin[1].lat); gchar *east = a_coords_dtostr(maxmin[0].lon); gchar *west = a_coords_dtostr(maxmin[1].lon); uri = g_strdup_printf(GEONAMES_WIKIPEDIA_URL_FMT, north, south, east, west); g_free(north); north = NULL; g_free(south); south = NULL; g_free(east); east = NULL; g_free(west); west = NULL; tmpname = download_url(uri); if (!tmpname) { none_found(vw); return; } wiki_places = get_entries_from_file(tmpname); if (g_list_length(wiki_places) == 0) { none_found(vw); return; } selected = a_select_geoname_from_list(VIK_GTK_WINDOW_FROM_WIDGET(vw), wiki_places, TRUE, "Select articles", "Select the articles you want to add."); wp_runner = selected; while (wp_runner) { wiki_geoname = (found_geoname *)wp_runner->data; wiki_wp = vik_waypoint_new(); wiki_wp->visible = TRUE; vik_coord_load_from_latlon(&(wiki_wp->coord), vik_trw_layer_get_coord_mode ( vtl ), &(wiki_geoname->ll)); vik_waypoint_set_comment(wiki_wp, wiki_geoname->desc); vik_trw_layer_filein_add_waypoint ( vtl, wiki_geoname->name, wiki_wp ); wp_runner = g_list_next(wp_runner); } free_geoname_list(wiki_places); free_geoname_list(selected); g_free(uri); if (tmpname) { g_free(tmpname); } vik_layers_panel_emit_update(vlp); }
static int parse_file_for_latlon(VikWindow *vw, gchar *file_name, struct LatLon *ll) { /* return codes: 1 : All OK, position selected; 2 : No position selected; 3 : No places found. */ int found = 1; found_geoname *geoname; GList *found_places = get_entries_from_file(file_name); int num_found_places; num_found_places = g_list_length(found_places); if (num_found_places == 0) { found = 3; } else { if (num_found_places == 1) { geoname = (found_geoname *)found_places->data; ll->lat = geoname->ll.lat; ll->lon = geoname->ll.lon; } else { GList *selected = a_select_geoname_from_list(VIK_GTK_WINDOW_FROM_WIDGET(vw), found_places, FALSE, "Select place", "Select the place to go to"); if (selected) { geoname = (found_geoname *)selected->data; ll->lat = geoname->ll.lat; ll->lon = geoname->ll.lon; g_list_foreach(selected, (GFunc)free_list_geonames, NULL); } else { found = 2; } } } free_geoname_list(found_places); return (found); }