Contents of /trunk/src/main.c

Parent Directory Parent Directory | Revision Log Revision Log


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