void a_gpx_write_file( VikTrwLayer *vtl, FILE *f ) { a_gpx_write_file_options(NULL, vtl, f); }
/** * uploading function executed by the background" thread */ static void osm_traces_upload_thread ( OsmTracesInfo *oti, gpointer threaddata ) { /* Due to OSM limits, we have to enforce ele and time fields */ static GpxWritingOptions options = { TRUE, TRUE }; FILE *file = NULL; gchar *filename = NULL; int fd; GError *error = NULL; int ret; g_assert(oti != NULL); /* Opening temporary file */ fd = g_file_open_tmp("viking_osm_upload_XXXXXX.gpx", &filename, &error); if (fd < 0) { g_error(_("failed to open temporary file: %s"), strerror(errno)); return; } g_clear_error(&error); g_debug("%s: temporary file = %s", __FUNCTION__, filename); /* Creating FILE* */ file = fdopen(fd, "w"); /* writing gpx file */ if (oti->track_name != NULL) { /* Upload only the selected track */ VikTrack *track = vik_trw_layer_get_track(oti->vtl, oti->track_name); a_gpx_write_track_file_options(&options, oti->track_name, track, file); } else { /* Upload the whole VikTrwLayer */ a_gpx_write_file_options(&options, oti->vtl, file); } /* We can close the file */ /* This also close the associated fd */ fclose(file); file = NULL; /* finally, upload it */ gint ans = osm_traces_upload_file(user, password, filename, oti->name, oti->description, oti->tags, oti->vistype); // // Show result in statusbar or failure in dialog for user feedback // // Get current time to put into message to show when result was generated // since need to show difference between operations (when displayed on statusbar) // NB If on dialog then don't need time. time_t timenow; struct tm* timeinfo; time ( &timenow ); timeinfo = localtime ( &timenow ); gchar timestr[80]; // Compact time only - as days/date isn't very useful here strftime ( timestr, sizeof(timestr), "%X)", timeinfo ); // // Test to see if window it was invoked on is still valid // Not sure if this test really works! (i.e. if the window was closed in the mean time) // if ( IS_VIK_WINDOW ((VikWindow *)VIK_GTK_WINDOW_FROM_LAYER(oti->vtl)) ) { gchar* msg; if ( ans == 0 ) { // Success msg = g_strdup_printf ( "%s (@%s)", _("Uploaded to OSM"), timestr ); vik_statusbar_set_message ( vik_window_get_statusbar ( (VikWindow *)VIK_GTK_WINDOW_FROM_LAYER(oti->vtl) ), VIK_STATUSBAR_INFO, msg ); } // Use UPPER CASE for bad news :( else if ( ans < 0 ) { msg = g_strdup_printf ( "%s (@%s)", _("FAILED TO UPLOAD DATA TO OSM - CURL PROBLEM"), timestr ); vik_statusbar_set_message ( vik_window_get_statusbar ( (VikWindow *)VIK_GTK_WINDOW_FROM_LAYER(oti->vtl) ), VIK_STATUSBAR_INFO, msg ); //a_dialog_error_msg ( VIK_GTK_WINDOW_FROM_LAYER(oti->vtl), msg ); } else { msg = g_strdup_printf ( "%s : %s %d (@%s)", _("FAILED TO UPLOAD DATA TO OSM"), _("HTTP response code"), ans, timestr ); vik_statusbar_set_message ( vik_window_get_statusbar ( (VikWindow *)VIK_GTK_WINDOW_FROM_LAYER(oti->vtl) ), VIK_STATUSBAR_INFO, msg ); //VikTrwLayer *vtl = oti->vtl; // Crashes here - multi-thread issue... //a_dialog_error_msg ( VIK_GTK_WINDOW_FROM_LAYER(vtl), msg ); } g_free (msg); } /* Removing temporary file */ ret = g_unlink(filename); if (ret != 0) { g_error(_("failed to unlink temporary file: %s"), strerror(errno)); } }