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