Contents of /trunk/src/settings.c

Parent Directory Parent Directory | Revision Log Revision Log


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