Contents of /trunk/src/main.c

Parent Directory Parent Directory | Revision Log Revision Log


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