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