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