Contents of /trunk/src/main.c

Parent Directory Parent Directory | Revision Log Revision Log


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