Parent Directory | Revision Log
BCT cleanup
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 | context->view = gtk_tree_view_new(); | ||
385 | |||
386 | gtk_tree_selection_set_select_function( | ||
387 | gtk_tree_view_get_selection(GTK_TREE_VIEW(context->view)), | ||
388 | view_selection_func, | ||
389 | context, NULL); | ||
390 | |||
391 | #ifndef USE_MAEMO | ||
392 | gtk_tree_view_set_headers_visible(GTK_TREE_VIEW(context->view), FALSE); | ||
393 | #endif | ||
394 | |||
395 | /* --- "Name" column --- */ | ||
396 | GtkCellRenderer *renderer = gtk_cell_renderer_text_new(); | ||
397 | g_object_set(renderer, "ellipsize", PANGO_ELLIPSIZE_END, NULL ); | ||
398 | GtkTreeViewColumn *column = gtk_tree_view_column_new_with_attributes( | ||
399 | _("Name"), renderer, "text", LOCATION_COL_NAME, NULL); | ||
400 | gtk_tree_view_column_set_expand(column, TRUE); | ||
401 | gtk_tree_view_insert_column(GTK_TREE_VIEW(context->view), column, -1); | ||
402 | |||
403 | /* --- "Latitude" column --- */ | ||
404 | renderer = gtk_cell_renderer_text_new(); | ||
405 | // g_object_set(renderer, "xalign", 1.0, NULL ); | ||
406 | gtk_tree_view_insert_column_with_attributes(GTK_TREE_VIEW(context->view), | ||
407 | -1, _("Latitude"), renderer, "text", LOCATION_COL_LAT, NULL); | ||
408 | |||
409 | /* --- "Longitude" column --- */ | ||
410 | renderer = gtk_cell_renderer_text_new(); | ||
411 | // g_object_set(renderer, "xalign", 1.0, NULL ); | ||
412 | gtk_tree_view_insert_column_with_attributes(GTK_TREE_VIEW(context->view), | ||
413 | -1, _("Longitude"), renderer, "text", LOCATION_COL_LON, NULL); | ||
414 | |||
415 | /* build and fill the store */ | ||
416 | context->store = gtk_list_store_new(LOCATION_NUM_COLS, | ||
417 | G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_POINTER); | ||
418 | |||
419 | gtk_tree_view_set_model(GTK_TREE_VIEW(context->view), | ||
420 | GTK_TREE_MODEL(context->store)); | ||
421 | |||
422 | char lat[32], lon[32]; | ||
423 | GtkTreeIter iter; | ||
424 | |||
425 | /* add home position */ | ||
426 | pos_lat_str(lat, sizeof(lat), context->appdata->home.lat); | ||
427 | pos_lon_str(lon, sizeof(lon), context->appdata->home.lon); | ||
428 | gtk_list_store_append(context->store, &iter); | ||
429 | gtk_list_store_set(context->store, &iter, | ||
430 | LOCATION_COL_NAME, _("Home"), | ||
431 | LOCATION_COL_LAT, lat, | ||
432 | LOCATION_COL_LON, lon, | ||
433 | LOCATION_COL_DATA, NULL, | ||
434 | -1); | ||
435 | |||
436 | location_t *loc = context->appdata->location; | ||
437 | while(loc) { | ||
438 | pos_lat_str(lat, sizeof(lat), loc->pos.lat); | ||
439 | pos_lon_str(lon, sizeof(lon), loc->pos.lon); | ||
440 | |||
441 | /* Append a row and fill in some data */ | ||
442 | gtk_list_store_append(context->store, &iter); | ||
443 | gtk_list_store_set(context->store, &iter, | ||
444 | LOCATION_COL_NAME, loc->name, | ||
445 | LOCATION_COL_LAT, lat, | ||
446 | LOCATION_COL_LON, lon, | ||
447 | LOCATION_COL_DATA, loc, | ||
448 | -1); | ||
449 | loc = loc->next; | ||
450 | } | ||
451 | |||
452 | g_object_unref(context->store); | ||
453 | |||
454 | #if 0 | ||
455 | /* make list react on clicks */ | ||
456 | g_signal_connect(context->view, "row-activated", | ||
457 | (GCallback)gpxlist_view_onRowActivated, appdata); | ||
458 | #endif | ||
459 | |||
460 | /* select the "active" row */ | ||
461 | location_select(context); | ||
462 | |||
463 | /* put it into a scrolled window */ | ||
464 | 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_set_border_width(GTK_CONTAINER(scrolled_window), 3); | ||
470 | gtk_container_add(GTK_CONTAINER(scrolled_window), context->view); | ||
471 | gtk_box_pack_start_defaults(GTK_BOX(vbox), scrolled_window); | ||
472 | |||
473 | /* ------- button box ------------ */ | ||
474 | |||
475 | GtkWidget *hbox = gtk_hbox_new(TRUE,3); | ||
476 | harbaum | 7 | context->but_add = gtk_button_new_with_label(_("Add")); |
477 | harbaum | 1 | gtk_box_pack_start_defaults(GTK_BOX(hbox), context->but_add); |
478 | gtk_signal_connect(GTK_OBJECT(context->but_add), "clicked", | ||
479 | GTK_SIGNAL_FUNC(on_location_add), context); | ||
480 | |||
481 | harbaum | 7 | context->but_edit = gtk_button_new_with_label(_("Edit")); |
482 | harbaum | 1 | gtk_box_pack_start_defaults(GTK_BOX(hbox), context->but_edit); |
483 | gtk_signal_connect(GTK_OBJECT(context->but_edit), "clicked", | ||
484 | GTK_SIGNAL_FUNC(on_location_edit), context); | ||
485 | |||
486 | context->but_remove = gtk_button_new_with_label(_("Remove")); | ||
487 | gtk_widget_set_sensitive(context->but_remove, | ||
488 | context->appdata->active_location); | ||
489 | gtk_box_pack_start_defaults(GTK_BOX(hbox), context->but_remove); | ||
490 | gtk_signal_connect(GTK_OBJECT(context->but_remove), "clicked", | ||
491 | GTK_SIGNAL_FUNC(on_location_remove), context); | ||
492 | |||
493 | gtk_box_pack_start_defaults(GTK_BOX(vbox), hbox); | ||
494 | return vbox; | ||
495 | } | ||
496 | |||
497 | void cb_menu_settings(GtkWidget *window, gpointer data) { | ||
498 | appdata_t *appdata = (appdata_t *)data; | ||
499 | GtkWidget *table, *label, *hbox, *notebook; | ||
500 | harbaum | 12 | GtkWidget *cbox_imperial; |
501 | harbaum | 1 | settings_dialog_state_t hstate; |
502 | |||
503 | GtkWidget *dialog = gtk_dialog_new_with_buttons(_("Settings"), | ||
504 | GTK_WINDOW(appdata->window), GTK_DIALOG_MODAL, | ||
505 | GTK_STOCK_OK, GTK_RESPONSE_ACCEPT, | ||
506 | GTK_STOCK_CANCEL, GTK_RESPONSE_REJECT, | ||
507 | NULL); | ||
508 | |||
509 | #if defined(USE_MAEMO) && defined(HILDON_HELP) | ||
510 | hildon_help_dialog_help_enable(GTK_DIALOG(dialog), | ||
511 | HELP_ID_SETTINGS, appdata->osso_context); | ||
512 | gtk_window_set_default_size(GTK_WINDOW(dialog), 550, 100); | ||
513 | #endif | ||
514 | |||
515 | gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dialog)->vbox), | ||
516 | notebook = gtk_notebook_new(), TRUE, TRUE, 0); | ||
517 | |||
518 | |||
519 | /* ------------------ the "home" widget ---------------------- */ | ||
520 | table = gtk_table_new(2, 2, FALSE); | ||
521 | |||
522 | hstate.cbox_gps = gtk_check_button_new_with_label(_("Enable GPS")); | ||
523 | gtk_table_attach(GTK_TABLE(table), | ||
524 | hstate.cbox_gps, 0, 2, 0, 1, GTK_FILL, 0, 2, 0); | ||
525 | gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(hstate.cbox_gps), | ||
526 | appdata->use_gps); | ||
527 | |||
528 | location_context_t location_context; | ||
529 | memset(&location_context, 0, sizeof(location_context_t)); | ||
530 | location_context.appdata = appdata; | ||
531 | location_context.settings_dialog = dialog; | ||
532 | |||
533 | /* location widget */ | ||
534 | gtk_table_attach_defaults(GTK_TABLE(table), | ||
535 | hstate.loc = location_widget(&location_context), 0, 2, 1, 2); | ||
536 | |||
537 | settings_update(NULL, &hstate); | ||
538 | |||
539 | /* Connect the "clicked" signal of the button to our callback */ | ||
540 | gtk_signal_connect (GTK_OBJECT (hstate.cbox_gps), "clicked", | ||
541 | GTK_SIGNAL_FUNC(settings_update), (gpointer)&hstate); | ||
542 | |||
543 | gtk_notebook_append_page(GTK_NOTEBOOK(notebook), table, | ||
544 | gtk_label_new(_("GPS"))); | ||
545 | |||
546 | /* ---------------- misc old main menu entries ----------------- */ | ||
547 | |||
548 | table = gtk_table_new(2, 2, FALSE); | ||
549 | |||
550 | cbox_imperial = gtk_check_button_new_with_label( | ||
551 | _("Imperial units")); | ||
552 | gtk_table_attach(GTK_TABLE(table), | ||
553 | cbox_imperial, 0, 2, 0, 1, GTK_FILL, 0, 2, 0); | ||
554 | gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(cbox_imperial), | ||
555 | appdata->imperial); | ||
556 | gtk_notebook_append_page(GTK_NOTEBOOK(notebook), table, | ||
557 | gtk_label_new(_("Misc"))); | ||
558 | |||
559 | /* ----------------- gpxlist settings ------------------- */ | ||
560 | |||
561 | table = gtk_table_new(1, 2, FALSE); | ||
562 | |||
563 | hbox = gtk_hbox_new(FALSE,2); | ||
564 | gtk_box_pack_start_defaults(GTK_BOX(hbox), | ||
565 | label = gtk_label_new(_("Visible items:"))); | ||
566 | gtk_misc_set_alignment(GTK_MISC(label), 0.f, 0.5f); | ||
567 | |||
568 | GtkWidget *cbox_fname = gtk_check_button_new_with_label(_("Filename")); | ||
569 | gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(cbox_fname), | ||
570 | appdata->gpxlist_items & GPXLIST_ITEM_FILENAME); | ||
571 | gtk_box_pack_start_defaults(GTK_BOX(hbox), cbox_fname); | ||
572 | GtkWidget *cbox_date = gtk_check_button_new_with_label(_("Date")); | ||
573 | gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(cbox_date), | ||
574 | appdata->gpxlist_items & GPXLIST_ITEM_DATE); | ||
575 | gtk_box_pack_start_defaults(GTK_BOX(hbox), cbox_date); | ||
576 | GtkWidget *cbox_num = gtk_check_button_new_with_label(_("# Caches")); | ||
577 | gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(cbox_num), | ||
578 | appdata->gpxlist_items & GPXLIST_ITEM_CNUM); | ||
579 | gtk_box_pack_start_defaults(GTK_BOX(hbox), cbox_num); | ||
580 | |||
581 | gtk_table_attach(GTK_TABLE(table), hbox, 0, 2, 0, 1, GTK_FILL, 0, 2, 0); | ||
582 | |||
583 | gtk_notebook_append_page(GTK_NOTEBOOK(notebook), table, | ||
584 | gtk_label_new(_("GPX list"))); | ||
585 | |||
586 | /* ----------------- cachelist settings ------------------- */ | ||
587 | |||
588 | table = gtk_table_new(4, 2, FALSE); | ||
589 | |||
590 | hbox = gtk_hbox_new(FALSE,2); | ||
591 | gtk_box_pack_start_defaults(GTK_BOX(hbox), | ||
592 | label = gtk_label_new(_("Visible items:"))); | ||
593 | gtk_misc_set_alignment(GTK_MISC(label), 0.f, 0.5f); | ||
594 | |||
595 | GtkWidget *cbox_wpt = gtk_check_button_new_with_label(_("Wpt")); | ||
596 | gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(cbox_wpt), | ||
597 | appdata->cachelist_items & CACHELIST_ITEM_ID); | ||
598 | gtk_box_pack_start_defaults(GTK_BOX(hbox), cbox_wpt); | ||
599 | GtkWidget *cbox_size = gtk_check_button_new_with_label(_("Size")); | ||
600 | gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(cbox_size), | ||
601 | appdata->cachelist_items & CACHELIST_ITEM_SIZE); | ||
602 | gtk_box_pack_start_defaults(GTK_BOX(hbox), cbox_size); | ||
603 | GtkWidget *cbox_rate = gtk_check_button_new_with_label(_("Rating")); | ||
604 | gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(cbox_rate), | ||
605 | appdata->cachelist_items & CACHELIST_ITEM_RATING); | ||
606 | gtk_box_pack_start_defaults(GTK_BOX(hbox), cbox_rate); | ||
607 | |||
608 | gtk_table_attach(GTK_TABLE(table), hbox, 0, 2, 0, 1, GTK_FILL, 0, 2, 0); | ||
609 | |||
610 | GtkWidget *cbox_cachelist_hidef = | ||
611 | gtk_check_button_new_with_label(_("Hide caches marked \"found\"")); | ||
612 | gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(cbox_cachelist_hidef), | ||
613 | appdata->cachelist_hide_found); | ||
614 | gtk_table_attach(GTK_TABLE(table), cbox_cachelist_hidef, | ||
615 | 0, 2, 1, 2, GTK_FILL, 0, 2, 0); | ||
616 | |||
617 | |||
618 | #ifdef USE_MAEMO | ||
619 | GtkWidget *cbox_cachelist_dss = | ||
620 | gtk_check_button_new_with_label(_("Disable screen saver")); | ||
621 | gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(cbox_cachelist_dss), | ||
622 | appdata->cachelist_disable_screensaver); | ||
623 | gtk_table_attach(GTK_TABLE(table), cbox_cachelist_dss, | ||
624 | 0, 2, 2, 3, GTK_FILL, 0, 2, 0); | ||
625 | harbaum | 129 | #endif |
626 | harbaum | 1 | |
627 | GtkWidget *cbox_update = | ||
628 | gtk_check_button_new_with_label(_("Update every 30 sec")); | ||
629 | gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(cbox_update), | ||
630 | appdata->cachelist_update); | ||
631 | gtk_table_attach(GTK_TABLE(table), cbox_update, | ||
632 | 0, 2, 3, 4, GTK_FILL, 0, 2, 0); | ||
633 | |||
634 | gtk_notebook_append_page(GTK_NOTEBOOK(notebook), table, | ||
635 | gtk_label_new(_("Cache list"))); | ||
636 | |||
637 | /* ----------------- cache settings ------------------- */ | ||
638 | |||
639 | table = gtk_table_new(2, 2, FALSE); | ||
640 | |||
641 | hbox = gtk_hbox_new(FALSE,2); | ||
642 | gtk_box_pack_start_defaults(GTK_BOX(hbox), | ||
643 | label = gtk_label_new(_("Compass damping:"))); | ||
644 | gtk_misc_set_alignment(GTK_MISC(label), 0.f, 0.5f); | ||
645 | |||
646 | gtk_box_pack_start(GTK_BOX(hbox), gtk_label_new(_("Min")), FALSE, FALSE,0); | ||
647 | GtkWidget *scale = gtk_hscale_new_with_range(1, MAX_AVERAGE, 1); | ||
648 | gtk_scale_set_value_pos(GTK_SCALE(scale), GTK_POS_LEFT); | ||
649 | gtk_scale_set_draw_value(GTK_SCALE(scale), FALSE); | ||
650 | gtk_range_set_value(GTK_RANGE(scale), appdata->compass_damping); | ||
651 | gtk_box_pack_start_defaults(GTK_BOX(hbox), scale); | ||
652 | gtk_box_pack_start(GTK_BOX(hbox), gtk_label_new(_("Max")), FALSE, FALSE,0); | ||
653 | |||
654 | gtk_table_attach(GTK_TABLE(table), hbox, 0, 2, 0, 1, GTK_FILL | GTK_EXPAND, 0, 0, 0); | ||
655 | |||
656 | #ifdef USE_MAEMO | ||
657 | GtkWidget *cbox_goto_dss = gtk_check_button_new_with_label( | ||
658 | _("Disable screen saver in \"goto\" view")); | ||
659 | gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(cbox_goto_dss), | ||
660 | appdata->goto_disable_screensaver); | ||
661 | gtk_table_attach(GTK_TABLE(table), cbox_goto_dss, 0, 2, 1, 2, GTK_FILL, 0, 2, 0); | ||
662 | #endif | ||
663 | |||
664 | gtk_notebook_append_page(GTK_NOTEBOOK(notebook), table, | ||
665 | gtk_label_new(_("Cache"))); | ||
666 | |||
667 | |||
668 | /* -------------------------------------------------------- */ | ||
669 | |||
670 | gtk_widget_show_all(dialog); | ||
671 | |||
672 | if(GTK_RESPONSE_ACCEPT == gtk_dialog_run(GTK_DIALOG(dialog))) { | ||
673 | gboolean prev_cachelist_hide_found = appdata->cachelist_hide_found; | ||
674 | |||
675 | appdata->use_gps = gtk_toggle_button_get_active( | ||
676 | GTK_TOGGLE_BUTTON(hstate.cbox_gps)); | ||
677 | appdata->imperial = gtk_toggle_button_get_active( | ||
678 | GTK_TOGGLE_BUTTON(cbox_imperial)); | ||
679 | |||
680 | appdata->compass_damping = 0.5 + gtk_range_get_value(GTK_RANGE(scale)); | ||
681 | |||
682 | appdata->gpxlist_items = GPXLIST_ITEM_VALID; | ||
683 | if(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(cbox_fname))) | ||
684 | appdata->gpxlist_items |= GPXLIST_ITEM_FILENAME; | ||
685 | if(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(cbox_date))) | ||
686 | appdata->gpxlist_items |= GPXLIST_ITEM_DATE; | ||
687 | if(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(cbox_num))) | ||
688 | appdata->gpxlist_items |= GPXLIST_ITEM_CNUM; | ||
689 | |||
690 | appdata->cachelist_items = CACHELIST_ITEM_VALID; | ||
691 | if(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(cbox_wpt))) | ||
692 | appdata->cachelist_items |= CACHELIST_ITEM_ID; | ||
693 | if(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(cbox_size))) | ||
694 | appdata->cachelist_items |= CACHELIST_ITEM_SIZE; | ||
695 | if(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(cbox_rate))) | ||
696 | appdata->cachelist_items |= CACHELIST_ITEM_RATING; | ||
697 | |||
698 | appdata->cachelist_hide_found = gtk_toggle_button_get_active( | ||
699 | GTK_TOGGLE_BUTTON(cbox_cachelist_hidef)); | ||
700 | |||
701 | #ifdef USE_MAEMO | ||
702 | appdata->goto_disable_screensaver = gtk_toggle_button_get_active( | ||
703 | GTK_TOGGLE_BUTTON(cbox_goto_dss)); | ||
704 | appdata->cachelist_disable_screensaver = gtk_toggle_button_get_active( | ||
705 | GTK_TOGGLE_BUTTON(cbox_cachelist_dss)); | ||
706 | harbaum | 129 | #endif |
707 | harbaum | 1 | appdata->cachelist_update = gtk_toggle_button_get_active( |
708 | GTK_TOGGLE_BUTTON(cbox_update)); | ||
709 | |||
710 | /* build some additional flags that are used to decide whether a */ | ||
711 | /* redraw is necessary */ | ||
712 | int flags = CHANGE_FLAG_POS; | ||
713 | |||
714 | if(prev_cachelist_hide_found != appdata->cachelist_hide_found) | ||
715 | flags |= CHANGE_FLAG_MASK; // visibility mask has changed | ||
716 | |||
717 | main_after_settings_redraw(appdata, flags); | ||
718 | } | ||
719 | gtk_widget_destroy(dialog); | ||
720 | } | ||
721 |