--- trunk/src/gconf.c 2009/06/27 11:09:19 13 +++ trunk/src/gconf.c 2009/07/29 19:24:15 34 @@ -20,6 +20,7 @@ #include #include #include +#include // for isnan #include "gpxview.h" #define GCONF_PATH "/apps/gpxview/" @@ -156,9 +157,8 @@ /* store everything listed in the store table */ store_t *st = store; while(st->key) { - char key[256]; void **ptr = ((void*)appdata) + st->offset; - snprintf(key, sizeof(key), GCONF_PATH "%s", st->key); + char *key = g_strdup_printf(GCONF_PATH "%s", st->key); switch(st->type) { case STORE_STRING: @@ -176,7 +176,8 @@ break; case STORE_FLOAT: - gconf_client_set_float(appdata->gconf_client, key, *((float*)ptr), NULL); + if(!isnan(*((float*)ptr))) + gconf_client_set_float(appdata->gconf_client, key, *((float*)ptr), NULL); break; default: @@ -184,6 +185,7 @@ break; } + g_free(key); st++; } } @@ -195,6 +197,11 @@ gpx_dialog_t *dialog = NULL; + /* default positions are invalid */ + appdata->home.lat = appdata->home.lon = NAN; + appdata->manual_goto.lat = appdata->manual_goto.lon = NAN; + appdata->gps.lat = appdata->gps.lon = NAN; + int i, entries = gconf_client_get_int(appdata->gconf_client, GCONF_KEY_CNT, NULL); @@ -255,55 +262,43 @@ /* restore everything listed in the store table */ store_t *st = store; while(st->key) { - char key[256]; void **ptr = ((void*)appdata) + st->offset; - snprintf(key, sizeof(key), GCONF_PATH "%s", st->key); + char *key = g_strdup_printf(GCONF_PATH "%s", st->key); - switch(st->type) { - case STORE_STRING: { - char **str = (char**)ptr; - *str = gconf_client_get_string(appdata->gconf_client, key, NULL); + /* check if key is present */ + GConfValue *value = gconf_client_get(appdata->gconf_client, key, NULL); + if(value) { + gconf_value_free(value); + + switch(st->type) { + case STORE_STRING: { + char **str = (char**)ptr; + *str = gconf_client_get_string(appdata->gconf_client, key, NULL); } break; - - case STORE_BOOL: - *((int*)ptr) = gconf_client_get_bool(appdata->gconf_client, key, NULL); - break; - - case STORE_INT: - *((int*)ptr) = gconf_client_get_int(appdata->gconf_client, key, NULL); - break; - - case STORE_FLOAT: - *((float*)ptr) = gconf_client_get_float(appdata->gconf_client, key, NULL); - break; - - default: - printf("Unsupported type %d\n", st->type); - break; + + case STORE_BOOL: + *((int*)ptr) = gconf_client_get_bool(appdata->gconf_client, key, NULL); + break; + + case STORE_INT: + *((int*)ptr) = gconf_client_get_int(appdata->gconf_client, key, NULL); + break; + + case STORE_FLOAT: + *((float*)ptr) = gconf_client_get_float(appdata->gconf_client, key, NULL); + break; + + default: + printf("Unsupported type %d\n", st->type); + break; + } } - + g_free(key); st++; } /* ----- set all kinds of defaults ------- */ -#if 0 - if(!appdata->home.lon || !appdata->home.lat) { - appdata->home.lat = DEFAULT_LAT; - appdata->home.lon = DEFAULT_LON; - } - - if(!appdata->manual_goto.lon || !appdata->manual_goto.lat) { - appdata->manual_goto.lat = DEFAULT_LAT; - appdata->manual_goto.lon = DEFAULT_LON; - } - - if(!appdata->gps.lon || !appdata->gps.lat) { - appdata->gps.lat = DEFAULT_LAT; - appdata->gps.lon = DEFAULT_LON; - } -#endif - if(!appdata->compass_damping) appdata->compass_damping = 1; if(!appdata->mmpoi_radius) @@ -314,6 +309,9 @@ if(!appdata->image_path) { + /* use gps by default */ + appdata->use_gps = TRUE; + #ifndef USE_MAEMO char *p = getenv("HOME"); if(p) { @@ -392,7 +390,7 @@ /* if there are no entries in the main list, try to add the */ /* "welcome" one */ if(!appdata->gpx) { - char *name = g_strdup("/usr/share/gpxview/welcome.gpx"); + char *name = g_strdup(ICONPATH "welcome.gpx"); dialog = gpx_busy_dialog_new(GTK_WIDGET(appdata->window)); printf("No GPX file loaded, trying to load demo\n"); appdata->gpx = gpx_parse(dialog, name);