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