Contents of /trunk/src/settings.c

Parent Directory Parent Directory | Revision Log Revision Log


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