--- trunk/src/gconf.c 2009/06/27 19:18:40 14 +++ trunk/src/gconf.c 2009/09/21 13:15:25 122 @@ -20,6 +20,7 @@ #include #include #include +#include // for isnan #include "gpxview.h" #define GCONF_PATH "/apps/gpxview/" @@ -83,7 +84,12 @@ { "goto_dss", STORE_BOOL, OFFSET(goto_disable_screensaver) }, { "cachelist_update", STORE_BOOL, OFFSET(cachelist_update) }, #endif - +#ifdef ENABLE_OSM_GPS_MAP + { "map_lat", STORE_FLOAT, OFFSET(map.pos.lat) }, + { "map_lon", STORE_FLOAT, OFFSET(map.pos.lon) }, + { "map_zoom", STORE_INT, OFFSET(map.zoom) }, + { "map_source", STORE_INT, OFFSET(map.source) }, +#endif { NULL, -1, -1 } }; @@ -156,9 +162,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 +181,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 +190,7 @@ break; } + g_free(key); st++; } } @@ -195,6 +202,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); @@ -205,7 +217,6 @@ char str[128]; snprintf(str, sizeof(str), GCONF_KEY_GPX, i); char *fname = gconf_client_get_string(appdata->gconf_client, str, NULL); - if(fname) { /* check if there's a valid name stored for this file. */ /* if yes it's a "closed" file */ @@ -221,13 +232,25 @@ else *gpx = gpx_parse(dialog, fname); - free(fname); + if(!*gpx) { + /* restoring the gpx file failed, mark it as unusable, but save */ + /* its presence for later use */ + + /* create "closed" entry to remember this file for next */ + /* load attempt */ + *gpx = g_new0(gpx_t, 1); + (*gpx)->filename = fname; + char *p = fname; + if(strrchr(fname, '/')) + p = strrchr(fname, '/')+1; + + (*gpx)->name = g_strdup_printf(_("Failed to load: %s"), p); + (*gpx)->closed = TRUE; + } else + free(fname); } - } - - /* use next gpx entry of this was loaded successfully */ - if(*gpx) gpx = &((*gpx)->next); + } } gpx_busy_dialog_destroy(dialog); @@ -255,55 +278,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) @@ -313,6 +324,10 @@ appdata->search = SEARCH_NAME | SEARCH_ID; if(!appdata->image_path) { +#ifdef USE_MAEMO + /* update cachelist by default */ + appdata->cachelist_update = TRUE; +#endif /* use gps by default */ appdata->use_gps = TRUE; @@ -331,6 +346,22 @@ #endif appdata->image_path = strdup(DEFAULT_IMAGE_PATH); + /* check if this path is actually accessible */ + /* and change it to the current users home if not */ + /* (this should only happen on scratchbox) */ + if(!g_file_test(appdata->image_path, G_FILE_TEST_IS_DIR)) { + if(g_mkdir_with_parents(appdata->image_path, 0700) != 0) { + char *p = getenv("HOME"); + if(!p) p = "/tmp/"; + + appdata->image_path = + g_strdup_printf("%s%s%s", p, + (p[strlen(p)-1]!='/')?"/":"", + DEFAULT_IMAGE_PATH_HOME); + printf("using alt path %s\n", appdata->image_path); + } + } + } else { /* some versions old versions messed up the path */ if(appdata->image_path[strlen(appdata->image_path)-1] != '/') { @@ -395,7 +426,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);