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