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