126 |
|
|
127 |
} else if(strcasecmp((char*)node->name, "osm") == 0) { |
} else if(strcasecmp((char*)node->name, "osm") == 0) { |
128 |
str = (char*)xmlNodeListGetString(doc, node->children, 1); |
str = (char*)xmlNodeListGetString(doc, node->children, 1); |
129 |
project->osm = g_strdup(str); |
printf("osm = %s\n", str); |
130 |
printf("osm = %s\n", project->osm); |
|
131 |
|
/* make this a relative path if possible */ |
132 |
|
/* if the project path actually is a prefix of this, */ |
133 |
|
/* then just remove this prefix */ |
134 |
|
if((str[0] == '/') && |
135 |
|
(strlen(str) > strlen(project->path)) && |
136 |
|
!strncmp(str, project->path, strlen(project->path))) { |
137 |
|
|
138 |
|
project->osm = g_strdup(str + strlen(project->path)); |
139 |
|
project->dirty = TRUE; |
140 |
|
printf("osm name converted to relative %s\n", project->osm); |
141 |
|
} else |
142 |
|
project->osm = g_strdup(str); |
143 |
|
|
144 |
xmlFree(str); |
xmlFree(str); |
145 |
|
|
146 |
} else if(strcasecmp((char*)node->name, "min") == 0) { |
} else if(strcasecmp((char*)node->name, "min") == 0) { |
147 |
if((str = (char*)xmlGetProp(node, BAD_CAST "lat"))) { |
if((str = (char*)xmlGetProp(node, BAD_CAST "lat"))) { |
148 |
project->min.lat = g_ascii_strtod(str, NULL); |
project->min.lat = g_ascii_strtod(str, NULL); |
349 |
PROJECT_NUM_COLS |
PROJECT_NUM_COLS |
350 |
}; |
}; |
351 |
|
|
352 |
|
static gboolean osm_file_exists(char *path, char *name) { |
353 |
|
gboolean exists = FALSE; |
354 |
|
|
355 |
|
if(name[0] == '/') |
356 |
|
exists = g_file_test(name, G_FILE_TEST_IS_REGULAR); |
357 |
|
else { |
358 |
|
char *full = g_strjoin(NULL, path, name, NULL); |
359 |
|
exists = g_file_test(full, G_FILE_TEST_IS_REGULAR); |
360 |
|
g_free(full); |
361 |
|
} |
362 |
|
return exists; |
363 |
|
} |
364 |
|
|
365 |
static void view_selected(select_context_t *context, project_t *project) { |
static void view_selected(select_context_t *context, project_t *project) { |
366 |
list_button_enable(context->list, LIST_BUTTON_REMOVE, project != NULL); |
list_button_enable(context->list, LIST_BUTTON_REMOVE, project != NULL); |
367 |
list_button_enable(context->list, LIST_BUTTON_EDIT, project != NULL); |
list_button_enable(context->list, LIST_BUTTON_EDIT, project != NULL); |
369 |
/* check if the selected project also has a valid osm file */ |
/* check if the selected project also has a valid osm file */ |
370 |
gtk_dialog_set_response_sensitive(GTK_DIALOG(context->dialog), |
gtk_dialog_set_response_sensitive(GTK_DIALOG(context->dialog), |
371 |
GTK_RESPONSE_ACCEPT, |
GTK_RESPONSE_ACCEPT, |
372 |
project && g_file_test(project->osm, G_FILE_TEST_IS_REGULAR)); |
project && osm_file_exists(project->path, project->osm)); |
373 |
} |
} |
374 |
|
|
375 |
static gboolean |
static gboolean |
554 |
project->server = g_strdup(context->settings->server); |
project->server = g_strdup(context->settings->server); |
555 |
|
|
556 |
/* build project osm file name */ |
/* build project osm file name */ |
557 |
project->osm = g_strdup_printf("%s%s.osm", project->path, project->name); |
project->osm = g_strdup_printf("%s.osm", project->name); |
558 |
|
|
559 |
/* around the castle in karlsruhe, germany ... */ |
/* around the castle in karlsruhe, germany ... */ |
560 |
project->min.lat = 49.005; project->min.lon = 8.3911; |
project->min.lat = 49.005; project->min.lon = 8.3911; |
777 |
/* ---------------------------------------------------- */ |
/* ---------------------------------------------------- */ |
778 |
|
|
779 |
/* return file length or -1 on error */ |
/* return file length or -1 on error */ |
780 |
static gsize file_length(char *name) { |
static gsize file_length(char *path, char *name) { |
781 |
GMappedFile *gmap = g_mapped_file_new(name, FALSE, NULL); |
char *str = NULL; |
782 |
|
|
783 |
|
if(name[0] == '/') str = g_strdup(name); |
784 |
|
else str = g_strjoin(NULL, path, name, NULL); |
785 |
|
|
786 |
|
GMappedFile *gmap = g_mapped_file_new(str, FALSE, NULL); |
787 |
|
g_free(str); |
788 |
|
|
789 |
if(!gmap) return -1; |
if(!gmap) return -1; |
790 |
gsize size = g_mapped_file_get_length(gmap); |
gsize size = g_mapped_file_get_length(gmap); |
791 |
g_mapped_file_free(gmap); |
g_mapped_file_free(gmap); |
797 |
|
|
798 |
printf("Checking size of %s\n", context->project->osm); |
printf("Checking size of %s\n", context->project->osm); |
799 |
|
|
800 |
if(!g_file_test(context->project->osm, G_FILE_TEST_IS_REGULAR)) { |
if(!osm_file_exists(context->project->path, context->project->osm)) { |
801 |
GdkColor color; |
GdkColor color; |
802 |
gdk_color_parse("red", &color); |
gdk_color_parse("red", &color); |
803 |
gtk_widget_modify_fg(context->fsize, GTK_STATE_NORMAL, &color); |
gtk_widget_modify_fg(context->fsize, GTK_STATE_NORMAL, &color); |
810 |
|
|
811 |
if(!context->project->data_dirty) |
if(!context->project->data_dirty) |
812 |
str = g_strdup_printf(_("%d bytes present"), |
str = g_strdup_printf(_("%d bytes present"), |
813 |
file_length(context->project->osm)); |
file_length(context->project->path, |
814 |
|
context->project->osm)); |
815 |
else |
else |
816 |
str = g_strdup_printf(_("Outdated, please download!")); |
str = g_strdup_printf(_("Outdated, please download!")); |
817 |
|
|
1072 |
appdata->project = project; |
appdata->project = project; |
1073 |
|
|
1074 |
printf("project_open: loading osm %s\n", project->osm); |
printf("project_open: loading osm %s\n", project->osm); |
1075 |
appdata->osm = osm_parse(project->osm); |
appdata->osm = osm_parse(project->path, project->osm); |
1076 |
if(!appdata->osm) { |
if(!appdata->osm) { |
1077 |
printf("OSM parsing failed\n"); |
printf("OSM parsing failed\n"); |
1078 |
return FALSE; |
return FALSE; |