152 |
dialog->dialog = gtk_dialog_new(); |
dialog->dialog = gtk_dialog_new(); |
153 |
|
|
154 |
gtk_dialog_set_has_separator(GTK_DIALOG(dialog->dialog), FALSE); |
gtk_dialog_set_has_separator(GTK_DIALOG(dialog->dialog), FALSE); |
155 |
gtk_window_set_title(GTK_WINDOW(dialog->dialog), _("Loading...")); |
gtk_window_set_title(GTK_WINDOW(dialog->dialog), _("Loading")); |
156 |
gtk_window_set_default_size(GTK_WINDOW(dialog->dialog), 300, 10); |
gtk_window_set_default_size(GTK_WINDOW(dialog->dialog), 300, 10); |
157 |
|
|
158 |
gtk_window_set_modal(GTK_WINDOW(dialog), TRUE); |
gtk_window_set_modal(GTK_WINDOW(dialog->dialog), TRUE); |
159 |
gtk_window_set_transient_for(GTK_WINDOW(dialog->dialog), GTK_WINDOW(parent)); |
gtk_window_set_transient_for(GTK_WINDOW(dialog->dialog), GTK_WINDOW(parent)); |
160 |
|
|
161 |
dialog->label = gtk_label_new("---"); |
dialog->label = gtk_label_new("---"); |
360 |
|
|
361 |
static char *process_text(xmlTextReaderPtr reader) { |
static char *process_text(xmlTextReaderPtr reader) { |
362 |
char *text = NULL; |
char *text = NULL; |
|
int depth = xmlTextReaderDepth(reader); |
|
|
int ret = xmlTextReaderRead(reader); |
|
|
while((ret == 1) && |
|
|
((xmlTextReaderNodeType(reader) != XML_READER_TYPE_END_ELEMENT) || |
|
|
(xmlTextReaderDepth(reader) != depth))) { |
|
363 |
|
|
364 |
/* found a text fragment */ |
if(!xmlTextReaderIsEmptyElement(reader)) { |
365 |
if((xmlTextReaderNodeType(reader) == XML_READER_TYPE_TEXT) || |
|
366 |
(xmlTextReaderNodeType(reader) == XML_READER_TYPE_CDATA)) { |
int depth = xmlTextReaderDepth(reader); |
367 |
char *frag = (char*)xmlTextReaderConstValue(reader); |
int ret = xmlTextReaderRead(reader); |
368 |
|
while((ret == 1) && |
369 |
if(!text) text = strdup(frag); |
((xmlTextReaderNodeType(reader) != XML_READER_TYPE_END_ELEMENT) || |
370 |
else { |
(xmlTextReaderDepth(reader) != depth))) { |
371 |
char *old = text; |
|
372 |
text = malloc(strlen(old) + strlen(frag) + 1); |
/* found a text fragment */ |
373 |
strcpy(text, old); |
if((xmlTextReaderNodeType(reader) == XML_READER_TYPE_TEXT) || |
374 |
strcat(text, frag); |
(xmlTextReaderNodeType(reader) == XML_READER_TYPE_CDATA)) { |
375 |
free(old); |
char *frag = (char*)xmlTextReaderConstValue(reader); |
376 |
|
|
377 |
|
if(!text) text = strdup(frag); |
378 |
|
else { |
379 |
|
char *old = text; |
380 |
|
text = malloc(strlen(old) + strlen(frag) + 1); |
381 |
|
strcpy(text, old); |
382 |
|
strcat(text, frag); |
383 |
|
free(old); |
384 |
|
} |
385 |
} |
} |
386 |
|
ret = xmlTextReaderRead(reader); |
387 |
} |
} |
|
ret = xmlTextReaderRead(reader); |
|
388 |
} |
} |
389 |
|
|
390 |
return text; |
return text; |
467 |
ret = xmlTextReaderRead(reader); |
ret = xmlTextReaderRead(reader); |
468 |
} |
} |
469 |
|
|
470 |
g_assert(0); |
gpx_free_log(log); |
471 |
return log; |
return NULL; |
472 |
} |
} |
473 |
|
|
474 |
static log_t *process_gpx_wpt_gc_logs(xmlTextReaderPtr reader) { |
static log_t *process_gpx_wpt_gc_logs(xmlTextReaderPtr reader) { |
517 |
ret = xmlTextReaderRead(reader); |
ret = xmlTextReaderRead(reader); |
518 |
} |
} |
519 |
|
|
520 |
g_assert(0); |
/* free the entire log chain */ |
521 |
return log_chain; |
while(log_chain) { |
522 |
|
log_t *next = log_chain->next; |
523 |
|
gpx_free_log(log_chain); |
524 |
|
log_chain = next; |
525 |
|
} |
526 |
|
|
527 |
|
return NULL; |
528 |
} |
} |
529 |
|
|
530 |
static tb_t *process_gpx_wpt_gc_tbs_travelbug(xmlTextReaderPtr reader) { |
static tb_t *process_gpx_wpt_gc_tbs_travelbug(xmlTextReaderPtr reader) { |
573 |
ret = xmlTextReaderRead(reader); |
ret = xmlTextReaderRead(reader); |
574 |
} |
} |
575 |
|
|
576 |
g_assert(0); |
gpx_free_tb(tb); |
577 |
return tb; |
return NULL; |
578 |
} |
} |
579 |
|
|
580 |
static tb_t *process_gpx_wpt_gc_tbs(xmlTextReaderPtr reader) { |
static tb_t *process_gpx_wpt_gc_tbs(xmlTextReaderPtr reader) { |
615 |
ret = xmlTextReaderRead(reader); |
ret = xmlTextReaderRead(reader); |
616 |
} |
} |
617 |
|
|
618 |
g_assert(0); |
while(tb) { |
619 |
return tb; |
tb_t *next = tb; |
620 |
|
gpx_free_tb(tb); |
621 |
|
tb = next; |
622 |
|
} |
623 |
|
|
624 |
|
return NULL; |
625 |
} |
} |
626 |
|
|
627 |
static void process_gpx_wpt_gc(xmlTextReaderPtr reader, cache_t *cache) { |
static void process_gpx_wpt_gc(xmlTextReaderPtr reader, cache_t *cache) { |
668 |
(strcasecmp(name, "hints") == 0)) { |
(strcasecmp(name, "hints") == 0)) { |
669 |
if(!cache->hint) { |
if(!cache->hint) { |
670 |
cache->hint = process_text(reader); |
cache->hint = process_text(reader); |
671 |
|
|
672 |
/* often hints aren't more than just a bunch of blanks ... */ |
/* often hints aren't more than just a bunch of blanks ... */ |
673 |
if(cache->hint && all_is_white(cache->hint)) { |
if(cache->hint && all_is_white(cache->hint)) { |
674 |
free(cache->hint); |
free(cache->hint); |
780 |
/* neither geocaching.com GC* nor opencaching.com OC* nor */ |
/* neither geocaching.com GC* nor opencaching.com OC* nor */ |
781 |
/* geocaching australia GA* waypoint */ |
/* geocaching australia GA* waypoint */ |
782 |
if(cache->id && |
if(cache->id && |
783 |
|
(strncasecmp(cache->id, "__", 2) != 0) && |
784 |
(strncasecmp(cache->id, "GC", 2) != 0) && |
(strncasecmp(cache->id, "GC", 2) != 0) && |
785 |
(strncasecmp(cache->id, "OC", 2) != 0) && |
(strncasecmp(cache->id, "OC", 2) != 0) && |
786 |
(strncasecmp(cache->id, "GA", 2) != 0)) { |
(strncasecmp(cache->id, "GA", 2) != 0)) { |
847 |
ret = xmlTextReaderRead(reader); |
ret = xmlTextReaderRead(reader); |
848 |
} |
} |
849 |
|
|
850 |
g_assert(0); |
gpx_free_cache(cache); |
851 |
return cache; |
return NULL; |
852 |
} |
} |
853 |
|
|
854 |
static void process_gpx(xmlTextReaderPtr reader, gpx_dialog_t *dialog, |
static gboolean process_gpx(xmlTextReaderPtr reader, gpx_dialog_t *dialog, |
855 |
gpx_t *gpx) { |
gpx_t *gpx) { |
856 |
|
|
857 |
/* no attributes of interest */ |
/* no attributes of interest */ |
858 |
|
|
863 |
while(*cache) cache = &(*cache)->next; |
while(*cache) cache = &(*cache)->next; |
864 |
|
|
865 |
const xmlChar *name = xmlTextReaderConstName(reader); |
const xmlChar *name = xmlTextReaderConstName(reader); |
866 |
g_assert(name); |
if(!name) return FALSE; |
867 |
|
|
868 |
/* read next node */ |
/* read next node */ |
869 |
int ret = xmlTextReaderRead(reader); |
int ret = xmlTextReaderRead(reader); |
893 |
case XML_READER_TYPE_END_ELEMENT: |
case XML_READER_TYPE_END_ELEMENT: |
894 |
/* end element must be for the current element */ |
/* end element must be for the current element */ |
895 |
g_assert(xmlTextReaderDepth(reader) == 0); |
g_assert(xmlTextReaderDepth(reader) == 0); |
896 |
return; |
return TRUE; |
897 |
break; |
break; |
898 |
|
|
899 |
default: |
default: |
902 |
ret = xmlTextReaderRead(reader); |
ret = xmlTextReaderRead(reader); |
903 |
} |
} |
904 |
|
|
905 |
g_assert(0); |
return FALSE; |
906 |
} |
} |
907 |
|
|
908 |
/* parse loc waypoint entry */ |
/* parse loc waypoint entry */ |
1086 |
*dot = 0; |
*dot = 0; |
1087 |
snprintf(wpts_name, sizeof(wpts_name), "%s-wpts.gpx", filename); |
snprintf(wpts_name, sizeof(wpts_name), "%s-wpts.gpx", filename); |
1088 |
*dot = '.'; |
*dot = '.'; |
|
|
|
1089 |
if(g_file_test(wpts_name, G_FILE_TEST_EXISTS)) { |
if(g_file_test(wpts_name, G_FILE_TEST_EXISTS)) { |
|
|
|
1090 |
xmlTextReaderPtr reader = xmlReaderForFile(wpts_name, NULL, 0); |
xmlTextReaderPtr reader = xmlReaderForFile(wpts_name, NULL, 0); |
1091 |
if (reader != NULL) { |
if (reader != NULL) { |
1092 |
gpx = process_root(reader, dialog, wpts_name, gpx); |
gpx = process_root(reader, dialog, wpts_name, gpx); |
1362 |
|
|
1363 |
void gpx_pos_get_distance_str(char *str, int len, |
void gpx_pos_get_distance_str(char *str, int len, |
1364 |
pos_t p1, pos_t p2, int mil) { |
pos_t p1, pos_t p2, int mil) { |
1365 |
if(!p1.lat && !p1.lon) { |
if(isnan(p1.lat) || isnan(p1.lon)) { |
1366 |
snprintf(str, len, "---"); |
snprintf(str, len, "---"); |
1367 |
return; |
return; |
1368 |
} |
} |
1371 |
distance_str(str, len, dist, mil); |
distance_str(str, len, dist, mil); |
1372 |
} |
} |
1373 |
|
|
|
/* http://library.gnome.org/devel/gtk/unstable/GtkRadioButton.html */ |
|
1374 |
void gpx_sort(gpx_t *gpx, int by, pos_t *refpos) { |
void gpx_sort(gpx_t *gpx, int by, pos_t *refpos) { |
1375 |
cache_t **new; |
cache_t **new; |
1376 |
cache_t *cur = gpx->cache; |
cache_t *cur = gpx->cache; |
1379 |
|
|
1380 |
gpx->cache = NULL; /* detach old chain */ |
gpx->cache = NULL; /* detach old chain */ |
1381 |
while(cur) { |
while(cur) { |
1382 |
float cur_dist = gpx_pos_get_distance(*refpos, gpx_cache_pos(cur), 0); |
float cur_dist = -1; |
1383 |
int cur_cnt = 0; |
int cur_cnt = 0; |
1384 |
|
|
1385 |
|
if(!isnan(cur->pos.lat) && !isnan(cur->pos.lon)) |
1386 |
|
cur_dist = gpx_pos_get_distance(*refpos, gpx_cache_pos(cur), 0); |
1387 |
|
|
1388 |
new = &(gpx->cache); |
new = &(gpx->cache); |
1389 |
|
|
1390 |
/* search for currect insertion point */ |
/* search for currect insertion point */ |