Contents of /trunk/src/settings.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 7 - (show annotations)
Thu Jun 25 15:24:24 2009 UTC (14 years, 10 months ago) by harbaum
File MIME type: text/plain
File size: 24851 byte(s)
Translations
1 /*
2 * Copyright (C) 2008 Till Harbaum <till@harbaum.org>.
3 *
4 * This file is part of GPXView.
5 *
6 * GPXView is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * GPXView is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with GPXView. If not, see <http://www.gnu.org/licenses/>.
18 */
19
20 #include "gpxview.h"
21 #include <math.h>
22
23 typedef struct {
24 GtkWidget *cbox_gps;
25 GtkWidget *loc;
26 } settings_dialog_state_t;
27
28 /* Our usual callback function */
29 static void settings_update(GtkWidget *widget, gpointer data) {
30 settings_dialog_state_t *hstate = (settings_dialog_state_t *)data;
31
32 if(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(hstate->cbox_gps)))
33 gtk_widget_set_sensitive(hstate->loc, FALSE);
34 else
35 gtk_widget_set_sensitive(hstate->loc, TRUE);
36 }
37
38 typedef struct {
39 appdata_t *appdata;
40 GtkWidget *settings_dialog;
41 GtkWidget *view;
42 GtkListStore *store;
43 GtkWidget *but_add, *but_edit, *but_remove;
44 gboolean changed;
45 } location_context_t;
46
47 enum {
48 LOCATION_COL_NAME = 0,
49 LOCATION_COL_LAT,
50 LOCATION_COL_LON,
51 LOCATION_COL_DATA,
52 LOCATION_NUM_COLS
53 };
54
55 static void location_select(location_context_t *context) {
56 GtkTreeSelection *selection =
57 gtk_tree_view_get_selection(GTK_TREE_VIEW(context->view));
58
59 GtkTreePath *path = gtk_tree_path_new_from_indices(
60 context->appdata->active_location, -1);
61
62 /* Modify a particular row */
63 GtkTreeIter iter;
64 gtk_tree_model_get_iter(GTK_TREE_MODEL(context->store), &iter, path);
65 gtk_tree_selection_select_iter(selection, &iter);
66 gtk_tree_view_scroll_to_cell(GTK_TREE_VIEW(context->view),
67 path, NULL, TRUE, 0, 0);
68 gtk_tree_path_free(path);
69
70 if(!context->appdata->active_location && context->but_remove)
71 gtk_widget_set_sensitive(context->but_remove, FALSE);
72 }
73
74 #ifdef USE_MAEMO
75 #include "dbus.h"
76
77 typedef struct {
78 appdata_t *appdata;
79 pos_t pos;
80 GtkWidget *import_button;
81 GtkWidget *export_button;
82 GtkWidget *lat, *lon;
83 } mm_context_t;
84
85 static void on_mm_import_clicked(GtkButton *button, gpointer data) {
86 char str[32];
87 mm_context_t *context = (mm_context_t*)data;
88
89 pos_lat_str(str, sizeof(str), context->appdata->mmpos.lat);
90 gtk_entry_set_text(GTK_ENTRY(context->lat), str);
91 pos_lon_str(str, sizeof(str), context->appdata->mmpos.lon);
92 gtk_entry_set_text(GTK_ENTRY(context->lon), str);
93 }
94
95 static void on_mm_export_clicked(GtkButton *button, gpointer data) {
96 mm_context_t *context = (mm_context_t*)data;
97
98 /* update position from entries */
99 pos_t pos;
100 pos.lat = lat_get(context->lat);
101 pos.lon = lon_get(context->lon);
102
103 g_assert(!isnan(pos.lat) && !isnan(pos.lon));
104
105 dbus_mm_set_position(context->appdata, &pos);
106 }
107
108 static void callback_modified_pos(GtkWidget *widget, gpointer data ) {
109 mm_context_t *context = (mm_context_t*)data;
110
111 gboolean valid =
112 (!isnan(lat_get(context->lat))) && (!isnan(lon_get(context->lon)));
113
114 gtk_widget_set_sensitive(context->export_button, valid);
115 }
116 #endif
117
118 static void on_location_edit(GtkWidget *button, location_context_t *context) {
119 GtkWidget *dialog = gtk_dialog_new_with_buttons(_("Edit Location"),
120 GTK_WINDOW(context->settings_dialog), GTK_DIALOG_MODAL,
121 GTK_STOCK_OK, GTK_RESPONSE_ACCEPT,
122 GTK_STOCK_CANCEL, GTK_RESPONSE_REJECT, NULL);
123
124 #if defined(USE_MAEMO) && defined(HILDON_HELP)
125 hildon_help_dialog_help_enable(GTK_DIALOG(dialog),
126 HELP_ID_LOCEDIT, context->appdata->osso_context);
127 #endif
128
129 printf("edit, active = %d\n", context->appdata->active_location);
130
131 location_t *loc = NULL;
132 if(context->appdata->active_location) {
133 loc = context->appdata->location;
134 int i = context->appdata->active_location-1;
135 while(i--) {
136 g_assert(loc->next);
137 loc = loc->next;
138 }
139 printf("location edit for %s\n", loc->name);
140 } else
141 printf("location edit for Home\n");
142
143 #ifdef USE_MAEMO
144 mm_context_t mm_context;
145 #else
146 GtkWidget *lat, *lon;
147 #endif
148
149 GtkWidget *label, *name;
150 GtkWidget *table = gtk_table_new(2, 3, FALSE);
151
152 gtk_table_attach_defaults(GTK_TABLE(table),
153 label = gtk_label_new(_("Name:")), 0, 1, 0, 1);
154 gtk_misc_set_alignment(GTK_MISC(label), 1.f, 0.5f);
155 gtk_table_attach_defaults(GTK_TABLE(table),
156 name = gtk_entry_new(), 1, 2, 0, 1);
157
158 pos_t pos;
159 if(loc) pos = loc->pos;
160 else pos = context->appdata->home;
161
162 gtk_table_attach_defaults(GTK_TABLE(table),
163 label = gtk_label_new(_("Latitude:")), 0, 1, 1, 2);
164 gtk_misc_set_alignment(GTK_MISC(label), 1.f, 0.5f);
165 #ifdef USE_MAEMO
166 gtk_table_attach_defaults(GTK_TABLE(table),
167 mm_context.lat = lat_entry_new(pos.lat), 1, 2, 1, 2);
168 g_signal_connect(G_OBJECT(mm_context.lat), "changed",
169 G_CALLBACK(callback_modified_pos), &mm_context);
170 #else
171 gtk_table_attach_defaults(GTK_TABLE(table),
172 lat = lat_entry_new(pos.lat), 1, 2, 1, 2);
173 #endif
174
175
176 gtk_table_attach_defaults(GTK_TABLE(table),
177 label = gtk_label_new(_("Longitude:")), 0, 1, 2, 3);
178 gtk_misc_set_alignment(GTK_MISC(label), 1.f, 0.5f);
179 #ifdef USE_MAEMO
180 gtk_table_attach_defaults(GTK_TABLE(table),
181 mm_context.lon = lon_entry_new(pos.lon), 1, 2, 2, 3);
182 g_signal_connect(G_OBJECT(mm_context.lon), "changed",
183 G_CALLBACK(callback_modified_pos), &mm_context);
184 #else
185 gtk_table_attach_defaults(GTK_TABLE(table),
186 lon = lon_entry_new(pos.lon), 1, 2, 2, 3);
187 #endif
188
189 if(loc)
190 gtk_entry_set_text(GTK_ENTRY(name), loc->name);
191 else {
192 gtk_entry_set_text(GTK_ENTRY(name), _("Home"));
193 gtk_widget_set_sensitive(GTK_WIDGET(name), FALSE);
194 }
195
196 #ifdef USE_MAEMO
197 mm_context.appdata = context->appdata;
198 if(loc) mm_context.pos = loc->pos;
199 else mm_context.pos = context->appdata->home;
200
201 mm_context.import_button = gtk_button_new();
202 gtk_button_set_image(GTK_BUTTON(mm_context.import_button),
203 icon_get_widget(ICON_MISC, 5));
204 gtk_container_add(GTK_CONTAINER(GTK_DIALOG(dialog)->action_area),
205 mm_context.import_button);
206 gtk_signal_connect(GTK_OBJECT(mm_context.import_button), "clicked",
207 (GtkSignalFunc)on_mm_import_clicked, &mm_context);
208
209 if(!context->appdata->mmpos_valid)
210 gtk_widget_set_sensitive(mm_context.import_button, FALSE);
211
212 mm_context.export_button = gtk_button_new();
213 gtk_button_set_image(GTK_BUTTON(mm_context.export_button),
214 icon_get_widget(ICON_MISC, 0));
215 gtk_signal_connect(GTK_OBJECT(mm_context.export_button), "clicked",
216 (GtkSignalFunc)on_mm_export_clicked, &mm_context);
217 gtk_container_add(GTK_CONTAINER(GTK_DIALOG(dialog)->action_area),
218 mm_context.export_button);
219 #endif
220
221 gtk_box_pack_start_defaults(GTK_BOX(GTK_DIALOG(dialog)->vbox), table);
222
223 gtk_widget_show_all(dialog);
224
225 if(GTK_RESPONSE_ACCEPT == gtk_dialog_run(GTK_DIALOG(dialog))) {
226 pos_t pos;
227
228 #ifdef USE_MAEMO
229 pos.lat = lat_get(mm_context.lat);
230 pos.lon = lon_get(mm_context.lon);
231 #else
232 pos.lat = lat_get(lat);
233 pos.lon = lon_get(lon);
234 #endif
235
236 if(isnan(pos.lat) || isnan(pos.lon))
237 errorf(_("Ignoring invalid position"));
238 else {
239 char *p = (char*)gtk_entry_get_text(GTK_ENTRY(name));
240 printf("%s is at %f/%f\n", p, pos.lat, pos.lon);
241
242 /* now the list has to be re-done */
243 GtkTreePath *path = gtk_tree_path_new_from_indices(
244 context->appdata->active_location, -1);
245
246 /* Modify a particular row or create a new one if that doesn't exist */
247 GtkTreeIter iter;
248 if(!gtk_tree_model_get_iter(GTK_TREE_MODEL(context->store),&iter,path))
249 gtk_list_store_append(context->store, &iter);
250
251 char lat_str[32], lon_str[32];
252 pos_lat_str(lat_str, sizeof(lat_str), pos.lat);
253 pos_lon_str(lon_str, sizeof(lon_str), pos.lon);
254
255 if(loc) {
256 free(loc->name);
257 loc->name = strdup(p);
258 loc->pos.lat = pos.lat;
259 loc->pos.lon = pos.lon;
260
261 gtk_list_store_set(context->store, &iter,
262 LOCATION_COL_NAME, loc->name,
263 LOCATION_COL_LAT, lat_str,
264 LOCATION_COL_LON, lon_str,
265 LOCATION_COL_DATA, loc,
266 -1);
267
268 } else {
269 context->appdata->home.lat = pos.lat;
270 context->appdata->home.lon = pos.lon;
271
272 gtk_list_store_set(context->store, &iter,
273 LOCATION_COL_LAT, lat_str,
274 LOCATION_COL_LON, lon_str,
275 -1);
276 }
277 context->changed = TRUE;
278 }
279 }
280 gtk_widget_destroy(dialog);
281 }
282
283 static void on_location_add(GtkWidget *button, location_context_t *context) {
284 location_t **loc = &context->appdata->location;
285 int prev_active = context->appdata->active_location;
286
287 int i = 1;
288 while(*loc) {
289 loc = &(*loc)->next;
290 i++;
291 }
292
293 *loc = g_new0(location_t, 1);
294 if(!*loc) {
295 errorf(_("Out of memory"));
296 return;
297 }
298
299 (*loc)->name = strdup(_("<new>"));
300 #if 0
301 (*loc)->pos.lat = DEFAULT_LAT;
302 (*loc)->pos.lon = DEFAULT_LON;
303 #endif
304
305 context->changed = FALSE;
306 context->appdata->active_location = i;
307 on_location_edit(button, context);
308
309 if(context->changed)
310 location_select(context);
311 else {
312 /* remove newly attached entry and select previous one */
313 location_t *tmp = *loc;
314 *loc = NULL;
315 free(tmp->name);
316 free(tmp);
317
318 context->appdata->active_location = prev_active;
319 }
320 }
321
322 static void on_location_remove(GtkWidget *but, location_context_t *context) {
323 GtkTreeSelection *selection;
324 GtkTreeModel *model;
325 GtkTreeIter iter;
326
327 selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(context->view));
328 if(gtk_tree_selection_get_selected(selection, &model, &iter)) {
329 location_t *loc;
330 gtk_tree_model_get(model, &iter, LOCATION_COL_DATA, &loc, -1);
331
332 g_assert(loc);
333
334 /* de-chain */
335 location_t **prev = &context->appdata->location;
336 while(*prev != loc) prev = &((*prev)->next);
337 *prev = loc->next;
338
339 /* free location itself */
340 if(loc->name) free(loc->name);
341 free(loc);
342
343 /* and remove from store */
344 gtk_list_store_remove(GTK_LIST_STORE(model), &iter);
345 }
346
347 /* disable remove button */
348 gtk_widget_set_sensitive(context->but_remove, FALSE);
349 /* select the first entry */
350
351 context->appdata->active_location = 0;
352 location_select(context);
353 }
354
355 static gboolean
356 view_selection_func(GtkTreeSelection *selection, GtkTreeModel *model,
357 GtkTreePath *path, gboolean path_currently_selected,
358 gpointer userdata) {
359 location_context_t *context = (location_context_t*)userdata;
360 GtkTreeIter iter;
361
362 if(gtk_tree_model_get_iter(model, &iter, path)) {
363 g_assert(gtk_tree_path_get_depth(path) == 1);
364
365 /* if the first entry has been selected */
366 if(!path_currently_selected && context->but_remove) {
367 context->appdata->active_location = gtk_tree_path_get_indices(path)[0];
368 gtk_widget_set_sensitive(context->but_remove,
369 context->appdata->active_location);
370 }
371 }
372
373 return TRUE; /* allow selection state to change */
374 }
375
376 static GtkWidget *location_widget(location_context_t *context) {
377
378 GtkWidget *vbox = gtk_vbox_new(FALSE,3);
379 context->view = gtk_tree_view_new();
380
381 gtk_tree_selection_set_select_function(
382 gtk_tree_view_get_selection(GTK_TREE_VIEW(context->view)),
383 view_selection_func,
384 context, NULL);
385
386 #ifndef USE_MAEMO
387 gtk_tree_view_set_headers_visible(GTK_TREE_VIEW(context->view), FALSE);
388 #endif
389
390 /* --- "Name" column --- */
391 GtkCellRenderer *renderer = gtk_cell_renderer_text_new();
392 g_object_set(renderer, "ellipsize", PANGO_ELLIPSIZE_END, NULL );
393 GtkTreeViewColumn *column = gtk_tree_view_column_new_with_attributes(
394 _("Name"), renderer, "text", LOCATION_COL_NAME, NULL);
395 gtk_tree_view_column_set_expand(column, TRUE);
396 gtk_tree_view_insert_column(GTK_TREE_VIEW(context->view), column, -1);
397
398 /* --- "Latitude" column --- */
399 renderer = gtk_cell_renderer_text_new();
400 // g_object_set(renderer, "xalign", 1.0, NULL );
401 gtk_tree_view_insert_column_with_attributes(GTK_TREE_VIEW(context->view),
402 -1, _("Latitude"), renderer, "text", LOCATION_COL_LAT, NULL);
403
404 /* --- "Longitude" column --- */
405 renderer = gtk_cell_renderer_text_new();
406 // g_object_set(renderer, "xalign", 1.0, NULL );
407 gtk_tree_view_insert_column_with_attributes(GTK_TREE_VIEW(context->view),
408 -1, _("Longitude"), renderer, "text", LOCATION_COL_LON, NULL);
409
410 /* build and fill the store */
411 context->store = gtk_list_store_new(LOCATION_NUM_COLS,
412 G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_POINTER);
413
414 gtk_tree_view_set_model(GTK_TREE_VIEW(context->view),
415 GTK_TREE_MODEL(context->store));
416
417 char lat[32], lon[32];
418 GtkTreeIter iter;
419
420 /* add home position */
421 pos_lat_str(lat, sizeof(lat), context->appdata->home.lat);
422 pos_lon_str(lon, sizeof(lon), context->appdata->home.lon);
423 gtk_list_store_append(context->store, &iter);
424 gtk_list_store_set(context->store, &iter,
425 LOCATION_COL_NAME, _("Home"),
426 LOCATION_COL_LAT, lat,
427 LOCATION_COL_LON, lon,
428 LOCATION_COL_DATA, NULL,
429 -1);
430
431 location_t *loc = context->appdata->location;
432 while(loc) {
433 pos_lat_str(lat, sizeof(lat), loc->pos.lat);
434 pos_lon_str(lon, sizeof(lon), loc->pos.lon);
435
436 /* Append a row and fill in some data */
437 gtk_list_store_append(context->store, &iter);
438 gtk_list_store_set(context->store, &iter,
439 LOCATION_COL_NAME, loc->name,
440 LOCATION_COL_LAT, lat,
441 LOCATION_COL_LON, lon,
442 LOCATION_COL_DATA, loc,
443 -1);
444 loc = loc->next;
445 }
446
447 g_object_unref(context->store);
448
449 #if 0
450 /* make list react on clicks */
451 g_signal_connect(context->view, "row-activated",
452 (GCallback)gpxlist_view_onRowActivated, appdata);
453 #endif
454
455 /* select the "active" row */
456 location_select(context);
457
458 /* put it into a scrolled window */
459 GtkWidget *scrolled_window = gtk_scrolled_window_new (NULL, NULL);
460 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolled_window),
461 GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC);
462 gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(scrolled_window),
463 GTK_SHADOW_ETCHED_IN);
464 // gtk_container_set_border_width(GTK_CONTAINER(scrolled_window), 3);
465 gtk_container_add(GTK_CONTAINER(scrolled_window), context->view);
466 gtk_box_pack_start_defaults(GTK_BOX(vbox), scrolled_window);
467
468 /* ------- button box ------------ */
469
470 GtkWidget *hbox = gtk_hbox_new(TRUE,3);
471 context->but_add = gtk_button_new_with_label(_("Add"));
472 gtk_box_pack_start_defaults(GTK_BOX(hbox), context->but_add);
473 gtk_signal_connect(GTK_OBJECT(context->but_add), "clicked",
474 GTK_SIGNAL_FUNC(on_location_add), context);
475
476 context->but_edit = gtk_button_new_with_label(_("Edit"));
477 gtk_box_pack_start_defaults(GTK_BOX(hbox), context->but_edit);
478 gtk_signal_connect(GTK_OBJECT(context->but_edit), "clicked",
479 GTK_SIGNAL_FUNC(on_location_edit), context);
480
481 context->but_remove = gtk_button_new_with_label(_("Remove"));
482 gtk_widget_set_sensitive(context->but_remove,
483 context->appdata->active_location);
484 gtk_box_pack_start_defaults(GTK_BOX(hbox), context->but_remove);
485 gtk_signal_connect(GTK_OBJECT(context->but_remove), "clicked",
486 GTK_SIGNAL_FUNC(on_location_remove), context);
487
488 gtk_box_pack_start_defaults(GTK_BOX(vbox), hbox);
489 return vbox;
490 }
491
492 void cb_menu_settings(GtkWidget *window, gpointer data) {
493 appdata_t *appdata = (appdata_t *)data;
494 GtkWidget *table, *label, *hbox, *notebook;
495 GtkWidget *cbox_imperial, *cbox_load_images;
496 settings_dialog_state_t hstate;
497
498 GtkWidget *dialog = gtk_dialog_new_with_buttons(_("Settings"),
499 GTK_WINDOW(appdata->window), GTK_DIALOG_MODAL,
500 GTK_STOCK_OK, GTK_RESPONSE_ACCEPT,
501 GTK_STOCK_CANCEL, GTK_RESPONSE_REJECT,
502 NULL);
503
504 #if defined(USE_MAEMO) && defined(HILDON_HELP)
505 hildon_help_dialog_help_enable(GTK_DIALOG(dialog),
506 HELP_ID_SETTINGS, appdata->osso_context);
507 gtk_window_set_default_size(GTK_WINDOW(dialog), 550, 100);
508 #endif
509
510 gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dialog)->vbox),
511 notebook = gtk_notebook_new(), TRUE, TRUE, 0);
512
513
514 /* ------------------ the "home" widget ---------------------- */
515 table = gtk_table_new(2, 2, FALSE);
516
517 hstate.cbox_gps = gtk_check_button_new_with_label(_("Enable GPS"));
518 gtk_table_attach(GTK_TABLE(table),
519 hstate.cbox_gps, 0, 2, 0, 1, GTK_FILL, 0, 2, 0);
520 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(hstate.cbox_gps),
521 appdata->use_gps);
522
523 location_context_t location_context;
524 memset(&location_context, 0, sizeof(location_context_t));
525 location_context.appdata = appdata;
526 location_context.settings_dialog = dialog;
527
528 /* location widget */
529 gtk_table_attach_defaults(GTK_TABLE(table),
530 hstate.loc = location_widget(&location_context), 0, 2, 1, 2);
531
532 settings_update(NULL, &hstate);
533
534 /* Connect the "clicked" signal of the button to our callback */
535 gtk_signal_connect (GTK_OBJECT (hstate.cbox_gps), "clicked",
536 GTK_SIGNAL_FUNC(settings_update), (gpointer)&hstate);
537
538 gtk_notebook_append_page(GTK_NOTEBOOK(notebook), table,
539 gtk_label_new(_("GPS")));
540
541 /* ---------------- misc old main menu entries ----------------- */
542
543 table = gtk_table_new(2, 2, FALSE);
544
545 cbox_imperial = gtk_check_button_new_with_label(
546 _("Imperial units"));
547 gtk_table_attach(GTK_TABLE(table),
548 cbox_imperial, 0, 2, 0, 1, GTK_FILL, 0, 2, 0);
549 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(cbox_imperial),
550 appdata->imperial);
551 cbox_load_images = gtk_check_button_new_with_label(
552 _("Load images"));
553 gtk_table_attach(GTK_TABLE(table),
554 cbox_load_images, 0, 2, 1, 2, GTK_FILL, 0, 2, 0);
555 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(cbox_load_images),
556 appdata->load_images);
557
558 gtk_notebook_append_page(GTK_NOTEBOOK(notebook), table,
559 gtk_label_new(_("Misc")));
560
561 /* ----------------- gpxlist settings ------------------- */
562
563 table = gtk_table_new(1, 2, FALSE);
564
565 hbox = gtk_hbox_new(FALSE,2);
566 gtk_box_pack_start_defaults(GTK_BOX(hbox),
567 label = gtk_label_new(_("Visible items:")));
568 gtk_misc_set_alignment(GTK_MISC(label), 0.f, 0.5f);
569
570 GtkWidget *cbox_fname = gtk_check_button_new_with_label(_("Filename"));
571 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(cbox_fname),
572 appdata->gpxlist_items & GPXLIST_ITEM_FILENAME);
573 gtk_box_pack_start_defaults(GTK_BOX(hbox), cbox_fname);
574 GtkWidget *cbox_date = gtk_check_button_new_with_label(_("Date"));
575 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(cbox_date),
576 appdata->gpxlist_items & GPXLIST_ITEM_DATE);
577 gtk_box_pack_start_defaults(GTK_BOX(hbox), cbox_date);
578 GtkWidget *cbox_num = gtk_check_button_new_with_label(_("# Caches"));
579 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(cbox_num),
580 appdata->gpxlist_items & GPXLIST_ITEM_CNUM);
581 gtk_box_pack_start_defaults(GTK_BOX(hbox), cbox_num);
582
583 gtk_table_attach(GTK_TABLE(table), hbox, 0, 2, 0, 1, GTK_FILL, 0, 2, 0);
584
585 gtk_notebook_append_page(GTK_NOTEBOOK(notebook), table,
586 gtk_label_new(_("GPX list")));
587
588 /* ----------------- cachelist settings ------------------- */
589
590 table = gtk_table_new(4, 2, FALSE);
591
592 hbox = gtk_hbox_new(FALSE,2);
593 gtk_box_pack_start_defaults(GTK_BOX(hbox),
594 label = gtk_label_new(_("Visible items:")));
595 gtk_misc_set_alignment(GTK_MISC(label), 0.f, 0.5f);
596
597 GtkWidget *cbox_wpt = gtk_check_button_new_with_label(_("Wpt"));
598 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(cbox_wpt),
599 appdata->cachelist_items & CACHELIST_ITEM_ID);
600 gtk_box_pack_start_defaults(GTK_BOX(hbox), cbox_wpt);
601 GtkWidget *cbox_size = gtk_check_button_new_with_label(_("Size"));
602 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(cbox_size),
603 appdata->cachelist_items & CACHELIST_ITEM_SIZE);
604 gtk_box_pack_start_defaults(GTK_BOX(hbox), cbox_size);
605 GtkWidget *cbox_rate = gtk_check_button_new_with_label(_("Rating"));
606 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(cbox_rate),
607 appdata->cachelist_items & CACHELIST_ITEM_RATING);
608 gtk_box_pack_start_defaults(GTK_BOX(hbox), cbox_rate);
609
610 gtk_table_attach(GTK_TABLE(table), hbox, 0, 2, 0, 1, GTK_FILL, 0, 2, 0);
611
612 GtkWidget *cbox_cachelist_hidef =
613 gtk_check_button_new_with_label(_("Hide caches marked \"found\""));
614 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(cbox_cachelist_hidef),
615 appdata->cachelist_hide_found);
616 gtk_table_attach(GTK_TABLE(table), cbox_cachelist_hidef,
617 0, 2, 1, 2, GTK_FILL, 0, 2, 0);
618
619
620 #ifdef USE_MAEMO
621 GtkWidget *cbox_cachelist_dss =
622 gtk_check_button_new_with_label(_("Disable screen saver"));
623 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(cbox_cachelist_dss),
624 appdata->cachelist_disable_screensaver);
625 gtk_table_attach(GTK_TABLE(table), cbox_cachelist_dss,
626 0, 2, 2, 3, GTK_FILL, 0, 2, 0);
627
628 GtkWidget *cbox_update =
629 gtk_check_button_new_with_label(_("Update every 30 sec"));
630 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(cbox_update),
631 appdata->cachelist_update);
632 gtk_table_attach(GTK_TABLE(table), cbox_update,
633 0, 2, 3, 4, GTK_FILL, 0, 2, 0);
634 #endif
635
636 gtk_notebook_append_page(GTK_NOTEBOOK(notebook), table,
637 gtk_label_new(_("Cache list")));
638
639 /* ----------------- cache settings ------------------- */
640
641 table = gtk_table_new(2, 2, FALSE);
642
643 hbox = gtk_hbox_new(FALSE,2);
644 gtk_box_pack_start_defaults(GTK_BOX(hbox),
645 label = gtk_label_new(_("Compass damping:")));
646 gtk_misc_set_alignment(GTK_MISC(label), 0.f, 0.5f);
647
648 gtk_box_pack_start(GTK_BOX(hbox), gtk_label_new(_("Min")), FALSE, FALSE,0);
649 GtkWidget *scale = gtk_hscale_new_with_range(1, MAX_AVERAGE, 1);
650 gtk_scale_set_value_pos(GTK_SCALE(scale), GTK_POS_LEFT);
651 gtk_scale_set_draw_value(GTK_SCALE(scale), FALSE);
652 gtk_range_set_value(GTK_RANGE(scale), appdata->compass_damping);
653 gtk_box_pack_start_defaults(GTK_BOX(hbox), scale);
654 gtk_box_pack_start(GTK_BOX(hbox), gtk_label_new(_("Max")), FALSE, FALSE,0);
655
656 gtk_table_attach(GTK_TABLE(table), hbox, 0, 2, 0, 1, GTK_FILL | GTK_EXPAND, 0, 0, 0);
657
658 #ifdef USE_MAEMO
659 GtkWidget *cbox_goto_dss = gtk_check_button_new_with_label(
660 _("Disable screen saver in \"goto\" view"));
661 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(cbox_goto_dss),
662 appdata->goto_disable_screensaver);
663 gtk_table_attach(GTK_TABLE(table), cbox_goto_dss, 0, 2, 1, 2, GTK_FILL, 0, 2, 0);
664 #endif
665
666 gtk_notebook_append_page(GTK_NOTEBOOK(notebook), table,
667 gtk_label_new(_("Cache")));
668
669
670 /* -------------------------------------------------------- */
671
672 gtk_widget_show_all(dialog);
673
674 if(GTK_RESPONSE_ACCEPT == gtk_dialog_run(GTK_DIALOG(dialog))) {
675 gboolean prev_cachelist_hide_found = appdata->cachelist_hide_found;
676
677 appdata->use_gps = gtk_toggle_button_get_active(
678 GTK_TOGGLE_BUTTON(hstate.cbox_gps));
679 appdata->imperial = gtk_toggle_button_get_active(
680 GTK_TOGGLE_BUTTON(cbox_imperial));
681 appdata->load_images = gtk_toggle_button_get_active(
682 GTK_TOGGLE_BUTTON(cbox_load_images));
683
684 appdata->compass_damping = 0.5 + gtk_range_get_value(GTK_RANGE(scale));
685
686 appdata->gpxlist_items = GPXLIST_ITEM_VALID;
687 if(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(cbox_fname)))
688 appdata->gpxlist_items |= GPXLIST_ITEM_FILENAME;
689 if(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(cbox_date)))
690 appdata->gpxlist_items |= GPXLIST_ITEM_DATE;
691 if(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(cbox_num)))
692 appdata->gpxlist_items |= GPXLIST_ITEM_CNUM;
693
694 appdata->cachelist_items = CACHELIST_ITEM_VALID;
695 if(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(cbox_wpt)))
696 appdata->cachelist_items |= CACHELIST_ITEM_ID;
697 if(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(cbox_size)))
698 appdata->cachelist_items |= CACHELIST_ITEM_SIZE;
699 if(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(cbox_rate)))
700 appdata->cachelist_items |= CACHELIST_ITEM_RATING;
701
702 appdata->cachelist_hide_found = gtk_toggle_button_get_active(
703 GTK_TOGGLE_BUTTON(cbox_cachelist_hidef));
704
705 #ifdef USE_MAEMO
706 appdata->goto_disable_screensaver = gtk_toggle_button_get_active(
707 GTK_TOGGLE_BUTTON(cbox_goto_dss));
708 appdata->cachelist_disable_screensaver = gtk_toggle_button_get_active(
709 GTK_TOGGLE_BUTTON(cbox_cachelist_dss));
710 appdata->cachelist_update = gtk_toggle_button_get_active(
711 GTK_TOGGLE_BUTTON(cbox_update));
712 #endif
713
714 /* build some additional flags that are used to decide whether a */
715 /* redraw is necessary */
716 int flags = CHANGE_FLAG_POS;
717
718 if(prev_cachelist_hide_found != appdata->cachelist_hide_found)
719 flags |= CHANGE_FLAG_MASK; // visibility mask has changed
720
721 main_after_settings_redraw(appdata, flags);
722 }
723 gtk_widget_destroy(dialog);
724 }
725