Parent Directory
|
Revision Log
Detail level adjustments
1 | /* |
2 | * Copyright (C) 2008 Till Harbaum <till@harbaum.org>. |
3 | * |
4 | * This file is part of OSM2Go. |
5 | * |
6 | * OSM2Go is free software: you can redistribute it and/or modify |
7 | * it under the terms of the GNU General Public License as published by |
8 | * the Free Software Foundation, either version 3 of the License, or |
9 | * (at your option) any later version. |
10 | * |
11 | * OSM2Go is distributed in the hope that it will be useful, |
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
14 | * GNU General Public License for more details. |
15 | * |
16 | * You should have received a copy of the GNU General Public License |
17 | * along with OSM2Go. If not, see <http://www.gnu.org/licenses/>. |
18 | */ |
19 | |
20 | #include "appdata.h" |
21 | #include "banner.h" |
22 | |
23 | #include <sys/stat.h> |
24 | |
25 | #include <libxml/parser.h> |
26 | #include <libxml/tree.h> |
27 | |
28 | #if !defined(LIBXML_TREE_ENABLED) || !defined(LIBXML_OUTPUT_ENABLED) |
29 | #error "libxml doesn't support required tree or output" |
30 | #endif |
31 | |
32 | typedef struct { |
33 | // appdata_t *appdata; |
34 | project_t *project; |
35 | GtkWidget *dialog, *fsize, *diff_stat, *diff_remove; |
36 | GtkWidget *desc, *server; |
37 | GtkWidget *minlat, *minlon, *maxlat, *maxlon; |
38 | area_edit_t area_edit; |
39 | } project_context_t; |
40 | |
41 | /* ------------ project file io ------------- */ |
42 | |
43 | static gboolean project_read(appdata_t *appdata, |
44 | char *project_file, project_t *project) { |
45 | |
46 | LIBXML_TEST_VERSION; |
47 | |
48 | xmlDoc *doc = NULL; |
49 | xmlNode *root_element = NULL; |
50 | |
51 | /* parse the file and get the DOM */ |
52 | if((doc = xmlReadFile(project_file, NULL, 0)) == NULL) { |
53 | printf("error: could not parse file %s\n", project_file); |
54 | return FALSE; |
55 | } |
56 | |
57 | /* Get the root element node */ |
58 | root_element = xmlDocGetRootElement(doc); |
59 | |
60 | xmlNode *cur_node = NULL; |
61 | for (cur_node = root_element; cur_node; cur_node = cur_node->next) { |
62 | if (cur_node->type == XML_ELEMENT_NODE) { |
63 | if(strcasecmp((char*)cur_node->name, "proj") == 0) { |
64 | char *str; |
65 | |
66 | if((str = (char*)xmlGetProp(cur_node, BAD_CAST "dirty"))) { |
67 | project->data_dirty = (strcasecmp(str, "true") == 0); |
68 | xmlFree(str); |
69 | } else |
70 | project->data_dirty = FALSE; |
71 | |
72 | xmlNode *node = cur_node->children; |
73 | |
74 | while(node != NULL) { |
75 | if(node->type == XML_ELEMENT_NODE) { |
76 | |
77 | if(strcasecmp((char*)node->name, "desc") == 0) { |
78 | str = (char*)xmlNodeListGetString(doc, node->children, 1); |
79 | project->desc = g_strdup(str); |
80 | printf("desc = %s\n", project->desc); |
81 | xmlFree(str); |
82 | |
83 | } else if(strcasecmp((char*)node->name, "server") == 0) { |
84 | str = (char*)xmlNodeListGetString(doc, node->children, 1); |
85 | project->server = g_strdup(str); |
86 | printf("server = %s\n", project->server); |
87 | xmlFree(str); |
88 | |
89 | } else if(project->map_state && |
90 | strcasecmp((char*)node->name, "map") == 0) { |
91 | if((str = (char*)xmlGetProp(node, BAD_CAST "zoom"))) { |
92 | project->map_state->zoom = g_ascii_strtod(str, NULL); |
93 | xmlFree(str); |
94 | } |
95 | if((str = (char*)xmlGetProp(node, BAD_CAST "detail"))) { |
96 | project->map_state->detail = g_ascii_strtod(str, NULL); |
97 | xmlFree(str); |
98 | } |
99 | if((str = (char*)xmlGetProp(node, BAD_CAST "scroll-offset-x"))) { |
100 | project->map_state->scroll_offset.x = strtoul(str, NULL, 10); |
101 | xmlFree(str); |
102 | } |
103 | if((str = (char*)xmlGetProp(node, BAD_CAST "scroll-offset-y"))) { |
104 | project->map_state->scroll_offset.y = strtoul(str, NULL, 10); |
105 | xmlFree(str); |
106 | } |
107 | |
108 | } else if(strcasecmp((char*)node->name, "wms") == 0) { |
109 | |
110 | if((str = (char*)xmlGetProp(node, BAD_CAST "server"))) { |
111 | project->wms_server = g_strdup(str); |
112 | xmlFree(str); |
113 | } |
114 | if((str = (char*)xmlGetProp(node, BAD_CAST "path"))) { |
115 | project->wms_path = g_strdup(str); |
116 | xmlFree(str); |
117 | } |
118 | if((str = (char*)xmlGetProp(node, BAD_CAST "x-offset"))) { |
119 | project->wms_offset.x = strtoul(str, NULL, 10); |
120 | xmlFree(str); |
121 | } |
122 | if((str = (char*)xmlGetProp(node, BAD_CAST "y-offset"))) { |
123 | project->wms_offset.y = strtoul(str, NULL, 10); |
124 | xmlFree(str); |
125 | } |
126 | |
127 | } else if(strcasecmp((char*)node->name, "osm") == 0) { |
128 | str = (char*)xmlNodeListGetString(doc, node->children, 1); |
129 | project->osm = g_strdup(str); |
130 | printf("osm = %s\n", project->osm); |
131 | xmlFree(str); |
132 | } else if(strcasecmp((char*)node->name, "min") == 0) { |
133 | if((str = (char*)xmlGetProp(node, BAD_CAST "lat"))) { |
134 | project->min.lat = g_ascii_strtod(str, NULL); |
135 | xmlFree(str); |
136 | } |
137 | if((str = (char*)xmlGetProp(node, BAD_CAST "lon"))) { |
138 | project->min.lon = g_ascii_strtod(str, NULL); |
139 | xmlFree(str); |
140 | } |
141 | |
142 | } else if(strcasecmp((char*)node->name, "max") == 0) { |
143 | if((str = (char*)xmlGetProp(node, BAD_CAST "lat"))) { |
144 | project->max.lat = g_ascii_strtod(str, NULL); |
145 | xmlFree(str); |
146 | } |
147 | if((str = (char*)xmlGetProp(node, BAD_CAST "lon"))) { |
148 | project->max.lon = g_ascii_strtod(str, NULL); |
149 | xmlFree(str); |
150 | } |
151 | } |
152 | } |
153 | node = node->next; |
154 | } |
155 | } |
156 | } |
157 | } |
158 | |
159 | xmlFreeDoc(doc); |
160 | xmlCleanupParser(); |
161 | |
162 | return TRUE; |
163 | } |
164 | |
165 | gboolean project_save(GtkWidget *parent, project_t *project) { |
166 | char str[32]; |
167 | char *project_file = g_strdup_printf("%s%s.proj", |
168 | project->path, project->name); |
169 | |
170 | printf("saving project to %s\n", project_file); |
171 | |
172 | /* check if project path exists */ |
173 | if(!g_file_test(project->path, G_FILE_TEST_IS_DIR)) { |
174 | /* make sure project base path exists */ |
175 | if(g_mkdir_with_parents(project->path, S_IRWXU) != 0) { |
176 | errorf(GTK_WIDGET(parent), |
177 | _("Unable to create project path %s"), project->path); |
178 | return FALSE; |
179 | } |
180 | } |
181 | |
182 | LIBXML_TEST_VERSION; |
183 | |
184 | xmlDocPtr doc = xmlNewDoc(BAD_CAST "1.0"); |
185 | xmlNodePtr node, root_node = xmlNewNode(NULL, BAD_CAST "proj"); |
186 | xmlNewProp(root_node, BAD_CAST "name", BAD_CAST project->name); |
187 | if(project->data_dirty) |
188 | xmlNewProp(root_node, BAD_CAST "dirty", BAD_CAST "true"); |
189 | |
190 | xmlDocSetRootElement(doc, root_node); |
191 | |
192 | node = xmlNewChild(root_node, NULL, BAD_CAST "server", |
193 | BAD_CAST project->server); |
194 | |
195 | xmlNewChild(root_node, NULL, BAD_CAST "desc", BAD_CAST project->desc); |
196 | xmlNewChild(root_node, NULL, BAD_CAST "osm", BAD_CAST project->osm); |
197 | |
198 | node = xmlNewChild(root_node, NULL, BAD_CAST "min", NULL); |
199 | g_ascii_formatd(str, sizeof(str), LL_FORMAT, project->min.lat); |
200 | xmlNewProp(node, BAD_CAST "lat", BAD_CAST str); |
201 | g_ascii_formatd(str, sizeof(str), LL_FORMAT, project->min.lon); |
202 | xmlNewProp(node, BAD_CAST "lon", BAD_CAST str); |
203 | |
204 | node = xmlNewChild(root_node, NULL, BAD_CAST "max", NULL); |
205 | g_ascii_formatd(str, sizeof(str), LL_FORMAT, project->max.lat); |
206 | xmlNewProp(node, BAD_CAST "lat", BAD_CAST str); |
207 | g_ascii_formatd(str, sizeof(str), LL_FORMAT, project->max.lon); |
208 | xmlNewProp(node, BAD_CAST "lon", BAD_CAST str); |
209 | |
210 | if(project->map_state) { |
211 | node = xmlNewChild(root_node, NULL, BAD_CAST "map", BAD_CAST NULL); |
212 | g_ascii_formatd(str, sizeof(str), "%.04f", project->map_state->zoom); |
213 | xmlNewProp(node, BAD_CAST "zoom", BAD_CAST str); |
214 | g_ascii_formatd(str, sizeof(str), "%.04f", project->map_state->detail); |
215 | xmlNewProp(node, BAD_CAST "detail", BAD_CAST str); |
216 | snprintf(str, sizeof(str), "%d", project->map_state->scroll_offset.x); |
217 | xmlNewProp(node, BAD_CAST "scroll-offset-x", BAD_CAST str); |
218 | snprintf(str, sizeof(str), "%d", project->map_state->scroll_offset.y); |
219 | xmlNewProp(node, BAD_CAST "scroll-offset-y", BAD_CAST str); |
220 | } |
221 | |
222 | node = xmlNewChild(root_node, NULL, BAD_CAST "wms", NULL); |
223 | if(project->wms_server) |
224 | xmlNewProp(node, BAD_CAST "server", BAD_CAST project->wms_server); |
225 | if(project->wms_path) |
226 | xmlNewProp(node, BAD_CAST "path", BAD_CAST project->wms_path); |
227 | snprintf(str, sizeof(str), "%d", project->wms_offset.x); |
228 | xmlNewProp(node, BAD_CAST "x-offset", BAD_CAST str); |
229 | snprintf(str, sizeof(str), "%d", project->wms_offset.y); |
230 | xmlNewProp(node, BAD_CAST "y-offset", BAD_CAST str); |
231 | |
232 | xmlSaveFormatFileEnc(project_file, doc, "UTF-8", 1); |
233 | xmlFreeDoc(doc); |
234 | xmlCleanupParser(); |
235 | |
236 | g_free(project_file); |
237 | |
238 | return TRUE; |
239 | } |
240 | |
241 | /* ------------ freeing projects --------------------- */ |
242 | |
243 | void project_free(project_t *project) { |
244 | if(!project) return; |
245 | |
246 | if(project->name) g_free(project->name); |
247 | if(project->desc) g_free(project->desc); |
248 | if(project->server) g_free(project->server); |
249 | |
250 | if(project->wms_server) g_free(project->wms_server); |
251 | if(project->wms_path) g_free(project->wms_path); |
252 | |
253 | if(project->path) g_free(project->path); |
254 | if(project->osm) g_free(project->osm); |
255 | |
256 | map_state_free(project->map_state); |
257 | |
258 | g_free(project); |
259 | } |
260 | |
261 | /* ------------ project selection dialog ------------- */ |
262 | |
263 | static char *project_fullname(settings_t *settings, const char *name) { |
264 | return g_strdup_printf("%s%s/%s.proj", settings->base_path, name, name); |
265 | } |
266 | |
267 | static gboolean project_exists(settings_t *settings, const char *name) { |
268 | gboolean ok = FALSE; |
269 | char *fulldir = g_strdup_printf("%s%s", settings->base_path, name); |
270 | |
271 | if(g_file_test(fulldir, G_FILE_TEST_IS_DIR)) { |
272 | |
273 | /* check for project file */ |
274 | char *fullname = project_fullname(settings, name); |
275 | |
276 | if(g_file_test(fullname, G_FILE_TEST_IS_REGULAR)) |
277 | ok = TRUE; |
278 | |
279 | g_free(fullname); |
280 | } |
281 | g_free(fulldir); |
282 | |
283 | return ok; |
284 | } |
285 | |
286 | static project_t *project_scan(appdata_t *appdata) { |
287 | project_t *projects = NULL, **current = &projects; |
288 | |
289 | /* scan for projects */ |
290 | GDir *dir = g_dir_open(appdata->settings->base_path, 0, NULL); |
291 | const char *name = NULL; |
292 | do { |
293 | if((name = g_dir_read_name(dir))) { |
294 | if(project_exists(appdata->settings, name)) { |
295 | printf("found project %s\n", name); |
296 | |
297 | /* try to read project and append it to chain */ |
298 | *current = g_new0(project_t, 1); |
299 | (*current)->name = g_strdup(name); |
300 | (*current)->path = g_strdup_printf("%s%s/", |
301 | appdata->settings->base_path, name); |
302 | |
303 | char *fullname = project_fullname(appdata->settings, name); |
304 | if(project_read(appdata, fullname, *current)) |
305 | current = &((*current)->next); |
306 | else { |
307 | g_free(*current); |
308 | *current = NULL; |
309 | } |
310 | g_free(fullname); |
311 | } |
312 | } |
313 | } while(name); |
314 | |
315 | g_dir_close(dir); |
316 | |
317 | return projects; |
318 | } |
319 | |
320 | typedef struct { |
321 | project_t *project; |
322 | GtkWidget *dialog, *list; |
323 | settings_t *settings; |
324 | #ifdef USE_HILDON |
325 | dbus_mm_pos_t *mmpos; |
326 | osso_context_t *osso_context; |
327 | #endif |
328 | } select_context_t; |
329 | |
330 | enum { |
331 | PROJECT_COL_NAME = 0, |
332 | PROJECT_COL_STATUS, |
333 | PROJECT_COL_DESCRIPTION, |
334 | PROJECT_COL_DATA, |
335 | PROJECT_NUM_COLS |
336 | }; |
337 | |
338 | static void view_selected(select_context_t *context, project_t *project) { |
339 | list_button_enable(context->list, LIST_BUTTON_REMOVE, project != NULL); |
340 | list_button_enable(context->list, LIST_BUTTON_EDIT, project != NULL); |
341 | |
342 | /* check if the selected project also has a valid osm file */ |
343 | gtk_dialog_set_response_sensitive(GTK_DIALOG(context->dialog), |
344 | GTK_RESPONSE_ACCEPT, |
345 | project && g_file_test(project->osm, G_FILE_TEST_IS_REGULAR)); |
346 | } |
347 | |
348 | static gboolean |
349 | view_selection_func(GtkTreeSelection *selection, GtkTreeModel *model, |
350 | GtkTreePath *path, gboolean path_currently_selected, |
351 | gpointer userdata) { |
352 | select_context_t *context = (select_context_t*)userdata; |
353 | GtkTreeIter iter; |
354 | |
355 | if(gtk_tree_model_get_iter(model, &iter, path)) { |
356 | project_t *project = NULL; |
357 | gtk_tree_model_get(model, &iter, PROJECT_COL_DATA, &project, -1); |
358 | g_assert(gtk_tree_path_get_depth(path) == 1); |
359 | |
360 | view_selected(context, project); |
361 | } |
362 | |
363 | return TRUE; /* allow selection state to change */ |
364 | } |
365 | |
366 | /* get the currently selected project in the list, NULL if none */ |
367 | static project_t *project_get_selected(GtkWidget *list) { |
368 | project_t *project = NULL; |
369 | GtkTreeModel *model; |
370 | GtkTreeIter iter; |
371 | |
372 | GtkTreeSelection *selection = list_get_selection(list); |
373 | g_assert(gtk_tree_selection_get_selected(selection, &model, &iter)); |
374 | gtk_tree_model_get(model, &iter, PROJECT_COL_DATA, &project, -1); |
375 | |
376 | return project; |
377 | } |
378 | |
379 | /* ------------------------- create a new project ---------------------- */ |
380 | |
381 | /* returns true of str contains one of the characters in chars */ |
382 | static gboolean strchrs(char *str, char *chars) { |
383 | while(*chars) { |
384 | char *p = str; |
385 | while(*p) { |
386 | if(*p == *chars) |
387 | return TRUE; |
388 | |
389 | p++; |
390 | } |
391 | chars++; |
392 | } |
393 | return FALSE; |
394 | } |
395 | |
396 | typedef struct { |
397 | GtkWidget *dialog; |
398 | settings_t *settings; |
399 | } name_callback_context_t; |
400 | |
401 | static void callback_modified_name(GtkWidget *widget, gpointer data) { |
402 | name_callback_context_t *context = (name_callback_context_t*)data; |
403 | |
404 | char *name = (char*)gtk_entry_get_text(GTK_ENTRY(widget)); |
405 | |
406 | /* name must not contain some special chars */ |
407 | gboolean ok = FALSE; |
408 | |
409 | /* check if there's a name */ |
410 | if(name && strlen(name) > 0) { |
411 | /* check if it consists of valid characters */ |
412 | if(!strchrs(name, "\\*?()\n\t\r")) { |
413 | /* check if such a project already exists */ |
414 | if(!project_exists(context->settings, name)) |
415 | ok = TRUE; |
416 | } |
417 | } |
418 | |
419 | gtk_dialog_set_response_sensitive(GTK_DIALOG(context->dialog), |
420 | GTK_RESPONSE_ACCEPT, ok); |
421 | } |
422 | |
423 | |
424 | gboolean project_delete(select_context_t *context, project_t *project) { |
425 | |
426 | /* remove entire directory from disk */ |
427 | GDir *dir = g_dir_open(project->path, 0, NULL); |
428 | const char *name = NULL; |
429 | do { |
430 | if((name = g_dir_read_name(dir))) { |
431 | char *fullname = g_strdup_printf("%s/%s", project->path, name); |
432 | g_remove(fullname); |
433 | g_free(fullname); |
434 | } |
435 | } while(name); |
436 | |
437 | /* remove the projects directory */ |
438 | g_remove(project->path); |
439 | |
440 | /* remove from view */ |
441 | GtkTreeIter iter; |
442 | GtkTreeModel *model = list_get_model(context->list); |
443 | gboolean deleted = FALSE; |
444 | if(gtk_tree_model_get_iter_first(model, &iter)) { |
445 | do { |
446 | project_t *prj = NULL; |
447 | gtk_tree_model_get(model, &iter, PROJECT_COL_DATA, &prj, -1); |
448 | if(prj && (prj == project)) { |
449 | printf("found %s to remove\n", prj->name); |
450 | /* and remove from store */ |
451 | gtk_list_store_remove(GTK_LIST_STORE(model), &iter); |
452 | deleted = TRUE; |
453 | } |
454 | } while(!deleted && gtk_tree_model_iter_next(model, &iter)); |
455 | } |
456 | |
457 | /* de-chain entry from project list */ |
458 | project_t **project_list = &context->project; |
459 | while(*project_list) { |
460 | if(*project_list == project) |
461 | *project_list = (*project_list)->next; |
462 | else |
463 | project_list = &((*project_list)->next); |
464 | } |
465 | |
466 | /* free project structure */ |
467 | project_free(project); |
468 | |
469 | /* disable edit/remove buttons */ |
470 | view_selected(context, NULL); |
471 | |
472 | return TRUE; |
473 | } |
474 | |
475 | project_t *project_new(select_context_t *context) { |
476 | printf("creating project with default values\n"); |
477 | |
478 | /* -------------- first choose a name for the project --------------- */ |
479 | GtkWidget *dialog = gtk_dialog_new_with_buttons(_("Project name"), |
480 | GTK_WINDOW(context->dialog), GTK_DIALOG_MODAL, |
481 | GTK_STOCK_CANCEL, GTK_RESPONSE_REJECT, |
482 | GTK_STOCK_OK, GTK_RESPONSE_ACCEPT, |
483 | NULL); |
484 | |
485 | GtkWidget *hbox = gtk_hbox_new(FALSE, 8); |
486 | gtk_box_pack_start_defaults(GTK_BOX(hbox), gtk_label_new(_("Name:"))); |
487 | |
488 | name_callback_context_t name_context = { dialog, context->settings }; |
489 | GtkWidget *entry = gtk_entry_new(); |
490 | // gtk_entry_set_text(GTK_ENTRY(entry), "<enter name>"); |
491 | gtk_box_pack_start_defaults(GTK_BOX(hbox), entry); |
492 | g_signal_connect(G_OBJECT(entry), "changed", |
493 | G_CALLBACK(callback_modified_name), &name_context); |
494 | |
495 | gtk_box_pack_start_defaults(GTK_BOX(GTK_DIALOG(dialog)->vbox), hbox); |
496 | |
497 | /* don't all user to click ok until something useful has been entered */ |
498 | gtk_dialog_set_response_sensitive(GTK_DIALOG(dialog), |
499 | GTK_RESPONSE_ACCEPT, FALSE); |
500 | |
501 | gtk_widget_show_all(dialog); |
502 | if(GTK_RESPONSE_ACCEPT != gtk_dialog_run(GTK_DIALOG(dialog))) { |
503 | gtk_widget_destroy(dialog); |
504 | return NULL; |
505 | } |
506 | |
507 | project_t *project = g_new0(project_t, 1); |
508 | project->name = g_strdup(gtk_entry_get_text(GTK_ENTRY(entry))); |
509 | gtk_widget_destroy(dialog); |
510 | |
511 | |
512 | project->path = g_strdup_printf("%s%s/", |
513 | context->settings->base_path, project->name); |
514 | project->desc = g_strdup(_("<project description>")); |
515 | |
516 | /* no data downloaded yet */ |
517 | project->data_dirty = TRUE; |
518 | |
519 | /* use global server/access settings */ |
520 | project->server = g_strdup(context->settings->server); |
521 | |
522 | /* build project osm file name */ |
523 | project->osm = g_strdup_printf("%s%s.osm", project->path, project->name); |
524 | |
525 | /* around the castle in karlsruhe, germany ... */ |
526 | project->min.lat = 49.005; project->min.lon = 8.3911; |
527 | project->max.lat = 49.023; project->max.lon = 8.4185; |
528 | |
529 | /* create project file on disk */ |
530 | project_save(context->dialog, project); |
531 | |
532 | #ifdef USE_HILDON |
533 | if(!project_edit(context->dialog, project, context->mmpos, |
534 | context->osso_context)) |
535 | #else |
536 | if(!project_edit(context->dialog, project)) |
537 | #endif |
538 | { |
539 | printf("edit cancelled!!\n"); |
540 | |
541 | project_delete(context, project); |
542 | |
543 | project = NULL; |
544 | } |
545 | |
546 | /* enable/disable edit/remove buttons */ |
547 | view_selected(context, project); |
548 | |
549 | return project; |
550 | } |
551 | |
552 | // predecs |
553 | void project_get_status_icon_stock_id(project_t *project, gchar **stock_id); |
554 | |
555 | static void on_project_new(GtkButton *button, gpointer data) { |
556 | select_context_t *context = (select_context_t*)data; |
557 | project_t **project = &context->project; |
558 | *project = project_new(context); |
559 | if(*project) { |
560 | |
561 | GtkTreeModel *model = list_get_model(context->list); |
562 | |
563 | GtkTreeIter iter; |
564 | gchar *status_stock_id = NULL; |
565 | project_get_status_icon_stock_id(*project, &status_stock_id); |
566 | gtk_list_store_append(GTK_LIST_STORE(model), &iter); |
567 | gtk_list_store_set(GTK_LIST_STORE(model), &iter, |
568 | PROJECT_COL_NAME, (*project)->name, |
569 | PROJECT_COL_STATUS, status_stock_id, |
570 | PROJECT_COL_DESCRIPTION, (*project)->desc, |
571 | PROJECT_COL_DATA, *project, |
572 | -1); |
573 | |
574 | GtkTreeSelection *selection = list_get_selection(context->list); |
575 | gtk_tree_selection_select_iter(selection, &iter); |
576 | } |
577 | } |
578 | |
579 | static void on_project_delete(GtkButton *button, gpointer data) { |
580 | select_context_t *context = (select_context_t*)data; |
581 | project_t *project = project_get_selected(context->list); |
582 | |
583 | char *str = g_strdup_printf(_("Do you really want to delete the " |
584 | "project \"%s\"?"), project->name); |
585 | GtkWidget *dialog = gtk_message_dialog_new( |
586 | GTK_WINDOW(context->dialog), |
587 | GTK_DIALOG_DESTROY_WITH_PARENT, |
588 | GTK_MESSAGE_QUESTION, GTK_BUTTONS_YES_NO, str); |
589 | g_free(str); |
590 | |
591 | gtk_window_set_title(GTK_WINDOW(dialog), _("Delete project?")); |
592 | |
593 | /* set the active flag again if the user answered "no" */ |
594 | if(GTK_RESPONSE_NO == gtk_dialog_run(GTK_DIALOG(dialog))) { |
595 | gtk_widget_destroy(dialog); |
596 | return; |
597 | } |
598 | |
599 | gtk_widget_destroy(dialog); |
600 | |
601 | if(!project_delete(context, project)) |
602 | printf("unable to delete project\n"); |
603 | } |
604 | |
605 | static void on_project_edit(GtkButton *button, gpointer data) { |
606 | select_context_t *context = (select_context_t*)data; |
607 | project_t *project = project_get_selected(context->list); |
608 | g_assert(project); |
609 | #ifdef USE_HILDON |
610 | if(project_edit(context->dialog, project, |
611 | context->mmpos, context->osso_context)) |
612 | #else |
613 | if(project_edit(context->dialog, project)) |
614 | #endif |
615 | { |
616 | GtkTreeModel *model; |
617 | GtkTreeIter iter; |
618 | |
619 | /* description etc. may have changed, so update list */ |
620 | GtkTreeSelection *selection = list_get_selection(context->list); |
621 | g_assert(gtk_tree_selection_get_selected(selection, &model, &iter)); |
622 | |
623 | // gtk_tree_model_get(model, &iter, PROJECT_COL_DATA, &project, -1); |
624 | gchar *status_stock_id = NULL; |
625 | project_get_status_icon_stock_id(project, &status_stock_id); |
626 | gtk_list_store_set(GTK_LIST_STORE(model), &iter, |
627 | PROJECT_COL_NAME, project->name, |
628 | PROJECT_COL_STATUS, status_stock_id, |
629 | PROJECT_COL_DESCRIPTION, project->desc, |
630 | -1); |
631 | |
632 | |
633 | } |
634 | |
635 | /* enable/disable edit/remove buttons */ |
636 | view_selected(context, project); |
637 | } |
638 | |
639 | |
640 | gboolean project_osm_present(project_t *project) { |
641 | char *osm_name = g_strdup_printf("%s/%s.osm", project->path, project->name); |
642 | gboolean is_present = g_file_test(osm_name, G_FILE_TEST_EXISTS); |
643 | g_free(osm_name); |
644 | return is_present; |
645 | } |
646 | |
647 | void project_get_status_icon_stock_id(project_t *project, gchar **stock_id) { |
648 | *stock_id = (! project_osm_present(project)) ? GTK_STOCK_DIALOG_WARNING |
649 | : diff_present(project) ? GTK_STOCK_PROPERTIES |
650 | : GTK_STOCK_FILE; |
651 | // TODO: check for outdatedness too. Which icon to use? |
652 | } |
653 | |
654 | static GtkWidget *project_list_widget(select_context_t *context) { |
655 | context->list = list_new(LIST_HILDON_WITHOUT_HEADERS); |
656 | |
657 | list_set_selection_function(context->list, view_selection_func, context); |
658 | |
659 | list_set_columns(context->list, |
660 | _("Name"), PROJECT_COL_NAME, 0, |
661 | _("State"), PROJECT_COL_STATUS, LIST_FLAG_STOCK_ICON, |
662 | _("Description"), PROJECT_COL_DESCRIPTION, LIST_FLAG_ELLIPSIZE, |
663 | NULL); |
664 | |
665 | |
666 | /* build the store */ |
667 | GtkListStore *store = gtk_list_store_new(PROJECT_NUM_COLS, |
668 | G_TYPE_STRING, // name |
669 | G_TYPE_STRING, // status |
670 | G_TYPE_STRING, // desc |
671 | G_TYPE_POINTER); // data |
672 | |
673 | GtkTreeIter iter; |
674 | project_t *project = context->project; |
675 | while(project) { |
676 | gchar *status_stock_id = NULL; |
677 | project_get_status_icon_stock_id(project, &status_stock_id); |
678 | /* Append a row and fill in some data */ |
679 | gtk_list_store_append(store, &iter); |
680 | gtk_list_store_set(store, &iter, |
681 | PROJECT_COL_NAME, project->name, |
682 | PROJECT_COL_STATUS, status_stock_id, |
683 | PROJECT_COL_DESCRIPTION, project->desc, |
684 | PROJECT_COL_DATA, project, |
685 | -1); |
686 | project = project->next; |
687 | } |
688 | |
689 | list_set_store(context->list, store); |
690 | g_object_unref(store); |
691 | |
692 | list_set_static_buttons(context->list, G_CALLBACK(on_project_new), |
693 | G_CALLBACK(on_project_edit), G_CALLBACK(on_project_delete), context); |
694 | |
695 | return context->list; |
696 | } |
697 | |
698 | char *project_select(appdata_t *appdata) { |
699 | char *name = NULL; |
700 | |
701 | select_context_t *context = g_new0(select_context_t, 1); |
702 | #ifdef USE_HILDON |
703 | context->mmpos = &appdata->mmpos; |
704 | context->osso_context = appdata->osso_context; |
705 | #endif |
706 | context->settings = appdata->settings; |
707 | context->project = project_scan(appdata); |
708 | |
709 | /* create project selection dialog */ |
710 | context->dialog = gtk_dialog_new_with_buttons(_("Project selection"), |
711 | GTK_WINDOW(appdata->window), GTK_DIALOG_MODAL, |
712 | GTK_STOCK_CANCEL, GTK_RESPONSE_REJECT, |
713 | GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT, |
714 | NULL); |
715 | |
716 | #ifdef USE_HILDON |
717 | gtk_window_set_default_size(GTK_WINDOW(context->dialog), 500, 300); |
718 | #else |
719 | gtk_window_set_default_size(GTK_WINDOW(context->dialog), 400, 200); |
720 | #endif |
721 | |
722 | gtk_box_pack_start_defaults(GTK_BOX(GTK_DIALOG(context->dialog)->vbox), |
723 | project_list_widget(context)); |
724 | |
725 | /* don't all user to click ok until something is selected */ |
726 | gtk_dialog_set_response_sensitive(GTK_DIALOG(context->dialog), |
727 | GTK_RESPONSE_ACCEPT, FALSE); |
728 | |
729 | gtk_widget_show_all(context->dialog); |
730 | if(GTK_RESPONSE_ACCEPT == gtk_dialog_run(GTK_DIALOG(context->dialog))) |
731 | name = g_strdup(project_get_selected(context->list)->name); |
732 | |
733 | gtk_widget_destroy(context->dialog); |
734 | |
735 | /* free all entries */ |
736 | project_t *project = context->project; |
737 | while(project) { |
738 | project_t *next = project->next; |
739 | project_free(project); |
740 | project = next; |
741 | } |
742 | |
743 | g_free(context); |
744 | |
745 | return name; |
746 | } |
747 | |
748 | /* ---------------------------------------------------- */ |
749 | |
750 | /* return file length or -1 on error */ |
751 | static gsize file_length(char *name) { |
752 | GMappedFile *gmap = g_mapped_file_new(name, FALSE, NULL); |
753 | if(!gmap) return -1; |
754 | gsize size = g_mapped_file_get_length(gmap); |
755 | g_mapped_file_free(gmap); |
756 | return size; |
757 | } |
758 | |
759 | void project_filesize(project_context_t *context) { |
760 | char *str = NULL; |
761 | |
762 | printf("Checking size of %s\n", context->project->osm); |
763 | |
764 | if(!g_file_test(context->project->osm, G_FILE_TEST_IS_REGULAR)) { |
765 | GdkColor color; |
766 | gdk_color_parse("red", &color); |
767 | gtk_widget_modify_fg(context->fsize, GTK_STATE_NORMAL, &color); |
768 | |
769 | str = g_strdup(_("Not downloaded!")); |
770 | gtk_dialog_set_response_sensitive(GTK_DIALOG(context->dialog), |
771 | GTK_RESPONSE_ACCEPT, 0); |
772 | } else { |
773 | gtk_widget_modify_fg(context->fsize, GTK_STATE_NORMAL, NULL); |
774 | |
775 | if(!context->project->data_dirty) |
776 | str = g_strdup_printf(_("%d bytes present"), |
777 | file_length(context->project->osm)); |
778 | else |
779 | str = g_strdup_printf(_("Outdated, please download!")); |
780 | |
781 | /* project also must not be dirty to proceed */ |
782 | gtk_dialog_set_response_sensitive(GTK_DIALOG(context->dialog), |
783 | GTK_RESPONSE_ACCEPT, !context->project->data_dirty); |
784 | } |
785 | |
786 | if(str) { |
787 | gtk_label_set_text(GTK_LABEL(context->fsize), str); |
788 | g_free(str); |
789 | } |
790 | } |
791 | |
792 | void project_diffstat(project_context_t *context) { |
793 | char *str = NULL; |
794 | |
795 | if(diff_present(context->project)) |
796 | str = g_strdup(_("present")); |
797 | else |
798 | str = g_strdup(_("not present")); |
799 | |
800 | gtk_label_set_text(GTK_LABEL(context->diff_stat), str); |
801 | g_free(str); |
802 | } |
803 | |
804 | static void project_update(project_context_t *context) { |
805 | |
806 | /* fetch values from dialog */ |
807 | if(context->project->desc) g_free(context->project->desc); |
808 | context->project->desc = g_strdup(gtk_entry_get_text( |
809 | GTK_ENTRY(context->desc))); |
810 | |
811 | if(context->project->server) g_free(context->project->server); |
812 | context->project->server = g_strdup(gtk_entry_get_text( |
813 | GTK_ENTRY(context->server))); |
814 | } |
815 | |
816 | static void on_edit_clicked(GtkButton *button, gpointer data) { |
817 | project_context_t *context = (project_context_t*)data; |
818 | |
819 | if(area_edit(&context->area_edit)) { |
820 | printf("coordinates changed!!\n"); |
821 | |
822 | pos_lon_label_set(context->minlat, context->project->min.lat); |
823 | pos_lon_label_set(context->minlon, context->project->min.lon); |
824 | pos_lon_label_set(context->maxlat, context->project->max.lat); |
825 | pos_lon_label_set(context->maxlon, context->project->max.lon); |
826 | } |
827 | } |
828 | |
829 | static void on_download_clicked(GtkButton *button, gpointer data) { |
830 | project_context_t *context = (project_context_t*)data; |
831 | |
832 | project_update(context); |
833 | |
834 | printf("download %s\n", context->project->osm); |
835 | |
836 | if(osm_download(context->dialog, context->project)) { |
837 | context->project->data_dirty = FALSE; |
838 | project_filesize(context); |
839 | } else |
840 | printf("download failed\n"); |
841 | } |
842 | |
843 | static void on_diff_remove_clicked(GtkButton *button, gpointer data) { |
844 | project_context_t *context = (project_context_t*)data; |
845 | |
846 | printf("clicked diff remove\n"); |
847 | |
848 | GtkWidget *dialog = gtk_message_dialog_new( |
849 | GTK_WINDOW(context->dialog), |
850 | GTK_DIALOG_DESTROY_WITH_PARENT, |
851 | GTK_MESSAGE_QUESTION, GTK_BUTTONS_YES_NO, |
852 | _("Do you really want to remove the diff file? This " |
853 | "will delete all changes you've made so far and which " |
854 | "you didn't upload yet.")); |
855 | |
856 | gtk_window_set_title(GTK_WINDOW(dialog), _("Remove diff?")); |
857 | |
858 | /* set the active flag again if the user answered "no" */ |
859 | if(GTK_RESPONSE_YES == gtk_dialog_run(GTK_DIALOG(dialog))) { |
860 | diff_remove(context->project); |
861 | project_diffstat(context); |
862 | gtk_widget_set_sensitive(context->diff_remove, FALSE); |
863 | } |
864 | |
865 | gtk_widget_destroy(dialog); |
866 | } |
867 | |
868 | gboolean project_edit(GtkWidget *parent, project_t *project POS_PARM) { |
869 | gboolean ok = FALSE; |
870 | |
871 | /* ------------ project edit dialog ------------- */ |
872 | |
873 | project_context_t *context = g_new0(project_context_t, 1); |
874 | context->project = project; |
875 | |
876 | context->area_edit.min = &project->min; |
877 | context->area_edit.max = &project->max; |
878 | #ifdef USE_HILDON |
879 | context->area_edit.mmpos = mmpos; |
880 | context->area_edit.osso_context = osso_context; |
881 | #endif |
882 | |
883 | char *str = g_strdup_printf(_("Project - %s"), project->name); |
884 | context->area_edit.parent = |
885 | context->dialog = gtk_dialog_new_with_buttons(str, |
886 | GTK_WINDOW(parent), GTK_DIALOG_MODAL, |
887 | GTK_STOCK_CANCEL, GTK_RESPONSE_REJECT, |
888 | GTK_STOCK_OK, GTK_RESPONSE_ACCEPT, |
889 | NULL); |
890 | g_free(str); |
891 | |
892 | #ifdef USE_HILDON |
893 | /* making the dialog a little wider makes it less "crowded" */ |
894 | gtk_window_set_default_size(GTK_WINDOW(context->dialog), 640, 100); |
895 | #else |
896 | gtk_window_set_default_size(GTK_WINDOW(context->dialog), 400, 100); |
897 | #endif |
898 | |
899 | GtkWidget *download, *label; |
900 | GtkWidget *table = gtk_table_new(4, 6, FALSE); // x, y |
901 | |
902 | label = gtk_label_new(_("Description:")); |
903 | gtk_misc_set_alignment(GTK_MISC(label), 1.f, 0.5f); |
904 | gtk_table_attach_defaults(GTK_TABLE(table), label, 0, 1, 0, 1); |
905 | context->desc = gtk_entry_new(); |
906 | gtk_entry_set_text(GTK_ENTRY(context->desc), project->desc); |
907 | gtk_table_attach_defaults(GTK_TABLE(table), context->desc, 1, 4, 0, 1); |
908 | |
909 | gtk_table_set_row_spacing(GTK_TABLE(table), 0, 4); |
910 | |
911 | label = gtk_label_new(_("Latitude")); |
912 | gtk_table_attach_defaults(GTK_TABLE(table), label, 1, 2, 1, 2); |
913 | label = gtk_label_new(_("Longitude")); |
914 | gtk_table_attach_defaults(GTK_TABLE(table), label, 2, 3, 1, 2); |
915 | |
916 | label = gtk_label_new(_("Min:")); |
917 | gtk_misc_set_alignment(GTK_MISC(label), 1.f, 0.5f); |
918 | gtk_table_attach_defaults(GTK_TABLE(table), label, 0, 1, 2, 3); |
919 | context->minlat = pos_lat_label_new(project->min.lat); |
920 | gtk_table_attach_defaults(GTK_TABLE(table), context->minlat, 1, 2, 2, 3); |
921 | context->minlon = pos_lon_label_new(project->min.lon); |
922 | gtk_table_attach_defaults(GTK_TABLE(table), context->minlon, 2, 3, 2, 3); |
923 | |
924 | label = gtk_label_new(_("Max:")); |
925 | gtk_misc_set_alignment(GTK_MISC(label), 1.f, 0.5f); |
926 | gtk_table_attach_defaults(GTK_TABLE(table), label, 0, 1, 3, 4); |
927 | context->maxlat = pos_lat_label_new(project->max.lat); |
928 | gtk_table_attach_defaults(GTK_TABLE(table), context->maxlat, 1, 2, 3, 4); |
929 | context->maxlon = pos_lon_label_new(project->max.lon); |
930 | gtk_table_attach_defaults(GTK_TABLE(table), context->maxlon, 2, 3, 3, 4); |
931 | |
932 | GtkWidget *edit = gtk_button_new_with_label(_("Edit...")); |
933 | gtk_signal_connect(GTK_OBJECT(edit), "clicked", |
934 | (GtkSignalFunc)on_edit_clicked, context); |
935 | gtk_table_attach(GTK_TABLE(table), edit, 3, 4, 2, 4, |
936 | GTK_EXPAND | GTK_FILL,0,0,0); |
937 | |
938 | gtk_table_set_col_spacing(GTK_TABLE(table), 0, 4); |
939 | gtk_table_set_row_spacing(GTK_TABLE(table), 3, 4); |
940 | |
941 | label = gtk_label_new(_("Server:")); |
942 | gtk_misc_set_alignment(GTK_MISC(label), 1.f, 0.5f); |
943 | gtk_table_attach_defaults(GTK_TABLE(table), label, 0, 1, 4, 5); |
944 | context->server = gtk_entry_new(); |
945 | HILDON_ENTRY_NO_AUTOCAP(context->server); |
946 | gtk_entry_set_text(GTK_ENTRY(context->server), project->server); |
947 | gtk_table_attach_defaults(GTK_TABLE(table), context->server, 1, 4, 4, 5); |
948 | |
949 | label = gtk_label_new(_("OSM file:")); |
950 | gtk_misc_set_alignment(GTK_MISC(label), 1.f, 0.5f); |
951 | gtk_table_attach_defaults(GTK_TABLE(table), label, 0, 1, 5, 6); |
952 | GtkWidget *hbox = gtk_hbox_new(FALSE, 0); |
953 | context->fsize = gtk_label_new(_("")); |
954 | gtk_misc_set_alignment(GTK_MISC(context->fsize), 0.f, 0.5f); |
955 | project_filesize(context); |
956 | gtk_box_pack_start_defaults(GTK_BOX(hbox), context->fsize); |
957 | download = gtk_button_new_with_label(_("Download...")); |
958 | gtk_signal_connect(GTK_OBJECT(download), "clicked", |
959 | (GtkSignalFunc)on_download_clicked, context); |
960 | gtk_box_pack_start(GTK_BOX(hbox), download, FALSE, FALSE, 0); |
961 | gtk_table_attach_defaults(GTK_TABLE(table), hbox, 1, 4, 5, 6); |
962 | |
963 | label = gtk_label_new(_("Diff file:")); |
964 | gtk_misc_set_alignment(GTK_MISC(label), 1.f, 0.5f); |
965 | gtk_table_attach_defaults(GTK_TABLE(table), label, 0, 1, 6, 7); |
966 | hbox = gtk_hbox_new(FALSE, 0); |
967 | context->diff_stat = gtk_label_new(_("")); |
968 | gtk_misc_set_alignment(GTK_MISC(context->diff_stat), 0.f, 0.5f); |
969 | project_diffstat(context); |
970 | gtk_box_pack_start_defaults(GTK_BOX(hbox), context->diff_stat); |
971 | context->diff_remove = gtk_button_new_with_label(_("Remove...")); |
972 | if(!diff_present(project)) |
973 | gtk_widget_set_sensitive(context->diff_remove, FALSE); |
974 | gtk_signal_connect(GTK_OBJECT(context->diff_remove), "clicked", |
975 | (GtkSignalFunc)on_diff_remove_clicked, context); |
976 | gtk_box_pack_start(GTK_BOX(hbox), context->diff_remove, FALSE, FALSE, 0); |
977 | gtk_table_attach_defaults(GTK_TABLE(table), hbox, 1, 4, 6, 7); |
978 | |
979 | |
980 | gtk_box_pack_start_defaults(GTK_BOX(GTK_DIALOG(context->dialog)->vbox), |
981 | table); |
982 | gtk_widget_show_all(context->dialog); |
983 | |
984 | if(GTK_RESPONSE_ACCEPT == gtk_dialog_run(GTK_DIALOG(context->dialog))) { |
985 | ok = TRUE; |
986 | |
987 | /* transfer values from edit dialog into project structure */ |
988 | project_update(context); |
989 | |
990 | /* save project */ |
991 | project_save(context->dialog, project); |
992 | } |
993 | |
994 | gtk_widget_destroy(context->dialog); |
995 | g_free(context); |
996 | |
997 | return ok; |
998 | } |
999 | |
1000 | gboolean project_open(appdata_t *appdata, char *name) { |
1001 | project_t *project = g_new0(project_t, 1); |
1002 | |
1003 | /* link to map state if a map already exists */ |
1004 | if(appdata->map) { |
1005 | printf("Project: Using map state\n"); |
1006 | project->map_state = appdata->map->state; |
1007 | } else { |
1008 | printf("Project: Creating new map_state\n"); |
1009 | project->map_state = g_new0(map_state_t,1); |
1010 | } |
1011 | project->map_state->refcount++; |
1012 | |
1013 | /* build project path */ |
1014 | project->path = g_strdup_printf("%s%s/", |
1015 | appdata->settings->base_path, name); |
1016 | project->name = g_strdup(name); |
1017 | |
1018 | char *project_file = g_strdup_printf("%s%s.proj", project->path, name); |
1019 | |
1020 | printf("project file = %s\n", project_file); |
1021 | if(!g_file_test(project_file, G_FILE_TEST_IS_REGULAR)) { |
1022 | printf("requested project file doesn't exist\n"); |
1023 | project_free(project); |
1024 | g_free(project_file); |
1025 | return FALSE; |
1026 | } |
1027 | |
1028 | if(!project_read(appdata, project_file, project)) { |
1029 | printf("error reading project file\n"); |
1030 | project_free(project); |
1031 | g_free(project_file); |
1032 | return FALSE; |
1033 | } |
1034 | |
1035 | g_free(project_file); |
1036 | |
1037 | /* --------- project structure ok: load its OSM file --------- */ |
1038 | appdata->project = project; |
1039 | |
1040 | printf("project_open: loading osm\n"); |
1041 | appdata->osm = osm_parse(project->osm); |
1042 | if(!appdata->osm) return FALSE; |
1043 | |
1044 | printf("parsing ok\n"); |
1045 | |
1046 | return TRUE; |
1047 | } |
1048 | |
1049 | gboolean project_close(appdata_t *appdata) { |
1050 | if(!appdata->project) return FALSE; |
1051 | |
1052 | printf("closing current project\n"); |
1053 | |
1054 | /* redraw the entire map by destroying all map items and redrawing them */ |
1055 | if(appdata->osm) |
1056 | diff_save(appdata->project, appdata->osm); |
1057 | |
1058 | /* Save track and turn off the handler callback */ |
1059 | track_save(appdata->project, appdata->track.track); |
1060 | track_clear(appdata, appdata->track.track); |
1061 | appdata->track.track = NULL; |
1062 | |
1063 | map_clear(appdata, MAP_LAYER_ALL); |
1064 | |
1065 | if(appdata->osm) { |
1066 | osm_free(&appdata->icon, appdata->osm); |
1067 | appdata->osm = NULL; |
1068 | } |
1069 | |
1070 | project_free(appdata->project); |
1071 | appdata->project = NULL; |
1072 | |
1073 | return TRUE; |
1074 | } |
1075 | |
1076 | #define _PROJECT_LOAD_BUF_SIZ 64 |
1077 | |
1078 | gboolean project_load(appdata_t *appdata, char *name) { |
1079 | char *proj_name = NULL; |
1080 | |
1081 | if(!name) { |
1082 | /* make user select a project */ |
1083 | proj_name = project_select(appdata); |
1084 | if(!proj_name) { |
1085 | printf("no project selected\n"); |
1086 | return FALSE; |
1087 | } |
1088 | } |
1089 | else { |
1090 | proj_name = g_strdup(name); |
1091 | } |
1092 | |
1093 | char banner_txt[_PROJECT_LOAD_BUF_SIZ]; |
1094 | memset(banner_txt, 0, _PROJECT_LOAD_BUF_SIZ); |
1095 | |
1096 | snprintf(banner_txt, _PROJECT_LOAD_BUF_SIZ, _("Loading %s"), proj_name); |
1097 | banner_busy_start(appdata, TRUE, banner_txt); |
1098 | |
1099 | /* close current project */ |
1100 | banner_busy_tick(); |
1101 | if(appdata->project) |
1102 | project_close(appdata); |
1103 | |
1104 | /* open project itself */ |
1105 | banner_busy_tick(); |
1106 | if(!project_open(appdata, proj_name)) { |
1107 | printf("error opening requested project\n"); |
1108 | |
1109 | if(appdata->project) { |
1110 | project_free(appdata->project); |
1111 | appdata->project = NULL; |
1112 | } |
1113 | |
1114 | if(appdata->osm) { |
1115 | osm_free(&appdata->icon, appdata->osm); |
1116 | appdata->osm = NULL; |
1117 | } |
1118 | |
1119 | snprintf(banner_txt, _PROJECT_LOAD_BUF_SIZ, |
1120 | _("Error opening %s"), proj_name); |
1121 | banner_busy_stop(appdata); |
1122 | banner_show_info(appdata, banner_txt); |
1123 | |
1124 | g_free(proj_name); |
1125 | return FALSE; |
1126 | } |
1127 | |
1128 | /* check if OSM data is valid */ |
1129 | banner_busy_tick(); |
1130 | if(!osm_sanity_check(GTK_WIDGET(appdata->window), appdata->osm)) { |
1131 | printf("project/osm sanity checks failed, unloading project\n"); |
1132 | |
1133 | if(appdata->project) { |
1134 | project_free(appdata->project); |
1135 | appdata->project = NULL; |
1136 | } |
1137 | |
1138 | if(appdata->osm) { |
1139 | osm_free(&appdata->icon, appdata->osm); |
1140 | appdata->osm = NULL; |
1141 | } |
1142 | |
1143 | snprintf(banner_txt, _PROJECT_LOAD_BUF_SIZ, |
1144 | _("Error opening %s"), proj_name); |
1145 | banner_busy_stop(appdata); |
1146 | banner_show_info(appdata, banner_txt); |
1147 | |
1148 | g_free(proj_name); |
1149 | return FALSE; |
1150 | } |
1151 | |
1152 | /* load diff possibly preset */ |
1153 | banner_busy_tick(); |
1154 | diff_restore(appdata, appdata->project, appdata->osm); |
1155 | |
1156 | /* prepare colors etc, draw data and adjust scroll/zoom settings */ |
1157 | banner_busy_tick(); |
1158 | map_init(appdata); |
1159 | |
1160 | /* restore a track */ |
1161 | banner_busy_tick(); |
1162 | appdata->track.track = track_restore(appdata, appdata->project); |
1163 | if(appdata->track.track) |
1164 | map_track_draw(appdata->map, appdata->track.track); |
1165 | |
1166 | /* finally load a background if present */ |
1167 | banner_busy_tick(); |
1168 | wms_load(appdata); |
1169 | |
1170 | /* save the name of the project for the perferences */ |
1171 | if(appdata->settings->project) |
1172 | g_free(appdata->settings->project); |
1173 | appdata->settings->project = g_strdup(appdata->project->name); |
1174 | |
1175 | snprintf(banner_txt, _PROJECT_LOAD_BUF_SIZ, _("Loaded %s"), proj_name); |
1176 | banner_busy_stop(appdata); |
1177 | banner_show_info(appdata, banner_txt); |
1178 | statusbar_set(appdata, NULL, 0); |
1179 | |
1180 | g_free(proj_name); |
1181 | return TRUE; |
1182 | } |
1183 | // vim:et:ts=8:sw=2:sts=2:ai |