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