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