Contents of /trunk/src/main.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 190 - (show annotations)
Tue Nov 17 10:22:41 2009 UTC (14 years, 6 months ago) by harbaum
File MIME type: text/plain
File size: 71763 byte(s)
More fremantleization
1 /*
2 * This file is part of GPXView.
3 *
4 * GPXView is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
8 *
9 * GPXView is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with GPXView. If not, see <http://www.gnu.org/licenses/>.
16 */
17
18 #include <stdio.h>
19 #include <string.h>
20 #include <math.h>
21
22 #include <curl/curl.h>
23
24 #include <time.h>
25 #include <sys/time.h>
26
27 #include "gpxview.h"
28 #include "custom_size_renderer.h"
29 #include "custom_rating_renderer.h"
30 #include "custom_type_renderer.h"
31
32 #ifdef USE_MAEMO
33 #include <hildon/hildon-banner.h>
34 #if MAEMO_VERSION_MAJOR >= 5
35 #include <hildon/hildon-note.h>
36 #include <hildon/hildon-entry.h>
37 #include <hildon/hildon-check-button.h>
38 #endif
39 #endif
40
41 #include <locale.h>
42
43 extern char *strcasestr (__const char *__haystack, __const char *__needle);
44
45 #if defined(USE_BREAD_CRUMB_TRAIL) || defined(BCT)
46 static void crumb_add(appdata_t *appdata, char *name, int level,
47 gpointer user_data);
48
49 enum {
50 CRUMB_GPXLIST = 0,
51 CRUMB_CACHELIST,
52 CRUMB_SEARCH_GLOBAL,
53 CRUMB_SEARCH_GPX,
54 CRUMB_CACHE,
55 };
56 #endif
57
58 /* size of first buffer malloc; start small to exercise grow routines */
59 #define FIRSTSIZE 1
60
61 void errorf(const char *fmt, ...) {
62 va_list args;
63 char *buf = NULL;
64 size_t bufsize;
65 char *newbuf;
66 size_t nextsize = 0;
67 int outsize;
68
69 bufsize = 0;
70 for (;;) {
71 if (bufsize == 0) {
72 if ((buf = (char *)malloc(FIRSTSIZE)) == NULL)
73 return;
74
75 bufsize = 1;
76 } else if ((newbuf = (char *)realloc(buf, nextsize)) != NULL) {
77 buf = newbuf;
78 bufsize = nextsize;
79 } else {
80 free(buf);
81 return;
82 }
83
84 va_start(args, fmt);
85 outsize = vsnprintf(buf, bufsize, fmt, args);
86 va_end(args);
87
88 if (outsize == -1) {
89 nextsize = bufsize * 2;
90 } else if (outsize == bufsize) {
91 nextsize = bufsize * 2;
92 } else if (outsize > bufsize) {
93 nextsize = outsize + 2; // Linux!
94 } else if (outsize == bufsize - 1) {
95 nextsize = bufsize * 2;
96 } else {
97 /* Output was not truncated */
98 break;
99 }
100 }
101
102 #if !defined(USE_MAEMO) || (MAEMO_VERSION_MAJOR < 5)
103 GtkWidget *dialog = gtk_message_dialog_new(
104 GTK_WINDOW(NULL),
105 GTK_DIALOG_DESTROY_WITH_PARENT,
106 GTK_MESSAGE_ERROR,
107 GTK_BUTTONS_CLOSE, buf);
108
109 gtk_window_set_title(GTK_WINDOW(dialog), _("ERROR"));
110 #else
111 GtkWidget *dialog =
112 hildon_note_new_information(GTK_WINDOW(NULL), buf);
113 #endif
114
115 gtk_dialog_run(GTK_DIALOG(dialog));
116 gtk_widget_destroy(dialog);
117
118 free(buf);
119 }
120
121 gpx_t *choose_file(appdata_t *appdata, gboolean whole_dir) {
122 GtkWidget *dialog;
123 gpx_t *gpx = NULL;
124
125 #ifdef USE_MAEMO
126 dialog = hildon_file_chooser_dialog_new(GTK_WINDOW(appdata->window),
127 whole_dir?GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER :
128 GTK_FILE_CHOOSER_ACTION_OPEN);
129
130 #ifdef HILDON_HELP
131 hildon_help_dialog_help_enable(GTK_DIALOG(dialog),
132 HELP_ID_IMPORT, appdata->osso_context);
133 #endif
134 #else
135 dialog = gtk_file_chooser_dialog_new (whole_dir?_("Import directory"):
136 _("Import file"),
137 GTK_WINDOW(appdata->window),
138 whole_dir?GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER :
139 GTK_FILE_CHOOSER_ACTION_OPEN,
140 GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
141 GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT,
142 NULL);
143 #endif
144
145 /* use path if one is present */
146 if(appdata->path)
147 gtk_file_chooser_set_current_folder(GTK_FILE_CHOOSER(dialog),
148 appdata->path);
149
150 gtk_widget_show_all (GTK_WIDGET(dialog));
151 if (gtk_dialog_run (GTK_DIALOG(dialog)) == GTK_FM_OK) {
152 char *filename = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (dialog));
153
154 if(filename) {
155 gpx_dialog_t *dialog = gpx_busy_dialog_new(GTK_WIDGET(appdata->window));
156
157 if(!whole_dir)
158 gpx = gpx_parse(dialog, filename);
159 else {
160 /* cur trailing '/' if present */
161 if(strlastchr(filename) == '/')
162 filename[strlen(filename)] = 0;
163
164 gpx = gpx_parse_dir(dialog, filename);
165 }
166
167 gpx_busy_dialog_destroy(dialog);
168
169 /* save path if gpx was successfully loaded */
170 if(gpx) {
171 char *r = strrchr(filename, '/');
172
173 /* there is a delimiter, use everything left of it as path */
174 if(r && !whole_dir) {
175 *r = 0;
176 if(appdata->path) free(appdata->path);
177 appdata->path = strdup(filename);
178 /* restore path ... just in case ... */
179 *r = '/';
180 }
181
182 if(whole_dir)
183 appdata->path = strdup(filename);
184 } else
185 errorf(_("Load error"));
186
187 g_free (filename);
188 } else {
189 #ifndef USE_MAEMO
190 errorf(_("Error accessing the file."));
191 #else
192 errorf(_("Error accessing the file. This may happen if the file "
193 "resides on a remote file system. Please copy the file onto "
194 "the device (e.g. onto the memory card) and try again."));
195 #endif
196 }
197 }
198
199 gtk_widget_destroy (dialog);
200
201 return gpx;
202 }
203
204 /******************** begin of cachelist ********************/
205
206 enum {
207 CACHELIST_COL_TYPE = 0,
208 CACHELIST_COL_ID,
209 CACHELIST_COL_NAME,
210 CACHELIST_COL_SIZE,
211 CACHELIST_COL_RATING,
212 CACHELIST_COL_BEARING,
213 CACHELIST_COL_DISTANCE,
214 CACHELIST_COL_DATA,
215 CACHELIST_COL_AVAIL,
216 CACHELIST_COL_ARCHIVE,
217 CACHELIST_NUM_COLS
218 } ;
219
220 void cachelist_goto_cache(appdata_t *appdata, cache_t *cache) {
221 #if !defined(USE_BREAD_CRUMB_TRAIL) && !defined(BCT)
222 cache_dialog(appdata, cache);
223 #else
224 gtk_container_remove(GTK_CONTAINER(appdata->vbox), appdata->cur_view);
225 appdata->cur_view = cache_view(appdata, cache);
226 gtk_box_pack_start_defaults(GTK_BOX(appdata->vbox), appdata->cur_view);
227 gtk_widget_show_all(appdata->vbox);
228
229 crumb_add(appdata, cache->name, CRUMB_CACHE, cache);
230 #endif
231 }
232
233 static void cachelist_view_onRowActivated(GtkTreeView *treeview,
234 GtkTreePath *path,
235 GtkTreeViewColumn *col,
236 gpointer userdata) {
237 appdata_t *appdata = (appdata_t*)userdata;
238 GtkTreeIter iter;
239 GtkTreeModel *model = gtk_tree_view_get_model(treeview);
240
241 #ifdef USE_MAEMO
242 /* check if a cache is already selected and ignore click if yes */
243 /* (was probably a double click) */
244 if(appdata->cur_cache) return;
245 #endif
246
247 if(gtk_tree_model_get_iter(model, &iter, path)) {
248 cache_t *cache;
249 gtk_tree_model_get(model, &iter, CACHELIST_COL_DATA, &cache, -1);
250 cachelist_goto_cache(appdata, cache);
251 }
252 }
253
254 typedef struct {
255 appdata_t *appdata;
256 GtkTreePath *path;
257 gboolean done;
258 } cachelist_expose_t;
259
260 static gboolean cachelist_expose(GtkWidget *widget, GdkEventExpose *event,
261 gpointer user_data) {
262 cachelist_expose_t *ce = (cachelist_expose_t*)user_data;
263
264 if(event->type == GDK_EXPOSE) {
265 if(ce->path && !ce->done) {
266 gtk_tree_view_scroll_to_cell(GTK_TREE_VIEW(widget),
267 ce->path, NULL, TRUE, 0.5, 0.5);
268 gtk_tree_path_free(ce->path);
269 ce->done = TRUE;
270 }
271 }
272
273 return FALSE;
274 }
275
276 static void cachelist_destroy(GtkWidget *widget, gpointer user_data) {
277 cachelist_expose_t *ce = (cachelist_expose_t*)user_data;
278
279 printf("cachelist timer removed\n");
280 g_assert(ce->appdata->cachelist_handler_id);
281 gtk_timeout_remove(ce->appdata->cachelist_handler_id);
282 ce->appdata->cachelist_handler_id = 0;
283
284 free(user_data);
285 }
286
287 #define CACHELIST_UPDATE_TIMEOUT (30000)
288
289 static GtkWidget *cachelist_create(appdata_t *appdata, gpx_t *gpx,
290 cache_t *sel_cache);
291
292 void cachelist_redraw(appdata_t *appdata) {
293 if(!appdata->cur_view) {
294 printf("cachelist redraw: no active view\n");
295 return;
296 }
297
298 g_assert(!appdata->cur_cache);
299 int redraw = 0;
300 if(appdata->search_results)
301 redraw = 1;
302 else {
303 if(appdata->cur_gpx)
304 redraw = 2; // redraw cachelist
305 }
306
307 if(redraw) {
308 GtkWidget *container = appdata->vbox;
309
310 #ifdef USE_STACKABLE_WINDOW
311 HildonWindowStack *stack = hildon_window_stack_get_default();
312 container = hildon_window_stack_peek(stack);
313 #endif
314
315 gtk_container_remove(GTK_CONTAINER(container), appdata->cur_view);
316 switch(redraw) {
317 case 1:
318 appdata->cur_view = cachelist_create(appdata,
319 appdata->search_results, NULL);
320 break;
321 case 2:
322 appdata->cur_view = cachelist_create(appdata,
323 appdata->cur_gpx, NULL);
324 break;
325 }
326
327 #ifdef USE_STACKABLE_WINDOW
328 if(container != appdata->vbox)
329 gtk_container_add(GTK_CONTAINER(container), appdata->cur_view);
330 else
331 #endif
332 gtk_box_pack_start_defaults(GTK_BOX(container), appdata->cur_view);
333
334 gtk_widget_show_all(container);
335 }
336 }
337
338
339 static gboolean cachelist_update(gpointer data) {
340
341 printf("cachelist timer fired!\n");
342
343 appdata_t *appdata = (appdata_t*)data;
344
345 if(appdata->cur_cache)
346 return TRUE;
347
348 #ifdef USE_MAEMO
349 if(appdata->cachelist_disable_screensaver)
350 if (osso_display_blanking_pause(appdata->osso_context) != OSSO_OK)
351 fprintf(stderr, "error with display blank\n");
352 #endif
353
354 if(appdata->cachelist_update)
355 cachelist_redraw(appdata);
356
357 return TRUE;
358 }
359
360 static void cachelist_timer_reset(appdata_t *appdata) {
361 printf("cachelist timer reset\n");
362 g_assert(appdata->cachelist_handler_id);
363 gtk_timeout_remove(appdata->cachelist_handler_id);
364 appdata->cachelist_handler_id =
365 gtk_timeout_add(CACHELIST_UPDATE_TIMEOUT, cachelist_update, appdata);
366 }
367
368 static gboolean cachelist_update_reset0(GtkWidget *widget,
369 GdkEventButton *event,
370 gpointer user_data) {
371 cachelist_timer_reset((appdata_t*)user_data);
372 return FALSE;
373 }
374
375 static void cachelist_update_reset1(GtkAdjustment *adj,
376 gpointer user_data) {
377 cachelist_timer_reset((appdata_t*)user_data);
378 }
379
380 static GtkWidget *cachelist_create(appdata_t *appdata, gpx_t *gpx,
381 cache_t *sel_cache) {
382 GtkCellRenderer *renderer;
383 GtkWidget *view;
384 GtkListStore *store;
385 GtkTreeIter iter;
386
387 if(!gpx->notes_loaded) {
388 notes_load_all(appdata, gpx);
389 gpx->notes_loaded = TRUE;
390 }
391
392 appdata->cur_items = appdata->cachelist_items;
393
394 /* first sort the caches */
395 pos_t *refpos = get_pos(appdata);
396 gpx_sort(gpx, GPX_SORT_BY_DISTANCE, refpos);
397
398 view = gtk_tree_view_new();
399
400 /* --- "Type" column --- */
401 renderer = custom_cell_renderer_type_new();
402 gtk_tree_view_insert_column_with_attributes(GTK_TREE_VIEW(view),
403 -1, "Type", renderer, "type", CACHELIST_COL_TYPE, NULL);
404
405 /* --- "Id" column --- */
406 if(appdata->cachelist_items & CACHELIST_ITEM_ID) {
407 renderer = gtk_cell_renderer_text_new();
408 gtk_tree_view_insert_column_with_attributes(GTK_TREE_VIEW(view),
409 -1, "Id", renderer, "text", CACHELIST_COL_ID, NULL);
410 }
411
412 /* --- "Name" column --- */
413 renderer = gtk_cell_renderer_text_new();
414 g_object_set(renderer, "ellipsize", PANGO_ELLIPSIZE_END, NULL );
415
416 GtkTreeViewColumn *column = gtk_tree_view_column_new_with_attributes(
417 "Name", renderer, "text", CACHELIST_COL_NAME, NULL);
418 gtk_tree_view_column_set_expand(column, TRUE);
419 gtk_tree_view_insert_column(GTK_TREE_VIEW(view), column, -1);
420
421 g_object_set(renderer, "foreground", "#ff0000", NULL );
422 gtk_tree_view_column_add_attribute(column, renderer, "strikethrough",
423 CACHELIST_COL_AVAIL);
424 gtk_tree_view_column_add_attribute(column, renderer,
425 "foreground-set", CACHELIST_COL_ARCHIVE);
426
427 /* --- "Size" column --- */
428 if(appdata->cachelist_items & CACHELIST_ITEM_SIZE) {
429 renderer = custom_cell_renderer_size_new();
430 gtk_tree_view_insert_column_with_attributes(GTK_TREE_VIEW(view),
431 -1, "Size", renderer, "size", CACHELIST_COL_SIZE, NULL);
432 }
433
434 /* --- "Rating" column --- */
435 if(appdata->cachelist_items & CACHELIST_ITEM_RATING) {
436 renderer = custom_cell_renderer_rating_new();
437 gtk_tree_view_insert_column_with_attributes(GTK_TREE_VIEW(view),
438 -1, "Rating", renderer, "rating", CACHELIST_COL_RATING, NULL);
439 }
440
441 /* --- "Bearing" column --- */
442 renderer = gtk_cell_renderer_pixbuf_new();
443 gtk_tree_view_insert_column_with_attributes(GTK_TREE_VIEW(view),
444 -1, "Bearing", renderer, "pixbuf", CACHELIST_COL_BEARING, NULL);
445
446 /* --- "Distance" column --- */
447 renderer = gtk_cell_renderer_text_new();
448 gtk_tree_view_insert_column_with_attributes(GTK_TREE_VIEW(view),
449 -1, "Distance", renderer, "text", CACHELIST_COL_DISTANCE, NULL);
450
451 store = gtk_list_store_new(CACHELIST_NUM_COLS, G_TYPE_INT,
452 G_TYPE_STRING, G_TYPE_STRING, G_TYPE_INT,
453 G_TYPE_INT, GDK_TYPE_PIXBUF, G_TYPE_STRING,
454 G_TYPE_POINTER, G_TYPE_BOOLEAN,
455 G_TYPE_BOOLEAN);
456
457 GtkTreeSelection *sel = gtk_tree_view_get_selection(GTK_TREE_VIEW(view));
458
459 GtkTreeIter sel_iter;
460 gboolean sel_iter_valid = FALSE;
461 GtkTreePath *path = NULL;
462 cache_t *cache = gpx->cache;
463 while(cache) {
464 char str[32];
465 gpx_pos_get_distance_str(str, sizeof(str),
466 *refpos, gpx_cache_pos(cache), appdata->imperial);
467
468 int dint = (int)(cache->difficulty*2-2);
469 if(dint < 0) dint = 0;
470 if(dint > 8) dint = 8;
471
472 int tint = (int)(cache->terrain*2-2);
473 if(tint < 0) tint = 0;
474 if(tint > 8) tint = 8;
475
476 /* cache type includes "solved" flag in lowest bit */
477 int type = (cache->type<<8) +
478 (cache->notes?4:0) +
479 ((cache->notes && cache->notes->override)?1:0) +
480 ((cache->notes && cache->notes->found)?2:0);
481
482 if((!(type & 2)) || !appdata->cachelist_hide_found) {
483
484 /* Append a row and fill in some data */
485 gtk_list_store_append (store, &iter);
486
487 gtk_list_store_set(store, &iter,
488 CACHELIST_COL_TYPE, type,
489 CACHELIST_COL_ID, cache->id,
490 CACHELIST_COL_NAME, cache->name,
491 CACHELIST_COL_SIZE, cache->container,
492 CACHELIST_COL_RATING, 100 * dint + tint,
493 CACHELIST_COL_BEARING,
494 icon_bearing(*refpos, gpx_cache_pos(cache)),
495 CACHELIST_COL_DISTANCE, str,
496 CACHELIST_COL_DATA, cache,
497 CACHELIST_COL_AVAIL, !cache->available ||
498 cache->archived,
499 CACHELIST_COL_ARCHIVE, cache->archived,
500 -1);
501
502 if(cache == sel_cache) {
503 sel_iter = iter;
504 sel_iter_valid = TRUE;
505 }
506 }
507
508 cache = cache->next;
509 }
510
511 gtk_tree_view_set_model(GTK_TREE_VIEW(view), GTK_TREE_MODEL(store));
512 g_object_unref(store);
513
514 if(sel_iter_valid) {
515 gtk_tree_selection_select_iter(sel, &sel_iter);
516 path = gtk_tree_model_get_path(GTK_TREE_MODEL(store), &sel_iter);
517 }
518
519 /* make list react on clicks */
520 g_signal_connect(view, "row-activated",
521 (GCallback)cachelist_view_onRowActivated, appdata);
522
523 cachelist_expose_t *ce = malloc(sizeof(cachelist_expose_t));
524 ce->appdata = appdata;
525 ce->path = path;
526 ce->done = FALSE;
527
528 g_signal_connect(view, "expose-event",
529 (GCallback)cachelist_expose, ce);
530 g_signal_connect(view, "destroy",
531 (GCallback)cachelist_destroy, ce);
532
533 /* put this inside a scrolled view */
534 #ifndef USE_PANNABLE_AREA
535 GtkWidget *scrolled_window = gtk_scrolled_window_new (NULL, NULL);
536 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolled_window),
537 GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC);
538 gtk_container_add(GTK_CONTAINER(scrolled_window), view);
539 #else
540 GtkWidget *pannable_area = hildon_pannable_area_new();
541
542 gtk_container_add(GTK_CONTAINER(pannable_area), view);
543 #endif
544
545 /* add a timer for automatic update */
546 g_assert(!appdata->cachelist_handler_id);
547 appdata->cachelist_handler_id =
548 gtk_timeout_add(CACHELIST_UPDATE_TIMEOUT, cachelist_update, appdata);
549
550 /* update timer is being reset if the user scrolls or selects */
551 g_signal_connect(view, "button-press-event",
552 (GCallback)cachelist_update_reset0, appdata);
553
554 #ifndef USE_PANNABLE_AREA
555 g_signal_connect(gtk_scrolled_window_get_vadjustment(
556 GTK_SCROLLED_WINDOW(scrolled_window)),
557 "value-changed",
558 (GCallback)cachelist_update_reset1, appdata);
559
560 return scrolled_window;
561 #else
562 g_signal_connect(hildon_pannable_area_get_vadjustment(
563 HILDON_PANNABLE_AREA(pannable_area)),
564 "value-changed",
565 (GCallback)cachelist_update_reset1, appdata);
566
567
568 return pannable_area;
569 #endif
570 }
571
572 #ifndef USE_MAEMO
573 void cachelist_dialog(appdata_t *appdata, gpx_t *gpx) {
574 GtkWidget *dialog =
575 gtk_dialog_new_with_buttons(gpx->name, GTK_WINDOW(appdata->window),
576 GTK_DIALOG_NO_SEPARATOR | GTK_DIALOG_MODAL |
577 GTK_DIALOG_DESTROY_WITH_PARENT,
578 GTK_STOCK_CLOSE, GTK_RESPONSE_CLOSE,
579 NULL);
580
581 gtk_window_set_default_size(GTK_WINDOW(dialog), DIALOG_WIDTH, DIALOG_HEIGHT);
582
583 gtk_container_add(GTK_CONTAINER(GTK_DIALOG(dialog)->vbox),
584 cachelist_create(appdata, gpx, NULL));
585
586 gtk_widget_show_all(dialog);
587
588 gtk_dialog_run(GTK_DIALOG(dialog));
589 gtk_widget_destroy(dialog);
590 }
591 #else
592 #ifdef USE_STACKABLE_WINDOW
593 static void search_result_free(gpx_t *result);
594
595 void on_cachelist_destroy(GtkWidget *widget, appdata_t *appdata) {
596 if(appdata->search_results) {
597 search_result_free(appdata->search_results);
598 appdata->search_results = NULL;
599 }
600 appdata->cur_gpx = NULL;
601
602 #ifdef ENABLE_OSM_GPS_MAP
603 map_update(appdata);
604 #endif
605
606 /* restore cur_view */
607 appdata->cur_view = g_object_get_data(G_OBJECT(widget), "cur_view");
608 }
609
610 void cachelist_dialog(appdata_t *appdata, gpx_t *gpx) {
611 GtkWidget *window = hildon_stackable_window_new();
612
613 /* store last "cur_view" in window */
614 g_object_set_data(G_OBJECT(window), "cur_view", appdata->cur_view);
615
616 appdata->cur_gpx = gpx;
617 char *title = g_strdup_printf("%s - GPXView", gpx->name);
618 gtk_window_set_title(GTK_WINDOW(window), title);
619 g_free(title);
620
621 appdata->cur_view = cachelist_create(appdata, gpx, NULL);
622 gtk_container_add(GTK_CONTAINER(window), appdata->cur_view);
623
624
625 hildon_window_set_app_menu(HILDON_WINDOW(window),
626 menu_create(appdata, MENU_CACHELIST));
627
628 g_signal_connect(G_OBJECT(window), "destroy",
629 G_CALLBACK(on_cachelist_destroy), appdata);
630
631 gtk_widget_show_all(window);
632
633 #ifdef ENABLE_OSM_GPS_MAP
634 map_update(appdata);
635 #endif
636 }
637 #endif
638 #endif
639
640 /******************** end of cachelist ********************/
641
642 /******************** begin of gpxlist ********************/
643
644 enum {
645 GPXLIST_COL_ICON = 0,
646 GPXLIST_COL_FILENAME,
647 GPXLIST_COL_NAME,
648 GPXLIST_COL_DATE,
649 GPXLIST_COL_CACHES,
650 GPXLIST_COL_OPEN,
651 #ifdef USE_PANNABLE_AREA
652 GPXLIST_COL_DELETE,
653 #endif
654 GPXLIST_COL_DATA,
655 GPXLIST_NUM_COLS
656 } ;
657
658 static GdkPixbuf *gpx_icon_get(gpx_t *gpx) {
659 if(gpx->filename && g_file_test(gpx->filename, G_FILE_TEST_IS_DIR))
660 return icon_get(ICON_FILE, 1);
661
662 if(gpx->filename&& !strcasecmp(gpx->filename+strlen(gpx->filename)-4,".zip"))
663 return icon_get(ICON_FILE, 2);
664
665 return icon_get(ICON_FILE, 0);
666 }
667
668 static void gpxlist_set(GtkListStore *store, GtkTreeIter *iter, gpx_t *gpx) {
669 char date_str[32], cnum[32];
670
671 if(gpx->year && gpx->month && gpx->day) {
672 GDate *date = g_date_new_dmy(gpx->day, gpx->month, gpx->year);
673 g_date_strftime(date_str, sizeof(date_str), "%x", date);
674 g_date_free(date);
675 } else
676 strcpy(date_str, "---");
677
678 char *fname = strrchr(gpx->filename, '/');
679 if(!fname) fname = gpx->filename;
680 else fname++; /* skip '/' */
681
682 snprintf(cnum, sizeof(cnum), "%d", gpx_total_caches(gpx));
683
684 /* Append a row and fill in some data */
685 gtk_list_store_set(store, iter,
686 GPXLIST_COL_ICON, gpx_icon_get(gpx),
687 GPXLIST_COL_FILENAME, fname,
688 GPXLIST_COL_NAME, gpx->name,
689 GPXLIST_COL_DATE, gpx->closed?NULL:date_str,
690 GPXLIST_COL_OPEN, !gpx->closed,
691 GPXLIST_COL_CACHES, gpx->closed?NULL:cnum,
692 #ifdef USE_PANNABLE_AREA
693 GPXLIST_COL_DELETE, icon_get(ICON_MISC, 4),
694 #endif
695 GPXLIST_COL_DATA, gpx,
696 -1);
697 }
698
699 static void gpxlist_remove(appdata_t *appdata,
700 GtkListStore *store, GtkTreeIter *iter,
701 gpx_t *gpx) {
702
703 printf("removing %s\n", gpx->name);
704
705 /* de-chain */
706 gpx_t **prev = &appdata->gpx;
707 while(*prev != gpx) prev = &((*prev)->next);
708 *prev = gpx->next;
709
710 /* remove gconf entry if file was closed */
711 gconf_remove_closed_name(appdata, gpx->filename);
712
713 /* free gpx itself */
714 gpx_free(gpx);
715
716 /* and remove from store */
717 gtk_list_store_remove(store, iter);
718 }
719
720 static void gpxlist_close(appdata_t *appdata,
721 GtkListStore *store, GtkTreeIter *iter,
722 gpx_t *gpx) {
723
724 printf("closing %s\n", gpx->name);
725
726 g_assert(!gpx->closed);
727 gpx->closed = TRUE;
728
729 /* free all associated caches */
730 gpx_free_caches(gpx);
731
732 /* update entry */
733 gpxlist_set(store, iter, gpx);
734
735 /* save name in gconf so we know this has been closed */
736 gconf_save_closed_name(appdata, gpx->filename, gpx->name);
737 }
738
739 void gpxlist_goto_cachelist(appdata_t *appdata, gpx_t *gpx) {
740 #if !defined(USE_BREAD_CRUMB_TRAIL) && !defined(BCT)
741 #ifdef USE_STACKABLE_WINDOW
742 if(!appdata->cur_gpx)
743 #endif
744 cachelist_dialog(appdata, gpx);
745 #ifdef USE_STACKABLE_WINDOW
746 else
747 printf("selected gpx, but cachelist window already present\n");
748 #endif
749 #else
750 gtk_container_remove(GTK_CONTAINER(appdata->vbox), appdata->cur_view);
751 appdata->cur_view = cachelist_create(appdata, gpx, NULL);
752 gtk_box_pack_start_defaults(GTK_BOX(appdata->vbox), appdata->cur_view);
753 gtk_widget_show_all(appdata->vbox);
754
755 crumb_add(appdata, gpx->name, CRUMB_CACHELIST, gpx);
756 #endif
757 }
758
759 static void gpxlist_view_onRowActivated(GtkTreeView *treeview,
760 GtkTreePath *path,
761 GtkTreeViewColumn *col,
762 gpointer userdata) {
763 appdata_t *appdata = (appdata_t*)userdata;
764 GtkTreeIter iter;
765 GtkTreeModel *model = gtk_tree_view_get_model(treeview);
766
767 #ifdef USE_MAEMO
768 /* check if a cache is already selected and ignore click if yes */
769 /* (was probably a double click) */
770 if(appdata->cur_gpx) return;
771 #endif
772
773 if (gtk_tree_model_get_iter(model, &iter, path)) {
774 gpx_t *gpx;
775 gtk_tree_model_get(model, &iter, GPXLIST_COL_DATA, &gpx, -1);
776
777 #ifdef USE_PANNABLE_AREA
778 /* get name of column the user clicked on */
779 const char *col_name = NULL;
780 if(col) col_name = gtk_tree_view_column_get_title(col);
781
782 if(col_name && !strcmp(col_name, "Del")) {
783 printf("clicked delete\n");
784
785 #if !defined(USE_MAEMO) || (MAEMO_VERSION_MAJOR < 5)
786 /* ask user what he wants */
787 GtkWidget *dialog = gtk_message_dialog_new(
788 GTK_WINDOW(appdata->window),
789 GTK_DIALOG_DESTROY_WITH_PARENT,
790 GTK_MESSAGE_QUESTION,
791 GTK_BUTTONS_CANCEL,
792 _("Do you want to close this entry only or do "
793 "you want to remove it completely from the list?"));
794
795 gtk_dialog_add_buttons(GTK_DIALOG(dialog),
796 _("Remove"), 1,
797 _("Close"), 2,
798 NULL);
799
800 gtk_window_set_title(GTK_WINDOW(dialog), _("Close or remove entry?"));
801 #else
802
803 GtkWidget *dialog =
804 gtk_dialog_new_with_buttons(_("Close or remove entry?"),
805 GTK_WINDOW(appdata->window),
806 GTK_DIALOG_DESTROY_WITH_PARENT,
807 GTK_STOCK_CANCEL, GTK_RESPONSE_REJECT,
808 _("Remove"), 1,
809 _("Close"), 2,
810 NULL);
811
812 GtkWidget *content_area =
813 gtk_dialog_get_content_area (GTK_DIALOG (dialog));
814
815 GtkWidget *hbox = gtk_hbox_new(FALSE, 0);
816
817 gtk_box_pack_start(GTK_BOX(hbox),
818 gtk_image_new_from_stock( GTK_STOCK_DIALOG_QUESTION,
819 GTK_ICON_SIZE_DIALOG),
820 FALSE, FALSE, 0);
821
822 GtkWidget *label = gtk_label_new(
823 _("Do you want to close this entry only or do "
824 "you want to remove it completely from the list?"));
825
826 gtk_label_set_line_wrap(GTK_LABEL(label), TRUE);
827 gtk_label_set_line_wrap_mode(GTK_LABEL(label), PANGO_WRAP_WORD);
828
829 gtk_box_pack_start_defaults(GTK_BOX(hbox), label);
830 gtk_container_add (GTK_CONTAINER (content_area), hbox);
831
832 gtk_widget_show_all (dialog);
833 #endif
834
835 if(gpx->closed)
836 gtk_dialog_set_response_sensitive(GTK_DIALOG(dialog), 2, FALSE);
837
838 /* set the active flag again if the user answered "no" */
839 switch(gtk_dialog_run(GTK_DIALOG(dialog))) {
840
841 case 1:
842 gpxlist_remove(appdata, GTK_LIST_STORE(model), &iter, gpx);
843 break;
844
845 case 2:
846 gpxlist_close(appdata, GTK_LIST_STORE(model), &iter, gpx);
847 break;
848
849 default:
850 break;
851 }
852
853 gtk_widget_destroy(dialog);
854
855 } else
856 #endif
857 {
858
859 /* this gpx file may be closed. Since the user definitely wants */
860 /* to use it, we just open it again */
861 if(gpx->closed) {
862 gpx_dialog_t *dialog =
863 gpx_busy_dialog_new(GTK_WIDGET(appdata->window));
864 gpx_t *new = NULL;
865
866 if(g_file_test(gpx->filename, G_FILE_TEST_IS_DIR))
867 new = gpx_parse_dir(dialog, gpx->filename);
868 else
869 new = gpx_parse(dialog, gpx->filename);
870
871 if(new) {
872 gpx_t **prev = &(appdata->gpx);
873 while(*prev && *prev != gpx)
874 prev = &(*prev)->next;
875
876 /* this entry _must_ be in the list */
877 g_assert(*prev);
878
879 /* replace gpx entry with the new "open" one */
880 (*prev) = new;
881 new->next = gpx->next;
882 gpx->next = NULL;
883
884 /* free old closed one */
885 gpx_free(gpx);
886
887 gpx = new;
888
889 /* finally update the visible list */
890 gpxlist_set(appdata->gpxstore, &iter, gpx);
891
892 /* and remove gconf entry */
893 gconf_remove_closed_name(appdata, gpx->filename);
894
895 #ifndef USE_PANNABLE_AREA
896 gtk_widget_set_sensitive(appdata->menu_close, TRUE);
897 #endif
898 } else {
899 printf("unable to reopen file %s\n", gpx->filename);
900 return;
901 }
902
903 gpx_busy_dialog_destroy(dialog);
904 }
905
906 gpxlist_goto_cachelist(appdata, gpx);
907 }
908 }
909 }
910
911 #ifndef USE_PANNABLE_AREA
912 static gboolean
913 view_selection_func(GtkTreeSelection *selection, GtkTreeModel *model,
914 GtkTreePath *path, gboolean path_currently_selected,
915 gpointer userdata) {
916 appdata_t *appdata = (appdata_t*)userdata;
917 GtkTreeIter iter;
918
919 if(gtk_tree_model_get_iter(model, &iter, path)) {
920 gpx_t *gpx;
921 gtk_tree_model_get(model, &iter, GPXLIST_COL_DATA, &gpx, -1);
922
923 gtk_widget_set_sensitive(appdata->menu_remove, !path_currently_selected);
924
925 if(!gpx->closed)
926 gtk_widget_set_sensitive(appdata->menu_close, !path_currently_selected);
927 }
928
929 return TRUE; /* allow selection state to change */
930 }
931 #endif
932
933 static GtkWidget *gpxlist_create_view_and_model(appdata_t *appdata,
934 gpx_t *sel_gpx) {
935 gpx_t *gpx = appdata->gpx;
936 GtkCellRenderer *renderer;
937
938 /* saved displayed items */
939 appdata->cur_items = appdata->gpxlist_items;
940
941 #ifndef USE_PANNABLE_AREA
942 /* nothing selected yet */
943 gtk_widget_set_sensitive(appdata->menu_remove, FALSE);
944 gtk_widget_set_sensitive(appdata->menu_close, FALSE);
945 #endif
946
947 appdata->gpxview = gtk_tree_view_new ();
948
949 GtkTreeSelection *selection =
950 gtk_tree_view_get_selection(GTK_TREE_VIEW(appdata->gpxview));
951 #ifndef USE_PANNABLE_AREA
952 gtk_tree_selection_set_select_function(selection, view_selection_func,
953 appdata, NULL);
954 #endif
955
956 /* --- "Icon" column --- */
957 renderer = gtk_cell_renderer_pixbuf_new();
958 gtk_tree_view_insert_column_with_attributes(GTK_TREE_VIEW(appdata->gpxview),
959 -1, "Icon", renderer,
960 "pixbuf", GPXLIST_COL_ICON,
961 #ifdef USE_PANNABLE_AREA
962 /* at least one entry needs to be sensitive. */
963 /* This is the delete icon if the PANNABLE_AREA is used */
964 "sensitive", GPXLIST_COL_OPEN,
965 #endif
966 NULL);
967
968 /* --- "FileName" column --- */
969 if(appdata->gpxlist_items & GPXLIST_ITEM_FILENAME) {
970 renderer = gtk_cell_renderer_text_new();
971 gtk_tree_view_insert_column_with_attributes(
972 GTK_TREE_VIEW(appdata->gpxview),
973 -1, "Filename", renderer,
974 "text", GPXLIST_COL_FILENAME,
975 "sensitive", GPXLIST_COL_OPEN,
976 NULL);
977 }
978
979 /* --- "Name" column --- */
980 renderer = gtk_cell_renderer_text_new();
981 g_object_set(renderer, "ellipsize", PANGO_ELLIPSIZE_END, NULL );
982
983 GtkTreeViewColumn *column = gtk_tree_view_column_new_with_attributes(
984 "Name", renderer,
985 "text", GPXLIST_COL_NAME,
986 "sensitive", GPXLIST_COL_OPEN,
987 NULL);
988 gtk_tree_view_column_set_expand(column, TRUE);
989 gtk_tree_view_insert_column(GTK_TREE_VIEW(appdata->gpxview), column, -1);
990
991 /* --- "Date" column --- */
992 if(appdata->gpxlist_items & GPXLIST_ITEM_DATE) {
993 renderer = gtk_cell_renderer_text_new();
994 g_object_set(renderer, "xalign", 1.0, NULL );
995 gtk_tree_view_insert_column_with_attributes(
996 GTK_TREE_VIEW(appdata->gpxview),
997 -1, "Date", renderer,
998 "text", GPXLIST_COL_DATE,
999 "sensitive", GPXLIST_COL_OPEN,
1000 NULL);
1001 }
1002
1003 /* --- "Number of caches" column --- */
1004 if(appdata->gpxlist_items & GPXLIST_ITEM_CNUM) {
1005 renderer = gtk_cell_renderer_text_new();
1006 g_object_set(renderer, "xalign", 1.0, NULL );
1007 gtk_tree_view_insert_column_with_attributes(
1008 GTK_TREE_VIEW(appdata->gpxview),
1009 -1, "#Caches", renderer,
1010 "text", GPXLIST_COL_CACHES,
1011 "sensitive", GPXLIST_COL_OPEN,
1012 NULL);
1013 }
1014
1015 #ifdef USE_PANNABLE_AREA
1016 /* --- "Delete" column --- */
1017 renderer = gtk_cell_renderer_pixbuf_new();
1018 gtk_tree_view_insert_column_with_attributes(GTK_TREE_VIEW(appdata->gpxview),
1019 -1, "Del", renderer,
1020 "pixbuf", GPXLIST_COL_DELETE,
1021 // "sensitive", GPXLIST_COL_OPEN,
1022 NULL);
1023 #endif
1024
1025 /* build and fill the store */
1026 appdata->gpxstore = gtk_list_store_new(GPXLIST_NUM_COLS, GDK_TYPE_PIXBUF,
1027 G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING,
1028 G_TYPE_STRING, G_TYPE_BOOLEAN,
1029 #ifdef USE_PANNABLE_AREA
1030 GDK_TYPE_PIXBUF,
1031 #endif
1032 G_TYPE_POINTER);
1033
1034 GtkTreePath *path = NULL;
1035 GtkTreeIter sel_iter;
1036 gboolean sel_iter_valid = FALSE;
1037 while(gpx) {
1038 GtkTreeIter iter;
1039 gtk_list_store_append(appdata->gpxstore, &iter);
1040 gpxlist_set(appdata->gpxstore, &iter, gpx);
1041
1042 if(gpx == sel_gpx) {
1043 sel_iter = iter;
1044 sel_iter_valid = TRUE;
1045 }
1046
1047 gpx = gpx->next;
1048 }
1049
1050 gtk_tree_view_set_model(GTK_TREE_VIEW(appdata->gpxview),
1051 GTK_TREE_MODEL(appdata->gpxstore));
1052
1053 g_object_unref(appdata->gpxstore);
1054
1055 if(sel_iter_valid) {
1056 gtk_tree_selection_select_iter(selection, &sel_iter);
1057 path = gtk_tree_model_get_path(GTK_TREE_MODEL(appdata->gpxstore),
1058 &sel_iter);
1059 gtk_tree_view_scroll_to_cell(GTK_TREE_VIEW(appdata->gpxview),
1060 path, NULL, TRUE, 0.0, 0.0);
1061 gtk_tree_path_free(path);
1062 }
1063
1064 /* make list react on clicks */
1065 g_signal_connect(appdata->gpxview, "row-activated",
1066 (GCallback)gpxlist_view_onRowActivated, appdata);
1067
1068 /* put this inside a scrolled view */
1069 #ifndef USE_PANNABLE_AREA
1070 GtkWidget *scrolled_window = gtk_scrolled_window_new(NULL, NULL);
1071 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolled_window),
1072 GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC);
1073 gtk_container_add(GTK_CONTAINER(scrolled_window), appdata->gpxview);
1074
1075 return scrolled_window;
1076 #else
1077 GtkWidget *pannable_area = hildon_pannable_area_new();
1078 gtk_container_add(GTK_CONTAINER(pannable_area), appdata->gpxview);
1079
1080 return pannable_area;
1081 #endif
1082 }
1083
1084 /* add last entry in gpx list to visual representation */
1085 static void gpxlist_add(appdata_t *appdata, gpx_t *new) {
1086 GtkTreeIter iter;
1087
1088 gtk_list_store_append(appdata->gpxstore, &iter);
1089 gpxlist_set(appdata->gpxstore, &iter, new);
1090
1091 /* and attach entry to end of list */
1092 gpx_t **gpx = &appdata->gpx;
1093 while(*gpx) gpx = &((*gpx)->next);
1094 *gpx = new;
1095 }
1096
1097 /******************** end of gpxlist ********************/
1098
1099 /******************** begin of menu *********************/
1100
1101 typedef struct {
1102 appdata_t *appdata;
1103 GtkWidget *dialog;
1104 } about_context_t;
1105
1106 #ifdef ENABLE_BROWSER_INTERFACE
1107 void on_paypal_button_clicked(GtkButton *button, about_context_t *context) {
1108 gtk_dialog_response(GTK_DIALOG(context->dialog), GTK_RESPONSE_ACCEPT);
1109 browser_url(context->appdata,
1110 "https://www.paypal.com/cgi-bin/webscr"
1111 "?cmd=_s-xclick&hosted_button_id=7400558");
1112 }
1113 #endif
1114
1115 static void
1116 cb_menu_about(GtkWidget *window, gpointer data) {
1117 about_context_t context;
1118
1119 context.appdata = (appdata_t *)data;
1120
1121 #ifdef ENABLE_LIBLOCATION
1122 char *uses = "uses liblocation";
1123 #elif defined(ENABLE_GPSBT)
1124 char *uses = "uses gpsbt and gpsd";
1125 #else
1126 char *uses = "uses gpsd";
1127 #endif
1128
1129 const gchar *authors[] = {
1130 "Till Harbaum <till@harbaum.org>",
1131 "John Stowers <john.stowers@gmail.com>",
1132 "GCVote: Guido Wegener <guido.wegener@gmx.de>",
1133 NULL };
1134
1135 context.dialog = g_object_new(GTK_TYPE_ABOUT_DIALOG,
1136 "name", "GPXView",
1137 "version", VERSION,
1138 "copyright", _("Copyright 2008-2009"),
1139 "authors", authors,
1140 "website", _("http://www.harbaum.org/till/maemo"),
1141 "comments", _(uses),
1142 NULL);
1143
1144 #ifdef ENABLE_BROWSER_INTERFACE
1145 /* add a way to donate to the project */
1146 GtkWidget *alignment = gtk_alignment_new(0.5, 0, 0, 0);
1147
1148 GtkWidget *hbox = gtk_hbox_new(FALSE, 8);
1149 gtk_box_pack_start(GTK_BOX(hbox),
1150 gtk_label_new(_("Do you like GPXView?")),
1151 FALSE, FALSE, 0);
1152
1153 GtkWidget *button = gtk_button_new();
1154 gtk_button_set_image(GTK_BUTTON(button),
1155 icon_get_widget(ICON_MISC, 5));
1156 gtk_button_set_relief(GTK_BUTTON(button), GTK_RELIEF_NONE);
1157 g_signal_connect(button, "clicked",
1158 G_CALLBACK(on_paypal_button_clicked), &context);
1159 gtk_box_pack_start(GTK_BOX(hbox), button, FALSE, FALSE, 0);
1160
1161 gtk_container_add(GTK_CONTAINER(alignment), hbox);
1162 gtk_box_pack_start_defaults(GTK_BOX((GTK_DIALOG(context.dialog))->vbox),
1163 alignment);
1164
1165 gtk_widget_show_all(alignment);
1166 #endif
1167
1168 gtk_dialog_run(GTK_DIALOG(context.dialog));
1169 gtk_widget_destroy(context.dialog);
1170 }
1171
1172 #if defined(USE_MAEMO) && defined(HILDON_HELP)
1173 static void
1174 cb_menu_help(GtkWidget *window, gpointer data) {
1175 appdata_t *appdata = (appdata_t*)data;
1176
1177 hildon_help_show(appdata->osso_context, HELP_ID_INTRO, 0);
1178 }
1179 #endif
1180
1181 static void
1182 cb_menu_add(GtkWidget *window, gpointer data) {
1183 appdata_t *appdata = (appdata_t *)data;
1184
1185 gpx_t *new = choose_file(appdata, FALSE);
1186 if(new) gpxlist_add(appdata, new);
1187 }
1188
1189 static void
1190 cb_menu_adddir(GtkWidget *window, gpointer data) {
1191 appdata_t *appdata = (appdata_t *)data;
1192
1193 gpx_t *new = choose_file(appdata, TRUE);
1194 if(new) gpxlist_add(appdata, new);
1195 }
1196
1197 #ifndef USE_PANNABLE_AREA
1198 static void
1199 cb_menu_close(GtkWidget *window, gpointer data) {
1200 appdata_t *appdata = (appdata_t *)data;
1201 GtkTreeSelection *selection;
1202 GtkTreeModel *model;
1203 GtkTreeIter iter;
1204
1205 printf("selected close\n");
1206
1207 /* the entry cannot be closed again */
1208 gtk_widget_set_sensitive(appdata->menu_close, FALSE);
1209
1210 selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(appdata->gpxview));
1211
1212 printf("gpxlist close\n");
1213
1214 if (gtk_tree_selection_get_selected(selection, &model, &iter)) {
1215 gpx_t *gpx = NULL;
1216 gtk_tree_model_get(model, &iter, GPXLIST_COL_DATA, &gpx, -1);
1217
1218 if(gpx) gpxlist_close(appdata, GTK_LIST_STORE(model), &iter, gpx);
1219 } else {
1220 g_print ("no row selected.\n");
1221 }
1222 }
1223
1224 static void
1225 cb_menu_remove(GtkWidget *window, gpointer data) {
1226 appdata_t *appdata = (appdata_t *)data;
1227
1228 /* disable menu item */
1229 gtk_widget_set_sensitive(appdata->menu_remove, FALSE);
1230 gtk_widget_set_sensitive(appdata->menu_close, FALSE);
1231
1232 GtkTreeModel *model;
1233 GtkTreeIter iter;
1234 GtkTreeSelection *selection =
1235 gtk_tree_view_get_selection(GTK_TREE_VIEW(appdata->gpxview));
1236
1237 printf("gpxlist remove\n");
1238
1239 if(gtk_tree_selection_get_selected(selection, &model, &iter)) {
1240 gpx_t *gpx = NULL;
1241 gtk_tree_model_get(model, &iter, GPXLIST_COL_DATA, &gpx, -1);
1242
1243 if(gpx) gpxlist_remove(appdata, GTK_LIST_STORE(model), &iter, gpx);
1244 } else {
1245 g_print ("no row selected.\n");
1246 }
1247 }
1248
1249 #endif // !USE_PANNABLE_AREA
1250
1251 static void search_result_free(gpx_t *result) {
1252 printf("freeing search results\n");
1253
1254 /* free found chain */
1255 cache_t *cache = result->cache;
1256 while(cache) {
1257 cache_t *next = cache->next;
1258 free(cache);
1259 cache = next;
1260 }
1261 free(result->name);
1262 free(result);
1263 }
1264
1265 #define MAX_HITS 50
1266
1267 static time_t localize_time(time_t in) {
1268 time_t ret;
1269 char *tz;
1270 struct tm *tm = localtime(&in);
1271
1272 tz = getenv("TZ");
1273 setenv("TZ", "", 1);
1274 tzset();
1275 ret = mktime(tm);
1276 if (tz)
1277 setenv("TZ", tz, 1);
1278 else
1279 unsetenv("TZ");
1280 tzset();
1281 return ret;
1282 }
1283
1284 static int days_ago(time_t in) {
1285 int day_in = localize_time(in) / (60*60*24);
1286 int day_now = localize_time(time(NULL)) / (60*60*24);
1287
1288 return day_now - day_in;
1289 }
1290
1291 gpx_t *search_do(appdata_t *appdata, gpx_t *gpx, char *phrase,
1292 int what, gboolean local) {
1293 /* walk through all caches */
1294
1295 int hits = 0;
1296 gpx_t *found = malloc(sizeof(gpx_t));
1297 memset(found, 0, sizeof(gpx_t));
1298 cache_t **cacheP = &(found->cache);
1299
1300 if(what & SEARCH_FINDS) {
1301 time_t loc_now = localize_time(time(NULL));
1302 printf("now: %ld days since 1/1/1970, days hour is %ld\n",
1303 loc_now/(60*60*24), loc_now%(60*60*24)/(60*60));
1304 }
1305
1306 while(gpx && hits < MAX_HITS) {
1307
1308 /* we need all notes ... */
1309 if(what & SEARCH_FINDS) {
1310 notes_load_all(appdata, gpx);
1311 gpx->notes_loaded = TRUE;
1312 }
1313
1314 cache_t *cache = gpx->cache;
1315
1316 while(cache && hits < MAX_HITS) {
1317 gboolean hit = FALSE;
1318
1319 if(what & SEARCH_FINDS) {
1320 if(cache->notes && cache->notes->found ) {
1321 int days = days_ago(cache->notes->ftime);
1322
1323 if(cache->id)
1324 printf("find of %s is %d days ago\n", cache->id, days);
1325
1326 if(days <= appdata->search_days)
1327 hit = 1;
1328 }
1329 } else if(cache->id && (what & SEARCH_ID) &&
1330 strcasestr(cache->id, phrase))
1331 hit = 1;
1332 else if(cache->name && (what & SEARCH_NAME) &&
1333 strcasestr(cache->name, phrase))
1334 hit = 1;
1335 else if(cache->short_description && (what & SEARCH_DESC) &&
1336 strcasestr(cache->short_description, phrase))
1337 hit = 1;
1338 else if(cache->long_description && (what & SEARCH_DESC) &&
1339 strcasestr(cache->long_description, phrase))
1340 hit = 1;
1341 else if(cache->owner && cache->owner->name && (what & SEARCH_OWNER) &&
1342 strcasestr(cache->owner->name, phrase))
1343 hit = 1;
1344
1345 if(hit) {
1346 /* chain a copy of this cache structure into the found list */
1347 *cacheP = malloc(sizeof(cache_t));
1348 memcpy(*cacheP, cache, sizeof(cache_t));
1349 (*cacheP)->next = NULL;
1350 cacheP = &((*cacheP)->next);
1351 hits++;
1352 }
1353 cache = cache->next;
1354 }
1355
1356 if(!local) gpx = gpx->next;
1357 else gpx = NULL; /* local search within one gpx only */
1358 }
1359
1360 found->name = strdup(_("Search results"));
1361
1362 return found;
1363 }
1364
1365 typedef struct {
1366 appdata_t *appdata;
1367 GtkWidget *entry, *spinner;
1368 GtkWidget *in_id, *in_name, *in_desc, *in_owner, *in_finds;
1369 } search_context_t;
1370
1371
1372 static GtkWidget *check_button_new_with_label(char *label) {
1373 #if !defined(USE_MAEMO) || (MAEMO_VERSION_MAJOR < 5)
1374 return gtk_check_button_new_with_label(label);
1375 #else
1376 GtkWidget *cbut =
1377 hildon_check_button_new(HILDON_SIZE_FINGER_HEIGHT | HILDON_SIZE_AUTO_WIDTH);
1378 gtk_button_set_label(GTK_BUTTON(cbut), label);
1379 return cbut;
1380 #endif
1381 }
1382
1383 static void check_button_set_active(GtkWidget *button, gboolean active) {
1384 #if !defined(USE_MAEMO) || (MAEMO_VERSION_MAJOR < 5)
1385 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(button), active);
1386 #else
1387 hildon_check_button_set_active(HILDON_CHECK_BUTTON(button), active);
1388 #endif
1389 }
1390
1391 static gboolean check_button_get_active(GtkWidget *button) {
1392 #if !defined(USE_MAEMO) || (MAEMO_VERSION_MAJOR < 5)
1393 return gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(button));
1394 #else
1395 return hildon_check_button_get_active(HILDON_CHECK_BUTTON(button));
1396 #endif
1397 }
1398
1399 static void callback_finds_toggled(GtkWidget *widget, gpointer data ) {
1400 search_context_t *context = (search_context_t*)data;
1401
1402 gboolean in_finds = check_button_get_active(context->in_finds);
1403
1404 gtk_widget_set_sensitive(context->entry, !in_finds);
1405 gtk_widget_set_sensitive(context->in_id, !in_finds);
1406 gtk_widget_set_sensitive(context->in_name, !in_finds);
1407 gtk_widget_set_sensitive(context->in_desc, !in_finds);
1408 gtk_widget_set_sensitive(context->in_owner, !in_finds);
1409 gtk_widget_set_sensitive(context->spinner, in_finds);
1410 }
1411
1412 static void
1413 cb_menu_search(GtkWidget *window, gpointer data) {
1414 appdata_t *appdata = (appdata_t *)data;
1415
1416 search_context_t context;
1417 memset(&context, 0, sizeof(search_context_t));
1418 context.appdata = appdata;
1419
1420 GtkWidget *dialog = gtk_dialog_new_with_buttons(_("Enter search phrase"),
1421 GTK_WINDOW(appdata->window), GTK_DIALOG_MODAL,
1422 GTK_STOCK_OK, GTK_RESPONSE_ACCEPT,
1423 GTK_STOCK_CANCEL, GTK_RESPONSE_REJECT,
1424 NULL);
1425
1426 gtk_box_pack_start_defaults(GTK_BOX(GTK_DIALOG(dialog)->vbox),
1427 gtk_label_new(_("Search in:")));
1428
1429 GtkWidget *table = gtk_table_new(2, 2, TRUE);
1430 gtk_table_set_col_spacing(GTK_TABLE(table), 0, 8);
1431
1432 context.in_id = check_button_new_with_label(_("Waypoint IDs"));
1433 check_button_set_active(context.in_id, appdata->search & SEARCH_ID);
1434 gtk_table_attach_defaults(GTK_TABLE(table), context.in_id, 0, 1, 0, 1);
1435
1436 context.in_name = check_button_new_with_label(_("Names"));
1437 check_button_set_active(context.in_name, appdata->search & SEARCH_NAME);
1438 gtk_table_attach_defaults(GTK_TABLE(table), context.in_name, 1, 2, 0, 1);
1439
1440 context.in_desc = check_button_new_with_label(_("Descriptions"));
1441 check_button_set_active(context.in_desc, appdata->search & SEARCH_DESC);
1442 gtk_table_attach_defaults(GTK_TABLE(table), context.in_desc, 0, 1, 1, 2);
1443
1444 context.in_owner = check_button_new_with_label(_("Owner"));
1445 check_button_set_active(context.in_owner, appdata->search & SEARCH_OWNER);
1446 gtk_table_attach_defaults(GTK_TABLE(table), context.in_owner, 1, 2, 1, 2);
1447
1448 gtk_box_pack_start_defaults(GTK_BOX(GTK_DIALOG(dialog)->vbox), table);
1449
1450 /* -------------------------------------------------------------- */
1451
1452 gtk_box_pack_start_defaults(GTK_BOX(GTK_DIALOG(dialog)->vbox),
1453 gtk_label_new(_("Search for:")));
1454 #if !defined(USE_MAEMO) || (MAEMO_VERSION_MAJOR < 5)
1455 context.entry = gtk_entry_new();
1456 #else
1457 context.entry = hildon_entry_new(HILDON_SIZE_AUTO);
1458 #endif
1459
1460 gtk_box_pack_start_defaults(GTK_BOX(GTK_DIALOG(dialog)->vbox),
1461 context.entry);
1462
1463 if(appdata->search_str)
1464 gtk_entry_set_text(GTK_ENTRY(context.entry), appdata->search_str);
1465
1466 /* -------------------------------------------------------------- */
1467
1468 gtk_box_pack_start_defaults(GTK_BOX(GTK_DIALOG(dialog)->vbox),
1469 gtk_hseparator_new());
1470
1471 GtkWidget *hbox = gtk_hbox_new(FALSE, 5);
1472
1473 context.in_finds = check_button_new_with_label(_("Search finds for"));
1474 check_button_set_active(context.in_finds, appdata->search & SEARCH_FINDS);
1475 gtk_box_pack_start_defaults(GTK_BOX(hbox), context.in_finds);
1476 g_signal_connect(G_OBJECT(context.in_finds), "toggled",
1477 G_CALLBACK(callback_finds_toggled), &context);
1478
1479 #ifndef USE_MAEMO
1480 GtkObject *adj = gtk_adjustment_new(appdata->search_days, 0, 99, 1, 10, 10);
1481 context.spinner = gtk_spin_button_new(GTK_ADJUSTMENT(adj), 1, 0);
1482 #else
1483 context.spinner = hildon_number_editor_new(0, 99);
1484 hildon_number_editor_set_value(HILDON_NUMBER_EDITOR(context.spinner),
1485 appdata->search_days);
1486 #endif
1487 gtk_box_pack_start_defaults(GTK_BOX(hbox), context.spinner);
1488
1489 gtk_box_pack_start_defaults(GTK_BOX(hbox), gtk_label_new(_("days")));
1490
1491 gtk_box_pack_start_defaults(GTK_BOX(GTK_DIALOG(dialog)->vbox), hbox);
1492
1493 /* -------------------------------------------------------------- */
1494
1495 gtk_widget_show_all(dialog);
1496 callback_finds_toggled(NULL, &context);
1497
1498 if(GTK_RESPONSE_ACCEPT == gtk_dialog_run(GTK_DIALOG(dialog))) {
1499 char *p = strdup(gtk_entry_get_text(GTK_ENTRY(context.entry)));
1500
1501 /* update saved search string */
1502 if(appdata->search_str) free(appdata->search_str);
1503 if(strlen(p) > 0)
1504 appdata->search_str = strdup(p);
1505
1506 #ifndef USE_MAEMO
1507 appdata->search_days = gtk_spin_button_get_value_as_int(
1508 GTK_SPIN_BUTTON(context.spinner));
1509 #else
1510 appdata->search_days = hildon_number_editor_get_value(
1511 HILDON_NUMBER_EDITOR(context.spinner));
1512 #endif
1513
1514 if(check_button_get_active(context.in_finds))
1515 appdata->search |= SEARCH_FINDS;
1516 else
1517 appdata->search &= ~SEARCH_FINDS;
1518
1519 if(check_button_get_active(context.in_id))
1520 appdata->search |= SEARCH_ID;
1521 else
1522 appdata->search &= ~SEARCH_ID;
1523
1524 if(check_button_get_active(context.in_name))
1525 appdata->search |= SEARCH_NAME;
1526 else
1527 appdata->search &= ~SEARCH_NAME;
1528
1529 if(check_button_get_active(context.in_desc))
1530 appdata->search |= SEARCH_DESC;
1531 else
1532 appdata->search &= ~SEARCH_DESC;
1533
1534 if(check_button_get_active(context.in_owner))
1535 appdata->search |= SEARCH_OWNER;
1536 else
1537 appdata->search &= ~SEARCH_OWNER;
1538
1539 gtk_widget_destroy(dialog);
1540
1541 /* don't search if we are asked to search for nothing */
1542 if(((appdata->search & (SEARCH_ID|SEARCH_NAME|SEARCH_DESC|SEARCH_OWNER)) &&
1543 strlen(p) > 0) || (appdata->search & SEARCH_FINDS)) {
1544
1545 printf("Search for %s (flags = %x)...\n", p, appdata->search);
1546
1547 #if !defined(USE_BREAD_CRUMB_TRAIL) && !defined(BCT)
1548 gpx_t *found =
1549 search_do(appdata, appdata->gpx, p, appdata->search, FALSE);
1550
1551 /* do search result dialog here ... */
1552 cachelist_dialog(appdata, found);
1553 #ifndef USE_STACKABLE_WINDOW
1554 search_result_free(found);
1555 #else
1556 appdata->search_results = found;
1557 #endif
1558 #else
1559 gpx_t *found = NULL;
1560
1561 if(appdata->cur_gpx)
1562 found = search_do(appdata, appdata->cur_gpx, p, appdata->search, TRUE);
1563 else
1564 found = search_do(appdata, appdata->gpx, p, appdata->search, FALSE);
1565
1566 gtk_container_remove(GTK_CONTAINER(appdata->vbox), appdata->cur_view);
1567 appdata->cur_view = cachelist_create(appdata, found, NULL);
1568 gtk_box_pack_start_defaults(GTK_BOX(appdata->vbox), appdata->cur_view);
1569 gtk_widget_show_all(appdata->vbox);
1570 crumb_add(appdata, found->name,
1571 appdata->cur_gpx?CRUMB_SEARCH_GPX:CRUMB_SEARCH_GLOBAL, found);
1572 #endif
1573 } else
1574 printf("No valid search: \"%s\" with flags %x!\n", p, appdata->search);
1575
1576 free(p);
1577 } else
1578 gtk_widget_destroy(dialog);
1579 }
1580
1581 static void on_window_destroy (GtkWidget *widget, gpointer data);
1582
1583 #ifndef USE_MAEMO
1584 static void
1585 cb_menu_quit(GtkWidget *window, gpointer data) {
1586 on_window_destroy(window, data);
1587 }
1588 #endif
1589
1590 #ifndef NO_COPY_N_PASTE
1591 static void
1592 cb_menu_cut(GtkWidget *widget, gpointer data) {
1593 appdata_t *appdata = (appdata_t*)data;
1594
1595 if(appdata->active_buffer) {
1596 if(GTK_WIDGET_TYPE(appdata->active_buffer) == GTK_TYPE_TEXT_BUFFER) {
1597 gtk_text_buffer_cut_clipboard(GTK_TEXT_BUFFER(appdata->active_buffer),
1598 appdata->clipboard, TRUE);
1599 } else
1600 printf("cut: ERROR, not a text buffer\n");
1601 } else
1602 printf("cut: ERROR, no active buffer\n");
1603 }
1604
1605 static void
1606 cb_menu_copy(GtkWidget *widget, gpointer data) {
1607 appdata_t *appdata = (appdata_t*)data;
1608
1609 if(appdata->active_buffer) {
1610 if(GTK_WIDGET_TYPE(appdata->active_buffer) == GTK_TYPE_TEXT_BUFFER) {
1611 gtk_text_buffer_copy_clipboard(GTK_TEXT_BUFFER(appdata->active_buffer),
1612 appdata->clipboard);
1613 } else if(GTK_WIDGET_TYPE(appdata->active_buffer) == gtk_html_get_type()) {
1614 printf("copy from html buffer\n");
1615 html_copy_to_clipboard(appdata);
1616 } else
1617 printf("copy: ERROR, not a text nor a html buffer\n");
1618 } else
1619 printf("copy: ERROR, no active buffer\n");
1620 }
1621
1622 static void
1623 cb_menu_paste(GtkWidget *widget, gpointer data) {
1624 appdata_t *appdata = (appdata_t*)data;
1625
1626 if(appdata->active_buffer) {
1627 if(GTK_WIDGET_TYPE(appdata->active_buffer) == GTK_TYPE_TEXT_BUFFER) {
1628 gtk_text_buffer_paste_clipboard(GTK_TEXT_BUFFER(appdata->active_buffer),
1629 appdata->clipboard, NULL, TRUE);
1630 } else
1631 printf("paste: ERROR, not a text buffer\n");
1632 } else
1633 printf("paste: ERROR, no active buffer\n");
1634 }
1635 #endif
1636
1637 static void
1638 cb_menu_export_log(GtkWidget *widget, gpointer data) {
1639 appdata_t *appdata = (appdata_t*)data;
1640 notes_log_export(appdata);
1641 }
1642
1643 #ifdef ENABLE_MAEMO_MAPPER
1644 static void
1645 cb_menu_export_mmpoi(GtkWidget *widget, gpointer data) {
1646 appdata_t *appdata = (appdata_t*)data;
1647 mmpoi_export(appdata);
1648 }
1649 #endif
1650
1651 static void
1652 cb_menu_export_garmin(GtkWidget *widget, gpointer data) {
1653 appdata_t *appdata = (appdata_t*)data;
1654 garmin_export(appdata);
1655 }
1656
1657 #ifdef ENABLE_OSM_GPS_MAP
1658 static void
1659 cb_menu_map(GtkWidget *window, gpointer data) {
1660 map((appdata_t *)data);
1661 }
1662 #endif
1663
1664 static void
1665 cb_menu_geomath(GtkWidget *window, gpointer data) {
1666 geomath_dialog((appdata_t *)data);
1667 }
1668
1669 static void
1670 cb_menu_geotext(GtkWidget *window, gpointer data) {
1671 geotext_dialog((appdata_t *)data);
1672 }
1673
1674 static void
1675 cb_menu_precpos(GtkWidget *window, gpointer data) {
1676 precise_position((appdata_t *)data);
1677 }
1678
1679 #ifdef USE_STACKABLE_WINDOW
1680 typedef struct {
1681 char *label, *desc;
1682 GtkSignalFunc activate_cb;
1683 } menu_entry_t;
1684
1685 typedef struct {
1686 const char *title;
1687 const menu_entry_t *menu;
1688 int len;
1689 } submenu_t;
1690
1691 #define COLUMNS 1
1692
1693 void on_submenu_entry_clicked(GtkButton *button, GtkWidget *menu) {
1694
1695 /* force closing of submenu dialog */
1696 gtk_dialog_response(GTK_DIALOG(menu), GTK_RESPONSE_NONE);
1697 gtk_widget_hide(menu);
1698
1699 /* let gtk clean up */
1700 while(gtk_events_pending())
1701 gtk_main_iteration();
1702 }
1703
1704 static GtkWidget *app_submenu_create(appdata_t *appdata,
1705 const submenu_t *submenu) {
1706
1707 /* create a oridinary dialog box */
1708 GtkWidget *dialog = gtk_dialog_new();
1709 gtk_window_set_title(GTK_WINDOW(dialog), _(submenu->title));
1710 gtk_window_set_modal(GTK_WINDOW(dialog), TRUE);
1711 gtk_window_set_transient_for(GTK_WINDOW(dialog),
1712 GTK_WINDOW(appdata->window));
1713 gtk_dialog_set_has_separator(GTK_DIALOG(dialog), FALSE);
1714
1715 GtkWidget *table = gtk_table_new(submenu->len/COLUMNS, COLUMNS, TRUE);
1716 int x = 0, y = 0;
1717
1718 const menu_entry_t *menu_entries = submenu->menu;
1719 while(menu_entries->label) {
1720 GtkWidget *button = NULL;
1721
1722 button = hildon_button_new_with_text(
1723 HILDON_SIZE_FINGER_HEIGHT | HILDON_SIZE_AUTO_WIDTH,
1724 HILDON_BUTTON_ARRANGEMENT_VERTICAL,
1725 _(menu_entries->label), _(menu_entries->desc));
1726
1727 /* try to center both texts */
1728 hildon_button_set_title_alignment(HILDON_BUTTON(button), 0.5, 0.5);
1729 hildon_button_set_value_alignment(HILDON_BUTTON(button), 0.5, 0.5);
1730
1731 g_signal_connect(button, "clicked",
1732 G_CALLBACK(on_submenu_entry_clicked), dialog);
1733
1734 g_signal_connect(button, "clicked",
1735 menu_entries->activate_cb, appdata);
1736
1737 gtk_table_attach_defaults(GTK_TABLE(table), button, x, x+1, y, y+1);
1738
1739 x++;
1740 if(x == COLUMNS) { x = 0; y++; }
1741
1742 menu_entries++;
1743 }
1744
1745 gtk_box_pack_start_defaults(GTK_BOX(GTK_DIALOG(dialog)->vbox), table);
1746
1747 return dialog;
1748 }
1749
1750 /* popup the dialog shaped submenu */
1751 static void submenu_popup(GtkWidget *menu) {
1752 gtk_widget_show_all(menu);
1753 gtk_dialog_run(GTK_DIALOG(menu));
1754 gtk_widget_hide(menu);
1755 }
1756
1757 static void submenu_cleanup(GtkWidget *menu) {
1758 gtk_widget_destroy(menu);
1759 }
1760
1761 static const menu_entry_t submenu_export_entries[] = {
1762 #ifdef ENABLE_MAEMO_MAPPER
1763 { "Export to Maemo Mapper" , "Save a Maemo Mapper POI file",
1764 G_CALLBACK(cb_menu_export_mmpoi) },
1765 #endif
1766 { "Export Field Notes", "Save a Garmin Field Notes file",
1767 G_CALLBACK(cb_menu_export_log) },
1768 { "Export Garmin GPX", "Save modified waypoints in GPX file",
1769 G_CALLBACK(cb_menu_export_garmin) },
1770 { NULL, NULL, NULL }
1771 };
1772
1773 static const submenu_t submenu_export = {
1774 "Export", submenu_export_entries,
1775 sizeof(submenu_export_entries)/sizeof(menu_entry_t)-1
1776 };
1777
1778 /* the export submenu */
1779 void on_export_clicked(GtkButton *button, appdata_t *appdata) {
1780 if(!appdata->export_menu)
1781 appdata->export_menu = app_submenu_create(appdata, &submenu_export);
1782
1783 submenu_popup(appdata->export_menu);
1784 }
1785
1786 static const menu_entry_t submenu_tools_entries[] = {
1787 { "Geomath", "Geocoordinate calculation",
1788 G_CALLBACK(cb_menu_geomath) },
1789 { "Geotext", "Text analysis",
1790 G_CALLBACK(cb_menu_geotext) },
1791 { "Precise Position", "Calculate a precise GPS position",
1792 G_CALLBACK(cb_menu_precpos) },
1793 { NULL, NULL, NULL }
1794 };
1795
1796 static const submenu_t submenu_tools = {
1797 "Tools", submenu_tools_entries,
1798 sizeof(submenu_tools_entries)/sizeof(menu_entry_t)-1
1799 };
1800
1801 /* the tools submenu */
1802 void on_tools_clicked(GtkButton *button, appdata_t *appdata) {
1803 if(!appdata->tools_menu)
1804 appdata->tools_menu = app_submenu_create(appdata, &submenu_tools);
1805
1806 submenu_popup(appdata->tools_menu);
1807 }
1808
1809 HildonAppMenu *menu_create(appdata_t *appdata, int mode) {
1810 GtkWidget *button;
1811 HildonAppMenu *menu = HILDON_APP_MENU(hildon_app_menu_new());
1812
1813 /* ------- */
1814 button = gtk_button_new_with_label(_("About"));
1815 g_signal_connect_after(button, "clicked",
1816 G_CALLBACK(cb_menu_about), appdata);
1817 hildon_app_menu_append(menu, GTK_BUTTON(button));
1818
1819 button = gtk_button_new_with_label(_("Settings"));
1820 g_signal_connect_after(button, "clicked", G_CALLBACK(cb_menu_settings),
1821 appdata);
1822 hildon_app_menu_append(menu, GTK_BUTTON(button));
1823
1824 if(mode == MENU_GPXLIST) {
1825 button = gtk_button_new_with_label(_("Import file"));
1826 g_signal_connect_after(button, "clicked",
1827 G_CALLBACK(cb_menu_add), appdata);
1828 hildon_app_menu_append(menu, GTK_BUTTON(button));
1829
1830 button = gtk_button_new_with_label(_("Import directory"));
1831 g_signal_connect_after(button, "clicked",
1832 G_CALLBACK(cb_menu_adddir), appdata);
1833 hildon_app_menu_append(menu, GTK_BUTTON(button));
1834
1835 button = gtk_button_new_with_label(_("Export"));
1836 g_signal_connect_after(button, "clicked",
1837 G_CALLBACK(on_export_clicked), appdata);
1838 hildon_app_menu_append(menu, GTK_BUTTON(button));
1839
1840 button = gtk_button_new_with_label(_("Search"));
1841 g_signal_connect_after(button, "clicked",
1842 G_CALLBACK(cb_menu_search), appdata);
1843 hildon_app_menu_append(menu, GTK_BUTTON(button));
1844 }
1845
1846 button = gtk_button_new_with_label(_("Tools"));
1847 g_signal_connect_after(button, "clicked",
1848 G_CALLBACK(on_tools_clicked), appdata);
1849 hildon_app_menu_append(menu, GTK_BUTTON(button));
1850
1851 #ifdef ENABLE_OSM_GPS_MAP
1852 button = gtk_button_new_with_label(_("Map"));
1853 g_signal_connect_after(button, "clicked",
1854 G_CALLBACK(cb_menu_map), appdata);
1855 hildon_app_menu_append(menu, GTK_BUTTON(button));
1856 #endif
1857
1858 #ifdef HILDON_HELP
1859 button = gtk_button_new_with_label(_("Help"));
1860 g_signal_connect_after(button, "clicked",
1861 G_CALLBACK(cb_menu_help), appdata);
1862 hildon_app_menu_append(menu, GTK_BUTTON(button));
1863 #endif
1864
1865 gtk_widget_show_all(GTK_WIDGET(menu));
1866
1867 return menu;
1868 }
1869 #else
1870
1871 void menu_create(appdata_t *appdata) {
1872 GtkWidget *menu, *item;
1873 menu = gtk_menu_new();
1874
1875 #if defined(USE_BREAD_CRUMB_TRAIL) || defined(BCT)
1876 appdata->menu_import =
1877 #endif
1878 item = gtk_menu_item_new_with_label(_("Import"));
1879 gtk_menu_append(GTK_MENU_SHELL(menu), item);
1880 GtkWidget *submenu = gtk_menu_new();
1881 gtk_menu_item_set_submenu(GTK_MENU_ITEM(item), submenu);
1882
1883 item = gtk_menu_item_new_with_label( _("File") );
1884 gtk_menu_append(GTK_MENU_SHELL(submenu), item);
1885 g_signal_connect(item, "activate", GTK_SIGNAL_FUNC(cb_menu_add), appdata);
1886
1887 item = gtk_menu_item_new_with_label( _("Directory") );
1888 gtk_menu_append(GTK_MENU_SHELL(submenu), item);
1889 g_signal_connect(item, "activate", GTK_SIGNAL_FUNC(cb_menu_adddir), appdata);
1890
1891 #ifndef USE_PANNABLE_AREA
1892 gtk_menu_append(GTK_MENU_SHELL(submenu), gtk_separator_menu_item_new());
1893
1894 appdata->menu_close =
1895 item = gtk_menu_item_new_with_label( _("Close") );
1896 gtk_menu_append(GTK_MENU_SHELL(submenu), item);
1897 g_signal_connect(item, "activate", GTK_SIGNAL_FUNC(cb_menu_close), appdata);
1898
1899 appdata->menu_remove =
1900 item = gtk_menu_item_new_with_label( _("Remove") );
1901 gtk_menu_append(GTK_MENU_SHELL(submenu), item);
1902 g_signal_connect(item, "activate", GTK_SIGNAL_FUNC(cb_menu_remove), appdata);
1903 #endif
1904
1905 #if defined(USE_BREAD_CRUMB_TRAIL) || defined(BCT)
1906 appdata->menu_export =
1907 #endif
1908 item = gtk_menu_item_new_with_label(_("Export"));
1909 gtk_menu_append(GTK_MENU_SHELL(menu), item);
1910 submenu = gtk_menu_new();
1911 gtk_menu_item_set_submenu(GTK_MENU_ITEM(item), submenu);
1912
1913 #ifdef ENABLE_MAEMO_MAPPER
1914 item = gtk_menu_item_new_with_label( _("Maemo Mapper POI") );
1915 gtk_menu_append(GTK_MENU_SHELL(submenu), item);
1916 g_signal_connect(item, "activate",
1917 GTK_SIGNAL_FUNC(cb_menu_export_mmpoi), appdata);
1918 #endif
1919
1920 item = gtk_menu_item_new_with_label( _("Garmin Field Notes") );
1921 gtk_menu_append(GTK_MENU_SHELL(submenu), item);
1922 g_signal_connect(item, "activate",
1923 GTK_SIGNAL_FUNC(cb_menu_export_log), appdata);
1924
1925 item = gtk_menu_item_new_with_label( _("Garmin GPX") );
1926 gtk_menu_append(GTK_MENU_SHELL(submenu), item);
1927 g_signal_connect(item, "activate",
1928 GTK_SIGNAL_FUNC(cb_menu_export_garmin), appdata);
1929
1930 #if defined(USE_BREAD_CRUMB_TRAIL) || defined(BCT)
1931 appdata->menu_search =
1932 #endif
1933 item = gtk_menu_item_new_with_label( _("Search") );
1934 gtk_menu_append(GTK_MENU_SHELL(menu), item);
1935 g_signal_connect(item, "activate", GTK_SIGNAL_FUNC(cb_menu_search), appdata);
1936
1937 gtk_menu_append(GTK_MENU_SHELL(menu), gtk_separator_menu_item_new());
1938
1939 /* ----------- copy'n paste submenu ----------------- */
1940 #ifndef NO_COPY_N_PASTE
1941 item = gtk_menu_item_new_with_label(_("Edit"));
1942 gtk_menu_append(GTK_MENU_SHELL(menu), item);
1943 submenu = gtk_menu_new();
1944 gtk_menu_item_set_submenu(GTK_MENU_ITEM(item), submenu);
1945
1946 appdata->menu_cut = item = gtk_menu_item_new_with_label( _("Cut") );
1947 gtk_widget_set_sensitive(item, FALSE);
1948 gtk_menu_append(GTK_MENU_SHELL(submenu), item);
1949 g_signal_connect(item, "activate", GTK_SIGNAL_FUNC(cb_menu_cut), appdata);
1950 appdata->menu_copy = item = gtk_menu_item_new_with_label( _("Copy") );
1951 gtk_widget_set_sensitive(item, FALSE);
1952 gtk_menu_append(GTK_MENU_SHELL(submenu), item);
1953 g_signal_connect(item, "activate", GTK_SIGNAL_FUNC(cb_menu_copy), appdata);
1954 appdata->menu_paste = item = gtk_menu_item_new_with_label( _("Paste") );
1955 gtk_widget_set_sensitive(item, FALSE);
1956 gtk_menu_append(GTK_MENU_SHELL(submenu), item);
1957 g_signal_connect(item, "activate", GTK_SIGNAL_FUNC(cb_menu_paste), appdata);
1958 #endif
1959
1960 item = gtk_menu_item_new_with_label( _("Settings") );
1961 gtk_menu_append(GTK_MENU_SHELL(menu), item);
1962 g_signal_connect(item, "activate", GTK_SIGNAL_FUNC(cb_menu_settings),
1963 appdata);
1964
1965 gtk_menu_append(GTK_MENU_SHELL(menu), gtk_separator_menu_item_new());
1966
1967 #ifdef ENABLE_OSM_GPS_MAP
1968 item = gtk_menu_item_new_with_label( _("Map") );
1969 gtk_menu_append(GTK_MENU_SHELL(menu), item);
1970 g_signal_connect(item, "activate",
1971 GTK_SIGNAL_FUNC(cb_menu_map), appdata);
1972 #endif
1973
1974 item = gtk_menu_item_new_with_label(_("Tools"));
1975 gtk_menu_append(GTK_MENU_SHELL(menu), item);
1976 submenu = gtk_menu_new();
1977 gtk_menu_item_set_submenu(GTK_MENU_ITEM(item), submenu);
1978
1979 item = gtk_menu_item_new_with_label( _("Geomath") );
1980 gtk_menu_append(GTK_MENU_SHELL(submenu), item);
1981 g_signal_connect(item, "activate",
1982 GTK_SIGNAL_FUNC(cb_menu_geomath), appdata);
1983
1984 item = gtk_menu_item_new_with_label( _("Geotext") );
1985 gtk_menu_append(GTK_MENU_SHELL(submenu), item);
1986 g_signal_connect(item, "activate",
1987 GTK_SIGNAL_FUNC(cb_menu_geotext), appdata);
1988
1989 item = gtk_menu_item_new_with_label( _("Precise Position") );
1990 gtk_menu_append(GTK_MENU_SHELL(submenu), item);
1991 g_signal_connect(item, "activate",
1992 GTK_SIGNAL_FUNC(cb_menu_precpos), appdata);
1993
1994 gtk_menu_append(GTK_MENU_SHELL(menu), gtk_separator_menu_item_new());
1995
1996 #if defined(USE_MAEMO) && defined(HILDON_HELP)
1997 item = gtk_menu_item_new_with_label( _("Help") );
1998 gtk_menu_append(GTK_MENU_SHELL(menu), item);
1999 g_signal_connect(item, "activate", GTK_SIGNAL_FUNC(cb_menu_help), appdata);
2000 #endif
2001
2002 item = gtk_menu_item_new_with_label( _("About") );
2003 gtk_menu_append(GTK_MENU_SHELL(menu), item);
2004 g_signal_connect(item, "activate", GTK_SIGNAL_FUNC(cb_menu_about), appdata);
2005
2006 #ifndef USE_MAEMO
2007 item = gtk_menu_item_new_with_label( _("Quit") );
2008 gtk_menu_append(GTK_MENU_SHELL(menu), item);
2009 g_signal_connect(item, "activate", GTK_SIGNAL_FUNC(cb_menu_quit), appdata);
2010 #endif
2011
2012 #ifdef USE_MAEMO
2013 hildon_window_set_menu(appdata->window, GTK_MENU(menu));
2014 #else
2015 /* attach ordinary gtk menu */
2016 GtkWidget *menu_bar = gtk_menu_bar_new();
2017
2018 GtkWidget *root_menu = gtk_menu_item_new_with_label (_("Menu"));
2019 gtk_widget_show(root_menu);
2020
2021 gtk_menu_bar_append(menu_bar, root_menu);
2022 gtk_menu_item_set_submenu(GTK_MENU_ITEM (root_menu), menu);
2023
2024 gtk_widget_show(menu_bar);
2025 gtk_box_pack_start(GTK_BOX(appdata->vbox), menu_bar, 0, 0, 0);
2026 #endif
2027 }
2028 #endif
2029
2030 /********************* end of menu **********************/
2031
2032 void cleanup(appdata_t *appdata) {
2033 gpx_free_all(appdata->gpx);
2034 if(appdata->path) free(appdata->path);
2035 if(appdata->image_path) free(appdata->image_path);
2036 if(appdata->search_str) free(appdata->search_str);
2037
2038 #ifdef USE_STACKABLE_WINDOW
2039 if(appdata->export_menu) submenu_cleanup(appdata->export_menu);
2040 if(appdata->tools_menu) submenu_cleanup(appdata->tools_menu);
2041 #endif
2042
2043 gnome_vfs_shutdown();
2044 icons_free();
2045 gps_release(appdata);
2046
2047 #ifdef USE_MAEMO
2048 if(appdata->search_results) {
2049 printf("freeing pending search\n");
2050 search_result_free(appdata->search_results);
2051 }
2052
2053 if(appdata->osso_context)
2054 osso_deinitialize(appdata->osso_context);
2055
2056 appdata->program = NULL;
2057 #endif
2058
2059 /* free chain of locations */
2060 location_t *loc = appdata->location;
2061 while(loc) {
2062 location_t *next = loc->next;
2063 if(loc->name) free(loc->name);
2064 free(loc);
2065 loc = next;
2066 }
2067
2068 puts("everything is gone");
2069 }
2070
2071 static void on_window_destroy (GtkWidget *widget, gpointer data) {
2072 appdata_t *appdata = (appdata_t*)data;
2073
2074 gconf_save_state(appdata);
2075 gtk_main_quit();
2076 appdata->window = NULL;
2077 }
2078
2079 gboolean on_window_key_press(GtkWidget *widget,
2080 GdkEventKey *event, appdata_t *appdata) {
2081 int handled = FALSE;
2082
2083 // printf("key event %d\n", event->keyval);
2084
2085 switch(event->keyval) {
2086 #ifdef USE_MAEMO
2087
2088 #ifdef HILDON_HARDKEY_INCREASE
2089 case HILDON_HARDKEY_INCREASE:
2090 html_zoom(appdata, TRUE);
2091 handled = TRUE;
2092 break;
2093 #endif
2094
2095 #ifdef HILDON_HARDKEY_DECREASE
2096 case HILDON_HARDKEY_DECREASE:
2097 html_zoom(appdata, FALSE);
2098 handled = TRUE;
2099 break;
2100 #endif
2101
2102 #ifdef HILDON_HARDKEY_FULLSCREEN
2103 case HILDON_HARDKEY_FULLSCREEN:
2104 {
2105 appdata->fullscreen = !appdata->fullscreen;
2106
2107 if(appdata->fullscreen)
2108 gtk_window_fullscreen(GTK_WINDOW(appdata->window));
2109 else
2110 gtk_window_unfullscreen(GTK_WINDOW(appdata->window));
2111
2112 handled = TRUE;
2113 }
2114 break;
2115 #endif
2116
2117 #else
2118 case '+':
2119 printf("zoom+\n");
2120 html_zoom(appdata, TRUE);
2121 handled = TRUE;
2122 break;
2123 case '-':
2124 printf("zoom-\n");
2125 html_zoom(appdata, FALSE);
2126 handled = TRUE;
2127 break;
2128 #endif
2129 }
2130
2131 return handled;
2132 }
2133
2134 #if defined(USE_BREAD_CRUMB_TRAIL) || defined(BCT)
2135 typedef struct {
2136 int level;
2137 appdata_t *appdata;
2138 gpointer data;
2139 } crumb_t;
2140
2141 static void
2142 crumb_back(gpointer data) {
2143 crumb_t *crumb = (crumb_t*)data;
2144 printf("crumb_back called with %d\n", crumb->level);
2145
2146 /* don't do anything if main window has already been destroyed */
2147 if(!crumb->appdata->window) {
2148 printf("Main window gone ...\n");
2149 return;
2150 }
2151
2152 /* whatever is being displayed: we don't need it anymore */
2153 gtk_container_remove(GTK_CONTAINER(crumb->appdata->vbox),
2154 crumb->appdata->cur_view);
2155
2156 /* back from cache to cachelist */
2157 if(crumb->level == CRUMB_CACHE) {
2158 gpx_t *gpx = crumb->appdata->search_results;
2159
2160 if(!gpx) {
2161 gtk_widget_set_sensitive(crumb->appdata->menu_search, TRUE);
2162 gtk_widget_set_sensitive(crumb->appdata->menu_export, TRUE);
2163 printf("no search data found, return to gpx\n");
2164 gpx = crumb->appdata->cur_gpx;
2165 } else
2166 printf("returning to search result\n");
2167
2168 g_assert(gpx != NULL);
2169
2170 crumb->appdata->cur_view = cachelist_create(crumb->appdata, gpx,
2171 crumb->appdata->cur_cache);
2172
2173 /* returning from cache view: invalidate cache reference */
2174 crumb->appdata->cur_cache = NULL;
2175
2176 gtk_box_pack_start_defaults(GTK_BOX(crumb->appdata->vbox),
2177 crumb->appdata->cur_view);
2178 }
2179
2180 if(crumb->level == CRUMB_SEARCH_GPX) {
2181 printf("returning from a local search!\n");
2182
2183 g_assert((gpx_t*)crumb->data == crumb->appdata->search_results);
2184
2185 search_result_free((gpx_t*)crumb->data);
2186 crumb->appdata->search_results = NULL;
2187
2188 gtk_widget_set_sensitive(crumb->appdata->menu_search, TRUE);
2189
2190 crumb->appdata->cur_view = cachelist_create(crumb->appdata,
2191 crumb->appdata->cur_gpx, NULL);
2192 gtk_box_pack_start_defaults(GTK_BOX(crumb->appdata->vbox),
2193 crumb->appdata->cur_view);
2194 }
2195
2196 /* back from cachelist to gpxlist */
2197 if((crumb->level == CRUMB_CACHELIST) ||
2198 (crumb->level == CRUMB_SEARCH_GLOBAL)) {
2199
2200 crumb->appdata->cur_view = gpxlist_create_view_and_model(
2201 crumb->appdata, crumb->appdata->cur_gpx);
2202
2203 /* returning from cachelist/global search view: */
2204 /* invalidate gpx reference */
2205 crumb->appdata->cur_gpx = NULL;
2206
2207 gtk_box_pack_start_defaults(GTK_BOX(crumb->appdata->vbox),
2208 crumb->appdata->cur_view);
2209
2210 if((crumb->level == CRUMB_SEARCH_GLOBAL) ||
2211 (crumb->level == CRUMB_SEARCH_GPX)) {
2212 g_assert((gpx_t*)crumb->data == crumb->appdata->search_results);
2213
2214 search_result_free((gpx_t*)crumb->data);
2215 crumb->appdata->search_results = NULL;
2216 }
2217
2218 /* enable gpxlist related menu entries */
2219 gtk_widget_set_sensitive(crumb->appdata->menu_import, TRUE);
2220 gtk_widget_set_sensitive(crumb->appdata->menu_search, TRUE);
2221 gtk_widget_set_sensitive(crumb->appdata->menu_export, TRUE);
2222 }
2223
2224 gtk_widget_show_all(crumb->appdata->vbox);
2225 g_free(data);
2226
2227 #ifdef ENABLE_OSM_GPS_MAP
2228 map_update(crumb->appdata);
2229 #endif
2230 }
2231
2232 static void crumb_add(appdata_t *appdata, char *name, int level,
2233 gpointer user_data) {
2234 crumb_t *crumb = malloc(sizeof(crumb_t));
2235 crumb->level = level;
2236 crumb->appdata = appdata;
2237 crumb->data = user_data;
2238
2239 printf("crumb_add with level %d\n", level);
2240
2241 /* save that we are working on search results */
2242 if((level == CRUMB_SEARCH_GLOBAL) ||
2243 (level == CRUMB_SEARCH_GPX)) {
2244 appdata->search_results = (gpx_t*)user_data;
2245
2246 /* searches cannot be nested */
2247 gtk_widget_set_sensitive(appdata->menu_search, FALSE);
2248 }
2249
2250 /* save "path" pointers in appdata */
2251 if(crumb->level == CRUMB_CACHELIST)
2252 appdata->cur_gpx = (gpx_t*)user_data;
2253
2254 if(crumb->level == CRUMB_CACHE) {
2255 appdata->cur_cache = (cache_t*)user_data;
2256 /* the cache view cannot be searched */
2257 gtk_widget_set_sensitive(appdata->menu_search, FALSE);
2258 gtk_widget_set_sensitive(appdata->menu_export, FALSE);
2259 }
2260
2261 if(level != CRUMB_GPXLIST) {
2262 /* disable gpxlist related menu entries */
2263 gtk_widget_set_sensitive(appdata->menu_import, FALSE);
2264 #ifndef USE_PANNABLE_AREA
2265 gtk_widget_set_sensitive(appdata->menu_remove, FALSE);
2266 gtk_widget_set_sensitive(appdata->menu_close, FALSE);
2267 #endif
2268 }
2269
2270 #ifdef USE_BREAD_CRUMB_TRAIL
2271 hildon_bread_crumb_trail_push_text(HILDON_BREAD_CRUMB_TRAIL(appdata->bct),
2272 name, crumb, (GDestroyNotify)crumb_back);
2273 #else
2274 bct_push_text(appdata->bct, name, crumb, (GDestroyNotify)crumb_back);
2275 #endif
2276
2277 #ifdef ENABLE_OSM_GPS_MAP
2278 map_update(appdata);
2279 #endif
2280 }
2281 #endif // USE_BREAD_CRUMB_TRAIL
2282
2283 void main_after_settings_redraw(appdata_t *appdata, int flags) {
2284 printf("main after settings redraw\n");
2285
2286 if(!appdata->cur_view) {
2287 printf("no active view\n");
2288 return;
2289 }
2290
2291 /* a cache screen cannot be changed from the settings and thus doesn't */
2292 /* need to be redrawn */
2293 if(appdata->cur_cache) {
2294 printf("No redraw in cache view required\n");
2295 return;
2296 }
2297
2298 int redraw = 0; // nothing to redraw
2299
2300 if(appdata->search_results) {
2301 if((appdata->cur_items != appdata->cachelist_items) || flags)
2302 redraw = 1;
2303 } else {
2304 if(!appdata->cur_gpx) {
2305 if(appdata->cur_items != appdata->gpxlist_items)
2306 redraw = 2; // redraw gpxlist
2307 } else {
2308 if((appdata->cur_items != appdata->cachelist_items) || flags)
2309 redraw = 3; // redraw cachelist
2310 }
2311 }
2312
2313 if(redraw) {
2314 GtkWidget *container = appdata->vbox;
2315
2316 #ifdef USE_STACKABLE_WINDOW
2317 HildonWindowStack *stack = hildon_window_stack_get_default();
2318 container = hildon_window_stack_peek(stack);
2319 #endif
2320
2321 gtk_container_remove(GTK_CONTAINER(container), appdata->cur_view);
2322 switch(redraw) {
2323 case 1:
2324 appdata->cur_view = cachelist_create(appdata,
2325 appdata->search_results, NULL);
2326 break;
2327 case 2:
2328 appdata->cur_view = gpxlist_create_view_and_model(appdata, NULL);
2329 break;
2330 case 3:
2331 appdata->cur_view = cachelist_create(appdata,
2332 appdata->cur_gpx, NULL);
2333 break;
2334 }
2335
2336 #ifdef USE_STACKABLE_WINDOW
2337 if(container != appdata->vbox)
2338 gtk_container_add(GTK_CONTAINER(container), appdata->cur_view);
2339 else
2340 #endif
2341 gtk_box_pack_start_defaults(GTK_BOX(container), appdata->cur_view);
2342
2343 gtk_widget_show_all(container);
2344 }
2345 }
2346
2347 int main(int argc, char *argv[]) {
2348 appdata_t appdata;
2349
2350 /* init appdata */
2351 memset(&appdata, 0, sizeof(appdata));
2352
2353 printf("Using locale for %s in %s\n", PACKAGE, LOCALEDIR);
2354
2355 setlocale(LC_ALL, "");
2356 bindtextdomain(PACKAGE, LOCALEDIR);
2357 bind_textdomain_codeset(PACKAGE, "UTF-8");
2358 textdomain(PACKAGE);
2359
2360 /* prepare thread system */
2361 g_thread_init(NULL);
2362
2363 gtk_init (&argc, &argv);
2364
2365 curl_global_init(CURL_GLOBAL_ALL);
2366
2367 #ifdef USE_MAEMO
2368 printf("Installing osso context for \"org.harbaum." APP "\"\n");
2369 appdata.osso_context = osso_initialize("org.harbaum."APP,
2370 VERSION, TRUE, NULL);
2371 if(appdata.osso_context == NULL) {
2372 fprintf(stderr, "error initiating osso context\n");
2373 }
2374
2375 #ifdef ENABLE_MAEMO_MAPPER
2376 dbus_register(&appdata);
2377 #endif
2378 #endif
2379
2380 icons_init();
2381
2382 if(!gnome_vfs_init()) {
2383 g_error("Gnome VFS init failed\n");
2384 }
2385
2386 #ifdef USE_MAEMO
2387 /* Create the hildon program and setup the title */
2388 appdata.program = HILDON_PROGRAM(hildon_program_get_instance());
2389 g_set_application_name("GPXView");
2390
2391 /* Create HildonWindow and set it to HildonProgram */
2392 #ifdef USE_STACKABLE_WINDOW
2393 appdata.window = HILDON_WINDOW(hildon_stackable_window_new());
2394 #else
2395 appdata.window = HILDON_WINDOW(hildon_window_new());
2396 #endif
2397 hildon_program_add_window(appdata.program, appdata.window);
2398 #else
2399 /* Create a Window. */
2400 appdata.window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
2401 /* Set a decent default size for the window. */
2402 gtk_window_set_default_size(GTK_WINDOW(appdata.window), 640, 480);
2403 #endif
2404
2405 #if MAEMO_VERSION_MAJOR == 5
2406 gtk_window_set_title(GTK_WINDOW(appdata.window), "GPXView");
2407 #endif
2408
2409 g_signal_connect(G_OBJECT(appdata.window), "destroy",
2410 G_CALLBACK(on_window_destroy), &appdata);
2411
2412 g_signal_connect(G_OBJECT(appdata.window), "key_press_event",
2413 G_CALLBACK(on_window_key_press), &appdata);
2414
2415 /* prepare clipboard */
2416 appdata.clipboard = gtk_clipboard_get(GDK_SELECTION_CLIPBOARD);
2417 gtk_clipboard_set_can_store(appdata.clipboard, NULL, 0);
2418
2419 appdata.vbox = gtk_vbox_new(FALSE, 2);
2420 gtk_container_add(GTK_CONTAINER(appdata.window), appdata.vbox);
2421 #ifndef USE_STACKABLE_WINDOW
2422 menu_create(&appdata);
2423 #else
2424 hildon_window_set_app_menu(HILDON_WINDOW(appdata.window),
2425 menu_create(&appdata, MENU_GPXLIST));
2426 #endif
2427
2428 #ifdef USE_BREAD_CRUMB_TRAIL
2429 appdata.bct = hildon_bread_crumb_trail_new();
2430
2431 gtk_box_pack_start(GTK_BOX(appdata.vbox), appdata.bct, FALSE,FALSE,0);
2432
2433 hildon_bread_crumb_trail_clear(HILDON_BREAD_CRUMB_TRAIL(appdata.bct));
2434 #else
2435 #ifdef BCT
2436 /* on non-hildon machines we use some custom made breadcrumbtrail */
2437 /* replacement */
2438 appdata.bct = bct_new();
2439 gtk_box_pack_start(GTK_BOX(appdata.vbox), appdata.bct, FALSE,FALSE,0);
2440 #endif
2441 #endif
2442
2443 #if defined(USE_BREAD_CRUMB_TRAIL) || defined(BCT)
2444 crumb_add(&appdata, "GPX", CRUMB_GPXLIST, NULL);
2445 #endif
2446
2447 /* wait for main gui to appear */
2448 gtk_widget_show_all(GTK_WIDGET(appdata.window));
2449 while(gtk_events_pending())
2450 gtk_main_iteration();
2451
2452 appdata.gconf_client = gconf_client_get_default();
2453 gconf_load_state(&appdata);
2454 gps_init(&appdata);
2455
2456 appdata.cur_view = gpxlist_create_view_and_model(&appdata, NULL);
2457 gtk_box_pack_start_defaults(GTK_BOX(appdata.vbox), appdata.cur_view);
2458
2459 gtk_widget_show_all(GTK_WIDGET(appdata.window));
2460 gtk_main();
2461
2462 cleanup(&appdata);
2463
2464 return 0;
2465 }