Contents of /trunk/src/settings.c

Parent Directory Parent Directory | Revision Log Revision Log


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