Contents of /trunk/src/main.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 211 - (show annotations)
Wed Nov 25 10:13:26 2009 UTC (14 years, 5 months ago) by harbaum
File MIME type: text/plain
File size: 72830 byte(s)
GeoToad UI interaction
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 gtk_container_remove(GTK_CONTAINER(appdata->vbox), appdata->cur_view);
227 appdata->cur_view = cache_view(appdata, cache);
228 gtk_box_pack_start_defaults(GTK_BOX(appdata->vbox), appdata->cur_view);
229 gtk_widget_show_all(appdata->vbox);
230
231 crumb_add(appdata, cache->name, CRUMB_CACHE, cache);
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 static 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
1125 /******************** end of gpxlist ********************/
1126
1127 /******************** begin of menu *********************/
1128
1129 typedef struct {
1130 appdata_t *appdata;
1131 GtkWidget *dialog;
1132 } about_context_t;
1133
1134 #ifdef ENABLE_BROWSER_INTERFACE
1135 void on_paypal_button_clicked(GtkButton *button, about_context_t *context) {
1136 gtk_dialog_response(GTK_DIALOG(context->dialog), GTK_RESPONSE_ACCEPT);
1137 browser_url(context->appdata,
1138 "https://www.paypal.com/cgi-bin/webscr"
1139 "?cmd=_s-xclick&hosted_button_id=7400558");
1140 }
1141 #endif
1142
1143 static void
1144 cb_menu_about(GtkWidget *window, gpointer data) {
1145 about_context_t context;
1146
1147 context.appdata = (appdata_t *)data;
1148
1149 #ifdef ENABLE_LIBLOCATION
1150 char *uses = "uses liblocation";
1151 #elif defined(ENABLE_GPSBT)
1152 char *uses = "uses gpsbt and gpsd";
1153 #else
1154 char *uses = "uses gpsd";
1155 #endif
1156
1157 const gchar *authors[] = {
1158 "Till Harbaum <till@harbaum.org>",
1159 "John Stowers <john.stowers@gmail.com>",
1160 "GCVote: Guido Wegener <guido.wegener@gmx.de>",
1161 NULL };
1162
1163 context.dialog = g_object_new(GTK_TYPE_ABOUT_DIALOG,
1164 "name", "GPXView",
1165 "version", VERSION,
1166 "copyright", _("Copyright 2008-2009"),
1167 "authors", authors,
1168 "website", _("http://www.harbaum.org/till/maemo"),
1169 "comments", _(uses),
1170 NULL);
1171
1172 #ifdef ENABLE_BROWSER_INTERFACE
1173 /* add a way to donate to the project */
1174 GtkWidget *alignment = gtk_alignment_new(0.5, 0, 0, 0);
1175
1176 GtkWidget *hbox = gtk_hbox_new(FALSE, 8);
1177 gtk_box_pack_start(GTK_BOX(hbox),
1178 gtk_label_new(_("Do you like GPXView?")),
1179 FALSE, FALSE, 0);
1180
1181 GtkWidget *button = gtk_button_new();
1182 gtk_button_set_image(GTK_BUTTON(button),
1183 icon_get_widget(ICON_MISC, 5));
1184 gtk_button_set_relief(GTK_BUTTON(button), GTK_RELIEF_NONE);
1185 g_signal_connect(button, "clicked",
1186 G_CALLBACK(on_paypal_button_clicked), &context);
1187 gtk_box_pack_start(GTK_BOX(hbox), button, FALSE, FALSE, 0);
1188
1189 gtk_container_add(GTK_CONTAINER(alignment), hbox);
1190 gtk_box_pack_start_defaults(GTK_BOX((GTK_DIALOG(context.dialog))->vbox),
1191 alignment);
1192
1193 gtk_widget_show_all(alignment);
1194 #endif
1195
1196 gtk_dialog_run(GTK_DIALOG(context.dialog));
1197 gtk_widget_destroy(context.dialog);
1198 }
1199
1200 #if defined(USE_MAEMO) && defined(HILDON_HELP)
1201 static void
1202 cb_menu_help(GtkWidget *window, gpointer data) {
1203 appdata_t *appdata = (appdata_t*)data;
1204
1205 hildon_help_show(appdata->osso_context, HELP_ID_INTRO, 0);
1206 }
1207 #endif
1208
1209 static void
1210 cb_menu_add(GtkWidget *window, gpointer data) {
1211 appdata_t *appdata = (appdata_t *)data;
1212
1213 gpx_t *new = choose_file(appdata, FALSE);
1214 if(new) gpxlist_add(appdata, new);
1215 }
1216
1217 static void
1218 cb_menu_adddir(GtkWidget *window, gpointer data) {
1219 appdata_t *appdata = (appdata_t *)data;
1220
1221 gpx_t *new = choose_file(appdata, TRUE);
1222 if(new) gpxlist_add(appdata, new);
1223 }
1224
1225 #ifndef USE_PANNABLE_AREA
1226 static void
1227 cb_menu_close(GtkWidget *window, gpointer data) {
1228 appdata_t *appdata = (appdata_t *)data;
1229 GtkTreeSelection *selection;
1230 GtkTreeModel *model;
1231 GtkTreeIter iter;
1232
1233 printf("selected close\n");
1234
1235 /* the entry cannot be closed again */
1236 gtk_widget_set_sensitive(appdata->menu_close, FALSE);
1237
1238 selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(appdata->gpxview));
1239
1240 printf("gpxlist close\n");
1241
1242 if (gtk_tree_selection_get_selected(selection, &model, &iter)) {
1243 gpx_t *gpx = NULL;
1244 gtk_tree_model_get(model, &iter, GPXLIST_COL_DATA, &gpx, -1);
1245
1246 if(gpx) gpxlist_close(appdata, GTK_LIST_STORE(model), &iter, gpx);
1247 } else {
1248 g_print ("no row selected.\n");
1249 }
1250 }
1251
1252 static void
1253 cb_menu_remove(GtkWidget *window, gpointer data) {
1254 appdata_t *appdata = (appdata_t *)data;
1255
1256 /* disable menu item */
1257 gtk_widget_set_sensitive(appdata->menu_remove, FALSE);
1258 gtk_widget_set_sensitive(appdata->menu_close, FALSE);
1259
1260 GtkTreeModel *model;
1261 GtkTreeIter iter;
1262 GtkTreeSelection *selection =
1263 gtk_tree_view_get_selection(GTK_TREE_VIEW(appdata->gpxview));
1264
1265 printf("gpxlist remove\n");
1266
1267 if(gtk_tree_selection_get_selected(selection, &model, &iter)) {
1268 gpx_t *gpx = NULL;
1269 gtk_tree_model_get(model, &iter, GPXLIST_COL_DATA, &gpx, -1);
1270
1271 if(gpx) gpxlist_remove(appdata, GTK_LIST_STORE(model), &iter, gpx);
1272 } else {
1273 g_print ("no row selected.\n");
1274 }
1275 }
1276
1277 #endif // !USE_PANNABLE_AREA
1278
1279 static void search_result_free(gpx_t *result) {
1280 printf("freeing search results\n");
1281
1282 /* free found chain */
1283 cache_t *cache = result->cache;
1284 while(cache) {
1285 cache_t *next = cache->next;
1286 free(cache);
1287 cache = next;
1288 }
1289 free(result->name);
1290 free(result);
1291 }
1292
1293 #define MAX_HITS 50
1294
1295 static time_t localize_time(time_t in) {
1296 time_t ret;
1297 char *tz;
1298 struct tm *tm = localtime(&in);
1299
1300 tz = getenv("TZ");
1301 setenv("TZ", "", 1);
1302 tzset();
1303 ret = mktime(tm);
1304 if (tz)
1305 setenv("TZ", tz, 1);
1306 else
1307 unsetenv("TZ");
1308 tzset();
1309 return ret;
1310 }
1311
1312 static int days_ago(time_t in) {
1313 int day_in = localize_time(in) / (60*60*24);
1314 int day_now = localize_time(time(NULL)) / (60*60*24);
1315
1316 return day_now - day_in;
1317 }
1318
1319 gpx_t *search_do(appdata_t *appdata, gpx_t *gpx, char *phrase,
1320 int what, gboolean local) {
1321 /* walk through all caches */
1322
1323 int hits = 0;
1324 gpx_t *found = malloc(sizeof(gpx_t));
1325 memset(found, 0, sizeof(gpx_t));
1326 cache_t **cacheP = &(found->cache);
1327
1328 if(what & SEARCH_FINDS) {
1329 time_t loc_now = localize_time(time(NULL));
1330 printf("now: %ld days since 1/1/1970, days hour is %ld\n",
1331 loc_now/(60*60*24), loc_now%(60*60*24)/(60*60));
1332 }
1333
1334 while(gpx && hits < MAX_HITS) {
1335
1336 /* we need all notes ... */
1337 if(what & SEARCH_FINDS) {
1338 notes_load_all(appdata, gpx);
1339 gpx->notes_loaded = TRUE;
1340 }
1341
1342 cache_t *cache = gpx->cache;
1343
1344 while(cache && hits < MAX_HITS) {
1345 gboolean hit = FALSE;
1346
1347 if(what & SEARCH_FINDS) {
1348 if(cache->notes && cache->notes->found ) {
1349 int days = days_ago(cache->notes->ftime);
1350
1351 if(cache->id)
1352 printf("find of %s is %d days ago\n", cache->id, days);
1353
1354 if(days <= appdata->search_days)
1355 hit = 1;
1356 }
1357 } else if(cache->id && (what & SEARCH_ID) &&
1358 strcasestr(cache->id, phrase))
1359 hit = 1;
1360 else if(cache->name && (what & SEARCH_NAME) &&
1361 strcasestr(cache->name, phrase))
1362 hit = 1;
1363 else if(cache->short_description && (what & SEARCH_DESC) &&
1364 strcasestr(cache->short_description, phrase))
1365 hit = 1;
1366 else if(cache->long_description && (what & SEARCH_DESC) &&
1367 strcasestr(cache->long_description, phrase))
1368 hit = 1;
1369 else if(cache->owner && cache->owner->name && (what & SEARCH_OWNER) &&
1370 strcasestr(cache->owner->name, phrase))
1371 hit = 1;
1372
1373 if(hit) {
1374 /* chain a copy of this cache structure into the found list */
1375 *cacheP = malloc(sizeof(cache_t));
1376 memcpy(*cacheP, cache, sizeof(cache_t));
1377 (*cacheP)->next = NULL;
1378 cacheP = &((*cacheP)->next);
1379 hits++;
1380 }
1381 cache = cache->next;
1382 }
1383
1384 if(!local) gpx = gpx->next;
1385 else gpx = NULL; /* local search within one gpx only */
1386 }
1387
1388 found->name = strdup(_("Search results"));
1389
1390 return found;
1391 }
1392
1393 typedef struct {
1394 appdata_t *appdata;
1395 GtkWidget *entry, *spinner;
1396 GtkWidget *in_id, *in_name, *in_desc, *in_owner, *in_finds;
1397 } search_context_t;
1398
1399
1400 static GtkWidget *check_button_new_with_label(char *label) {
1401 #if !defined(USE_MAEMO) || (MAEMO_VERSION_MAJOR < 5)
1402 return gtk_check_button_new_with_label(label);
1403 #else
1404 GtkWidget *cbut =
1405 hildon_check_button_new(HILDON_SIZE_FINGER_HEIGHT | HILDON_SIZE_AUTO_WIDTH);
1406 gtk_button_set_label(GTK_BUTTON(cbut), label);
1407 return cbut;
1408 #endif
1409 }
1410
1411 static void check_button_set_active(GtkWidget *button, gboolean active) {
1412 #if !defined(USE_MAEMO) || (MAEMO_VERSION_MAJOR < 5)
1413 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(button), active);
1414 #else
1415 hildon_check_button_set_active(HILDON_CHECK_BUTTON(button), active);
1416 #endif
1417 }
1418
1419 static gboolean check_button_get_active(GtkWidget *button) {
1420 #if !defined(USE_MAEMO) || (MAEMO_VERSION_MAJOR < 5)
1421 return gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(button));
1422 #else
1423 return hildon_check_button_get_active(HILDON_CHECK_BUTTON(button));
1424 #endif
1425 }
1426
1427 static void callback_finds_toggled(GtkWidget *widget, gpointer data ) {
1428 search_context_t *context = (search_context_t*)data;
1429
1430 gboolean in_finds = check_button_get_active(context->in_finds);
1431
1432 gtk_widget_set_sensitive(context->entry, !in_finds);
1433 gtk_widget_set_sensitive(context->in_id, !in_finds);
1434 gtk_widget_set_sensitive(context->in_name, !in_finds);
1435 gtk_widget_set_sensitive(context->in_desc, !in_finds);
1436 gtk_widget_set_sensitive(context->in_owner, !in_finds);
1437 gtk_widget_set_sensitive(context->spinner, in_finds);
1438 }
1439
1440 static void
1441 cb_menu_search(GtkWidget *window, gpointer data) {
1442 appdata_t *appdata = (appdata_t *)data;
1443
1444 search_context_t context;
1445 memset(&context, 0, sizeof(search_context_t));
1446 context.appdata = appdata;
1447
1448 GtkWidget *dialog = gtk_dialog_new_with_buttons(_("Enter search phrase"),
1449 GTK_WINDOW(appdata->window), GTK_DIALOG_MODAL,
1450 GTK_STOCK_OK, GTK_RESPONSE_ACCEPT,
1451 GTK_STOCK_CANCEL, GTK_RESPONSE_REJECT,
1452 NULL);
1453
1454 gtk_box_pack_start_defaults(GTK_BOX(GTK_DIALOG(dialog)->vbox),
1455 gtk_label_new(_("Search in:")));
1456
1457 GtkWidget *table = gtk_table_new(2, 2, TRUE);
1458 gtk_table_set_col_spacing(GTK_TABLE(table), 0, 8);
1459
1460 context.in_id = check_button_new_with_label(_("Waypoint IDs"));
1461 check_button_set_active(context.in_id, appdata->search & SEARCH_ID);
1462 gtk_table_attach_defaults(GTK_TABLE(table), context.in_id, 0, 1, 0, 1);
1463
1464 context.in_name = check_button_new_with_label(_("Names"));
1465 check_button_set_active(context.in_name, appdata->search & SEARCH_NAME);
1466 gtk_table_attach_defaults(GTK_TABLE(table), context.in_name, 1, 2, 0, 1);
1467
1468 context.in_desc = check_button_new_with_label(_("Descriptions"));
1469 check_button_set_active(context.in_desc, appdata->search & SEARCH_DESC);
1470 gtk_table_attach_defaults(GTK_TABLE(table), context.in_desc, 0, 1, 1, 2);
1471
1472 context.in_owner = check_button_new_with_label(_("Owner"));
1473 check_button_set_active(context.in_owner, appdata->search & SEARCH_OWNER);
1474 gtk_table_attach_defaults(GTK_TABLE(table), context.in_owner, 1, 2, 1, 2);
1475
1476 gtk_box_pack_start_defaults(GTK_BOX(GTK_DIALOG(dialog)->vbox), table);
1477
1478 /* -------------------------------------------------------------- */
1479
1480 gtk_box_pack_start_defaults(GTK_BOX(GTK_DIALOG(dialog)->vbox),
1481 gtk_label_new(_("Search for:")));
1482 #if !defined(USE_MAEMO) || (MAEMO_VERSION_MAJOR < 5)
1483 context.entry = gtk_entry_new();
1484 #else
1485 context.entry = hildon_entry_new(HILDON_SIZE_AUTO);
1486 #endif
1487
1488 gtk_box_pack_start_defaults(GTK_BOX(GTK_DIALOG(dialog)->vbox),
1489 context.entry);
1490
1491 if(appdata->search_str)
1492 gtk_entry_set_text(GTK_ENTRY(context.entry), appdata->search_str);
1493
1494 /* -------------------------------------------------------------- */
1495
1496 gtk_box_pack_start_defaults(GTK_BOX(GTK_DIALOG(dialog)->vbox),
1497 gtk_hseparator_new());
1498
1499 GtkWidget *hbox = gtk_hbox_new(FALSE, 5);
1500
1501 context.in_finds = check_button_new_with_label(_("Search finds for"));
1502 check_button_set_active(context.in_finds, appdata->search & SEARCH_FINDS);
1503 gtk_box_pack_start_defaults(GTK_BOX(hbox), context.in_finds);
1504 g_signal_connect(G_OBJECT(context.in_finds), "toggled",
1505 G_CALLBACK(callback_finds_toggled), &context);
1506
1507 #ifndef USE_MAEMO
1508 GtkObject *adj = gtk_adjustment_new(appdata->search_days, 0, 99, 1, 10, 10);
1509 context.spinner = gtk_spin_button_new(GTK_ADJUSTMENT(adj), 1, 0);
1510 #else
1511 context.spinner = hildon_number_editor_new(0, 99);
1512 hildon_number_editor_set_value(HILDON_NUMBER_EDITOR(context.spinner),
1513 appdata->search_days);
1514 #endif
1515 gtk_box_pack_start_defaults(GTK_BOX(hbox), context.spinner);
1516
1517 gtk_box_pack_start_defaults(GTK_BOX(hbox), gtk_label_new(_("days")));
1518
1519 gtk_box_pack_start_defaults(GTK_BOX(GTK_DIALOG(dialog)->vbox), hbox);
1520
1521 /* -------------------------------------------------------------- */
1522
1523 gtk_widget_show_all(dialog);
1524 callback_finds_toggled(NULL, &context);
1525
1526 if(GTK_RESPONSE_ACCEPT == gtk_dialog_run(GTK_DIALOG(dialog))) {
1527 char *p = strdup(gtk_entry_get_text(GTK_ENTRY(context.entry)));
1528
1529 /* update saved search string */
1530 if(appdata->search_str) free(appdata->search_str);
1531 if(strlen(p) > 0)
1532 appdata->search_str = strdup(p);
1533
1534 #ifndef USE_MAEMO
1535 appdata->search_days = gtk_spin_button_get_value_as_int(
1536 GTK_SPIN_BUTTON(context.spinner));
1537 #else
1538 appdata->search_days = hildon_number_editor_get_value(
1539 HILDON_NUMBER_EDITOR(context.spinner));
1540 #endif
1541
1542 if(check_button_get_active(context.in_finds))
1543 appdata->search |= SEARCH_FINDS;
1544 else
1545 appdata->search &= ~SEARCH_FINDS;
1546
1547 if(check_button_get_active(context.in_id))
1548 appdata->search |= SEARCH_ID;
1549 else
1550 appdata->search &= ~SEARCH_ID;
1551
1552 if(check_button_get_active(context.in_name))
1553 appdata->search |= SEARCH_NAME;
1554 else
1555 appdata->search &= ~SEARCH_NAME;
1556
1557 if(check_button_get_active(context.in_desc))
1558 appdata->search |= SEARCH_DESC;
1559 else
1560 appdata->search &= ~SEARCH_DESC;
1561
1562 if(check_button_get_active(context.in_owner))
1563 appdata->search |= SEARCH_OWNER;
1564 else
1565 appdata->search &= ~SEARCH_OWNER;
1566
1567 gtk_widget_destroy(dialog);
1568
1569 /* don't search if we are asked to search for nothing */
1570 if(((appdata->search & (SEARCH_ID|SEARCH_NAME|SEARCH_DESC|SEARCH_OWNER)) &&
1571 strlen(p) > 0) || (appdata->search & SEARCH_FINDS)) {
1572
1573 printf("Search for %s (flags = %x)...\n", p, appdata->search);
1574
1575 #if !defined(USE_BREAD_CRUMB_TRAIL) && !defined(BCT)
1576 gpx_t *found =
1577 search_do(appdata, appdata->gpx, p, appdata->search, FALSE);
1578
1579 /* do search result dialog here ... */
1580 cachelist_dialog(appdata, found);
1581 #ifndef USE_STACKABLE_WINDOW
1582 search_result_free(found);
1583 #else
1584 appdata->search_results = found;
1585 #endif
1586 #else
1587 gpx_t *found = NULL;
1588
1589 if(appdata->cur_gpx)
1590 found = search_do(appdata, appdata->cur_gpx, p, appdata->search, TRUE);
1591 else
1592 found = search_do(appdata, appdata->gpx, p, appdata->search, FALSE);
1593
1594 gtk_container_remove(GTK_CONTAINER(appdata->vbox), appdata->cur_view);
1595 appdata->cur_view = cachelist_create(appdata, found, NULL);
1596 gtk_box_pack_start_defaults(GTK_BOX(appdata->vbox), appdata->cur_view);
1597 gtk_widget_show_all(appdata->vbox);
1598 crumb_add(appdata, found->name,
1599 appdata->cur_gpx?CRUMB_SEARCH_GPX:CRUMB_SEARCH_GLOBAL, found);
1600 #endif
1601 } else
1602 printf("No valid search: \"%s\" with flags %x!\n", p, appdata->search);
1603
1604 free(p);
1605 } else
1606 gtk_widget_destroy(dialog);
1607 }
1608
1609 static void on_window_destroy (GtkWidget *widget, gpointer data);
1610
1611 #ifndef USE_MAEMO
1612 static void
1613 cb_menu_quit(GtkWidget *window, gpointer data) {
1614 on_window_destroy(window, data);
1615 }
1616 #endif
1617
1618 #ifndef NO_COPY_N_PASTE
1619 static void
1620 cb_menu_cut(GtkWidget *widget, gpointer data) {
1621 appdata_t *appdata = (appdata_t*)data;
1622
1623 if(appdata->active_buffer) {
1624 if(GTK_WIDGET_TYPE(appdata->active_buffer) == GTK_TYPE_TEXT_BUFFER) {
1625 gtk_text_buffer_cut_clipboard(GTK_TEXT_BUFFER(appdata->active_buffer),
1626 appdata->clipboard, TRUE);
1627 } else
1628 printf("cut: ERROR, not a text buffer\n");
1629 } else
1630 printf("cut: ERROR, no active buffer\n");
1631 }
1632
1633 static void
1634 cb_menu_copy(GtkWidget *widget, gpointer data) {
1635 appdata_t *appdata = (appdata_t*)data;
1636
1637 if(appdata->active_buffer) {
1638 if(GTK_WIDGET_TYPE(appdata->active_buffer) == GTK_TYPE_TEXT_BUFFER) {
1639 gtk_text_buffer_copy_clipboard(GTK_TEXT_BUFFER(appdata->active_buffer),
1640 appdata->clipboard);
1641 } else if(GTK_WIDGET_TYPE(appdata->active_buffer) == gtk_html_get_type()) {
1642 printf("copy from html buffer\n");
1643 html_copy_to_clipboard(appdata);
1644 } else
1645 printf("copy: ERROR, not a text nor a html buffer\n");
1646 } else
1647 printf("copy: ERROR, no active buffer\n");
1648 }
1649
1650 static void
1651 cb_menu_paste(GtkWidget *widget, gpointer data) {
1652 appdata_t *appdata = (appdata_t*)data;
1653
1654 if(appdata->active_buffer) {
1655 if(GTK_WIDGET_TYPE(appdata->active_buffer) == GTK_TYPE_TEXT_BUFFER) {
1656 gtk_text_buffer_paste_clipboard(GTK_TEXT_BUFFER(appdata->active_buffer),
1657 appdata->clipboard, NULL, TRUE);
1658 } else
1659 printf("paste: ERROR, not a text buffer\n");
1660 } else
1661 printf("paste: ERROR, no active buffer\n");
1662 }
1663 #endif
1664
1665 static void
1666 cb_menu_export_log(GtkWidget *widget, gpointer data) {
1667 appdata_t *appdata = (appdata_t*)data;
1668 notes_log_export(appdata);
1669 }
1670
1671 #ifdef ENABLE_MAEMO_MAPPER
1672 static void
1673 cb_menu_export_mmpoi(GtkWidget *widget, gpointer data) {
1674 appdata_t *appdata = (appdata_t*)data;
1675 mmpoi_export(appdata);
1676 }
1677 #endif
1678
1679 static void
1680 cb_menu_export_garmin(GtkWidget *widget, gpointer data) {
1681 appdata_t *appdata = (appdata_t*)data;
1682 garmin_export(appdata);
1683 }
1684
1685 #ifdef ENABLE_OSM_GPS_MAP
1686 static void
1687 cb_menu_map(GtkWidget *window, gpointer data) {
1688 map((appdata_t *)data);
1689 }
1690 #endif
1691
1692 static void
1693 cb_menu_geomath(GtkWidget *window, gpointer data) {
1694 geomath_dialog((appdata_t *)data);
1695 }
1696
1697 static void
1698 cb_menu_geotext(GtkWidget *window, gpointer data) {
1699 geotext_dialog((appdata_t *)data);
1700 }
1701
1702 static void
1703 cb_menu_precpos(GtkWidget *window, gpointer data) {
1704 precise_position((appdata_t *)data);
1705 }
1706
1707 static void
1708 cb_menu_geotoad(GtkWidget *window, gpointer data) {
1709 geotoad((appdata_t *)data);
1710 }
1711
1712 #ifdef USE_STACKABLE_WINDOW
1713 typedef struct {
1714 char *label, *desc;
1715 GtkSignalFunc activate_cb;
1716 } menu_entry_t;
1717
1718 typedef struct {
1719 const char *title;
1720 const menu_entry_t *menu;
1721 int len;
1722 } submenu_t;
1723
1724 #define COLUMNS 1
1725
1726 void on_submenu_entry_clicked(GtkButton *button, GtkWidget *menu) {
1727
1728 /* force closing of submenu dialog */
1729 gtk_dialog_response(GTK_DIALOG(menu), GTK_RESPONSE_NONE);
1730 gtk_widget_hide(menu);
1731
1732 /* let gtk clean up */
1733 while(gtk_events_pending())
1734 gtk_main_iteration();
1735 }
1736
1737 static GtkWidget *app_submenu_create(appdata_t *appdata,
1738 const submenu_t *submenu) {
1739
1740 /* create a oridinary dialog box */
1741 GtkWidget *dialog = gtk_dialog_new();
1742 gtk_window_set_title(GTK_WINDOW(dialog), _(submenu->title));
1743 gtk_window_set_modal(GTK_WINDOW(dialog), TRUE);
1744 gtk_window_set_transient_for(GTK_WINDOW(dialog),
1745 GTK_WINDOW(appdata->window));
1746 gtk_dialog_set_has_separator(GTK_DIALOG(dialog), FALSE);
1747
1748 GtkWidget *table = gtk_table_new(submenu->len/COLUMNS, COLUMNS, TRUE);
1749 int x = 0, y = 0;
1750
1751 const menu_entry_t *menu_entries = submenu->menu;
1752 while(menu_entries->label) {
1753 GtkWidget *button = NULL;
1754
1755 button = hildon_button_new_with_text(
1756 HILDON_SIZE_FINGER_HEIGHT | HILDON_SIZE_AUTO_WIDTH,
1757 HILDON_BUTTON_ARRANGEMENT_VERTICAL,
1758 _(menu_entries->label), _(menu_entries->desc));
1759
1760 /* try to center both texts */
1761 hildon_button_set_title_alignment(HILDON_BUTTON(button), 0.5, 0.5);
1762 hildon_button_set_value_alignment(HILDON_BUTTON(button), 0.5, 0.5);
1763
1764 g_signal_connect(button, "clicked",
1765 G_CALLBACK(on_submenu_entry_clicked), dialog);
1766
1767 g_signal_connect(button, "clicked",
1768 menu_entries->activate_cb, appdata);
1769
1770 gtk_table_attach_defaults(GTK_TABLE(table), button, x, x+1, y, y+1);
1771
1772 x++;
1773 if(x == COLUMNS) { x = 0; y++; }
1774
1775 menu_entries++;
1776 }
1777
1778 gtk_box_pack_start_defaults(GTK_BOX(GTK_DIALOG(dialog)->vbox), table);
1779
1780 return dialog;
1781 }
1782
1783 /* popup the dialog shaped submenu */
1784 static void submenu_popup(GtkWidget *menu) {
1785 gtk_widget_show_all(menu);
1786 gtk_dialog_run(GTK_DIALOG(menu));
1787 gtk_widget_hide(menu);
1788 }
1789
1790 static void submenu_cleanup(GtkWidget *menu) {
1791 gtk_widget_destroy(menu);
1792 }
1793
1794 static const menu_entry_t submenu_export_entries[] = {
1795 #ifdef ENABLE_MAEMO_MAPPER
1796 { "Export to Maemo Mapper" , "Save a Maemo Mapper POI file",
1797 G_CALLBACK(cb_menu_export_mmpoi) },
1798 #endif
1799 { "Export Field Notes", "Save a Garmin Field Notes file",
1800 G_CALLBACK(cb_menu_export_log) },
1801 { "Export Garmin GPX", "Save modified waypoints in GPX file",
1802 G_CALLBACK(cb_menu_export_garmin) },
1803 { NULL, NULL, NULL }
1804 };
1805
1806 static const submenu_t submenu_export = {
1807 "Export", submenu_export_entries,
1808 sizeof(submenu_export_entries)/sizeof(menu_entry_t)-1
1809 };
1810
1811 /* the export submenu */
1812 void on_export_clicked(GtkButton *button, appdata_t *appdata) {
1813 if(!appdata->export_menu)
1814 appdata->export_menu = app_submenu_create(appdata, &submenu_export);
1815
1816 submenu_popup(appdata->export_menu);
1817 }
1818
1819 static const menu_entry_t submenu_tools_entries[] = {
1820 { "Geomath", "Geocoordinate calculation",
1821 G_CALLBACK(cb_menu_geomath) },
1822 { "Geotext", "Text analysis",
1823 G_CALLBACK(cb_menu_geotext) },
1824 { "Precise Position", "Calculate a precise GPS position",
1825 G_CALLBACK(cb_menu_precpos) },
1826 { "GeoToad", "Use GeoToad online downloader",
1827 G_CALLBACK(cb_menu_geotoad) },
1828 { NULL, NULL, NULL }
1829 };
1830
1831 static const submenu_t submenu_tools = {
1832 "Tools", submenu_tools_entries,
1833 sizeof(submenu_tools_entries)/sizeof(menu_entry_t)-1
1834 };
1835
1836 /* the tools submenu */
1837 void on_tools_clicked(GtkButton *button, appdata_t *appdata) {
1838 if(!appdata->tools_menu)
1839 appdata->tools_menu = app_submenu_create(appdata, &submenu_tools);
1840
1841 submenu_popup(appdata->tools_menu);
1842 }
1843
1844 HildonAppMenu *menu_create(appdata_t *appdata, int mode) {
1845 GtkWidget *button;
1846 HildonAppMenu *menu = HILDON_APP_MENU(hildon_app_menu_new());
1847
1848 /* ------- */
1849 button = gtk_button_new_with_label(_("About"));
1850 g_signal_connect_after(button, "clicked",
1851 G_CALLBACK(cb_menu_about), appdata);
1852 hildon_app_menu_append(menu, GTK_BUTTON(button));
1853
1854 button = gtk_button_new_with_label(_("Settings"));
1855 g_signal_connect_after(button, "clicked", G_CALLBACK(cb_menu_settings),
1856 appdata);
1857 hildon_app_menu_append(menu, GTK_BUTTON(button));
1858
1859 if(mode == MENU_GPXLIST) {
1860 button = gtk_button_new_with_label(_("Import file"));
1861 g_signal_connect_after(button, "clicked",
1862 G_CALLBACK(cb_menu_add), appdata);
1863 hildon_app_menu_append(menu, GTK_BUTTON(button));
1864
1865 button = gtk_button_new_with_label(_("Import directory"));
1866 g_signal_connect_after(button, "clicked",
1867 G_CALLBACK(cb_menu_adddir), appdata);
1868 hildon_app_menu_append(menu, GTK_BUTTON(button));
1869
1870 button = gtk_button_new_with_label(_("Export"));
1871 g_signal_connect_after(button, "clicked",
1872 G_CALLBACK(on_export_clicked), appdata);
1873 hildon_app_menu_append(menu, GTK_BUTTON(button));
1874
1875 button = gtk_button_new_with_label(_("Search"));
1876 g_signal_connect_after(button, "clicked",
1877 G_CALLBACK(cb_menu_search), appdata);
1878 hildon_app_menu_append(menu, GTK_BUTTON(button));
1879 }
1880
1881 button = gtk_button_new_with_label(_("Tools"));
1882 g_signal_connect_after(button, "clicked",
1883 G_CALLBACK(on_tools_clicked), appdata);
1884 hildon_app_menu_append(menu, GTK_BUTTON(button));
1885
1886 #ifdef ENABLE_OSM_GPS_MAP
1887 button = gtk_button_new_with_label(_("Map"));
1888 g_signal_connect_after(button, "clicked",
1889 G_CALLBACK(cb_menu_map), appdata);
1890 hildon_app_menu_append(menu, GTK_BUTTON(button));
1891 #endif
1892
1893 #ifdef HILDON_HELP
1894 button = gtk_button_new_with_label(_("Help"));
1895 g_signal_connect_after(button, "clicked",
1896 G_CALLBACK(cb_menu_help), appdata);
1897 hildon_app_menu_append(menu, GTK_BUTTON(button));
1898 #endif
1899
1900 gtk_widget_show_all(GTK_WIDGET(menu));
1901
1902 return menu;
1903 }
1904 #else
1905
1906 void menu_create(appdata_t *appdata) {
1907 GtkWidget *menu, *item;
1908 menu = gtk_menu_new();
1909
1910 #if defined(USE_BREAD_CRUMB_TRAIL) || defined(BCT)
1911 appdata->menu_import =
1912 #endif
1913 item = gtk_menu_item_new_with_label(_("Import"));
1914 gtk_menu_append(GTK_MENU_SHELL(menu), item);
1915 GtkWidget *submenu = gtk_menu_new();
1916 gtk_menu_item_set_submenu(GTK_MENU_ITEM(item), submenu);
1917
1918 item = gtk_menu_item_new_with_label( _("File") );
1919 gtk_menu_append(GTK_MENU_SHELL(submenu), item);
1920 g_signal_connect(item, "activate", GTK_SIGNAL_FUNC(cb_menu_add), appdata);
1921
1922 item = gtk_menu_item_new_with_label( _("Directory") );
1923 gtk_menu_append(GTK_MENU_SHELL(submenu), item);
1924 g_signal_connect(item, "activate", GTK_SIGNAL_FUNC(cb_menu_adddir), appdata);
1925
1926 #ifndef USE_PANNABLE_AREA
1927 gtk_menu_append(GTK_MENU_SHELL(submenu), gtk_separator_menu_item_new());
1928
1929 appdata->menu_close =
1930 item = gtk_menu_item_new_with_label( _("Close") );
1931 gtk_menu_append(GTK_MENU_SHELL(submenu), item);
1932 g_signal_connect(item, "activate", GTK_SIGNAL_FUNC(cb_menu_close), appdata);
1933
1934 appdata->menu_remove =
1935 item = gtk_menu_item_new_with_label( _("Remove") );
1936 gtk_menu_append(GTK_MENU_SHELL(submenu), item);
1937 g_signal_connect(item, "activate", GTK_SIGNAL_FUNC(cb_menu_remove), appdata);
1938 #endif
1939
1940 #if defined(USE_BREAD_CRUMB_TRAIL) || defined(BCT)
1941 appdata->menu_export =
1942 #endif
1943 item = gtk_menu_item_new_with_label(_("Export"));
1944 gtk_menu_append(GTK_MENU_SHELL(menu), item);
1945 submenu = gtk_menu_new();
1946 gtk_menu_item_set_submenu(GTK_MENU_ITEM(item), submenu);
1947
1948 #ifdef ENABLE_MAEMO_MAPPER
1949 item = gtk_menu_item_new_with_label( _("Maemo Mapper POI") );
1950 gtk_menu_append(GTK_MENU_SHELL(submenu), item);
1951 g_signal_connect(item, "activate",
1952 GTK_SIGNAL_FUNC(cb_menu_export_mmpoi), appdata);
1953 #endif
1954
1955 item = gtk_menu_item_new_with_label( _("Garmin Field Notes") );
1956 gtk_menu_append(GTK_MENU_SHELL(submenu), item);
1957 g_signal_connect(item, "activate",
1958 GTK_SIGNAL_FUNC(cb_menu_export_log), appdata);
1959
1960 item = gtk_menu_item_new_with_label( _("Garmin GPX") );
1961 gtk_menu_append(GTK_MENU_SHELL(submenu), item);
1962 g_signal_connect(item, "activate",
1963 GTK_SIGNAL_FUNC(cb_menu_export_garmin), appdata);
1964
1965 #if defined(USE_BREAD_CRUMB_TRAIL) || defined(BCT)
1966 appdata->menu_search =
1967 #endif
1968 item = gtk_menu_item_new_with_label( _("Search") );
1969 gtk_menu_append(GTK_MENU_SHELL(menu), item);
1970 g_signal_connect(item, "activate", GTK_SIGNAL_FUNC(cb_menu_search), appdata);
1971
1972 gtk_menu_append(GTK_MENU_SHELL(menu), gtk_separator_menu_item_new());
1973
1974 /* ----------- copy'n paste submenu ----------------- */
1975 #ifndef NO_COPY_N_PASTE
1976 item = gtk_menu_item_new_with_label(_("Edit"));
1977 gtk_menu_append(GTK_MENU_SHELL(menu), item);
1978 submenu = gtk_menu_new();
1979 gtk_menu_item_set_submenu(GTK_MENU_ITEM(item), submenu);
1980
1981 appdata->menu_cut = item = gtk_menu_item_new_with_label( _("Cut") );
1982 gtk_widget_set_sensitive(item, FALSE);
1983 gtk_menu_append(GTK_MENU_SHELL(submenu), item);
1984 g_signal_connect(item, "activate", GTK_SIGNAL_FUNC(cb_menu_cut), appdata);
1985 appdata->menu_copy = item = gtk_menu_item_new_with_label( _("Copy") );
1986 gtk_widget_set_sensitive(item, FALSE);
1987 gtk_menu_append(GTK_MENU_SHELL(submenu), item);
1988 g_signal_connect(item, "activate", GTK_SIGNAL_FUNC(cb_menu_copy), appdata);
1989 appdata->menu_paste = item = gtk_menu_item_new_with_label( _("Paste") );
1990 gtk_widget_set_sensitive(item, FALSE);
1991 gtk_menu_append(GTK_MENU_SHELL(submenu), item);
1992 g_signal_connect(item, "activate", GTK_SIGNAL_FUNC(cb_menu_paste), appdata);
1993 #endif
1994
1995 item = gtk_menu_item_new_with_label( _("Settings") );
1996 gtk_menu_append(GTK_MENU_SHELL(menu), item);
1997 g_signal_connect(item, "activate", GTK_SIGNAL_FUNC(cb_menu_settings),
1998 appdata);
1999
2000 gtk_menu_append(GTK_MENU_SHELL(menu), gtk_separator_menu_item_new());
2001
2002 #ifdef ENABLE_OSM_GPS_MAP
2003 item = gtk_menu_item_new_with_label( _("Map") );
2004 gtk_menu_append(GTK_MENU_SHELL(menu), item);
2005 g_signal_connect(item, "activate",
2006 GTK_SIGNAL_FUNC(cb_menu_map), appdata);
2007 #endif
2008
2009 item = gtk_menu_item_new_with_label(_("Tools"));
2010 gtk_menu_append(GTK_MENU_SHELL(menu), item);
2011 submenu = gtk_menu_new();
2012 gtk_menu_item_set_submenu(GTK_MENU_ITEM(item), submenu);
2013
2014 item = gtk_menu_item_new_with_label( _("Geomath") );
2015 gtk_menu_append(GTK_MENU_SHELL(submenu), item);
2016 g_signal_connect(item, "activate",
2017 GTK_SIGNAL_FUNC(cb_menu_geomath), appdata);
2018
2019 item = gtk_menu_item_new_with_label( _("Geotext") );
2020 gtk_menu_append(GTK_MENU_SHELL(submenu), item);
2021 g_signal_connect(item, "activate",
2022 GTK_SIGNAL_FUNC(cb_menu_geotext), appdata);
2023
2024 item = gtk_menu_item_new_with_label( _("Precise Position") );
2025 gtk_menu_append(GTK_MENU_SHELL(submenu), item);
2026 g_signal_connect(item, "activate",
2027 GTK_SIGNAL_FUNC(cb_menu_precpos), appdata);
2028
2029 item = gtk_menu_item_new_with_label( _("GeoToad") );
2030 gtk_menu_append(GTK_MENU_SHELL(submenu), item);
2031 g_signal_connect(item, "activate",
2032 GTK_SIGNAL_FUNC(cb_menu_geotoad), appdata);
2033
2034 gtk_menu_append(GTK_MENU_SHELL(menu), gtk_separator_menu_item_new());
2035
2036 #if defined(USE_MAEMO) && defined(HILDON_HELP)
2037 item = gtk_menu_item_new_with_label( _("Help") );
2038 gtk_menu_append(GTK_MENU_SHELL(menu), item);
2039 g_signal_connect(item, "activate", GTK_SIGNAL_FUNC(cb_menu_help), appdata);
2040 #endif
2041
2042 item = gtk_menu_item_new_with_label( _("About") );
2043 gtk_menu_append(GTK_MENU_SHELL(menu), item);
2044 g_signal_connect(item, "activate", GTK_SIGNAL_FUNC(cb_menu_about), appdata);
2045
2046 #ifndef USE_MAEMO
2047 item = gtk_menu_item_new_with_label( _("Quit") );
2048 gtk_menu_append(GTK_MENU_SHELL(menu), item);
2049 g_signal_connect(item, "activate", GTK_SIGNAL_FUNC(cb_menu_quit), appdata);
2050 #endif
2051
2052 #ifdef USE_MAEMO
2053 hildon_window_set_menu(appdata->window, GTK_MENU(menu));
2054 #else
2055 /* attach ordinary gtk menu */
2056 GtkWidget *menu_bar = gtk_menu_bar_new();
2057
2058 GtkWidget *root_menu = gtk_menu_item_new_with_label (_("Menu"));
2059 gtk_widget_show(root_menu);
2060
2061 gtk_menu_bar_append(menu_bar, root_menu);
2062 gtk_menu_item_set_submenu(GTK_MENU_ITEM (root_menu), menu);
2063
2064 gtk_widget_show(menu_bar);
2065 gtk_box_pack_start(GTK_BOX(appdata->vbox), menu_bar, 0, 0, 0);
2066 #endif
2067 }
2068 #endif
2069
2070 /********************* end of menu **********************/
2071
2072 void cleanup(appdata_t *appdata) {
2073 gpx_free_all(appdata->gpx);
2074 if(appdata->path) free(appdata->path);
2075 if(appdata->image_path) free(appdata->image_path);
2076 if(appdata->search_str) free(appdata->search_str);
2077
2078 #ifdef USE_STACKABLE_WINDOW
2079 if(appdata->export_menu) submenu_cleanup(appdata->export_menu);
2080 if(appdata->tools_menu) submenu_cleanup(appdata->tools_menu);
2081 #endif
2082
2083 gnome_vfs_shutdown();
2084 icons_free();
2085 gps_release(appdata);
2086
2087 #ifdef USE_MAEMO
2088 if(appdata->search_results) {
2089 printf("freeing pending search\n");
2090 search_result_free(appdata->search_results);
2091 }
2092
2093 if(appdata->osso_context)
2094 osso_deinitialize(appdata->osso_context);
2095
2096 appdata->program = NULL;
2097 #endif
2098
2099 /* free chain of locations */
2100 location_t *loc = appdata->location;
2101 while(loc) {
2102 location_t *next = loc->next;
2103 if(loc->name) free(loc->name);
2104 free(loc);
2105 loc = next;
2106 }
2107
2108 puts("everything is gone");
2109 }
2110
2111 static void on_window_destroy (GtkWidget *widget, gpointer data) {
2112 appdata_t *appdata = (appdata_t*)data;
2113
2114 gconf_save_state(appdata);
2115 gtk_main_quit();
2116 appdata->window = NULL;
2117 }
2118
2119 gboolean on_window_key_press(GtkWidget *widget,
2120 GdkEventKey *event, appdata_t *appdata) {
2121 int handled = FALSE;
2122
2123 // printf("key event %d\n", event->keyval);
2124
2125 switch(event->keyval) {
2126 #ifdef USE_MAEMO
2127
2128 #ifdef HILDON_HARDKEY_INCREASE
2129 case HILDON_HARDKEY_INCREASE:
2130 html_zoom(appdata, TRUE);
2131 handled = TRUE;
2132 break;
2133 #endif
2134
2135 #ifdef HILDON_HARDKEY_DECREASE
2136 case HILDON_HARDKEY_DECREASE:
2137 html_zoom(appdata, FALSE);
2138 handled = TRUE;
2139 break;
2140 #endif
2141
2142 #ifdef HILDON_HARDKEY_FULLSCREEN
2143 case HILDON_HARDKEY_FULLSCREEN:
2144 {
2145 appdata->fullscreen = !appdata->fullscreen;
2146
2147 if(appdata->fullscreen)
2148 gtk_window_fullscreen(GTK_WINDOW(appdata->window));
2149 else
2150 gtk_window_unfullscreen(GTK_WINDOW(appdata->window));
2151
2152 handled = TRUE;
2153 }
2154 break;
2155 #endif
2156
2157 #else
2158 case '+':
2159 printf("zoom+\n");
2160 html_zoom(appdata, TRUE);
2161 handled = TRUE;
2162 break;
2163 case '-':
2164 printf("zoom-\n");
2165 html_zoom(appdata, FALSE);
2166 handled = TRUE;
2167 break;
2168 #endif
2169 }
2170
2171 return handled;
2172 }
2173
2174 #if defined(USE_BREAD_CRUMB_TRAIL) || defined(BCT)
2175 typedef struct {
2176 int level;
2177 appdata_t *appdata;
2178 gpointer data;
2179 } crumb_t;
2180
2181 static void
2182 crumb_back(gpointer data) {
2183 crumb_t *crumb = (crumb_t*)data;
2184 printf("crumb_back called with %d\n", crumb->level);
2185
2186 /* don't do anything if main window has already been destroyed */
2187 if(!crumb->appdata->window) {
2188 printf("Main window gone ...\n");
2189 return;
2190 }
2191
2192 /* whatever is being displayed: we don't need it anymore */
2193 gtk_container_remove(GTK_CONTAINER(crumb->appdata->vbox),
2194 crumb->appdata->cur_view);
2195
2196 /* back from cache to cachelist */
2197 if(crumb->level == CRUMB_CACHE) {
2198 gpx_t *gpx = crumb->appdata->search_results;
2199
2200 if(!gpx) {
2201 gtk_widget_set_sensitive(crumb->appdata->menu_search, TRUE);
2202 gtk_widget_set_sensitive(crumb->appdata->menu_export, TRUE);
2203 printf("no search data found, return to gpx\n");
2204 gpx = crumb->appdata->cur_gpx;
2205 } else
2206 printf("returning to search result\n");
2207
2208 g_assert(gpx != NULL);
2209
2210 crumb->appdata->cur_view = cachelist_create(crumb->appdata, gpx,
2211 crumb->appdata->cur_cache);
2212
2213 /* returning from cache view: invalidate cache reference */
2214 crumb->appdata->cur_cache = NULL;
2215
2216 gtk_box_pack_start_defaults(GTK_BOX(crumb->appdata->vbox),
2217 crumb->appdata->cur_view);
2218 }
2219
2220 if(crumb->level == CRUMB_SEARCH_GPX) {
2221 printf("returning from a local search!\n");
2222
2223 g_assert((gpx_t*)crumb->data == crumb->appdata->search_results);
2224
2225 search_result_free((gpx_t*)crumb->data);
2226 crumb->appdata->search_results = NULL;
2227
2228 gtk_widget_set_sensitive(crumb->appdata->menu_search, TRUE);
2229
2230 crumb->appdata->cur_view = cachelist_create(crumb->appdata,
2231 crumb->appdata->cur_gpx, NULL);
2232 gtk_box_pack_start_defaults(GTK_BOX(crumb->appdata->vbox),
2233 crumb->appdata->cur_view);
2234 }
2235
2236 /* back from cachelist to gpxlist */
2237 if((crumb->level == CRUMB_CACHELIST) ||
2238 (crumb->level == CRUMB_SEARCH_GLOBAL)) {
2239
2240 crumb->appdata->cur_view = gpxlist_create_view_and_model(
2241 crumb->appdata, crumb->appdata->cur_gpx);
2242
2243 /* returning from cachelist/global search view: */
2244 /* invalidate gpx reference */
2245 crumb->appdata->cur_gpx = NULL;
2246
2247 gtk_box_pack_start_defaults(GTK_BOX(crumb->appdata->vbox),
2248 crumb->appdata->cur_view);
2249
2250 if((crumb->level == CRUMB_SEARCH_GLOBAL) ||
2251 (crumb->level == CRUMB_SEARCH_GPX)) {
2252 g_assert((gpx_t*)crumb->data == crumb->appdata->search_results);
2253
2254 search_result_free((gpx_t*)crumb->data);
2255 crumb->appdata->search_results = NULL;
2256 }
2257
2258 /* enable gpxlist related menu entries */
2259 gtk_widget_set_sensitive(crumb->appdata->menu_import, TRUE);
2260 gtk_widget_set_sensitive(crumb->appdata->menu_search, TRUE);
2261 gtk_widget_set_sensitive(crumb->appdata->menu_export, TRUE);
2262 }
2263
2264 gtk_widget_show_all(crumb->appdata->vbox);
2265 g_free(data);
2266
2267 #ifdef ENABLE_OSM_GPS_MAP
2268 map_update(crumb->appdata);
2269 #endif
2270 }
2271
2272 static void crumb_add(appdata_t *appdata, char *name, int level,
2273 gpointer user_data) {
2274 crumb_t *crumb = malloc(sizeof(crumb_t));
2275 crumb->level = level;
2276 crumb->appdata = appdata;
2277 crumb->data = user_data;
2278
2279 printf("crumb_add with level %d\n", level);
2280
2281 /* save that we are working on search results */
2282 if((level == CRUMB_SEARCH_GLOBAL) ||
2283 (level == CRUMB_SEARCH_GPX)) {
2284 appdata->search_results = (gpx_t*)user_data;
2285
2286 /* searches cannot be nested */
2287 gtk_widget_set_sensitive(appdata->menu_search, FALSE);
2288 }
2289
2290 /* save "path" pointers in appdata */
2291 if(crumb->level == CRUMB_CACHELIST)
2292 appdata->cur_gpx = (gpx_t*)user_data;
2293
2294 if(crumb->level == CRUMB_CACHE) {
2295 appdata->cur_cache = (cache_t*)user_data;
2296 /* the cache view cannot be searched */
2297 gtk_widget_set_sensitive(appdata->menu_search, FALSE);
2298 gtk_widget_set_sensitive(appdata->menu_export, FALSE);
2299 }
2300
2301 if(level != CRUMB_GPXLIST) {
2302 /* disable gpxlist related menu entries */
2303 gtk_widget_set_sensitive(appdata->menu_import, FALSE);
2304 #ifndef USE_PANNABLE_AREA
2305 gtk_widget_set_sensitive(appdata->menu_remove, FALSE);
2306 gtk_widget_set_sensitive(appdata->menu_close, FALSE);
2307 #endif
2308 }
2309
2310 #ifdef USE_BREAD_CRUMB_TRAIL
2311 hildon_bread_crumb_trail_push_text(HILDON_BREAD_CRUMB_TRAIL(appdata->bct),
2312 name, crumb, (GDestroyNotify)crumb_back);
2313 #else
2314 bct_push_text(appdata->bct, name, crumb, (GDestroyNotify)crumb_back);
2315 #endif
2316
2317 #ifdef ENABLE_OSM_GPS_MAP
2318 map_update(appdata);
2319 #endif
2320 }
2321 #endif // USE_BREAD_CRUMB_TRAIL
2322
2323 void main_after_settings_redraw(appdata_t *appdata, int flags) {
2324 printf("main after settings redraw\n");
2325
2326 if(!appdata->cur_view) {
2327 printf("no active view\n");
2328 return;
2329 }
2330
2331 /* a cache screen cannot be changed from the settings and thus doesn't */
2332 /* need to be redrawn */
2333 if(appdata->cur_cache) {
2334 printf("No redraw in cache view required\n");
2335 return;
2336 }
2337
2338 int redraw = 0; // nothing to redraw
2339
2340 if(appdata->search_results) {
2341 if((appdata->cur_items != appdata->cachelist_items) || flags)
2342 redraw = 1;
2343 } else {
2344 if(!appdata->cur_gpx) {
2345 if(appdata->cur_items != appdata->gpxlist_items)
2346 redraw = 2; // redraw gpxlist
2347 } else {
2348 if((appdata->cur_items != appdata->cachelist_items) || flags)
2349 redraw = 3; // redraw cachelist
2350 }
2351 }
2352
2353 if(redraw) {
2354 GtkWidget *container = appdata->vbox;
2355
2356 #ifdef USE_STACKABLE_WINDOW
2357 HildonWindowStack *stack = hildon_window_stack_get_default();
2358 container = hildon_window_stack_peek(stack);
2359 #endif
2360
2361 gtk_container_remove(GTK_CONTAINER(container), appdata->cur_view);
2362 switch(redraw) {
2363 case 1:
2364 appdata->cur_view = cachelist_create(appdata,
2365 appdata->search_results, NULL);
2366 break;
2367 case 2:
2368 appdata->cur_view = gpxlist_create_view_and_model(appdata, NULL);
2369 break;
2370 case 3:
2371 appdata->cur_view = cachelist_create(appdata,
2372 appdata->cur_gpx, NULL);
2373 break;
2374 }
2375
2376 #ifdef USE_STACKABLE_WINDOW
2377 if(container != appdata->vbox)
2378 gtk_container_add(GTK_CONTAINER(container), appdata->cur_view);
2379 else
2380 #endif
2381 gtk_box_pack_start_defaults(GTK_BOX(container), appdata->cur_view);
2382
2383 gtk_widget_show_all(container);
2384 }
2385 }
2386
2387 int main(int argc, char *argv[]) {
2388 appdata_t appdata;
2389
2390 /* init appdata */
2391 memset(&appdata, 0, sizeof(appdata));
2392
2393 printf("Using locale for %s in %s\n", PACKAGE, LOCALEDIR);
2394
2395 setlocale(LC_ALL, "");
2396 bindtextdomain(PACKAGE, LOCALEDIR);
2397 bind_textdomain_codeset(PACKAGE, "UTF-8");
2398 textdomain(PACKAGE);
2399
2400 /* prepare thread system */
2401 g_thread_init(NULL);
2402
2403 gtk_init (&argc, &argv);
2404
2405 curl_global_init(CURL_GLOBAL_ALL);
2406
2407 #ifdef USE_MAEMO
2408 printf("Installing osso context for \"org.harbaum." APP "\"\n");
2409 appdata.osso_context = osso_initialize("org.harbaum."APP,
2410 VERSION, TRUE, NULL);
2411 if(appdata.osso_context == NULL) {
2412 fprintf(stderr, "error initiating osso context\n");
2413 }
2414
2415 #ifdef ENABLE_MAEMO_MAPPER
2416 dbus_register(&appdata);
2417 #endif
2418 #endif
2419
2420 icons_init();
2421
2422 if(!gnome_vfs_init()) {
2423 g_error("Gnome VFS init failed\n");
2424 }
2425
2426 #ifdef USE_MAEMO
2427 /* Create the hildon program and setup the title */
2428 appdata.program = HILDON_PROGRAM(hildon_program_get_instance());
2429 g_set_application_name("GPXView");
2430
2431 /* Create HildonWindow and set it to HildonProgram */
2432 #ifdef USE_STACKABLE_WINDOW
2433 appdata.window = HILDON_WINDOW(hildon_stackable_window_new());
2434 #else
2435 appdata.window = HILDON_WINDOW(hildon_window_new());
2436 #endif
2437 hildon_program_add_window(appdata.program, appdata.window);
2438 #else
2439 /* Create a Window. */
2440 appdata.window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
2441 /* Set a decent default size for the window. */
2442 gtk_window_set_default_size(GTK_WINDOW(appdata.window), 640, 480);
2443 #endif
2444
2445 #if MAEMO_VERSION_MAJOR == 5
2446 gtk_window_set_title(GTK_WINDOW(appdata.window), "GPXView");
2447 #endif
2448
2449 g_signal_connect(G_OBJECT(appdata.window), "destroy",
2450 G_CALLBACK(on_window_destroy), &appdata);
2451
2452 g_signal_connect(G_OBJECT(appdata.window), "key_press_event",
2453 G_CALLBACK(on_window_key_press), &appdata);
2454
2455 /* prepare clipboard */
2456 appdata.clipboard = gtk_clipboard_get(GDK_SELECTION_CLIPBOARD);
2457 gtk_clipboard_set_can_store(appdata.clipboard, NULL, 0);
2458
2459 appdata.vbox = gtk_vbox_new(FALSE, 2);
2460 gtk_container_add(GTK_CONTAINER(appdata.window), appdata.vbox);
2461 #ifndef USE_STACKABLE_WINDOW
2462 menu_create(&appdata);
2463 #else
2464 hildon_window_set_app_menu(HILDON_WINDOW(appdata.window),
2465 menu_create(&appdata, MENU_GPXLIST));
2466 #endif
2467
2468 #ifdef USE_BREAD_CRUMB_TRAIL
2469 appdata.bct = hildon_bread_crumb_trail_new();
2470
2471 gtk_box_pack_start(GTK_BOX(appdata.vbox), appdata.bct, FALSE,FALSE,0);
2472
2473 hildon_bread_crumb_trail_clear(HILDON_BREAD_CRUMB_TRAIL(appdata.bct));
2474 #else
2475 #ifdef BCT
2476 /* on non-hildon machines we use some custom made breadcrumbtrail */
2477 /* replacement */
2478 appdata.bct = bct_new();
2479 gtk_box_pack_start(GTK_BOX(appdata.vbox), appdata.bct, FALSE,FALSE,0);
2480 #endif
2481 #endif
2482
2483 #if defined(USE_BREAD_CRUMB_TRAIL) || defined(BCT)
2484 crumb_add(&appdata, "GPX", CRUMB_GPXLIST, NULL);
2485 #endif
2486
2487 /* wait for main gui to appear */
2488 gtk_widget_show_all(GTK_WIDGET(appdata.window));
2489 while(gtk_events_pending())
2490 gtk_main_iteration();
2491
2492 appdata.gconf_client = gconf_client_get_default();
2493 gconf_load_state(&appdata);
2494 gps_init(&appdata);
2495
2496 appdata.cur_view = gpxlist_create_view_and_model(&appdata, NULL);
2497 gtk_box_pack_start_defaults(GTK_BOX(appdata.vbox), appdata.cur_view);
2498
2499 gtk_widget_show_all(GTK_WIDGET(appdata.window));
2500 gtk_main();
2501
2502 cleanup(&appdata);
2503
2504 return 0;
2505 }