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