]> err.no Git - mapper/blob - src/config-gconf.c
Move and rename repo string parser.
[mapper] / src / config-gconf.c
1 /*
2  * This file is part of mapper
3  *
4  * Copyright (C) 2007 Kaj-Michael Lang
5  * Copyright (C) 2006-2007 John Costigan.
6  *
7  * POI and GPS-Info code originally written by Cezary Jackiewicz.
8  *
9  * Default map data provided by http://www.openstreetmap.org/
10  *
11  * This program is free software; you can redistribute it and/or modify
12  * it under the terms of the GNU General Public License as published by
13  * the Free Software Foundation; either version 2 of the License, or
14  * (at your option) any later version.
15  *
16  * This program is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19  * GNU General Public License for more details.
20  *
21  * You should have received a copy of the GNU General Public License along
22  * with this program; if not, write to the Free Software Foundation, Inc.,
23  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
24  */
25
26 #include <config.h>
27
28 #include <unistd.h>
29 #include <stdlib.h>
30 #include <string.h>
31 #include <strings.h>
32 #include <stddef.h>
33 #include <math.h>
34 #include <errno.h>
35 #include <sys/wait.h>
36 #include <libintl.h>
37 #include <locale.h>
38 #include <glib/gstdio.h>
39 #include <gtk/gtk.h>
40 #include <libgnomevfs/gnome-vfs.h>
41 #include <curl/multi.h>
42 #include <gconf/gconf-client.h>
43
44 #include "config-gconf.h"
45 #include "utils.h"
46 #include "mapper-types.h"
47 #include "latlon.h"
48 #include "map.h"
49 #include "route.h"
50 #include "db.h"
51 #include "poi.h"
52 #include "gps.h"
53 #include "ui-common.h"
54 #include "settings.h"
55 #include "gpx.h"
56 #include "filter.h"
57 #include "dialogs.h"
58 #include "map-tile-repo.h"
59
60 #define PROXY_PORT (8080)
61
62 gint mapper_gconf_get_int(const gchar *path, gint def);
63 gint mapper_gconf_get_bound_int(const gchar *path, gint def, gint min, gint max);
64 gfloat mapper_gconf_get_float(const gchar *path, gfloat def);
65 gboolean mapper_gconf_get_boolean(const gchar *path, gboolean def);
66
67 void 
68 config_update_proxy(void)
69 {
70 if (_http_proxy_host)
71         g_free(_http_proxy_host);
72
73 _http_proxy_host=NULL;
74 _http_proxy_port=0;
75
76 /* Get proxy data and register for updates. */
77 if (gconf_client_get_bool(gconf_client, GCONF_KEY_HTTP_PROXY_ON, NULL)) {
78         _http_proxy_host=gconf_client_get_string(gconf_client, GCONF_KEY_HTTP_PROXY_HOST, NULL);
79         _http_proxy_port=mapper_gconf_get_int(GCONF_KEY_HTTP_PROXY_PORT, PROXY_PORT);
80 }
81 }
82
83 gboolean
84 config_save_repo(void)
85 {
86 GList *curr = _repo_list;
87 GSList *temp_list = NULL;
88 gint curr_repo_index = 0;
89
90 g_assert(gconf_client);
91 /* Save the repositories. */
92 for (curr = _repo_list; curr != NULL; curr = curr->next) {
93         /* Build from each part of a repo, delimited by newline characters:
94          * 1. url
95          * 2. cache_dir
96          * 3. dl_zoom_steps
97          * 4. view_zoom_steps
98          */
99         RepoData *rd = curr->data;
100         gchar buffer[BUFFER_SIZE];
101         g_snprintf(buffer, sizeof(buffer),
102                  "%s\t%s\t%s\t%d\t%d\t%d\t%d",
103                  rd->name,
104                  rd->url,
105                  rd->cache_dir,
106                  rd->dl_zoom_steps,
107                  rd->view_zoom_steps,
108                  rd->double_size, rd->nextable);
109         temp_list = g_slist_append(temp_list, g_strdup(buffer));
110         if (rd == _curr_repo)
111                 gconf_client_set_int(gconf_client, GCONF_KEY_CURRREPO, curr_repo_index, NULL);
112         curr_repo_index++;
113 }
114 gconf_client_set_list(gconf_client, GCONF_KEY_REPOSITORIES, GCONF_VALUE_STRING, temp_list, NULL);
115
116 g_slist_free(temp_list);
117
118 return TRUE;
119 }
120
121 static void
122 config_default_repo(void)
123 {
124 RepoData *repo;
125
126 g_assert(gconf_client);
127
128 /* We have no repositories - create a default one. */
129 repo=map_tile_repo_new();
130
131 /* Get Map Cache Dir.  Default is REPO_DEFAULT_CACHE_DIR. */
132 repo->cache_dir = gconf_client_get_string(gconf_client, GCONF_KEY_MAP_DIR_NAME, NULL);
133
134 if (!repo->cache_dir)
135         repo->cache_dir = gnome_vfs_expand_initial_tilde(REPO_DEFAULT_CACHE_DIR);
136
137 /* Get Map Download URL Format.  Default is "". */
138 repo->url = gconf_client_get_string(gconf_client, GCONF_KEY_MAP_URI_FORMAT, NULL);
139 if (!repo->url)
140         repo->url = g_strdup(REPO_DEFAULT_MAP_URI);
141
142 /* Get Map Download Zoom Steps.  Default is 1. */
143 repo->dl_zoom_steps = gconf_client_get_int(gconf_client, GCONF_KEY_MAP_ZOOM_STEPS, NULL);
144 if (!repo->dl_zoom_steps)
145         repo->dl_zoom_steps = REPO_DEFAULT_DL_ZOOM_STEPS;
146
147 repo->name = g_strdup(REPO_DEFAULT_NAME);
148 repo->view_zoom_steps = REPO_DEFAULT_VIEW_ZOOM_STEPS;
149 repo->double_size = FALSE;
150 repo->nextable = TRUE;
151 map_tile_repo_set_type(repo);
152
153 _repo_list=g_list_append(_repo_list, repo);
154 repo_set_curr(repo);
155 }
156
157 gboolean
158 config_load_repo(void)
159 {
160 GSList *list, *curr;
161 guint curr_repo_index;
162
163 g_assert(gconf_client);
164 curr_repo_index = gconf_client_get_int(gconf_client, GCONF_KEY_CURRREPO, NULL);
165 list = gconf_client_get_list(gconf_client, GCONF_KEY_REPOSITORIES, GCONF_VALUE_STRING, NULL);
166
167 for (curr = list; curr != NULL; curr = curr->next) {
168         RepoData *rd = map_tile_repo_new_from_string(curr->data);
169         _repo_list = g_list_append(_repo_list, rd);
170         if (!curr_repo_index--)
171                 repo_set_curr(rd);
172         g_free(curr->data);
173 }
174 g_slist_free(list);
175
176 if (_repo_list==NULL)
177         config_default_repo();
178
179 return TRUE;
180 }
181
182 gboolean
183 config_load_position(Position *pos, const gchar *key)
184 {
185 g_assert(gconf_client);
186
187 pos->valid=gconf_client_get_pair(gconf_client, key, GCONF_VALUE_FLOAT, GCONF_VALUE_FLOAT, &pos->lat, &pos->lon, NULL);
188 if (!pos->valid) {
189         pos->lat=NAN;
190         pos->lon=NAN;
191 } else if (pos->lat==NAN || pos->lon==NAN)
192         pos->valid=FALSE;
193 return pos->valid;
194 }
195
196 gboolean
197 config_save_position(Position *pos, const gchar *key)
198 {
199 g_assert(gconf_client);
200
201 return gconf_client_set_pair(gconf_client, key, GCONF_VALUE_FLOAT, GCONF_VALUE_FLOAT, &pos->lat, &pos->lon, NULL);
202 }
203
204 gboolean
205 config_save_filter(GpsTrackFilter *f)
206 {
207 g_assert(gconf_client);
208
209 /* Filtering */
210 gconf_client_set_bool(gconf_client, GCONF_KEY_GPS_FILTER, f->enabled, NULL);
211 gconf_client_set_float(gconf_client, GCONF_KEY_GPS_FILTER_HDOP, f->hdop, NULL);
212 gconf_client_set_float(gconf_client, GCONF_KEY_GPS_FILTER_VDOP, f->vdop, NULL);
213 gconf_client_set_float(gconf_client, GCONF_KEY_GPS_FILTER_ANGLE, f->angle, NULL);
214 gconf_client_set_float(gconf_client, GCONF_KEY_GPS_FILTER_OSM, f->osm, NULL);
215 gconf_client_set_float(gconf_client, GCONF_KEY_GPS_FILTER_MAXDROP, f->maxdrop, NULL);
216
217 gconf_client_suggest_sync(gconf_client, NULL);
218 return TRUE;
219 }
220
221 /**
222  * Save all configuration data to GCONF.
223  */
224 gboolean
225 config_save(void)
226 {
227 gchar *config_dir;
228 gchar buffer[16];
229 gfloat center_lat, center_lon;
230 gint i;
231
232 g_assert(gconf_client);
233
234 /* Initialize config_dir. */
235 config_dir = gnome_vfs_expand_initial_tilde(CONFIG_DIR_NAME);
236 g_mkdir_with_parents(config_dir, 0700);
237
238 /* Save Receiver MAC from GConf. */
239 if (_gps->io.address)
240         gconf_client_set_string(gconf_client, GCONF_KEY_GPS_MAC, _gps->io.address, NULL);
241 else
242         gconf_client_unset(gconf_client, GCONF_KEY_GPS_MAC, NULL);
243
244 gconf_client_set_int(gconf_client, GCONF_KEY_GPS_TYPE, _gps->io.type, NULL);
245 gconf_client_set_int(gconf_client, GCONF_KEY_GPS_PORT, _gps->io.port, NULL);
246
247 /* Save Auto-Download. */
248 gconf_client_set_bool(gconf_client, GCONF_KEY_AUTO_DOWNLOAD, _auto_download, NULL);
249
250 /* Save Auto-Center Sensitivity. */
251 gconf_client_set_int(gconf_client, GCONF_KEY_CENTER_SENSITIVITY, _center_ratio, NULL);
252
253 /* Save Auto-Center Lead Amount. */
254 gconf_client_set_int(gconf_client, GCONF_KEY_LEAD_AMOUNT, _lead_ratio, NULL);
255
256 /* Save Draw Line Width. */
257 gconf_client_set_int(gconf_client, GCONF_KEY_DRAW_WIDTH, _draw_width, NULL);
258
259 /* Save Announce Advance Notice Ratio. */
260 gconf_client_set_int(gconf_client, GCONF_KEY_ANNOUNCE_NOTICE, _announce_notice_ratio, NULL);
261
262 /* Set announcement flags */
263 gconf_client_set_bool(gconf_client, GCONF_KEY_ANNOUNCE_WAYPOINTS, _announce_waypoints, NULL);
264 gconf_client_set_bool(gconf_client, GCONF_KEY_ANNOUNCE_OVERSPEED, _announce_overspeed, NULL);
265 gconf_client_set_bool(gconf_client, GCONF_KEY_ANNOUNCE_DESTINATION, _announce_destination, NULL);
266
267 /* Save Enable Voice flag. */
268 gconf_client_set_bool(gconf_client, GCONF_KEY_ENABLE_VOICE, _enable_voice, NULL);
269
270 /* Save Keep On When Fullscreen flag. */
271 gconf_client_set_bool(gconf_client, GCONF_KEY_ALWAYS_KEEP_ON, _always_keep_on, NULL);
272
273 /* Save Units. */
274 gconf_client_set_string(gconf_client, GCONF_KEY_UNITS, UNITS_TEXT[_units], NULL);
275
276 /* Save Custom Key Actions. */
277 for (i = 0; i < CUSTOM_KEY_ENUM_COUNT; i++)
278         gconf_client_set_string(gconf_client, CUSTOM_KEY_GCONF[i], CUSTOM_ACTION_TEXT[_action[i]], NULL);
279
280 /* Save Deg Format. */
281 gconf_client_set_string(gconf_client, GCONF_KEY_DEG_FORMAT,     DEG_FORMAT_TEXT[_degformat], NULL);
282
283 /* Save Speed Limit On flag. */
284 gconf_client_set_bool(gconf_client, GCONF_KEY_SPEED_LIMIT_ON, _speed_on, NULL);
285
286 /* Save Speed Limit. */
287 gconf_client_set_int(gconf_client, GCONF_KEY_SPEED_LIMIT, _speed_limit, NULL);
288
289 /* Save Info Font Size. */
290 gconf_client_set_string(gconf_client, GCONF_KEY_INFO_FONT_SIZE, INFO_FONT_TEXT[_info_font_size], NULL);
291
292 /* Save last latitude/longiture. */
293 gconf_client_set_float(gconf_client, GCONF_KEY_LAT, _gps->data.lat, NULL);
294 gconf_client_set_float(gconf_client, GCONF_KEY_LON, _gps->data.lon, NULL);
295
296 /* Save last center latitude/longitude. */
297 unit2latlon(_center.unitx, _center.unity, center_lat, center_lon);
298 gconf_client_set_float(gconf_client, GCONF_KEY_CENTER_LAT, center_lat, NULL);
299 gconf_client_set_float(gconf_client, GCONF_KEY_CENTER_LON, center_lon, NULL);
300
301 /* Save last Zoom Level. */
302 gconf_client_set_int(gconf_client, GCONF_KEY_ZOOM, _zoom, NULL);
303
304 /* Save Route Directory. */
305 if (_route_dir_uri)
306         gconf_client_set_string(gconf_client, GCONF_KEY_ROUTEDIR, _route_dir_uri, NULL);
307
308 /* Save Last Track File. */
309 if (_track_file_uri)
310         gconf_client_set_string(gconf_client, GCONF_KEY_TRACKFILE, _track_file_uri, NULL);
311
312 /* Save Auto-Center Mode. */
313 gconf_client_set_int(gconf_client, GCONF_KEY_AUTOCENTER_MODE, _center_mode, NULL);
314
315 /* Save Show Scale flag. */
316 gconf_client_set_bool(gconf_client, GCONF_KEY_SHOWSCALE, _show_scale, NULL);
317
318 /* Save Show Tracks flag. */
319 gconf_client_set_bool(gconf_client, GCONF_KEY_SHOWTRACKS, _show_tracks & TRACKS_MASK, NULL);
320
321 /* Save Show Routes flag. */
322 gconf_client_set_bool(gconf_client, GCONF_KEY_SHOWROUTES, _show_tracks & ROUTES_MASK, NULL);
323
324 /* Save Show Velocity Vector flag. */
325 gconf_client_set_bool(gconf_client, GCONF_KEY_SHOWVELVEC, _show_velvec, NULL);
326
327 /* Save Show POIs flag. */
328 gconf_client_set_bool(gconf_client, GCONF_KEY_SHOWPOIS, _show_poi, NULL);
329
330 /* Save Enable GPS flag. */
331 gconf_client_set_bool(gconf_client, GCONF_KEY_ENABLE_GPS, _enable_gps, NULL);
332
333 /* Save Route Locations. */
334 gconf_client_set_list(gconf_client, GCONF_KEY_ROUTE_LOCATIONS, GCONF_VALUE_STRING, _loc_list, NULL);
335
336 /* Save GPS Info flag. */
337 gconf_client_set_bool(gconf_client, GCONF_KEY_GPS_INFO, _gps_info, NULL);
338
339 /* Save Route Download URL Format. */
340 gconf_client_set_string(gconf_client, GCONF_KEY_ROUTE_DL_URL, _route_dl_url, NULL);
341
342 /* Save Route Download Radius. */
343 gconf_client_set_int(gconf_client, GCONF_KEY_ROUTE_DL_RADIUS, _route_dl_radius, NULL);
344 gconf_client_set_int(gconf_client, GCONF_KEY_TRACK_DL_RADIUS, _track_dl_radius, NULL);
345
346 /* Save Colors. */
347 for (i = 0; i < COLORABLE_ENUM_COUNT; i++) {
348         g_snprintf(buffer, sizeof(buffer), "#%02x%02x%02x",
349                  _color[i].red >> 8, _color[i].green >> 8, _color[i].blue >> 8);
350         gconf_client_set_string(gconf_client, COLORABLE_GCONF[i], buffer, NULL);
351 }
352
353 /* Save Mapper database. */
354 if (_mapper_db)
355         gconf_client_set_string(gconf_client, GCONF_KEY_MAPPER_DB, _mapper_db, NULL);
356 else
357         gconf_client_unset(gconf_client, GCONF_KEY_MAPPER_DB, NULL);
358
359 /* Save Show POI below zoom. */
360 gconf_client_set_int(gconf_client, GCONF_KEY_POI_ZOOM, _poi_zoom, NULL);
361
362 gconf_client_suggest_sync(gconf_client, NULL);
363 g_free(config_dir);
364 return TRUE;
365 }
366
367 /**
368  *
369  */
370 gboolean
371 config_load_string_list(const gchar *gconf_key, GSList **list, GtkListStore **model)
372 {
373 GSList *curr;
374
375 *list=gconf_client_get_list(gconf_client, gconf_key, GCONF_VALUE_STRING, NULL);
376 *model=gtk_list_store_new(1, G_TYPE_STRING);
377 for (curr = *list; curr != NULL; curr = curr->next) {
378         GtkTreeIter iter;
379         gtk_list_store_insert_with_values(*model, &iter, INT_MAX, 0, curr->data, -1);
380 }
381 return TRUE;
382 }
383
384 /**
385  * Initialize all configuration from GCONF.  This should not be called more
386  * than once during execution.
387  */
388 void
389 config_init(void)
390 {
391 GConfValue *value;
392 gchar *config_dir;
393 gchar *str;
394 gint i;
395 CenterMode _center_mode = CENTER_LEAD;
396 UnitType _units = UNITS_KM;
397 guint _degformat = DDPDDDDD;
398 InfoFontSize _info_font_size = INFO_FONT_MEDIUM;
399
400 gconf_client=gconf_client_get_default();
401 if (!gconf_client) {
402         popup_error(_window, _("Failed to initialize GConf. Quitting."));
403         exit(1);
404 }
405
406 /* Preload configuration */
407 gconf_client_add_dir (gconf_client, GCONF_KEY_PREFIX, GCONF_CLIENT_PRELOAD_ONELEVEL, NULL);
408
409 /* Initialize config_dir. */
410 config_dir = gnome_vfs_expand_initial_tilde(CONFIG_DIR_NAME);
411 g_mkdir_with_parents(config_dir, 0700);
412
413 /* Get Receiver MAC from GConf.  Default is scanned via hci_inquiry. */
414 _gps->io.address=gconf_client_get_string(gconf_client, GCONF_KEY_GPS_MAC, NULL);
415 _gps->io.port=mapper_gconf_get_int(GCONF_KEY_GPS_PORT, 2947);
416 _gps->io.type=(GpsIOSourceType)mapper_gconf_get_bound_int(GCONF_KEY_GPS_TYPE, GPS_IO_SIMULATION, GPS_IO_TYPE_MIN+1, GPS_IO_TYPE_MAX-1);
417
418 /* Get Auto-Download.  Default is FALSE. */
419 _auto_download = gconf_client_get_bool(gconf_client, GCONF_KEY_AUTO_DOWNLOAD, NULL);
420
421 _center_ratio=mapper_gconf_get_int(GCONF_KEY_CENTER_SENSITIVITY, 7);
422 _lead_ratio=mapper_gconf_get_int(GCONF_KEY_LEAD_AMOUNT, 5);
423 _draw_width=mapper_gconf_get_int(GCONF_KEY_DRAW_WIDTH, 4);
424
425 /* Invalidate destination */
426 _dest.valid=FALSE;
427
428 /* Get Announce Advance Notice - Default is 30. */
429 _announce_notice_ratio=mapper_gconf_get_int(GCONF_KEY_ANNOUNCE_NOTICE, 8);
430
431 _announce_waypoints=mapper_gconf_get_boolean(GCONF_KEY_ANNOUNCE_WAYPOINTS, TRUE);
432 _announce_overspeed=mapper_gconf_get_boolean(GCONF_KEY_ANNOUNCE_OVERSPEED, FALSE);
433 _announce_destination=mapper_gconf_get_boolean(GCONF_KEY_ANNOUNCE_DESTINATION, FALSE);
434
435 /* Get Enable Voice flag.  Default is TRUE. */
436 _enable_voice=mapper_gconf_get_boolean(GCONF_KEY_ENABLE_VOICE, TRUE);
437 _voice_pitch=mapper_gconf_get_bound_int(GCONF_KEY_VOICE_PITCH, 50, 10, 99);
438 _voice_speed=mapper_gconf_get_bound_int(GCONF_KEY_VOICE_SPEED, 120, 80, 370);
439
440 /* Get Always Keep On flag.  Default is FALSE. */
441 _always_keep_on=mapper_gconf_get_boolean(GCONF_KEY_ALWAYS_KEEP_ON, FALSE);
442
443 filter.enabled = gconf_client_get_bool(gconf_client, GCONF_KEY_GPS_FILTER, NULL);
444 filter.hdop = gconf_client_get_float(gconf_client, GCONF_KEY_GPS_FILTER_HDOP, NULL);
445 filter.vdop = gconf_client_get_float(gconf_client, GCONF_KEY_GPS_FILTER_VDOP, NULL);
446 filter.angle = gconf_client_get_float(gconf_client, GCONF_KEY_GPS_FILTER_ANGLE, NULL);
447 filter.osm = gconf_client_get_float(gconf_client, GCONF_KEY_GPS_FILTER_OSM, NULL);
448 filter.maxdrop = gconf_client_get_float(gconf_client, GCONF_KEY_GPS_FILTER_MAXDROP, NULL);
449 filter.drop_cnt=0;
450 BOUND(filter.maxdrop, 0, 60);
451 BOUND(filter.hdop, 0, 50);
452 BOUND(filter.vdop, 0, 50);
453 BOUND(filter.angle, 0, 45);
454
455 /* Get Units.  Default is UNITS_KM. */
456 {
457         gchar *units_str = gconf_client_get_string(gconf_client, GCONF_KEY_UNITS, NULL);
458         guint i = 0;
459         if (units_str)
460                 for (i = UNITS_ENUM_COUNT - 1; i > 0; i--)
461                         if (!strcmp(units_str, UNITS_TEXT[i]))
462                                 break;
463         _units = i;
464 }
465
466         /* Get Custom Key Actions. */
467 {
468         gint i;
469         for (i = 0; i < CUSTOM_KEY_ENUM_COUNT; i++) {
470                 gint j = CUSTOM_KEY_DEFAULT[i];
471                 gchar *str = gconf_client_get_string(gconf_client, CUSTOM_KEY_GCONF[i], NULL);
472                 if (str)
473                         for (j = CUSTOM_ACTION_ENUM_COUNT - 1; j > 0; j--)
474                                 if (!strcmp(str, CUSTOM_ACTION_TEXT[j]))
475                                         break;
476                 _action[i] = j;
477         }
478 }
479
480 /* Get Deg format.  Default is DDPDDDDD. */
481 {
482         gchar *degformat_key_str = gconf_client_get_string(gconf_client, GCONF_KEY_DEG_FORMAT, NULL);
483         guint i = 0;
484         if (degformat_key_str)
485                 for (i = DEG_FORMAT_ENUM_COUNT - 1; i > 0; i--)
486                         if (!strcmp(degformat_key_str, DEG_FORMAT_TEXT[i]))
487                                 break;
488         _degformat = i;
489 }
490
491 /* Get Info Font Size.  Default is INFO_FONT_MEDIUM. */
492 {
493         gchar *info_font_size_str = gconf_client_get_string(gconf_client, GCONF_KEY_INFO_FONT_SIZE, NULL);
494         guint i = -1;
495         if (info_font_size_str)
496                 for (i = INFO_FONT_ENUM_COUNT - 1; i >= 0; i--)
497                         if (!strcmp(info_font_size_str, INFO_FONT_TEXT[i]))
498                                 break;
499         if (i == -1)
500                 i = INFO_FONT_MEDIUM;
501         _info_font_size = i;
502 }
503
504 /* Get Speed Limit On flag.  Default is FALSE. */
505 _speed_on = gconf_client_get_bool(gconf_client, GCONF_KEY_SPEED_LIMIT_ON, NULL);
506
507 /* Get Speed Limit */
508 _speed_limit = gconf_client_get_int(gconf_client, GCONF_KEY_SPEED_LIMIT, NULL);
509 BOUND(_speed_limit, 1, 200);
510
511 /* Get Auto-Download.  Default is FALSE. */
512 _auto_download=mapper_gconf_get_boolean(GCONF_KEY_AUTO_DOWNLOAD, FALSE);
513
514 /* Get saved location */
515 _gps->data.lat=mapper_gconf_get_float(GCONF_KEY_LAT, 60.20);
516 _gps->data.lon=mapper_gconf_get_float(GCONF_KEY_LON, 22.20);
517
518 /* Special positions Home and Dest */
519 config_load_position(&_home, GCONF_KEY_POSITION_HOME);
520 config_load_position(&_dest, GCONF_KEY_POSITION_DEST);
521
522 /* Get last center point. */
523 {
524         gfloat center_lat, center_lon;
525
526         /* Get last saved latitude.  Default is last saved latitude. */
527         value = gconf_client_get(gconf_client, GCONF_KEY_CENTER_LAT, NULL);
528         if (value) {
529                 center_lat = gconf_value_get_float(value);
530                 gconf_value_free(value);
531         } else {
532                 center_lat = _gps->data.lat;
533         }
534
535         /* Get last saved longitude.  Default is last saved longitude. */
536         value = gconf_client_get(gconf_client, GCONF_KEY_CENTER_LON, NULL);
537         if (value) {
538                 center_lon = gconf_value_get_float(value);
539                 gconf_value_free(value);
540         } else {
541                 center_lon = _gps->data.lon;
542         }
543
544         latlon2unit(center_lat, center_lon, _center.unitx, _center.unity);
545 }
546
547 config_load_repo();
548
549 /* Get last Zoom Level.  Default is 12. */
550 value = gconf_client_get(gconf_client, GCONF_KEY_ZOOM, NULL);
551 if (value) {
552         _zoom = gconf_value_get_int(value) / _curr_repo->view_zoom_steps * _curr_repo->view_zoom_steps;
553         gconf_value_free(value);
554 } else {
555         _zoom = 12 / _curr_repo->view_zoom_steps * _curr_repo->view_zoom_steps;
556 }
557 BOUND(_zoom, 0, MAX_ZOOM - 1);
558 _world_size_tiles = unit2tile(WORLD_SIZE_UNITS);
559
560 /* Get Route Directory.  Default is NULL. */
561 _route_dir_uri = gconf_client_get_string(gconf_client, GCONF_KEY_ROUTEDIR, NULL);
562
563 /* Get Last Track File.  Default is NULL. */
564 _track_file_uri = gconf_client_get_string(gconf_client, GCONF_KEY_TRACKFILE, NULL);
565
566 _center_mode=mapper_gconf_get_int(GCONF_KEY_AUTOCENTER_MODE, CENTER_LEAD);
567
568 /* Get Show Scale flag.  Default is TRUE. */
569 _show_scale=mapper_gconf_get_boolean(GCONF_KEY_SHOWSCALE, TRUE);
570
571 /* Get Show Tracks flag.  Default is TRUE. */
572 _show_tracks |= mapper_gconf_get_boolean(GCONF_KEY_SHOWTRACKS, TRUE) ? TRACKS_MASK : 0;
573
574 /* Get Show Routes flag.  Default is TRUE. */
575 _show_tracks |= mapper_gconf_get_boolean(GCONF_KEY_SHOWROUTES, TRUE) ? ROUTES_MASK : 0;
576
577 /* Get Show Velocity Vector flag.  Default is TRUE. */
578 _show_velvec=mapper_gconf_get_boolean(GCONF_KEY_SHOWVELVEC, TRUE);
579
580 _show_poi=mapper_gconf_get_boolean(GCONF_KEY_SHOWPOIS, TRUE);
581
582 /* Get Enable GPS flag. Default is FALSE. */
583 _enable_gps=mapper_gconf_get_boolean(GCONF_KEY_ENABLE_GPS, FALSE);
584
585 /* Initialize _conn_state based on _enable_gps-> */
586 _gps->io.conn = (_enable_gps ? RCVR_DOWN : RCVR_OFF);
587
588 config_load_string_list(GCONF_KEY_ROUTE_LOCATIONS, &_loc_list, &_loc_model);
589
590 /* Show POIs below zoom */
591 _poi_zoom = mapper_gconf_get_int(GCONF_KEY_POI_ZOOM, 6);
592
593 /* Get GPS Info flag. Default is FALSE. */
594 _gps_info=mapper_gconf_get_boolean(GCONF_KEY_GPS_INFO, FALSE);
595
596 /* Get Route Download URL. Default is:
597  * "http://www.gnuite.com/cgi-bin/gpx.cgi?saddr=%s&daddr=%s" */
598 _route_dl_url = gconf_client_get_string(gconf_client, GCONF_KEY_ROUTE_DL_URL, NULL);
599 if (_route_dl_url == NULL)
600         _route_dl_url = g_strdup("http://www.gnuite.com/cgi-bin/gpx.cgi?saddr=%s&daddr=%s");
601
602 /* Get Route Download Radius.  Default is 4. */
603 _route_dl_radius = mapper_gconf_get_int(GCONF_KEY_ROUTE_DL_RADIUS, 4);
604 _track_dl_radius = mapper_gconf_get_int(GCONF_KEY_TRACK_DL_RADIUS, 4);
605
606 /* Get Colors. */
607 for (i = 0; i < COLORABLE_ENUM_COUNT; i++) {
608         str = gconf_client_get_string(gconf_client, COLORABLE_GCONF[i], NULL);
609         if (!str || !gdk_color_parse(str, &_color[i]))
610                 _color[i] = COLORABLE_DEFAULT[i];
611 }
612
613 /* Get Mapper Database. Default is in REPO_DEFAULT_CACHE_BASE */
614 _mapper_db = gconf_client_get_string(gconf_client, GCONF_KEY_MAPPER_DB, NULL);
615 if (_mapper_db == NULL) {
616         gchar *db_base = gnome_vfs_expand_initial_tilde(REPO_DEFAULT_CACHE_BASE);
617         _mapper_db = gnome_vfs_uri_make_full_from_relative(db_base, "mapper.db");
618         g_free(db_base);
619 }
620
621 /* Get current proxy settings. */
622 config_update_proxy();
623
624 gconf_client_clear_cache(gconf_client);
625 g_free(config_dir);
626 }
627
628 /**
629  *
630  */
631 gint 
632 mapper_gconf_get_int(const gchar *path, gint def)
633 {
634 GConfValue *value;
635 gint v;
636
637 g_assert(gconf_client);
638 value=gconf_client_get(gconf_client, path, NULL);
639 if (value) {
640         v=gconf_value_get_int(value);
641         gconf_value_free(value);
642 } else {
643         v=def;
644 }
645 return v;
646 }
647
648 /**
649  *
650  */
651 gboolean
652 mapper_gconf_get_boolean(const gchar *path, gboolean def)
653 {
654 GConfValue *value;
655 gboolean r;
656
657 g_assert(gconf_client);
658 value = gconf_client_get(gconf_client, path, NULL);
659 if (value) {
660         r=gconf_value_get_bool(value);
661         gconf_value_free(value);
662 } else {
663         r=def;
664 }
665 return r;
666 }
667
668 /**
669  *
670  */
671 gint
672 mapper_gconf_get_bound_int(const gchar *path, gint def, gint min, gint max)
673 {
674 gint r;
675
676 r=mapper_gconf_get_int(path, def);
677 BOUND(r, min, max);
678 return r;
679 }
680
681 gfloat
682 mapper_gconf_get_float(const gchar *path, gfloat def)
683 {
684 GConfValue *value;
685 gfloat v;
686
687 g_assert(gconf_client);
688 value=gconf_client_get(gconf_client, path, NULL);
689 if (value) {
690         v=gconf_value_get_float(value);
691         gconf_value_free(value);
692 } else {
693         v=def;
694 }
695 return v;
696 }