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