Contents of /trunk/src/settings.c

Parent Directory Parent Directory | Revision Log Revision Log


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