Parent Directory | Revision Log
Stackable window control flow fixes
1 | harbaum | 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 | harbaum | 11 | dialog = gtk_file_chooser_dialog_new (whole_dir?_("Import directory"): |
124 | _("Import file"), | ||
125 | harbaum | 1 | 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 | harbaum | 11 | if(!appdata->cur_view) { |
268 | printf("cachelist redraw: no active view\n"); | ||
269 | return; | ||
270 | } | ||
271 | |||
272 | harbaum | 1 | 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 | harbaum | 11 | 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 | harbaum | 1 | 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 | harbaum | 11 | #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 | harbaum | 1 | } |
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 | harbaum | 11 | if(appdata->cur_cache) |
324 | return TRUE; | ||
325 | |||
326 | harbaum | 1 | 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 | harbaum | 11 | printf("cachelist timer reset\n"); |
339 | harbaum | 1 | 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 | harbaum | 11 | 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 | harbaum | 1 | void cachelist_dialog(appdata_t *appdata, gpx_t *gpx) { |
584 | GtkWidget *window = hildon_stackable_window_new(); | ||
585 | |||
586 | harbaum | 11 | /* store last "cur_view" in window */ |
587 | g_object_set_data(G_OBJECT(window), "cur_view", appdata->cur_view); | ||
588 | harbaum | 1 | |
589 | harbaum | 11 | 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 | harbaum | 1 | |
594 | harbaum | 11 | appdata->cur_view = cachelist_create(appdata, gpx, NULL); |
595 | gtk_container_add(GTK_CONTAINER(window), appdata->cur_view); | ||
596 | |||
597 | |||
598 | harbaum | 3 | hildon_window_set_app_menu(HILDON_WINDOW(window), |
599 | menu_create(appdata, MENU_CACHELIST)); | ||
600 | |||
601 | harbaum | 11 | g_signal_connect(G_OBJECT(window), "destroy", |
602 | G_CALLBACK(on_cachelist_destroy), appdata); | ||
603 | |||
604 | harbaum | 1 | 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 | harbaum | 11 | if(!appdata->cur_gpx) |
815 | cachelist_dialog(appdata, gpx); | ||
816 | else | ||
817 | printf("selected gpx, but cachelist window already present\n"); | ||
818 | harbaum | 1 | #else |
819 | gtk_container_remove(GTK_CONTAINER(appdata->vbox), appdata->cur_view); | ||
820 | appdata->cur_view = cachelist_create(appdata, gpx, NULL); | ||
821 | gtk_box_pack_start_defaults(GTK_BOX(appdata->vbox), appdata->cur_view); | ||
822 | gtk_widget_show_all(appdata->vbox); | ||
823 | |||
824 | crumb_add(appdata, gpx->name, CRUMB_CACHELIST, gpx); | ||
825 | #endif | ||
826 | } | ||
827 | } | ||
828 | } | ||
829 | |||
830 | #ifndef USE_PANNABLE_AREA | ||
831 | static gboolean | ||
832 | view_selection_func(GtkTreeSelection *selection, GtkTreeModel *model, | ||
833 | GtkTreePath *path, gboolean path_currently_selected, | ||
834 | gpointer userdata) { | ||
835 | appdata_t *appdata = (appdata_t*)userdata; | ||
836 | GtkTreeIter iter; | ||
837 | |||
838 | if(gtk_tree_model_get_iter(model, &iter, path)) { | ||
839 | gpx_t *gpx; | ||
840 | gtk_tree_model_get(model, &iter, GPXLIST_COL_DATA, &gpx, -1); | ||
841 | |||
842 | gtk_widget_set_sensitive(appdata->menu_remove, !path_currently_selected); | ||
843 | |||
844 | if(!gpx->closed) | ||
845 | gtk_widget_set_sensitive(appdata->menu_close, !path_currently_selected); | ||
846 | } | ||
847 | |||
848 | return TRUE; /* allow selection state to change */ | ||
849 | } | ||
850 | #endif | ||
851 | |||
852 | static GtkWidget *gpxlist_create_view_and_model(appdata_t *appdata, | ||
853 | gpx_t *sel_gpx) { | ||
854 | gpx_t *gpx = appdata->gpx; | ||
855 | GtkCellRenderer *renderer; | ||
856 | |||
857 | /* saved displayed items */ | ||
858 | appdata->cur_items = appdata->gpxlist_items; | ||
859 | |||
860 | #ifndef USE_PANNABLE_AREA | ||
861 | /* nothing selected yet */ | ||
862 | gtk_widget_set_sensitive(appdata->menu_remove, FALSE); | ||
863 | gtk_widget_set_sensitive(appdata->menu_close, FALSE); | ||
864 | #endif | ||
865 | |||
866 | appdata->gpxview = gtk_tree_view_new (); | ||
867 | |||
868 | GtkTreeSelection *selection = | ||
869 | gtk_tree_view_get_selection(GTK_TREE_VIEW(appdata->gpxview)); | ||
870 | #ifndef USE_PANNABLE_AREA | ||
871 | gtk_tree_selection_set_select_function(selection, view_selection_func, | ||
872 | appdata, NULL); | ||
873 | #endif | ||
874 | |||
875 | /* --- "Icon" column --- */ | ||
876 | renderer = gtk_cell_renderer_pixbuf_new(); | ||
877 | gtk_tree_view_insert_column_with_attributes(GTK_TREE_VIEW(appdata->gpxview), | ||
878 | -1, "Icon", renderer, | ||
879 | "pixbuf", GPXLIST_COL_ICON, | ||
880 | // "sensitive", GPXLIST_COL_OPEN, | ||
881 | NULL); | ||
882 | |||
883 | /* --- "FileName" column --- */ | ||
884 | if(appdata->gpxlist_items & GPXLIST_ITEM_FILENAME) { | ||
885 | renderer = gtk_cell_renderer_text_new(); | ||
886 | gtk_tree_view_insert_column_with_attributes( | ||
887 | GTK_TREE_VIEW(appdata->gpxview), | ||
888 | -1, "Filename", renderer, | ||
889 | "text", GPXLIST_COL_FILENAME, | ||
890 | "sensitive", GPXLIST_COL_OPEN, | ||
891 | NULL); | ||
892 | } | ||
893 | |||
894 | /* --- "Name" column --- */ | ||
895 | renderer = gtk_cell_renderer_text_new(); | ||
896 | g_object_set(renderer, "ellipsize", PANGO_ELLIPSIZE_END, NULL ); | ||
897 | |||
898 | GtkTreeViewColumn *column = gtk_tree_view_column_new_with_attributes( | ||
899 | "Name", renderer, | ||
900 | "text", GPXLIST_COL_NAME, | ||
901 | "sensitive", GPXLIST_COL_OPEN, | ||
902 | NULL); | ||
903 | gtk_tree_view_column_set_expand(column, TRUE); | ||
904 | gtk_tree_view_insert_column(GTK_TREE_VIEW(appdata->gpxview), column, -1); | ||
905 | |||
906 | /* --- "Date" column --- */ | ||
907 | if(appdata->gpxlist_items & GPXLIST_ITEM_DATE) { | ||
908 | renderer = gtk_cell_renderer_text_new(); | ||
909 | g_object_set(renderer, "xalign", 1.0, NULL ); | ||
910 | gtk_tree_view_insert_column_with_attributes( | ||
911 | GTK_TREE_VIEW(appdata->gpxview), | ||
912 | -1, "Date", renderer, | ||
913 | "text", GPXLIST_COL_DATE, | ||
914 | "sensitive", GPXLIST_COL_OPEN, | ||
915 | NULL); | ||
916 | } | ||
917 | |||
918 | /* --- "Number of caches" column --- */ | ||
919 | if(appdata->gpxlist_items & GPXLIST_ITEM_CNUM) { | ||
920 | renderer = gtk_cell_renderer_text_new(); | ||
921 | g_object_set(renderer, "xalign", 1.0, NULL ); | ||
922 | gtk_tree_view_insert_column_with_attributes( | ||
923 | GTK_TREE_VIEW(appdata->gpxview), | ||
924 | -1, "#Caches", renderer, | ||
925 | "text", GPXLIST_COL_CACHES, | ||
926 | "sensitive", GPXLIST_COL_OPEN, | ||
927 | NULL); | ||
928 | } | ||
929 | |||
930 | #ifdef USE_PANNABLE_AREA | ||
931 | /* --- "Delete" column --- */ | ||
932 | renderer = gtk_cell_renderer_pixbuf_new(); | ||
933 | gtk_tree_view_insert_column_with_attributes(GTK_TREE_VIEW(appdata->gpxview), | ||
934 | -1, "Del", renderer, | ||
935 | "pixbuf", GPXLIST_COL_DELETE, | ||
936 | "sensitive", GPXLIST_COL_OPEN, | ||
937 | NULL); | ||
938 | #endif | ||
939 | |||
940 | /* build and fill the store */ | ||
941 | appdata->gpxstore = gtk_list_store_new(GPXLIST_NUM_COLS, GDK_TYPE_PIXBUF, | ||
942 | G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, | ||
943 | G_TYPE_STRING, G_TYPE_BOOLEAN, | ||
944 | #ifdef USE_PANNABLE_AREA | ||
945 | GDK_TYPE_PIXBUF, | ||
946 | #endif | ||
947 | G_TYPE_POINTER); | ||
948 | |||
949 | GtkTreePath *path = NULL; | ||
950 | GtkTreeIter sel_iter; | ||
951 | gboolean sel_iter_valid = FALSE; | ||
952 | while(gpx) { | ||
953 | GtkTreeIter iter; | ||
954 | gtk_list_store_append(appdata->gpxstore, &iter); | ||
955 | gpxlist_set(appdata->gpxstore, &iter, gpx); | ||
956 | |||
957 | if(gpx == sel_gpx) { | ||
958 | sel_iter = iter; | ||
959 | sel_iter_valid = TRUE; | ||
960 | } | ||
961 | |||
962 | gpx = gpx->next; | ||
963 | } | ||
964 | |||
965 | gtk_tree_view_set_model(GTK_TREE_VIEW(appdata->gpxview), | ||
966 | GTK_TREE_MODEL(appdata->gpxstore)); | ||
967 | |||
968 | g_object_unref(appdata->gpxstore); | ||
969 | |||
970 | if(sel_iter_valid) { | ||
971 | gtk_tree_selection_select_iter(selection, &sel_iter); | ||
972 | path = gtk_tree_model_get_path(GTK_TREE_MODEL(appdata->gpxstore), | ||
973 | &sel_iter); | ||
974 | gtk_tree_view_scroll_to_cell(GTK_TREE_VIEW(appdata->gpxview), | ||
975 | path, NULL, TRUE, 0.0, 0.0); | ||
976 | gtk_tree_path_free(path); | ||
977 | } | ||
978 | |||
979 | /* make list react on clicks */ | ||
980 | g_signal_connect(appdata->gpxview, "row-activated", | ||
981 | (GCallback)gpxlist_view_onRowActivated, appdata); | ||
982 | |||
983 | /* put this inside a scrolled view */ | ||
984 | #ifndef USE_PANNABLE_AREA | ||
985 | GtkWidget *scrolled_window = gtk_scrolled_window_new(NULL, NULL); | ||
986 | gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolled_window), | ||
987 | GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC); | ||
988 | gtk_container_add(GTK_CONTAINER(scrolled_window), appdata->gpxview); | ||
989 | |||
990 | return scrolled_window; | ||
991 | #else | ||
992 | GtkWidget *pannable_area = hildon_pannable_area_new(); | ||
993 | gtk_container_add(GTK_CONTAINER(pannable_area), appdata->gpxview); | ||
994 | |||
995 | return pannable_area; | ||
996 | #endif | ||
997 | } | ||
998 | |||
999 | /* add last entry in gpx list to visual representation */ | ||
1000 | static void gpxlist_add(appdata_t *appdata, gpx_t *new) { | ||
1001 | GtkTreeIter iter; | ||
1002 | |||
1003 | gtk_list_store_append(appdata->gpxstore, &iter); | ||
1004 | gpxlist_set(appdata->gpxstore, &iter, new); | ||
1005 | |||
1006 | /* and attach entry to end of list */ | ||
1007 | gpx_t **gpx = &appdata->gpx; | ||
1008 | while(*gpx) gpx = &((*gpx)->next); | ||
1009 | *gpx = new; | ||
1010 | } | ||
1011 | |||
1012 | /******************** end of gpxlist ********************/ | ||
1013 | |||
1014 | /******************** begin of menu *********************/ | ||
1015 | |||
1016 | static void | ||
1017 | cb_menu_about(GtkWidget *window, gpointer data) { | ||
1018 | GtkAboutDialog *about = GTK_ABOUT_DIALOG(gtk_about_dialog_new()); | ||
1019 | |||
1020 | gtk_about_dialog_set_name(about, "GPXView"); | ||
1021 | gtk_about_dialog_set_version(about, VERSION); | ||
1022 | gtk_about_dialog_set_copyright(about, | ||
1023 | _("GPXView (c) 2008 by\n" | ||
1024 | "Till Harbaum <till@harbaum.org>\n" | ||
1025 | "Geocaching.com: Tantil")); | ||
1026 | |||
1027 | gtk_about_dialog_set_website(about, | ||
1028 | _("http://www.harbaum.org/till/maemo")); | ||
1029 | |||
1030 | gtk_about_dialog_set_comments(about, | ||
1031 | _("Geocaching.com GPX file viewer")); | ||
1032 | |||
1033 | gtk_widget_show_all(GTK_WIDGET(about)); | ||
1034 | gtk_dialog_run(GTK_DIALOG(about)); | ||
1035 | gtk_widget_destroy(GTK_WIDGET(about)); | ||
1036 | } | ||
1037 | |||
1038 | #if defined(USE_MAEMO) && defined(HILDON_HELP) | ||
1039 | static void | ||
1040 | cb_menu_help(GtkWidget *window, gpointer data) { | ||
1041 | appdata_t *appdata = (appdata_t*)data; | ||
1042 | |||
1043 | hildon_help_show(appdata->osso_context, HELP_ID_INTRO, 0); | ||
1044 | } | ||
1045 | #endif | ||
1046 | |||
1047 | static void | ||
1048 | cb_menu_add(GtkWidget *window, gpointer data) { | ||
1049 | appdata_t *appdata = (appdata_t *)data; | ||
1050 | |||
1051 | gpx_t *new = choose_file(appdata, FALSE); | ||
1052 | if(new) gpxlist_add(appdata, new); | ||
1053 | } | ||
1054 | |||
1055 | static void | ||
1056 | cb_menu_adddir(GtkWidget *window, gpointer data) { | ||
1057 | appdata_t *appdata = (appdata_t *)data; | ||
1058 | |||
1059 | gpx_t *new = choose_file(appdata, TRUE); | ||
1060 | if(new) gpxlist_add(appdata, new); | ||
1061 | } | ||
1062 | |||
1063 | #ifndef USE_PANNABLE_AREA | ||
1064 | static void | ||
1065 | cb_menu_close(GtkWidget *window, gpointer data) { | ||
1066 | appdata_t *appdata = (appdata_t *)data; | ||
1067 | GtkTreeSelection *selection; | ||
1068 | GtkTreeModel *model; | ||
1069 | GtkTreeIter iter; | ||
1070 | |||
1071 | printf("selected close\n"); | ||
1072 | |||
1073 | /* the entry cannot be closed again */ | ||
1074 | gtk_widget_set_sensitive(appdata->menu_close, FALSE); | ||
1075 | |||
1076 | selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(appdata->gpxview)); | ||
1077 | |||
1078 | printf("gpxlist close\n"); | ||
1079 | |||
1080 | if (gtk_tree_selection_get_selected(selection, &model, &iter)) { | ||
1081 | gpx_t *gpx = NULL; | ||
1082 | gtk_tree_model_get(model, &iter, GPXLIST_COL_DATA, &gpx, -1); | ||
1083 | |||
1084 | if(gpx) gpxlist_close(appdata, GTK_LIST_STORE(model), &iter, gpx); | ||
1085 | } else { | ||
1086 | g_print ("no row selected.\n"); | ||
1087 | } | ||
1088 | } | ||
1089 | |||
1090 | static void | ||
1091 | cb_menu_remove(GtkWidget *window, gpointer data) { | ||
1092 | appdata_t *appdata = (appdata_t *)data; | ||
1093 | |||
1094 | /* disable menu item */ | ||
1095 | gtk_widget_set_sensitive(appdata->menu_remove, FALSE); | ||
1096 | gtk_widget_set_sensitive(appdata->menu_close, FALSE); | ||
1097 | |||
1098 | GtkTreeModel *model; | ||
1099 | GtkTreeIter iter; | ||
1100 | GtkTreeSelection *selection = | ||
1101 | gtk_tree_view_get_selection(GTK_TREE_VIEW(appdata->gpxview)); | ||
1102 | |||
1103 | printf("gpxlist remove\n"); | ||
1104 | |||
1105 | if(gtk_tree_selection_get_selected(selection, &model, &iter)) { | ||
1106 | gpx_t *gpx = NULL; | ||
1107 | gtk_tree_model_get(model, &iter, GPXLIST_COL_DATA, &gpx, -1); | ||
1108 | |||
1109 | if(gpx) gpxlist_remove(appdata, GTK_LIST_STORE(model), &iter, gpx); | ||
1110 | } else { | ||
1111 | g_print ("no row selected.\n"); | ||
1112 | } | ||
1113 | } | ||
1114 | |||
1115 | #endif // !USE_PANNABLE_AREA | ||
1116 | |||
1117 | static void search_result_free(gpx_t *result) { | ||
1118 | printf("freeing search results\n"); | ||
1119 | |||
1120 | /* free found chain */ | ||
1121 | cache_t *cache = result->cache; | ||
1122 | while(cache) { | ||
1123 | cache_t *next = cache->next; | ||
1124 | free(cache); | ||
1125 | cache = next; | ||
1126 | } | ||
1127 | free(result->name); | ||
1128 | free(result); | ||
1129 | } | ||
1130 | |||
1131 | #define MAX_HITS 50 | ||
1132 | |||
1133 | static time_t localize_time(time_t in) { | ||
1134 | time_t ret; | ||
1135 | char *tz; | ||
1136 | struct tm *tm = localtime(&in); | ||
1137 | |||
1138 | tz = getenv("TZ"); | ||
1139 | setenv("TZ", "", 1); | ||
1140 | tzset(); | ||
1141 | ret = mktime(tm); | ||
1142 | if (tz) | ||
1143 | setenv("TZ", tz, 1); | ||
1144 | else | ||
1145 | unsetenv("TZ"); | ||
1146 | tzset(); | ||
1147 | return ret; | ||
1148 | } | ||
1149 | |||
1150 | static int days_ago(time_t in) { | ||
1151 | int day_in = localize_time(in) / (60*60*24); | ||
1152 | int day_now = localize_time(time(NULL)) / (60*60*24); | ||
1153 | |||
1154 | return day_now - day_in; | ||
1155 | } | ||
1156 | |||
1157 | gpx_t *search_do(appdata_t *appdata, gpx_t *gpx, char *phrase, | ||
1158 | int what, gboolean local) { | ||
1159 | /* walk through all caches */ | ||
1160 | |||
1161 | int hits = 0; | ||
1162 | gpx_t *found = malloc(sizeof(gpx_t)); | ||
1163 | memset(found, 0, sizeof(gpx_t)); | ||
1164 | cache_t **cacheP = &(found->cache); | ||
1165 | |||
1166 | if(what & SEARCH_FINDS) { | ||
1167 | time_t loc_now = localize_time(time(NULL)); | ||
1168 | printf("now: %ld days since 1/1/1970, days hour is %ld\n", | ||
1169 | loc_now/(60*60*24), loc_now%(60*60*24)/(60*60)); | ||
1170 | } | ||
1171 | |||
1172 | while(gpx && hits < MAX_HITS) { | ||
1173 | |||
1174 | /* we need all notes ... */ | ||
1175 | if(what & SEARCH_FINDS) { | ||
1176 | notes_load_all(appdata, gpx); | ||
1177 | gpx->notes_loaded = TRUE; | ||
1178 | } | ||
1179 | |||
1180 | cache_t *cache = gpx->cache; | ||
1181 | |||
1182 | while(cache && hits < MAX_HITS) { | ||
1183 | gboolean hit = FALSE; | ||
1184 | |||
1185 | if(what & SEARCH_FINDS) { | ||
1186 | if(cache->notes && cache->notes->found ) { | ||
1187 | int days = days_ago(cache->notes->ftime); | ||
1188 | |||
1189 | if(cache->id) | ||
1190 | printf("find of %s is %d days ago\n", cache->id, days); | ||
1191 | |||
1192 | if(days <= appdata->search_days) | ||
1193 | hit = 1; | ||
1194 | } | ||
1195 | } else if(cache->id && (what & SEARCH_ID) && | ||
1196 | strcasestr(cache->id, phrase)) | ||
1197 | hit = 1; | ||
1198 | else if(cache->name && (what & SEARCH_NAME) && | ||
1199 | strcasestr(cache->name, phrase)) | ||
1200 | hit = 1; | ||
1201 | else if(cache->short_description && (what & SEARCH_DESC) && | ||
1202 | strcasestr(cache->short_description, phrase)) | ||
1203 | hit = 1; | ||
1204 | else if(cache->long_description && (what & SEARCH_DESC) && | ||
1205 | strcasestr(cache->long_description, phrase)) | ||
1206 | hit = 1; | ||
1207 | else if(cache->owner && (what & SEARCH_OWNER) && | ||
1208 | strcasestr(cache->owner, phrase)) | ||
1209 | hit = 1; | ||
1210 | |||
1211 | if(hit) { | ||
1212 | /* chain a copy of this cache structure into the found list */ | ||
1213 | *cacheP = malloc(sizeof(cache_t)); | ||
1214 | memcpy(*cacheP, cache, sizeof(cache_t)); | ||
1215 | (*cacheP)->next = NULL; | ||
1216 | cacheP = &((*cacheP)->next); | ||
1217 | hits++; | ||
1218 | } | ||
1219 | cache = cache->next; | ||
1220 | } | ||
1221 | |||
1222 | if(!local) gpx = gpx->next; | ||
1223 | else gpx = NULL; /* local search within one gpx only */ | ||
1224 | } | ||
1225 | |||
1226 | found->name = strdup(_("Search results")); | ||
1227 | |||
1228 | return found; | ||
1229 | } | ||
1230 | |||
1231 | typedef struct { | ||
1232 | appdata_t *appdata; | ||
1233 | GtkWidget *entry, *spinner; | ||
1234 | GtkWidget *in_id, *in_name, *in_desc, *in_owner, *in_finds; | ||
1235 | } search_context_t; | ||
1236 | |||
1237 | static void callback_finds_toggled(GtkWidget *widget, gpointer data ) { | ||
1238 | search_context_t *context = (search_context_t*)data; | ||
1239 | |||
1240 | gboolean in_finds = gtk_toggle_button_get_active( | ||
1241 | GTK_TOGGLE_BUTTON(context->in_finds)); | ||
1242 | |||
1243 | gtk_widget_set_sensitive(context->entry, !in_finds); | ||
1244 | gtk_widget_set_sensitive(context->in_id, !in_finds); | ||
1245 | gtk_widget_set_sensitive(context->in_name, !in_finds); | ||
1246 | gtk_widget_set_sensitive(context->in_desc, !in_finds); | ||
1247 | gtk_widget_set_sensitive(context->in_owner, !in_finds); | ||
1248 | gtk_widget_set_sensitive(context->spinner, in_finds); | ||
1249 | } | ||
1250 | |||
1251 | static void | ||
1252 | cb_menu_search(GtkWidget *window, gpointer data) { | ||
1253 | appdata_t *appdata = (appdata_t *)data; | ||
1254 | |||
1255 | search_context_t context; | ||
1256 | memset(&context, 0, sizeof(search_context_t)); | ||
1257 | context.appdata = appdata; | ||
1258 | |||
1259 | GtkWidget *dialog = gtk_dialog_new_with_buttons(_("Enter search phrase"), | ||
1260 | GTK_WINDOW(appdata->window), GTK_DIALOG_MODAL, | ||
1261 | GTK_STOCK_OK, GTK_RESPONSE_ACCEPT, | ||
1262 | GTK_STOCK_CANCEL, GTK_RESPONSE_REJECT, | ||
1263 | NULL); | ||
1264 | |||
1265 | gtk_box_pack_start_defaults(GTK_BOX(GTK_DIALOG(dialog)->vbox), | ||
1266 | gtk_label_new(_("Search in:"))); | ||
1267 | |||
1268 | GtkWidget *table = gtk_table_new(2, 2, TRUE); | ||
1269 | gtk_table_set_col_spacing(GTK_TABLE(table), 0, 8); | ||
1270 | |||
1271 | context.in_id = gtk_check_button_new_with_label(_("Waypoint IDs")); | ||
1272 | gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(context.in_id), | ||
1273 | appdata->search & SEARCH_ID); | ||
1274 | gtk_table_attach_defaults(GTK_TABLE(table), context.in_id, 0, 1, 0, 1); | ||
1275 | |||
1276 | context.in_name = gtk_check_button_new_with_label(_("Names")); | ||
1277 | gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(context.in_name), | ||
1278 | appdata->search & SEARCH_NAME); | ||
1279 | gtk_table_attach_defaults(GTK_TABLE(table), context.in_name, 1, 2, 0, 1); | ||
1280 | |||
1281 | context.in_desc = gtk_check_button_new_with_label(_("Descriptions")); | ||
1282 | gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(context.in_desc), | ||
1283 | appdata->search & SEARCH_DESC); | ||
1284 | gtk_table_attach_defaults(GTK_TABLE(table), context.in_desc, 0, 1, 1, 2); | ||
1285 | |||
1286 | context.in_owner = gtk_check_button_new_with_label(_("Owner")); | ||
1287 | gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(context.in_owner), | ||
1288 | appdata->search & SEARCH_OWNER); | ||
1289 | gtk_table_attach_defaults(GTK_TABLE(table), context.in_owner, 1, 2, 1, 2); | ||
1290 | |||
1291 | gtk_box_pack_start_defaults(GTK_BOX(GTK_DIALOG(dialog)->vbox), table); | ||
1292 | |||
1293 | /* -------------------------------------------------------------- */ | ||
1294 | |||
1295 | gtk_box_pack_start_defaults(GTK_BOX(GTK_DIALOG(dialog)->vbox), | ||
1296 | gtk_label_new(_("Search for:"))); | ||
1297 | gtk_box_pack_start_defaults(GTK_BOX(GTK_DIALOG(dialog)->vbox), | ||
1298 | context.entry = gtk_entry_new()); | ||
1299 | if(appdata->search_str) | ||
1300 | gtk_entry_set_text(GTK_ENTRY(context.entry), appdata->search_str); | ||
1301 | |||
1302 | /* -------------------------------------------------------------- */ | ||
1303 | |||
1304 | gtk_box_pack_start_defaults(GTK_BOX(GTK_DIALOG(dialog)->vbox), | ||
1305 | gtk_hseparator_new()); | ||
1306 | |||
1307 | GtkWidget *hbox = gtk_hbox_new(FALSE, 5); | ||
1308 | |||
1309 | context.in_finds = gtk_check_button_new_with_label(_("Search finds for")); | ||
1310 | gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(context.in_finds), | ||
1311 | appdata->search & SEARCH_FINDS); | ||
1312 | gtk_box_pack_start_defaults(GTK_BOX(hbox), context.in_finds); | ||
1313 | g_signal_connect(G_OBJECT(context.in_finds), "toggled", | ||
1314 | G_CALLBACK(callback_finds_toggled), &context); | ||
1315 | |||
1316 | #ifndef USE_MAEMO | ||
1317 | GtkObject *adj = gtk_adjustment_new(appdata->search_days, 0, 99, 1, 10, 10); | ||
1318 | context.spinner = gtk_spin_button_new(GTK_ADJUSTMENT(adj), 1, 0); | ||
1319 | #else | ||
1320 | context.spinner = hildon_number_editor_new(0, 99); | ||
1321 | hildon_number_editor_set_value(HILDON_NUMBER_EDITOR(context.spinner), | ||
1322 | appdata->search_days); | ||
1323 | #endif | ||
1324 | gtk_box_pack_start_defaults(GTK_BOX(hbox), context.spinner); | ||
1325 | |||
1326 | gtk_box_pack_start_defaults(GTK_BOX(hbox), gtk_label_new(_("days"))); | ||
1327 | |||
1328 | gtk_box_pack_start_defaults(GTK_BOX(GTK_DIALOG(dialog)->vbox), hbox); | ||
1329 | |||
1330 | /* -------------------------------------------------------------- */ | ||
1331 | |||
1332 | gtk_widget_show_all(dialog); | ||
1333 | callback_finds_toggled(NULL, &context); | ||
1334 | |||
1335 | if(GTK_RESPONSE_ACCEPT == gtk_dialog_run(GTK_DIALOG(dialog))) { | ||
1336 | char *p = strdup(gtk_entry_get_text(GTK_ENTRY(context.entry))); | ||
1337 | |||
1338 | /* update saved search string */ | ||
1339 | if(appdata->search_str) free(appdata->search_str); | ||
1340 | if(strlen(p) > 0) | ||
1341 | appdata->search_str = strdup(p); | ||
1342 | |||
1343 | #ifndef USE_MAEMO | ||
1344 | appdata->search_days = gtk_spin_button_get_value_as_int( | ||
1345 | GTK_SPIN_BUTTON(context.spinner)); | ||
1346 | #else | ||
1347 | appdata->search_days = hildon_number_editor_get_value( | ||
1348 | HILDON_NUMBER_EDITOR(context.spinner)); | ||
1349 | #endif | ||
1350 | |||
1351 | if(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(context.in_finds))) | ||
1352 | appdata->search |= SEARCH_FINDS; | ||
1353 | else | ||
1354 | appdata->search &= ~SEARCH_FINDS; | ||
1355 | |||
1356 | if(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(context.in_id))) | ||
1357 | appdata->search |= SEARCH_ID; | ||
1358 | else | ||
1359 | appdata->search &= ~SEARCH_ID; | ||
1360 | |||
1361 | if(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(context.in_name))) | ||
1362 | appdata->search |= SEARCH_NAME; | ||
1363 | else | ||
1364 | appdata->search &= ~SEARCH_NAME; | ||
1365 | |||
1366 | if(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(context.in_desc))) | ||
1367 | appdata->search |= SEARCH_DESC; | ||
1368 | else | ||
1369 | appdata->search &= ~SEARCH_DESC; | ||
1370 | |||
1371 | if(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(context.in_owner))) | ||
1372 | appdata->search |= SEARCH_OWNER; | ||
1373 | else | ||
1374 | appdata->search &= ~SEARCH_OWNER; | ||
1375 | |||
1376 | gtk_widget_destroy(dialog); | ||
1377 | |||
1378 | /* don't search if we are asked to search for nothing */ | ||
1379 | if(((appdata->search & (SEARCH_ID|SEARCH_NAME|SEARCH_DESC|SEARCH_OWNER)) && | ||
1380 | strlen(p) > 0) || (appdata->search & SEARCH_FINDS)) { | ||
1381 | |||
1382 | printf("Search for %s (flags = %x)...\n", p, appdata->search); | ||
1383 | |||
1384 | #ifndef USE_BREAD_CRUMB_TRAIL | ||
1385 | harbaum | 11 | appdata->search_results = |
1386 | search_do(appdata, appdata->gpx, p, appdata->search, FALSE); | ||
1387 | harbaum | 1 | |
1388 | /* do search result dialog here ... */ | ||
1389 | harbaum | 11 | cachelist_dialog(appdata, appdata->search_results); |
1390 | #ifndef USE_STACKABLE_WINDOW | ||
1391 | search_result_free(appdata->search_results); | ||
1392 | appdata->search_results = NULL; | ||
1393 | #endif | ||
1394 | harbaum | 1 | #else |
1395 | harbaum | 11 | gpx_t *found = NULL; |
1396 | |||
1397 | harbaum | 1 | if(appdata->cur_gpx) |
1398 | found = search_do(appdata, appdata->cur_gpx, p, appdata->search, TRUE); | ||
1399 | else | ||
1400 | found = search_do(appdata, appdata->gpx, p, appdata->search, FALSE); | ||
1401 | |||
1402 | gtk_container_remove(GTK_CONTAINER(appdata->vbox), appdata->cur_view); | ||
1403 | appdata->cur_view = cachelist_create(appdata, found, NULL); | ||
1404 | gtk_box_pack_start_defaults(GTK_BOX(appdata->vbox), appdata->cur_view); | ||
1405 | gtk_widget_show_all(appdata->vbox); | ||
1406 | crumb_add(appdata, found->name, | ||
1407 | appdata->cur_gpx?CRUMB_SEARCH_GPX:CRUMB_SEARCH_GLOBAL, found); | ||
1408 | #endif | ||
1409 | } else | ||
1410 | printf("No valid search: \"%s\" with flags %x!\n", p, appdata->search); | ||
1411 | |||
1412 | free(p); | ||
1413 | } else | ||
1414 | gtk_widget_destroy(dialog); | ||
1415 | } | ||
1416 | |||
1417 | void on_window_destroy (GtkWidget *widget, gpointer data); | ||
1418 | |||
1419 | #ifndef USE_MAEMO | ||
1420 | static void | ||
1421 | cb_menu_quit(GtkWidget *window, gpointer data) { | ||
1422 | on_window_destroy(window, data); | ||
1423 | } | ||
1424 | #endif | ||
1425 | |||
1426 | harbaum | 2 | #ifndef NO_COPY_N_PASTE |
1427 | harbaum | 1 | static void |
1428 | cb_menu_cut(GtkWidget *widget, gpointer data) { | ||
1429 | appdata_t *appdata = (appdata_t*)data; | ||
1430 | |||
1431 | if(appdata->active_buffer) { | ||
1432 | if(GTK_WIDGET_TYPE(appdata->active_buffer) == GTK_TYPE_TEXT_BUFFER) { | ||
1433 | gtk_text_buffer_cut_clipboard(GTK_TEXT_BUFFER(appdata->active_buffer), | ||
1434 | appdata->clipboard, TRUE); | ||
1435 | } else | ||
1436 | printf("cut: ERROR, not a text buffer\n"); | ||
1437 | } else | ||
1438 | printf("cut: ERROR, no active buffer\n"); | ||
1439 | } | ||
1440 | |||
1441 | static void | ||
1442 | cb_menu_copy(GtkWidget *widget, gpointer data) { | ||
1443 | appdata_t *appdata = (appdata_t*)data; | ||
1444 | |||
1445 | if(appdata->active_buffer) { | ||
1446 | if(GTK_WIDGET_TYPE(appdata->active_buffer) == GTK_TYPE_TEXT_BUFFER) { | ||
1447 | gtk_text_buffer_copy_clipboard(GTK_TEXT_BUFFER(appdata->active_buffer), | ||
1448 | appdata->clipboard); | ||
1449 | } else if(GTK_WIDGET_TYPE(appdata->active_buffer) == gtk_html_get_type()) { | ||
1450 | printf("copy from html buffer\n"); | ||
1451 | html_copy_to_clipboard(appdata); | ||
1452 | } else | ||
1453 | printf("copy: ERROR, not a text nor a html buffer\n"); | ||
1454 | } else | ||
1455 | printf("copy: ERROR, no active buffer\n"); | ||
1456 | } | ||
1457 | |||
1458 | static void | ||
1459 | cb_menu_paste(GtkWidget *widget, gpointer data) { | ||
1460 | appdata_t *appdata = (appdata_t*)data; | ||
1461 | |||
1462 | if(appdata->active_buffer) { | ||
1463 | if(GTK_WIDGET_TYPE(appdata->active_buffer) == GTK_TYPE_TEXT_BUFFER) { | ||
1464 | gtk_text_buffer_paste_clipboard(GTK_TEXT_BUFFER(appdata->active_buffer), | ||
1465 | appdata->clipboard, NULL, TRUE); | ||
1466 | } else | ||
1467 | printf("paste: ERROR, not a text buffer\n"); | ||
1468 | } else | ||
1469 | printf("paste: ERROR, no active buffer\n"); | ||
1470 | } | ||
1471 | harbaum | 2 | #endif |
1472 | harbaum | 1 | |
1473 | harbaum | 6 | static void |
1474 | cb_menu_export_log(GtkWidget *widget, gpointer data) { | ||
1475 | appdata_t *appdata = (appdata_t*)data; | ||
1476 | notes_log_export(appdata); | ||
1477 | } | ||
1478 | harbaum | 5 | |
1479 | harbaum | 6 | #ifdef USE_MAEMO |
1480 | static void | ||
1481 | cb_menu_export_mmpoi(GtkWidget *widget, gpointer data) { | ||
1482 | appdata_t *appdata = (appdata_t*)data; | ||
1483 | mmpoi_export(appdata); | ||
1484 | } | ||
1485 | #endif | ||
1486 | harbaum | 5 | |
1487 | harbaum | 6 | static void |
1488 | cb_menu_export_garmin(GtkWidget *widget, gpointer data) { | ||
1489 | appdata_t *appdata = (appdata_t*)data; | ||
1490 | garmin_export(appdata); | ||
1491 | harbaum | 1 | } |
1492 | |||
1493 | harbaum | 6 | static void |
1494 | cb_menu_geomath(GtkWidget *window, gpointer data) { | ||
1495 | geomath_dialog((appdata_t *)data); | ||
1496 | } | ||
1497 | harbaum | 5 | |
1498 | harbaum | 6 | static void |
1499 | cb_menu_geotext(GtkWidget *window, gpointer data) { | ||
1500 | geotext_dialog((appdata_t *)data); | ||
1501 | harbaum | 1 | } |
1502 | |||
1503 | harbaum | 6 | static void |
1504 | cb_menu_precpos(GtkWidget *window, gpointer data) { | ||
1505 | precise_position((appdata_t *)data); | ||
1506 | harbaum | 1 | } |
1507 | |||
1508 | harbaum | 6 | #ifdef USE_STACKABLE_WINDOW |
1509 | harbaum | 11 | static void on_export_destroy(GtkWidget *widget, appdata_t *appdata) { |
1510 | appdata->cur_view = g_object_get_data(G_OBJECT(widget), "cur_view"); | ||
1511 | } | ||
1512 | harbaum | 6 | |
1513 | harbaum | 3 | void on_export_clicked(GtkButton *button, appdata_t *appdata) { |
1514 | harbaum | 6 | HildonStackableWindow *view_window; |
1515 | harbaum | 5 | GtkWidget *but; |
1516 | harbaum | 3 | |
1517 | harbaum | 6 | view_window = HILDON_STACKABLE_WINDOW (hildon_stackable_window_new ()); |
1518 | harbaum | 11 | gtk_window_set_title (GTK_WINDOW (view_window), "GPXView - Export"); |
1519 | harbaum | 3 | |
1520 | harbaum | 11 | /* store last "cur_view" in window */ |
1521 | g_object_set_data(G_OBJECT(view_window), "cur_view", appdata->cur_view); | ||
1522 | appdata->cur_view = NULL; | ||
1523 | |||
1524 | g_signal_connect(G_OBJECT(view_window), "destroy", | ||
1525 | G_CALLBACK(on_export_destroy), appdata); | ||
1526 | |||
1527 | harbaum | 6 | GtkVBox *contents = GTK_VBOX(gtk_vbox_new (12, FALSE)); |
1528 | harbaum | 5 | |
1529 | harbaum | 6 | but = hildon_button_new_with_text( |
1530 | HILDON_SIZE_FINGER_HEIGHT | HILDON_SIZE_AUTO_WIDTH, | ||
1531 | HILDON_BUTTON_ARRANGEMENT_VERTICAL, | ||
1532 | _("Export to Maemo Mapper"), | ||
1533 | _("Save a Maemo Mapper POI file")); | ||
1534 | g_signal_connect(but, "clicked", | ||
1535 | G_CALLBACK(cb_menu_export_mmpoi), appdata); | ||
1536 | gtk_box_pack_start(GTK_BOX(contents), but, FALSE, FALSE, 0); | ||
1537 | harbaum | 3 | |
1538 | harbaum | 6 | |
1539 | but = hildon_button_new_with_text( | ||
1540 | HILDON_SIZE_FINGER_HEIGHT | HILDON_SIZE_AUTO_WIDTH, | ||
1541 | HILDON_BUTTON_ARRANGEMENT_VERTICAL, | ||
1542 | _("Export Field Notes"), | ||
1543 | _("Save a Garmin Field Notes file")); | ||
1544 | g_signal_connect(but, "clicked", | ||
1545 | G_CALLBACK(cb_menu_export_log), appdata); | ||
1546 | gtk_box_pack_start(GTK_BOX(contents), but, FALSE, FALSE, 0); | ||
1547 | harbaum | 4 | |
1548 | |||
1549 | harbaum | 6 | but = hildon_button_new_with_text( |
1550 | HILDON_SIZE_FINGER_HEIGHT | HILDON_SIZE_AUTO_WIDTH, | ||
1551 | HILDON_BUTTON_ARRANGEMENT_VERTICAL, | ||
1552 | _("Export Garmin GPX"), | ||
1553 | _("Save a GPX file containing modified waypoints")); | ||
1554 | g_signal_connect(but, "clicked", | ||
1555 | G_CALLBACK(cb_menu_export_garmin), appdata); | ||
1556 | gtk_box_pack_start(GTK_BOX(contents), but, FALSE, FALSE, 0); | ||
1557 | harbaum | 5 | |
1558 | harbaum | 6 | gtk_container_add (GTK_CONTAINER (view_window), GTK_WIDGET (contents)); |
1559 | gtk_widget_show_all (GTK_WIDGET (view_window)); | ||
1560 | harbaum | 5 | } |
1561 | |||
1562 | harbaum | 11 | static void on_tools_destroy(GtkWidget *widget, appdata_t *appdata) { |
1563 | appdata->cur_view = g_object_get_data(G_OBJECT(widget), "cur_view"); | ||
1564 | } | ||
1565 | |||
1566 | harbaum | 5 | void on_tools_clicked(GtkButton *button, appdata_t *appdata) { |
1567 | harbaum | 6 | HildonStackableWindow *view_window; |
1568 | harbaum | 5 | GtkWidget *but; |
1569 | |||
1570 | harbaum | 6 | view_window = HILDON_STACKABLE_WINDOW (hildon_stackable_window_new ()); |
1571 | harbaum | 11 | gtk_window_set_title (GTK_WINDOW (view_window), "GPXView - Tools"); |
1572 | harbaum | 5 | |
1573 | harbaum | 11 | /* store last "cur_view" in window */ |
1574 | g_object_set_data(G_OBJECT(view_window), "cur_view", appdata->cur_view); | ||
1575 | appdata->cur_view = NULL; | ||
1576 | |||
1577 | g_signal_connect(G_OBJECT(view_window), "destroy", | ||
1578 | G_CALLBACK(on_tools_destroy), appdata); | ||
1579 | |||
1580 | harbaum | 6 | GtkVBox *contents = GTK_VBOX(gtk_vbox_new (12, FALSE)); |
1581 | harbaum | 5 | |
1582 | harbaum | 6 | but = hildon_button_new_with_text( |
1583 | HILDON_SIZE_FINGER_HEIGHT | HILDON_SIZE_AUTO_WIDTH, | ||
1584 | HILDON_BUTTON_ARRANGEMENT_VERTICAL, | ||
1585 | _("Geomath"), | ||
1586 | _("Geocoordinate calculation")); | ||
1587 | g_signal_connect(but, "clicked", | ||
1588 | G_CALLBACK(cb_menu_geomath), appdata); | ||
1589 | gtk_box_pack_start(GTK_BOX(contents), but, FALSE, FALSE, 0); | ||
1590 | harbaum | 5 | |
1591 | harbaum | 6 | |
1592 | but = hildon_button_new_with_text( | ||
1593 | HILDON_SIZE_FINGER_HEIGHT | HILDON_SIZE_AUTO_WIDTH, | ||
1594 | HILDON_BUTTON_ARRANGEMENT_VERTICAL, | ||
1595 | _("Geotext"), | ||
1596 | _("Text analysis, letter counting etc")); | ||
1597 | g_signal_connect(but, "clicked", | ||
1598 | G_CALLBACK(cb_menu_geotext), appdata); | ||
1599 | gtk_box_pack_start(GTK_BOX(contents), but, FALSE, FALSE, 0); | ||
1600 | harbaum | 4 | |
1601 | |||
1602 | harbaum | 6 | but = hildon_button_new_with_text( |
1603 | HILDON_SIZE_FINGER_HEIGHT | HILDON_SIZE_AUTO_WIDTH, | ||
1604 | HILDON_BUTTON_ARRANGEMENT_VERTICAL, | ||
1605 | _("Precise Position"), | ||
1606 | harbaum | 7 | _("Calculate a very precise GPS position")); |
1607 | harbaum | 6 | g_signal_connect(but, "clicked", |
1608 | G_CALLBACK(cb_menu_precpos), appdata); | ||
1609 | gtk_box_pack_start(GTK_BOX(contents), but, FALSE, FALSE, 0); | ||
1610 | harbaum | 3 | |
1611 | harbaum | 6 | gtk_container_add (GTK_CONTAINER (view_window), GTK_WIDGET (contents)); |
1612 | gtk_widget_show_all (GTK_WIDGET (view_window)); | ||
1613 | harbaum | 3 | } |
1614 | |||
1615 | HildonAppMenu *menu_create(appdata_t *appdata, int mode) { | ||
1616 | GtkWidget *button; | ||
1617 | HildonAppMenu *menu = HILDON_APP_MENU(hildon_app_menu_new()); | ||
1618 | |||
1619 | /* ------- */ | ||
1620 | harbaum | 7 | button = gtk_button_new_with_label(_("About")); |
1621 | g_signal_connect_after(button, "clicked", | ||
1622 | G_CALLBACK(cb_menu_about), appdata); | ||
1623 | hildon_app_menu_append(menu, GTK_BUTTON(button)); | ||
1624 | |||
1625 | harbaum | 3 | button = gtk_button_new_with_label(_("Settings")); |
1626 | g_signal_connect_after(button, "clicked", G_CALLBACK(cb_menu_settings), | ||
1627 | appdata); | ||
1628 | hildon_app_menu_append(menu, GTK_BUTTON(button)); | ||
1629 | |||
1630 | if(mode == MENU_GPXLIST) { | ||
1631 | button = gtk_button_new_with_label(_("Import file")); | ||
1632 | g_signal_connect_after(button, "clicked", | ||
1633 | G_CALLBACK(cb_menu_add), appdata); | ||
1634 | hildon_app_menu_append(menu, GTK_BUTTON(button)); | ||
1635 | |||
1636 | harbaum | 7 | button = gtk_button_new_with_label(_("Import directory")); |
1637 | harbaum | 3 | g_signal_connect_after(button, "clicked", |
1638 | G_CALLBACK(cb_menu_adddir), appdata); | ||
1639 | hildon_app_menu_append(menu, GTK_BUTTON(button)); | ||
1640 | } | ||
1641 | |||
1642 | if(mode == MENU_GPXLIST) { | ||
1643 | harbaum | 4 | button = gtk_button_new_with_label(_("Export")); |
1644 | g_signal_connect_after(button, "clicked", | ||
1645 | G_CALLBACK(on_export_clicked), appdata); | ||
1646 | hildon_app_menu_append(menu, GTK_BUTTON(button)); | ||
1647 | |||
1648 | button = gtk_button_new_with_label(_("Search")); | ||
1649 | g_signal_connect_after(button, "clicked", | ||
1650 | G_CALLBACK(cb_menu_search), appdata); | ||
1651 | hildon_app_menu_append(menu, GTK_BUTTON(button)); | ||
1652 | } | ||
1653 | |||
1654 | harbaum | 5 | button = gtk_button_new_with_label(_("Tools")); |
1655 | g_signal_connect_after(button, "clicked", | ||
1656 | G_CALLBACK(on_tools_clicked), appdata); | ||
1657 | hildon_app_menu_append(menu, GTK_BUTTON(button)); | ||
1658 | harbaum | 4 | |
1659 | harbaum | 3 | gtk_widget_show(GTK_WIDGET(menu)); |
1660 | |||
1661 | return menu; | ||
1662 | } | ||
1663 | #else | ||
1664 | harbaum | 5 | |
1665 | harbaum | 1 | void menu_create(appdata_t *appdata) { |
1666 | GtkWidget *menu, *item; | ||
1667 | menu = gtk_menu_new(); | ||
1668 | |||
1669 | harbaum | 3 | #ifdef USE_BREAD_CRUMB_TRAIL |
1670 | harbaum | 1 | appdata->menu_import = |
1671 | #endif | ||
1672 | item = gtk_menu_item_new_with_label(_("Import")); | ||
1673 | gtk_menu_append(GTK_MENU_SHELL(menu), item); | ||
1674 | GtkWidget *submenu = gtk_menu_new(); | ||
1675 | gtk_menu_item_set_submenu(GTK_MENU_ITEM(item), submenu); | ||
1676 | |||
1677 | harbaum | 7 | item = gtk_menu_item_new_with_label( _("File") ); |
1678 | harbaum | 1 | gtk_menu_append(GTK_MENU_SHELL(submenu), item); |
1679 | g_signal_connect(item, "activate", GTK_SIGNAL_FUNC(cb_menu_add), appdata); | ||
1680 | |||
1681 | harbaum | 7 | item = gtk_menu_item_new_with_label( _("Directory") ); |
1682 | harbaum | 1 | gtk_menu_append(GTK_MENU_SHELL(submenu), item); |
1683 | g_signal_connect(item, "activate", GTK_SIGNAL_FUNC(cb_menu_adddir), appdata); | ||
1684 | |||
1685 | #ifndef USE_PANNABLE_AREA | ||
1686 | gtk_menu_append(GTK_MENU_SHELL(submenu), gtk_separator_menu_item_new()); | ||
1687 | |||
1688 | appdata->menu_close = | ||
1689 | item = gtk_menu_item_new_with_label( _("Close") ); | ||
1690 | gtk_menu_append(GTK_MENU_SHELL(submenu), item); | ||
1691 | g_signal_connect(item, "activate", GTK_SIGNAL_FUNC(cb_menu_close), appdata); | ||
1692 | |||
1693 | appdata->menu_remove = | ||
1694 | item = gtk_menu_item_new_with_label( _("Remove") ); | ||
1695 | gtk_menu_append(GTK_MENU_SHELL(submenu), item); | ||
1696 | g_signal_connect(item, "activate", GTK_SIGNAL_FUNC(cb_menu_remove), appdata); | ||
1697 | #endif | ||
1698 | |||
1699 | harbaum | 3 | #ifdef USE_BREAD_CRUMB_TRAIL |
1700 | harbaum | 1 | appdata->menu_export = |
1701 | #endif | ||
1702 | item = gtk_menu_item_new_with_label(_("Export")); | ||
1703 | gtk_menu_append(GTK_MENU_SHELL(menu), item); | ||
1704 | submenu = gtk_menu_new(); | ||
1705 | gtk_menu_item_set_submenu(GTK_MENU_ITEM(item), submenu); | ||
1706 | |||
1707 | #ifdef USE_MAEMO | ||
1708 | harbaum | 7 | item = gtk_menu_item_new_with_label( _("Maemo Mapper POI") ); |
1709 | harbaum | 1 | gtk_menu_append(GTK_MENU_SHELL(submenu), item); |
1710 | g_signal_connect(item, "activate", | ||
1711 | GTK_SIGNAL_FUNC(cb_menu_export_mmpoi), appdata); | ||
1712 | #endif | ||
1713 | |||
1714 | harbaum | 7 | item = gtk_menu_item_new_with_label( _("Garmin Field Notes") ); |
1715 | harbaum | 1 | gtk_menu_append(GTK_MENU_SHELL(submenu), item); |
1716 | g_signal_connect(item, "activate", | ||
1717 | GTK_SIGNAL_FUNC(cb_menu_export_log), appdata); | ||
1718 | |||
1719 | harbaum | 7 | item = gtk_menu_item_new_with_label( _("Garmin GPX") ); |
1720 | harbaum | 1 | gtk_menu_append(GTK_MENU_SHELL(submenu), item); |
1721 | g_signal_connect(item, "activate", | ||
1722 | GTK_SIGNAL_FUNC(cb_menu_export_garmin), appdata); | ||
1723 | |||
1724 | harbaum | 3 | #ifdef USE_BREAD_CRUMB_TRAIL |
1725 | harbaum | 1 | appdata->menu_search = |
1726 | #endif | ||
1727 | harbaum | 7 | item = gtk_menu_item_new_with_label( _("Search") ); |
1728 | harbaum | 1 | gtk_menu_append(GTK_MENU_SHELL(menu), item); |
1729 | g_signal_connect(item, "activate", GTK_SIGNAL_FUNC(cb_menu_search), appdata); | ||
1730 | |||
1731 | gtk_menu_append(GTK_MENU_SHELL(menu), gtk_separator_menu_item_new()); | ||
1732 | harbaum | 2 | |
1733 | #ifndef NO_COPY_N_PASTE | ||
1734 | harbaum | 1 | /* ----------- copy'n paste submenu ----------------- */ |
1735 | appdata->clipboard = gtk_clipboard_get(GDK_SELECTION_CLIPBOARD); | ||
1736 | gtk_clipboard_set_can_store(appdata->clipboard, NULL, 0); | ||
1737 | |||
1738 | item = gtk_menu_item_new_with_label(_("Edit")); | ||
1739 | gtk_menu_append(GTK_MENU_SHELL(menu), item); | ||
1740 | submenu = gtk_menu_new(); | ||
1741 | gtk_menu_item_set_submenu(GTK_MENU_ITEM(item), submenu); | ||
1742 | |||
1743 | appdata->menu_cut = item = gtk_menu_item_new_with_label( _("Cut") ); | ||
1744 | gtk_widget_set_sensitive(item, FALSE); | ||
1745 | gtk_menu_append(GTK_MENU_SHELL(submenu), item); | ||
1746 | g_signal_connect(item, "activate", GTK_SIGNAL_FUNC(cb_menu_cut), appdata); | ||
1747 | appdata->menu_copy = item = gtk_menu_item_new_with_label( _("Copy") ); | ||
1748 | gtk_widget_set_sensitive(item, FALSE); | ||
1749 | gtk_menu_append(GTK_MENU_SHELL(submenu), item); | ||
1750 | g_signal_connect(item, "activate", GTK_SIGNAL_FUNC(cb_menu_copy), appdata); | ||
1751 | appdata->menu_paste = item = gtk_menu_item_new_with_label( _("Paste") ); | ||
1752 | gtk_widget_set_sensitive(item, FALSE); | ||
1753 | gtk_menu_append(GTK_MENU_SHELL(submenu), item); | ||
1754 | g_signal_connect(item, "activate", GTK_SIGNAL_FUNC(cb_menu_paste), appdata); | ||
1755 | harbaum | 2 | #endif |
1756 | harbaum | 1 | |
1757 | harbaum | 3 | item = gtk_menu_item_new_with_label( _("Settings") ); |
1758 | harbaum | 1 | gtk_menu_append(GTK_MENU_SHELL(menu), item); |
1759 | g_signal_connect(item, "activate", GTK_SIGNAL_FUNC(cb_menu_settings), | ||
1760 | appdata); | ||
1761 | |||
1762 | gtk_menu_append(GTK_MENU_SHELL(menu), gtk_separator_menu_item_new()); | ||
1763 | |||
1764 | item = gtk_menu_item_new_with_label(_("Tools")); | ||
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 | harbaum | 7 | item = gtk_menu_item_new_with_label( _("Geomath") ); |
1770 | harbaum | 1 | gtk_menu_append(GTK_MENU_SHELL(submenu), item); |
1771 | g_signal_connect(item, "activate", | ||
1772 | GTK_SIGNAL_FUNC(cb_menu_geomath), appdata); | ||
1773 | |||
1774 | harbaum | 7 | item = gtk_menu_item_new_with_label( _("Geotext") ); |
1775 | harbaum | 1 | gtk_menu_append(GTK_MENU_SHELL(submenu), item); |
1776 | g_signal_connect(item, "activate", | ||
1777 | GTK_SIGNAL_FUNC(cb_menu_geotext), appdata); | ||
1778 | |||
1779 | harbaum | 7 | item = gtk_menu_item_new_with_label( _("Precise Position") ); |
1780 | harbaum | 1 | gtk_menu_append(GTK_MENU_SHELL(submenu), item); |
1781 | g_signal_connect(item, "activate", | ||
1782 | GTK_SIGNAL_FUNC(cb_menu_precpos), appdata); | ||
1783 | |||
1784 | gtk_menu_append(GTK_MENU_SHELL(menu), gtk_separator_menu_item_new()); | ||
1785 | |||
1786 | #if defined(USE_MAEMO) && defined(HILDON_HELP) | ||
1787 | harbaum | 7 | item = gtk_menu_item_new_with_label( _("Help") ); |
1788 | harbaum | 1 | gtk_menu_append(GTK_MENU_SHELL(menu), item); |
1789 | g_signal_connect(item, "activate", GTK_SIGNAL_FUNC(cb_menu_help), appdata); | ||
1790 | #endif | ||
1791 | |||
1792 | harbaum | 7 | item = gtk_menu_item_new_with_label( _("About") ); |
1793 | harbaum | 1 | gtk_menu_append(GTK_MENU_SHELL(menu), item); |
1794 | g_signal_connect(item, "activate", GTK_SIGNAL_FUNC(cb_menu_about), appdata); | ||
1795 | |||
1796 | #ifndef USE_MAEMO | ||
1797 | item = gtk_menu_item_new_with_label( _("Quit") ); | ||
1798 | gtk_menu_append(GTK_MENU_SHELL(menu), item); | ||
1799 | g_signal_connect(item, "activate", GTK_SIGNAL_FUNC(cb_menu_quit), appdata); | ||
1800 | #endif | ||
1801 | |||
1802 | #ifdef USE_MAEMO | ||
1803 | hildon_window_set_menu(appdata->window, GTK_MENU(menu)); | ||
1804 | #else | ||
1805 | /* attach ordinary gtk menu */ | ||
1806 | GtkWidget *menu_bar = gtk_menu_bar_new(); | ||
1807 | |||
1808 | GtkWidget *root_menu = gtk_menu_item_new_with_label (_("Menu")); | ||
1809 | gtk_widget_show(root_menu); | ||
1810 | |||
1811 | gtk_menu_bar_append(menu_bar, root_menu); | ||
1812 | gtk_menu_item_set_submenu(GTK_MENU_ITEM (root_menu), menu); | ||
1813 | |||
1814 | gtk_widget_show(menu_bar); | ||
1815 | gtk_box_pack_start(GTK_BOX(appdata->vbox), menu_bar, 0, 0, 0); | ||
1816 | #endif | ||
1817 | } | ||
1818 | harbaum | 3 | #endif |
1819 | harbaum | 1 | |
1820 | /********************* end of menu **********************/ | ||
1821 | |||
1822 | void cleanup(appdata_t *appdata) { | ||
1823 | gpx_free_all(appdata->gpx); | ||
1824 | if(appdata->path) free(appdata->path); | ||
1825 | if(appdata->image_path) free(appdata->image_path); | ||
1826 | if(appdata->search_str) free(appdata->search_str); | ||
1827 | |||
1828 | gnome_vfs_shutdown(); | ||
1829 | icons_free(); | ||
1830 | gps_release(appdata); | ||
1831 | |||
1832 | #ifdef USE_MAEMO | ||
1833 | if(appdata->search_results) { | ||
1834 | printf("freeing pending search\n"); | ||
1835 | search_result_free(appdata->search_results); | ||
1836 | } | ||
1837 | |||
1838 | if(appdata->osso_context) | ||
1839 | osso_deinitialize(appdata->osso_context); | ||
1840 | |||
1841 | appdata->program = NULL; | ||
1842 | #endif | ||
1843 | |||
1844 | /* free chain of locations */ | ||
1845 | location_t *loc = appdata->location; | ||
1846 | while(loc) { | ||
1847 | location_t *next = loc->next; | ||
1848 | if(loc->name) free(loc->name); | ||
1849 | free(loc); | ||
1850 | loc = next; | ||
1851 | } | ||
1852 | |||
1853 | puts("everything is gone"); | ||
1854 | } | ||
1855 | |||
1856 | void on_window_destroy (GtkWidget *widget, gpointer data) { | ||
1857 | appdata_t *appdata = (appdata_t*)data; | ||
1858 | |||
1859 | gconf_save_state(appdata); | ||
1860 | gtk_main_quit(); | ||
1861 | appdata->window = NULL; | ||
1862 | } | ||
1863 | |||
1864 | gboolean on_window_key_press(GtkWidget *widget, | ||
1865 | harbaum | 11 | GdkEventKey *event, appdata_t *appdata) { |
1866 | harbaum | 1 | int handled = FALSE; |
1867 | |||
1868 | // printf("key event %d\n", event->keyval); | ||
1869 | |||
1870 | switch(event->keyval) { | ||
1871 | #ifdef USE_MAEMO | ||
1872 | |||
1873 | #ifdef HILDON_HARDKEY_INCREASE | ||
1874 | case HILDON_HARDKEY_INCREASE: | ||
1875 | html_zoom(appdata, TRUE); | ||
1876 | handled = TRUE; | ||
1877 | break; | ||
1878 | #endif | ||
1879 | |||
1880 | #ifdef HILDON_HARDKEY_DECREASE | ||
1881 | case HILDON_HARDKEY_DECREASE: | ||
1882 | html_zoom(appdata, FALSE); | ||
1883 | handled = TRUE; | ||
1884 | break; | ||
1885 | #endif | ||
1886 | |||
1887 | #ifdef HILDON_HARDKEY_FULLSCREEN | ||
1888 | case HILDON_HARDKEY_FULLSCREEN: | ||
1889 | { | ||
1890 | appdata->fullscreen = !appdata->fullscreen; | ||
1891 | |||
1892 | if(appdata->fullscreen) | ||
1893 | gtk_window_fullscreen(GTK_WINDOW(appdata->window)); | ||
1894 | else | ||
1895 | gtk_window_unfullscreen(GTK_WINDOW(appdata->window)); | ||
1896 | |||
1897 | handled = TRUE; | ||
1898 | } | ||
1899 | break; | ||
1900 | #endif | ||
1901 | |||
1902 | #else | ||
1903 | case '+': | ||
1904 | printf("zoom+\n"); | ||
1905 | html_zoom(appdata, TRUE); | ||
1906 | handled = TRUE; | ||
1907 | break; | ||
1908 | case '-': | ||
1909 | printf("zoom-\n"); | ||
1910 | html_zoom(appdata, FALSE); | ||
1911 | handled = TRUE; | ||
1912 | break; | ||
1913 | #endif | ||
1914 | } | ||
1915 | |||
1916 | return handled; | ||
1917 | } | ||
1918 | |||
1919 | #ifdef USE_BREAD_CRUMB_TRAIL | ||
1920 | typedef struct { | ||
1921 | int level; | ||
1922 | appdata_t *appdata; | ||
1923 | gpointer data; | ||
1924 | } crumb_t; | ||
1925 | |||
1926 | static void | ||
1927 | crumb_back(gpointer data) { | ||
1928 | crumb_t *crumb = (crumb_t*)data; | ||
1929 | printf("crumb_back called with %d\n", crumb->level); | ||
1930 | |||
1931 | /* don't do anything if main window has already been destroyed */ | ||
1932 | if(!crumb->appdata->window) { | ||
1933 | printf("Main window gone ...\n"); | ||
1934 | return; | ||
1935 | } | ||
1936 | |||
1937 | /* whatever is being displayed: we don't need it anymore */ | ||
1938 | gtk_container_remove(GTK_CONTAINER(crumb->appdata->vbox), | ||
1939 | crumb->appdata->cur_view); | ||
1940 | |||
1941 | /* back from cache to cachelist */ | ||
1942 | if(crumb->level == CRUMB_CACHE) { | ||
1943 | gpx_t *gpx = crumb->appdata->search_results; | ||
1944 | |||
1945 | if(!gpx) { | ||
1946 | gtk_widget_set_sensitive(crumb->appdata->menu_search, TRUE); | ||
1947 | gtk_widget_set_sensitive(crumb->appdata->menu_export, TRUE); | ||
1948 | printf("no search data found, return to gpx\n"); | ||
1949 | gpx = crumb->appdata->cur_gpx; | ||
1950 | } else | ||
1951 | printf("returning to search result\n"); | ||
1952 | |||
1953 | g_assert(gpx != NULL); | ||
1954 | |||
1955 | crumb->appdata->cur_view = cachelist_create(crumb->appdata, gpx, | ||
1956 | crumb->appdata->cur_cache); | ||
1957 | |||
1958 | /* returning from cache view: invalidate cache reference */ | ||
1959 | crumb->appdata->cur_cache = NULL; | ||
1960 | |||
1961 | gtk_box_pack_start_defaults(GTK_BOX(crumb->appdata->vbox), | ||
1962 | crumb->appdata->cur_view); | ||
1963 | } | ||
1964 | |||
1965 | if(crumb->level == CRUMB_SEARCH_GPX) { | ||
1966 | printf("returning from a local search!\n"); | ||
1967 | |||
1968 | g_assert((gpx_t*)crumb->data == crumb->appdata->search_results); | ||
1969 | |||
1970 | search_result_free((gpx_t*)crumb->data); | ||
1971 | crumb->appdata->search_results = NULL; | ||
1972 | |||
1973 | gtk_widget_set_sensitive(crumb->appdata->menu_search, TRUE); | ||
1974 | |||
1975 | crumb->appdata->cur_view = cachelist_create(crumb->appdata, | ||
1976 | crumb->appdata->cur_gpx, NULL); | ||
1977 | gtk_box_pack_start_defaults(GTK_BOX(crumb->appdata->vbox), | ||
1978 | crumb->appdata->cur_view); | ||
1979 | } | ||
1980 | |||
1981 | /* back from cachelist to gpxlist */ | ||
1982 | if((crumb->level == CRUMB_CACHELIST) || | ||
1983 | (crumb->level == CRUMB_SEARCH_GLOBAL)) { | ||
1984 | |||
1985 | crumb->appdata->cur_view = gpxlist_create_view_and_model( | ||
1986 | crumb->appdata, crumb->appdata->cur_gpx); | ||
1987 | |||
1988 | /* returning from cachelist/global search view: */ | ||
1989 | /* invalidate gpx reference */ | ||
1990 | crumb->appdata->cur_gpx = NULL; | ||
1991 | |||
1992 | gtk_box_pack_start_defaults(GTK_BOX(crumb->appdata->vbox), | ||
1993 | crumb->appdata->cur_view); | ||
1994 | |||
1995 | if((crumb->level == CRUMB_SEARCH_GLOBAL) || | ||
1996 | (crumb->level == CRUMB_SEARCH_GPX)) { | ||
1997 | g_assert((gpx_t*)crumb->data == crumb->appdata->search_results); | ||
1998 | |||
1999 | search_result_free((gpx_t*)crumb->data); | ||
2000 | crumb->appdata->search_results = NULL; | ||
2001 | } | ||
2002 | |||
2003 | /* enable gpxlist related menu entries */ | ||
2004 | gtk_widget_set_sensitive(crumb->appdata->menu_import, TRUE); | ||
2005 | gtk_widget_set_sensitive(crumb->appdata->menu_search, TRUE); | ||
2006 | gtk_widget_set_sensitive(crumb->appdata->menu_export, TRUE); | ||
2007 | } | ||
2008 | |||
2009 | gtk_widget_show_all(crumb->appdata->vbox); | ||
2010 | g_free(data); | ||
2011 | } | ||
2012 | |||
2013 | static void crumb_add(appdata_t *appdata, char *name, int level, | ||
2014 | gpointer user_data) { | ||
2015 | crumb_t *crumb = malloc(sizeof(crumb_t)); | ||
2016 | crumb->level = level; | ||
2017 | crumb->appdata = appdata; | ||
2018 | crumb->data = user_data; | ||
2019 | |||
2020 | printf("crumb_add with level %d\n", level); | ||
2021 | |||
2022 | /* save that we are working on search results */ | ||
2023 | if((level == CRUMB_SEARCH_GLOBAL) || | ||
2024 | (level == CRUMB_SEARCH_GPX)) { | ||
2025 | appdata->search_results = (gpx_t*)user_data; | ||
2026 | |||
2027 | /* searches cannot be nested */ | ||
2028 | gtk_widget_set_sensitive(appdata->menu_search, FALSE); | ||
2029 | } | ||
2030 | |||
2031 | /* save "path" pointers in appdata */ | ||
2032 | if(crumb->level == CRUMB_CACHELIST) | ||
2033 | appdata->cur_gpx = (gpx_t*)user_data; | ||
2034 | |||
2035 | if(crumb->level == CRUMB_CACHE) { | ||
2036 | appdata->cur_cache = (cache_t*)user_data; | ||
2037 | /* the cache view cannot be searched */ | ||
2038 | gtk_widget_set_sensitive(appdata->menu_search, FALSE); | ||
2039 | gtk_widget_set_sensitive(appdata->menu_export, FALSE); | ||
2040 | } | ||
2041 | |||
2042 | if(level != CRUMB_GPXLIST) { | ||
2043 | /* disable gpxlist related menu entries */ | ||
2044 | gtk_widget_set_sensitive(appdata->menu_import, FALSE); | ||
2045 | #ifndef USE_PANNABLE_AREA | ||
2046 | gtk_widget_set_sensitive(appdata->menu_remove, FALSE); | ||
2047 | gtk_widget_set_sensitive(appdata->menu_close, FALSE); | ||
2048 | #endif | ||
2049 | } | ||
2050 | |||
2051 | hildon_bread_crumb_trail_push_text(HILDON_BREAD_CRUMB_TRAIL(appdata->bct), | ||
2052 | name, crumb, (GDestroyNotify)crumb_back); | ||
2053 | } | ||
2054 | #endif // USE_BREAD_CRUMB_TRAIL | ||
2055 | |||
2056 | void main_after_settings_redraw(appdata_t *appdata, int flags) { | ||
2057 | harbaum | 11 | printf("main after settings redraw\n"); |
2058 | |||
2059 | if(!appdata->cur_view) { | ||
2060 | printf("no active view\n"); | ||
2061 | return; | ||
2062 | } | ||
2063 | |||
2064 | harbaum | 1 | #ifndef USE_MAEMO |
2065 | // in non-maemo setup this can only affect the main screen as | ||
2066 | // the menu is blocked while a dialog is open. also the main | ||
2067 | // screen is always present | ||
2068 | if(appdata->gpxlist_items != appdata->cur_items) { | ||
2069 | /* re-do the main screen */ | ||
2070 | gtk_container_remove(GTK_CONTAINER(appdata->vbox), appdata->cur_view); | ||
2071 | appdata->cur_view = gpxlist_create_view_and_model(appdata, NULL); | ||
2072 | gtk_box_pack_start_defaults(GTK_BOX(appdata->vbox), appdata->cur_view); | ||
2073 | gtk_widget_show_all(appdata->vbox); | ||
2074 | } | ||
2075 | #else | ||
2076 | /* a cache screen cannot be changed from the settings and thus doesn't */ | ||
2077 | /* need to be redrawn */ | ||
2078 | if(appdata->cur_cache) { | ||
2079 | printf("No redraw in cache view required\n"); | ||
2080 | return; | ||
2081 | } | ||
2082 | |||
2083 | int redraw = 0; // nothing to redraw | ||
2084 | |||
2085 | if(appdata->search_results) { | ||
2086 | if((appdata->cur_items != appdata->cachelist_items) || flags) | ||
2087 | redraw = 1; | ||
2088 | } else { | ||
2089 | if(!appdata->cur_gpx) { | ||
2090 | if(appdata->cur_items != appdata->gpxlist_items) | ||
2091 | redraw = 2; // redraw gpxlist | ||
2092 | } else { | ||
2093 | if((appdata->cur_items != appdata->cachelist_items) || flags) | ||
2094 | redraw = 3; // redraw cachelist | ||
2095 | } | ||
2096 | } | ||
2097 | |||
2098 | if(redraw) { | ||
2099 | harbaum | 11 | GtkWidget *container = appdata->vbox; |
2100 | |||
2101 | #ifdef USE_STACKABLE_WINDOW | ||
2102 | HildonWindowStack *stack = hildon_window_stack_get_default(); | ||
2103 | container = hildon_window_stack_peek(stack); | ||
2104 | #endif | ||
2105 | |||
2106 | gtk_container_remove(GTK_CONTAINER(container), appdata->cur_view); | ||
2107 | harbaum | 1 | switch(redraw) { |
2108 | case 1: | ||
2109 | appdata->cur_view = cachelist_create(appdata, | ||
2110 | appdata->search_results, NULL); | ||
2111 | break; | ||
2112 | case 2: | ||
2113 | appdata->cur_view = gpxlist_create_view_and_model(appdata, NULL); | ||
2114 | break; | ||
2115 | case 3: | ||
2116 | appdata->cur_view = cachelist_create(appdata, | ||
2117 | appdata->cur_gpx, NULL); | ||
2118 | break; | ||
2119 | } | ||
2120 | |||
2121 | harbaum | 11 | #ifdef USE_STACKABLE_WINDOW |
2122 | if(container != appdata->vbox) | ||
2123 | gtk_container_add(GTK_CONTAINER(container), appdata->cur_view); | ||
2124 | else | ||
2125 | #endif | ||
2126 | gtk_box_pack_start_defaults(GTK_BOX(container), appdata->cur_view); | ||
2127 | |||
2128 | gtk_widget_show_all(container); | ||
2129 | harbaum | 1 | } |
2130 | harbaum | 11 | #endif // USE_MAEMO |
2131 | harbaum | 1 | } |
2132 | |||
2133 | int main(int argc, char *argv[]) { | ||
2134 | appdata_t appdata; | ||
2135 | |||
2136 | /* init appdata */ | ||
2137 | memset(&appdata, 0, sizeof(appdata)); | ||
2138 | |||
2139 | printf("Using locale for %s in %s\n", PACKAGE, LOCALEDIR); | ||
2140 | |||
2141 | setlocale(LC_ALL, ""); | ||
2142 | bindtextdomain(PACKAGE, LOCALEDIR); | ||
2143 | bind_textdomain_codeset(PACKAGE, "UTF-8"); | ||
2144 | textdomain(PACKAGE); | ||
2145 | |||
2146 | /* prepare thread system */ | ||
2147 | g_thread_init(NULL); | ||
2148 | |||
2149 | gtk_init (&argc, &argv); | ||
2150 | |||
2151 | #ifdef USE_MAEMO | ||
2152 | printf("Installing osso context for \"org.harbaum." APP "\"\n"); | ||
2153 | appdata.osso_context = osso_initialize("org.harbaum."APP, | ||
2154 | VERSION, TRUE, NULL); | ||
2155 | if(appdata.osso_context == NULL) { | ||
2156 | fprintf(stderr, "error initiating osso context\n"); | ||
2157 | } | ||
2158 | |||
2159 | dbus_register(&appdata); | ||
2160 | #endif | ||
2161 | |||
2162 | icons_init(); | ||
2163 | |||
2164 | if(!gnome_vfs_init()) { | ||
2165 | g_error("Gnome VFS init failed\n"); | ||
2166 | } | ||
2167 | |||
2168 | #ifdef USE_MAEMO | ||
2169 | /* Create the hildon program and setup the title */ | ||
2170 | appdata.program = HILDON_PROGRAM(hildon_program_get_instance()); | ||
2171 | g_set_application_name("GPXView"); | ||
2172 | |||
2173 | /* Create HildonWindow and set it to HildonProgram */ | ||
2174 | #ifdef USE_STACKABLE_WINDOW | ||
2175 | appdata.window = HILDON_WINDOW(hildon_stackable_window_new()); | ||
2176 | #else | ||
2177 | appdata.window = HILDON_WINDOW(hildon_window_new()); | ||
2178 | #endif | ||
2179 | hildon_program_add_window(appdata.program, appdata.window); | ||
2180 | #else | ||
2181 | /* Create a Window. */ | ||
2182 | appdata.window = gtk_window_new(GTK_WINDOW_TOPLEVEL); | ||
2183 | /* Set a decent default size for the window. */ | ||
2184 | gtk_window_set_default_size(GTK_WINDOW(appdata.window), 500, 300); | ||
2185 | #endif | ||
2186 | |||
2187 | gtk_window_set_title(GTK_WINDOW(appdata.window), "GPXView"); | ||
2188 | g_signal_connect(G_OBJECT(appdata.window), "destroy", | ||
2189 | G_CALLBACK(on_window_destroy), &appdata); | ||
2190 | |||
2191 | g_signal_connect(G_OBJECT(appdata.window), "key_press_event", | ||
2192 | G_CALLBACK(on_window_key_press), &appdata); | ||
2193 | |||
2194 | appdata.vbox = gtk_vbox_new(FALSE, 2); | ||
2195 | gtk_container_add(GTK_CONTAINER(appdata.window), appdata.vbox); | ||
2196 | |||
2197 | harbaum | 3 | #ifndef USE_STACKABLE_WINDOW |
2198 | harbaum | 1 | menu_create(&appdata); |
2199 | harbaum | 3 | #else |
2200 | hildon_window_set_app_menu(HILDON_WINDOW(appdata.window), | ||
2201 | menu_create(&appdata, MENU_GPXLIST)); | ||
2202 | #endif | ||
2203 | harbaum | 1 | |
2204 | #ifdef USE_BREAD_CRUMB_TRAIL | ||
2205 | appdata.bct = hildon_bread_crumb_trail_new(); | ||
2206 | |||
2207 | gtk_box_pack_start(GTK_BOX(appdata.vbox), appdata.bct, FALSE,FALSE,0); | ||
2208 | |||
2209 | hildon_bread_crumb_trail_clear(HILDON_BREAD_CRUMB_TRAIL(appdata.bct)); | ||
2210 | crumb_add(&appdata, "GPX", CRUMB_GPXLIST, NULL); | ||
2211 | #endif | ||
2212 | |||
2213 | /* wait for main gui to appear */ | ||
2214 | gtk_widget_show_all(GTK_WIDGET(appdata.window)); | ||
2215 | while(gtk_events_pending()) | ||
2216 | gtk_main_iteration(); | ||
2217 | |||
2218 | appdata.gconf_client = gconf_client_get_default(); | ||
2219 | gconf_load_state(&appdata); | ||
2220 | gps_init(&appdata); | ||
2221 | |||
2222 | appdata.cur_view = gpxlist_create_view_and_model(&appdata, NULL); | ||
2223 | gtk_box_pack_start_defaults(GTK_BOX(appdata.vbox), appdata.cur_view); | ||
2224 | |||
2225 | gtk_widget_show_all(GTK_WIDGET(appdata.window)); | ||
2226 | gtk_main(); | ||
2227 | |||
2228 | cleanup(&appdata); | ||
2229 | |||
2230 | return 0; | ||
2231 | } |