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