#include "gpx.h"
#include "filter.h"
+#define PROXY_PORT (8080)
+
+gint mapper_gconf_get_bound_int(const gchar *path, gint def, gint min, gint max);
+gint mapper_gconf_get_int(const gchar *path, gint def);
+gfloat mapper_gconf_get_float(const gchar *path, gfloat def);
+
void
config_update_proxy(void)
{
if (_http_proxy_host)
g_free(_http_proxy_host);
+_http_proxy_host=NULL;
+_http_proxy_port=0;
+
/* Get proxy data and register for updates. */
if (gconf_client_get_bool(gconf_client, GCONF_KEY_HTTP_PROXY_ON, NULL)) {
- _http_proxy_host = gconf_client_get_string(gconf_client, GCONF_KEY_HTTP_PROXY_HOST, NULL);
- _http_proxy_port = gconf_client_get_int(gconf_client, GCONF_KEY_HTTP_PROXY_PORT, NULL);
-} else {
- _http_proxy_host = NULL;
- _http_proxy_port = 0;
+ _http_proxy_host=gconf_client_get_string(gconf_client, GCONF_KEY_HTTP_PROXY_HOST, NULL);
+ _http_proxy_port=mapper_gconf_get_int(GCONF_KEY_HTTP_PROXY_PORT, PROXY_PORT);
}
}
static void
-config_save_track(gchar *config_dir)
+track_save(const gchar *config_dir, const gchar *file)
{
GnomeVFSHandle *handle;
-gchar *track_file;
-track_file = gnome_vfs_uri_make_full_from_relative(config_dir, CONFIG_FILE_TRACK);
-if (GNOME_VFS_OK == gnome_vfs_create(&handle, track_file, GNOME_VFS_OPEN_WRITE, FALSE, 0600)) {
+gchar *tfile;
+tfile=gnome_vfs_uri_make_full_from_relative(config_dir, file);
+if (GNOME_VFS_OK == gnome_vfs_create(&handle, tfile, GNOME_VFS_OPEN_WRITE, FALSE, 0600)) {
write_gpx(&_track, handle);
gnome_vfs_close(handle);
}
-g_free(track_file);
-}
-
-static void
-config_save_route(gchar *config_dir)
-{
-GnomeVFSHandle *handle;
-gchar *route_file;
-route_file = gnome_vfs_uri_make_full_from_relative(config_dir, CONFIG_FILE_ROUTE);
-if (GNOME_VFS_OK == gnome_vfs_create(&handle, route_file, GNOME_VFS_OPEN_WRITE, FALSE, 0600)) {
- write_gpx(&_route, handle);
- gnome_vfs_close(handle);
-}
-g_free(route_file);
+g_free(tfile);
}
gboolean
GSList *temp_list = NULL;
gint curr_repo_index = 0;
+g_assert(gconf_client);
/* Save the repositories. */
for (curr = _repo_list; curr != NULL; curr = curr->next) {
/* Build from each part of a repo, delimited by newline characters:
static void
config_default_repo(void)
{
+g_assert(gconf_client);
+
/* We have no repositories - create a default one. */
RepoData *repo = g_new(RepoData, 1);
{
GSList *list, *curr;
GConfValue *value;
+guint curr_repo_index;
-guint curr_repo_index = gconf_client_get_int(gconf_client, GCONF_KEY_CURRREPO, NULL);
+g_assert(gconf_client);
+curr_repo_index = gconf_client_get_int(gconf_client, GCONF_KEY_CURRREPO, NULL);
list = gconf_client_get_list(gconf_client, GCONF_KEY_REPOSITORIES, GCONF_VALUE_STRING, NULL);
for (curr = list; curr != NULL; curr = curr->next) {
gboolean
config_save_home(void)
{
-if (!gconf_client)
- return FALSE;
+g_assert(gconf_client);
/* Save home lat/lon. */
gconf_client_set_float(gconf_client, GCONF_KEY_HOME_LAT, _home.lat, NULL);
gboolean
config_save_filter(GpsTrackFilter *f)
{
+g_assert(gconf_client);
+
/* Filtering */
gconf_client_set_bool(gconf_client, GCONF_KEY_GPS_FILTER, f->enabled, NULL);
gconf_client_set_float(gconf_client, GCONF_KEY_GPS_FILTER_HDOP, f->hdop, NULL);
gfloat center_lat, center_lon;
gint i;
+g_assert(gconf_client);
+
/* Initialize config_dir. */
config_dir = gnome_vfs_expand_initial_tilde(CONFIG_DIR_NAME);
g_mkdir_with_parents(config_dir, 0700);
/* Save Custom Key Actions. */
for (i = 0; i < CUSTOM_KEY_ENUM_COUNT; i++)
- gconf_client_set_string(gconf_client,
- CUSTOM_KEY_GCONF[i],
- CUSTOM_ACTION_TEXT[_action[i]],
- NULL);
+ gconf_client_set_string(gconf_client, CUSTOM_KEY_GCONF[i], CUSTOM_ACTION_TEXT[_action[i]], NULL);
/* Save Deg Format. */
-gconf_client_set_string(gconf_client,
- GCONF_KEY_DEG_FORMAT,
- DEG_FORMAT_TEXT[_degformat], NULL);
+gconf_client_set_string(gconf_client, GCONF_KEY_DEG_FORMAT, DEG_FORMAT_TEXT[_degformat], NULL);
/* Save Speed Limit On flag. */
gconf_client_set_bool(gconf_client, GCONF_KEY_SPEED_LIMIT_ON, _speed_on, NULL);
gconf_client_set_int(gconf_client, GCONF_KEY_SPEED_LIMIT, _speed_limit, NULL);
/* Save Info Font Size. */
-gconf_client_set_string(gconf_client,
- GCONF_KEY_INFO_FONT_SIZE,
- INFO_FONT_TEXT[_info_font_size], NULL);
+gconf_client_set_string(gconf_client, GCONF_KEY_INFO_FONT_SIZE, INFO_FONT_TEXT[_info_font_size], NULL);
/* Save last latitude/longiture. */
gconf_client_set_float(gconf_client, GCONF_KEY_LAT, _gps->data.lat, NULL);
/* Save Show POI below zoom. */
gconf_client_set_int(gconf_client, GCONF_KEY_POI_ZOOM, _poi_zoom, NULL);
-#if 0
-config_save_track(config_dir);
-config_save_route(config_dir);
-#endif
-
gconf_client_suggest_sync(gconf_client, NULL);
+#if 0
gconf_client_clear_cache(gconf_client);
+#endif
g_free(config_dir);
return TRUE;
}
exit(1);
}
+/* Preload configuration */
gconf_client_add_dir (gconf_client, GCONF_KEY_PREFIX, GCONF_CLIENT_PRELOAD_ONELEVEL, NULL);
CenterMode _center_mode = CENTER_LEAD;
g_mkdir_with_parents(config_dir, 0700);
/* Get Receiver MAC from GConf. Default is scanned via hci_inquiry. */
-_gps->io.address = gconf_client_get_string(gconf_client, GCONF_KEY_GPS_MAC, NULL);
-_gps->io.port = gconf_client_get_int(gconf_client, GCONF_KEY_GPS_PORT, NULL);
-
-value=gconf_client_get(gconf_client, GCONF_KEY_GPS_TYPE, NULL);
-if (value) {
- GpsIOSourceType type;
-
- type=gconf_value_get_int(value);
- if (type>GPS_IO_TYPE_MIN && type<GPS_IO_TYPE_MAX)
- _gps->io.type=type;
- else
- _gps->io.type=GPS_IO_SIMULATION;
- gconf_value_free(value);
-} else {
- _gps->io.type=GPS_IO_SIMULATION;
-}
-g_debug("GPS Type: %d", _gps->io.type);
+_gps->io.address=gconf_client_get_string(gconf_client, GCONF_KEY_GPS_MAC, NULL);
+_gps->io.port=mapper_gconf_get_int(GCONF_KEY_GPS_PORT, 2497);
+_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);
/* Get Auto-Download. Default is FALSE. */
_auto_download = gconf_client_get_bool(gconf_client, GCONF_KEY_AUTO_DOWNLOAD, NULL);
-/* Get Center Ratio - Default is 3. */
-_center_ratio = gconf_client_get_int(gconf_client, GCONF_KEY_CENTER_SENSITIVITY, NULL);
-if (!_center_ratio)
- _center_ratio = 7;
+_center_ratio=mapper_gconf_get_int(GCONF_KEY_CENTER_SENSITIVITY, 7);
+_lead_ratio=mapper_gconf_get_int(GCONF_KEY_LEAD_AMOUNT, 5);
+_draw_width=mapper_gconf_get_int(GCONF_KEY_DRAW_WIDTH, 4);
/* Invalidate destination */
_dest.valid=FALSE;
-/* Get Lead Ratio - Default is 5. */
-_lead_ratio = gconf_client_get_int(gconf_client, GCONF_KEY_LEAD_AMOUNT, NULL);
-if (!_lead_ratio)
- _lead_ratio = 5;
-
-/* Get Draw Line Width- Default is 4. */
-_draw_width = gconf_client_get_int(gconf_client, GCONF_KEY_DRAW_WIDTH, NULL);
-if (!_draw_width)
- _draw_width = 4;
-
/* Get Announce Advance Notice - Default is 30. */
-value = gconf_client_get(gconf_client, GCONF_KEY_ANNOUNCE_NOTICE, NULL);
-if (value) {
- _announce_notice_ratio = gconf_value_get_int(value);
- gconf_value_free(value);
-} else {
- _announce_notice_ratio = 8;
-}
+_announce_notice_ratio=mapper_gconf_get_int(GCONF_KEY_ANNOUNCE_NOTICE, 8);
/* Get Enable Voice flag. Default is TRUE. */
value = gconf_client_get(gconf_client, GCONF_KEY_ENABLE_VOICE, NULL);
_enable_voice = TRUE;
}
- /* Get Voice Speed - Default is 120 */
-value = gconf_client_get(gconf_client, GCONF_KEY_VOICE_SPEED, NULL);
-if (value) {
- _voice_speed = gconf_value_get_int(value);
- gconf_value_free(value);
-} else {
- _voice_speed = 120;
-}
-BOUND(_voice_speed, 80, 370);
-
-/* Get Voice Speed - Default is 50. */
-value = gconf_client_get(gconf_client, GCONF_KEY_VOICE_PITCH, NULL);
-if (value) {
- _voice_pitch = gconf_value_get_int(value);
- gconf_value_free(value);
-} else {
- _voice_pitch = 50;
-}
-BOUND(_voice_pitch, 10, 99);
+_voice_pitch=mapper_gconf_get_bound_int(GCONF_KEY_VOICE_PITCH, 50, 10, 99);
+_voice_speed=mapper_gconf_get_bound_int(GCONF_KEY_VOICE_SPEED, 120, 80, 370);
/* Get Always Keep On flag. Default is FALSE. */
_always_keep_on = gconf_client_get_bool(gconf_client,GCONF_KEY_ALWAYS_KEEP_ON, NULL);
/* Get Last Track File. Default is NULL. */
_track_file_uri = gconf_client_get_string(gconf_client, GCONF_KEY_TRACKFILE, NULL);
-/* Get Auto-Center Mode. Default is CENTER_LEAD. */
-value = gconf_client_get(gconf_client, GCONF_KEY_AUTOCENTER_MODE, NULL);
-if (value) {
- _center_mode = gconf_value_get_int(value);
- gconf_value_free(value);
-} else {
- _center_mode = CENTER_LEAD;
-}
+_center_mode=mapper_gconf_get_int(GCONF_KEY_AUTOCENTER_MODE, CENTER_LEAD);
/* Get Show Scale flag. Default is TRUE. */
value = gconf_client_get(gconf_client, GCONF_KEY_SHOWSCALE, NULL);
g_free(db_base);
}
-_poi_zoom = gconf_client_get_int(gconf_client, GCONF_KEY_POI_ZOOM, NULL);
-if (!_poi_zoom)
- _poi_zoom = 6;
+_poi_zoom = mapper_gconf_get_int(GCONF_KEY_POI_ZOOM, 6);
/* Get GPS Info flag. Default is FALSE. */
value = gconf_client_get(gconf_client, GCONF_KEY_GPS_INFO, NULL);
_route_dl_url = g_strdup("http://www.gnuite.com/cgi-bin/gpx.cgi?saddr=%s&daddr=%s");
/* Get Route Download Radius. Default is 4. */
-value = gconf_client_get(gconf_client, GCONF_KEY_ROUTE_DL_RADIUS, NULL);
-if (value) {
- _route_dl_radius = gconf_value_get_int(value);
- gconf_value_free(value);
-} else {
- _route_dl_radius = 4;
-}
+_route_dl_radius = mapper_gconf_get_int(GCONF_KEY_ROUTE_DL_RADIUS, 4);
/* Get Colors. */
for (i = 0; i < COLORABLE_ENUM_COUNT; i++) {
gconf_client_clear_cache(gconf_client);
g_free(config_dir);
}
+
+/**
+ *
+ */
+gint
+mapper_gconf_get_int(const gchar *path, gint def)
+{
+GConfValue *value;
+gint v;
+
+g_assert(gconf_client);
+value=gconf_client_get(gconf_client, path, NULL);
+if (value) {
+ v=gconf_value_get_int(value);
+ gconf_value_free(value);
+} else {
+ v=def;
+}
+return v;
+}
+
+/**
+ *
+ */
+gint
+mapper_gconf_get_bound_int(const gchar *path, gint def, gint min, gint max)
+{
+gint r;
+
+r=mapper_gconf_get_int(path, def);
+BOUND(r, min, max);
+return r;
+}
+
+gfloat
+mapper_gconf_get_float(const gchar *path, gfloat def)
+{
+GConfValue *value;
+gfloat v;
+
+g_assert(gconf_client);
+value=gconf_client_get(gconf_client, path, NULL);
+if (value) {
+ v=gconf_value_get_float(value);
+ gconf_value_free(value);
+} else {
+ v=def;
+}
+return v;
+}