--- trunk/src/gconf.c 2009/06/29 08:24:41 17 +++ trunk/src/gconf.c 2009/11/04 14:54:52 158 @@ -20,6 +20,7 @@ #include #include #include +#include // for isnan #include "gpxview.h" #define GCONF_PATH "/apps/gpxview/" @@ -77,13 +78,18 @@ { "cachelist_items", STORE_INT, OFFSET(cachelist_items) }, { "compass_damping", STORE_INT, OFFSET(compass_damping) }, { "cachelist_hide_found", STORE_BOOL, OFFSET(cachelist_hide_found) }, + { "cachelist_update", STORE_BOOL, OFFSET(cachelist_update) }, #ifdef USE_MAEMO { "mmpoi_dontlaunch", STORE_BOOL, OFFSET(mmpoi_dontlaunch) }, { "cachelist_dss", STORE_BOOL, OFFSET(cachelist_disable_screensaver) }, { "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 } }; @@ -126,6 +132,19 @@ void gconf_save_state(appdata_t *appdata) { int entries = 0; + /* free proxy settings */ + if(appdata->proxy) { + proxy_t *proxy = appdata->proxy; + + if(proxy->authentication_password) g_free(proxy->authentication_password); + if(proxy->authentication_user) g_free(proxy->authentication_user); + if(proxy->host) g_free(proxy->host); + if(proxy->ignore_hosts) g_free(proxy->ignore_hosts); + + g_free(proxy); + appdata->proxy = NULL; + } + gpx_t *gpx = appdata->gpx; while(gpx) { char str[128]; @@ -156,9 +175,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 +194,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 +203,7 @@ break; } + g_free(key); st++; } } @@ -195,6 +215,40 @@ 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; + + /* ------------- get proxy settings -------------------- */ + if(gconf_client_get_bool(appdata->gconf_client, + PROXY_KEY "use_http_proxy", NULL)) { + proxy_t *proxy = appdata->proxy = g_new0(proxy_t, 1); + + /* get basic settings */ + proxy->host = gconf_client_get_string(appdata->gconf_client, + PROXY_KEY "host", NULL); + proxy->port = gconf_client_get_int(appdata->gconf_client, + PROXY_KEY "port", NULL); + proxy->ignore_hosts = + gconf_client_get_string(appdata->gconf_client, + PROXY_KEY "ignore_hosts", NULL); + + /* check for authentication */ + proxy->use_authentication = + gconf_client_get_bool(appdata->gconf_client, + PROXY_KEY "use_authentication", NULL); + + if(proxy->use_authentication) { + proxy->authentication_user = + gconf_client_get_string(appdata->gconf_client, + PROXY_KEY "authentication_user", NULL); + proxy->authentication_password = + gconf_client_get_string(appdata->gconf_client, + PROXY_KEY "authentication_password", NULL); + } + } + int i, entries = gconf_client_get_int(appdata->gconf_client, GCONF_KEY_CNT, NULL); @@ -205,7 +259,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 +274,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 +320,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 +366,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 +388,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] != '/') {