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