-
- gpx_gather_tracks_passalong_t passalong_tracks;
- passalong_tracks.n_trks = g_hash_table_size ( vik_trw_layer_get_tracks (vtl) );
- passalong_tracks.i = 0;
- passalong_tracks.trks = g_new(gpx_track_and_timestamp,passalong_tracks.n_trks);
- g_hash_table_foreach (vik_trw_layer_get_tracks(vtl), (GHFunc) gpx_collect_track, &passalong_tracks);
- /* Sort by timestamp */
- qsort(passalong_tracks.trks, passalong_tracks.n_trks, sizeof(gpx_track_and_timestamp), gpx_track_and_timestamp_compar);
- for (i=0;i<passalong_tracks.n_trks; i++)
- {
- gpx_write_track(passalong_tracks.trks[i].name, (VikTrack *)g_hash_table_lookup(vik_trw_layer_get_tracks(vtl), passalong_tracks.trks[i].name), &context);
+
+ gl = g_hash_table_get_values ( vik_trw_layer_get_tracks ( vtl ) );
+ // Sort method determined by preference
+ if ( a_vik_get_gpx_export_trk_sort() == VIK_GPX_EXPORT_TRK_SORT_TIME )
+ gl = g_list_sort ( gl, gpx_track_compare_timestamp );
+ else
+ gl = g_list_sort ( gl, gpx_track_compare_name );
+
+ // Routes sorted by name
+ GList *glrte = g_hash_table_get_values ( vik_trw_layer_get_routes ( vtl ) );
+ glrte = g_list_sort ( glrte, gpx_track_compare_name );
+
+ // g_list_concat doesn't copy memory properly
+ // so process each list separately
+
+ GpxWritingContext context_tmp = context;
+ GpxWritingOptions opt_tmp = { FALSE, FALSE, FALSE };
+ // Force trackpoints on tracks
+ if ( !context.options )
+ context_tmp.options = &opt_tmp;
+ context_tmp.options->is_route = FALSE;
+
+ // Loop around each list and write each one
+ for (iter = g_list_first (gl); iter != NULL; iter = g_list_next (iter)) {
+ gpx_write_track ( (VikTrack*)iter->data, &context_tmp );