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