From bff16543a9a22926cb998b3a565ede40f03e4450 Mon Sep 17 00:00:00 2001 From: Kaj-Michael Lang Date: Fri, 21 Mar 2008 14:40:36 +0200 Subject: [PATCH] Add position save/load functions, config_load_position and config_save_position, remove home position save function. Use gconf pair to store lat/lon position pairs. --- src/config-gconf.c | 48 +++++++++++++++++----------------------------- src/config-gconf.h | 14 ++++++++++---- 2 files changed, 28 insertions(+), 34 deletions(-) diff --git a/src/config-gconf.c b/src/config-gconf.c index cfd804c..81058b8 100644 --- a/src/config-gconf.c +++ b/src/config-gconf.c @@ -231,16 +231,25 @@ return TRUE; } gboolean -config_save_home(void) +config_load_position(Position *pos, const gchar *key) { g_assert(gconf_client); -/* Save home lat/lon. */ -gconf_client_set_float(gconf_client, GCONF_KEY_HOME_LAT, _home.lat, NULL); -gconf_client_set_float(gconf_client, GCONF_KEY_HOME_LON, _home.lon, NULL); +pos->valid=gconf_client_get_pair(gconf_client, key, GCONF_VALUE_FLOAT, GCONF_VALUE_FLOAT, &pos->lat, &pos->lon, NULL); +if (!pos->valid) { + pos->lat=NAN; + pos->lon=NAN; +} else if (pos->lat==NAN || pos->lon==NAN) + pos->valid=FALSE; +return pos->valid; +} -gconf_client_suggest_sync(gconf_client, NULL); -return TRUE; +gboolean +config_save_position(Position *pos, const gchar *key) +{ +g_assert(gconf_client); + +return gconf_client_set_pair(gconf_client, key, GCONF_VALUE_FLOAT, GCONF_VALUE_FLOAT, &pos->lat, &pos->lon, NULL); } gboolean @@ -548,30 +557,9 @@ _auto_download=mapper_gconf_get_boolean(GCONF_KEY_AUTO_DOWNLOAD, FALSE); _gps->data.lat=mapper_gconf_get_float(GCONF_KEY_LAT, 60.20); _gps->data.lon=mapper_gconf_get_float(GCONF_KEY_LON, 22.20); -/* Home */ -_home.valid=TRUE; -value = gconf_client_get(gconf_client, GCONF_KEY_HOME_LAT, NULL); -if (value) { - _home.lat = gconf_value_get_float(value); - gconf_value_free(value); -} else { - _home.valid=FALSE; -} - -value = gconf_client_get(gconf_client, GCONF_KEY_HOME_LON, NULL); -if (value) { - _home.lon = gconf_value_get_float(value); - gconf_value_free(value); -} else { - _home.valid=FALSE; -} - -/* Turku is default */ -if (_home.valid==FALSE) { - _home.lat=64.20; - _home.lon=22.20; - _home.valid=TRUE; -} +/* Special positions Home and Dest */ +config_load_position(&_home, GCONF_KEY_POSITION_HOME); +config_load_position(&_dest, GCONF_KEY_POSITION_DEST); /* Get last center point. */ { diff --git a/src/config-gconf.h b/src/config-gconf.h index 5128e9d..3b41427 100644 --- a/src/config-gconf.h +++ b/src/config-gconf.h @@ -6,18 +6,24 @@ #include "filter.h" #include "mapper-types.h" #include "map-repo.h" +#include "path.h" GConfClient *gconf_client; void config_init(void); +gboolean config_save(void); + gboolean config_save_repo(void); gboolean config_load_repo(void); RepoData *config_parse_repo(gchar *str); -gboolean config_save_home(void); -gboolean config_save(void); -void config_update_proxy(void); -gboolean config_load_string_list(const gchar *gconf_key, GSList **list, GtkListStore **model); +gboolean config_load_position(Position *pos, const gchar *key); +gboolean config_save_position(Position *pos, const gchar *key); + gboolean config_save_filter(GpsTrackFilter *f); +gboolean config_load_string_list(const gchar *gconf_key, GSList **list, GtkListStore **model); + +void config_update_proxy(void); + #endif -- 2.39.5