static void latest_version_thread ( GtkWindow *window ) { // Need to allow a few redirects, as SF file is often served from different server DownloadMapOptions options = { FALSE, FALSE, NULL, 5, NULL, NULL, NULL }; gchar *filename = a_download_uri_to_tmp_file ( "http://sourceforge.net/projects/viking/files/VERSION", &options ); //gchar *filename = g_strdup ( "VERSION" ); if ( !filename ) { return; } GMappedFile *mf = g_mapped_file_new ( filename, FALSE, NULL ); if ( !mf ) return; gchar *text = g_mapped_file_get_contents ( mf ); gint latest_version = viking_version_to_number ( text ); gint my_version = viking_version_to_number ( VIKING_VERSION ); g_debug ( "The lastest version is: %s", text ); if ( my_version < latest_version ) { new_version_thread_data *nvtd = g_malloc ( sizeof(new_version_thread_data) ); nvtd->window = window; nvtd->version = g_strdup ( text ); gdk_threads_add_idle ( (GSourceFunc) new_version_available_message, nvtd ); } else g_debug ( "Running the lastest version: %s", VIKING_VERSION ); g_mapped_file_unref ( mf ); if ( filename ) { g_remove ( filename ); g_free ( filename ); } // Update last checked time GTimeVal time; g_get_current_time ( &time ); a_settings_set_string ( VIK_SETTINGS_VERSION_CHECKED_DATE, g_time_val_to_iso8601(&time) ); }
static gboolean datasource_osm_my_traces_process ( VikTrwLayer *vtl, const gchar *cmd, const gchar *extra, BabelStatusFunc status_cb, acq_dialog_widgets_t *adw, DownloadMapOptions *options_unused ) { //datasource_osm_my_traces_t *data = (datasource_osm_my_traces_t *)adw->user_data; gboolean result; gchar *user_pass = osm_get_login(); DownloadMapOptions options = { FALSE, FALSE, NULL, 2, NULL, user_pass }; // Allow a couple of redirects xml_data *xd = g_malloc ( sizeof (xml_data) ); //xd->xpath = g_string_new ( "" ); xd->c_cdata = g_string_new ( "" ); xd->current_tag = tt_unknown; xd->current_gpx_meta_data = new_gpx_meta_data_t(); xd->list_of_gpx_meta_data = NULL; gchar *tmpname = a_download_uri_to_tmp_file ( DS_OSM_TRACES_GPX_FILES, &options ); result = read_gpx_files_metadata_xml ( tmpname, xd ); // Test already downloaded metadata file: eg: //result = read_gpx_files_metadata_xml ( "/tmp/viking-download.GI47PW", xd ); if ( tmpname ) { g_remove ( tmpname ); g_free ( tmpname ); } if ( ! result ) return FALSE; if ( g_list_length ( xd->list_of_gpx_meta_data ) == 0 ) { if (!vik_datasource_osm_my_traces_interface.is_thread) none_found ( GTK_WINDOW(adw->vw) ); return FALSE; } xd->list_of_gpx_meta_data = g_list_reverse ( xd->list_of_gpx_meta_data ); set_in_current_view_property ( vtl, adw->user_data, xd->list_of_gpx_meta_data ); if (vik_datasource_osm_my_traces_interface.is_thread) gdk_threads_enter(); GList *selected = select_from_list ( GTK_WINDOW(adw->vw), xd->list_of_gpx_meta_data, "Select GPS Traces", "Select the GPS traces you want to add." ); if (vik_datasource_osm_my_traces_interface.is_thread) gdk_threads_leave(); // If passed in on an existing layer - we will create everything into that. // thus with many differing gpx's - this will combine all waypoints into this single layer! // Hence the preference is to create multiple layers // and so this creation of the layers must be managed here gboolean create_new_layer = ( !vtl ); // Only update the screen on the last layer acquired VikTrwLayer *vtl_last = vtl; gboolean got_something = FALSE; GList *selected_iterator = selected; while ( selected_iterator ) { VikTrwLayer *vtlX = vtl; if ( create_new_layer ) { // Have data but no layer - so create one vtlX = VIK_TRW_LAYER ( vik_layer_create ( VIK_LAYER_TRW, vik_window_viewport(adw->vw), NULL, FALSE ) ); if ( ((gpx_meta_data_t*)selected_iterator->data)->name ) vik_layer_rename ( VIK_LAYER ( vtlX ), ((gpx_meta_data_t*)selected_iterator->data)->name ); else vik_layer_rename ( VIK_LAYER ( vtlX ), _("My OSM Traces") ); vik_aggregate_layer_add_layer ( vik_layers_panel_get_top_layer (adw->vlp), VIK_LAYER(vtlX) ); } result = FALSE; gint gpx_id = ((gpx_meta_data_t*)selected_iterator->data)->id; if ( gpx_id ) { gchar *url = g_strdup_printf ( DS_OSM_TRACES_GPX_URL_FMT, gpx_id ); result = a_babel_convert_from_url ( vtlX, url, "gpx", status_cb, adw, &options ); // TODO investigate using a progress bar: // http://developer.gnome.org/gtk/2.24/GtkProgressBar.html got_something = got_something || result; // TODO feedback to UI to inform which traces failed if ( !result ) g_warning ( _("Unable to get trace: %s"), url ); } if ( result ) { // Move to area of the track vik_trw_layer_auto_set_view ( vtlX, vik_window_viewport(adw->vw) ); vik_layer_post_read ( VIK_LAYER(vtlX), vik_window_viewport(adw->vw), TRUE ); vtl_last = vtlX; } else if ( create_new_layer ) { // Layer not needed as no data has been acquired g_object_unref ( vtlX ); } selected_iterator = g_list_next ( selected_iterator ); } // Free memory if ( xd->current_gpx_meta_data ) free_gpx_meta_data ( xd->current_gpx_meta_data, NULL ); g_free ( xd->current_gpx_meta_data ); free_gpx_meta_data_list ( xd->list_of_gpx_meta_data ); free_gpx_meta_data_list ( selected ); g_free ( xd ); g_free ( user_pass ); // Would prefer to keep the update in acquire.c, // however since we may create the layer - need to do the update here if ( got_something ) vik_layer_emit_update ( VIK_LAYER(vtl_last) ); // ATM The user is only informed if all getting *all* of the traces failed if ( selected ) result = got_something; else // Process was cancelled but need to return that it proceeded as expected result = TRUE; return result; }
/** * Automatic attempt to find out where you are using: * 1. http://www.hostip.info ++ * 2. if not specific enough fallback to using the default goto tool with a country name * ++ Using returned JSON information * c.f. with googlesearch.c - similar implementation is used here * * returns: * 0 if failed to locate anything * 1 if exact latitude/longitude found * 2 if position only as precise as a city * 3 if position only as precise as a country * @name: Contains the name of place found. Free this string after use. */ gint a_vik_goto_where_am_i ( VikViewport *vvp, struct LatLon *ll, gchar **name ) { gint result = 0; *name = NULL; gchar *tmpname = a_download_uri_to_tmp_file ( "http://api.hostip.info/get_json.php?position=true", NULL ); //gchar *tmpname = g_strdup ("../test/hostip2.json"); if (!tmpname) { return result; } ll->lat = 0.0; ll->lon = 0.0; gchar *pat; GMappedFile *mf; gchar *ss; gint fragment_len; gchar lat_buf[32], lon_buf[32]; lat_buf[0] = lon_buf[0] = '\0'; gchar *country = NULL; gchar *city = NULL; if ((mf = g_mapped_file_new(tmpname, FALSE, NULL)) == NULL) { g_critical(_("couldn't map temp file")); goto tidy; } gsize len = g_mapped_file_get_length(mf); gchar *text = g_mapped_file_get_contents(mf); if ((pat = g_strstr_len(text, len, HOSTIP_COUNTRY_PATTERN))) { pat += strlen(HOSTIP_COUNTRY_PATTERN); fragment_len = 0; ss = pat; while (*pat != '"') { fragment_len++; pat++; } country = g_strndup(ss, fragment_len); } if ((pat = g_strstr_len(text, len, HOSTIP_CITY_PATTERN))) { pat += strlen(HOSTIP_CITY_PATTERN); fragment_len = 0; ss = pat; while (*pat != '"') { fragment_len++; pat++; } city = g_strndup(ss, fragment_len); } if ((pat = g_strstr_len(text, len, HOSTIP_LATITUDE_PATTERN))) { pat += strlen(HOSTIP_LATITUDE_PATTERN); ss = lat_buf; if (*pat == '-') *ss++ = *pat++; while ((ss < (lat_buf + sizeof(lat_buf))) && (pat < (text + len)) && (g_ascii_isdigit(*pat) || (*pat == '.'))) *ss++ = *pat++; *ss = '\0'; ll->lat = g_ascii_strtod(lat_buf, NULL); } if ((pat = g_strstr_len(text, len, HOSTIP_LONGITUDE_PATTERN))) { pat += strlen(HOSTIP_LONGITUDE_PATTERN); ss = lon_buf; if (*pat == '-') *ss++ = *pat++; while ((ss < (lon_buf + sizeof(lon_buf))) && (pat < (text + len)) && (g_ascii_isdigit(*pat) || (*pat == '.'))) *ss++ = *pat++; *ss = '\0'; ll->lon = g_ascii_strtod(lon_buf, NULL); } if ( ll->lat != 0.0 && ll->lon != 0.0 ) { if ( ll->lat > -90.0 && ll->lat < 90.0 && ll->lon > -180.0 && ll->lon < 180.0 ) { // Found a 'sensible' & 'precise' location result = 1; *name = g_strdup ( _("Locality") ); //Albeit maybe not known by an actual name! } } else { // Hopefully city name is unique enough to lookup position on // Maybe for American places where hostip appends the State code on the end // But if the country code is not appended if could easily get confused // e.g. 'Portsmouth' could be at least // Portsmouth, Hampshire, UK or // Portsmouth, Viginia, USA. // Try city name lookup if ( city ) { g_debug ( "%s: found city %s", __FUNCTION__, city ); if ( strcmp ( city, "(Unknown city)" ) != 0 ) { VikCoord new_center; if ( vik_goto_place ( NULL, vvp, city, &new_center ) ) { // Got something vik_coord_to_latlon ( &new_center, ll ); result = 2; *name = city; goto tidy; } } } // Try country name lookup if ( country ) { g_debug ( "%s: found country %s", __FUNCTION__, country ); if ( strcmp ( country, "(Unknown Country)" ) != 0 ) { VikCoord new_center; if ( vik_goto_place ( NULL, vvp, country, &new_center ) ) { // Finally got something vik_coord_to_latlon ( &new_center, ll ); result = 3; *name = country; goto tidy; } } } } tidy: g_mapped_file_unref ( mf ); g_remove ( tmpname ); g_free ( tmpname ); return result; }