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