Contents of /trunk/src/settings.c

Parent Directory Parent Directory | Revision Log Revision Log


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