20 |
#include <stddef.h> |
#include <stddef.h> |
21 |
#include <stdlib.h> |
#include <stdlib.h> |
22 |
#include <ctype.h> |
#include <ctype.h> |
23 |
|
#include <math.h> // for isnan |
24 |
#include "gpxview.h" |
#include "gpxview.h" |
25 |
|
|
26 |
#define GCONF_PATH "/apps/gpxview/" |
#define GCONF_PATH "/apps/gpxview/" |
84 |
{ "goto_dss", STORE_BOOL, OFFSET(goto_disable_screensaver) }, |
{ "goto_dss", STORE_BOOL, OFFSET(goto_disable_screensaver) }, |
85 |
{ "cachelist_update", STORE_BOOL, OFFSET(cachelist_update) }, |
{ "cachelist_update", STORE_BOOL, OFFSET(cachelist_update) }, |
86 |
#endif |
#endif |
87 |
|
#ifdef ENABLE_OSM_GPS_MAP |
88 |
|
{ "map_lat", STORE_FLOAT, OFFSET(map.pos.lat) }, |
89 |
|
{ "map_lon", STORE_FLOAT, OFFSET(map.pos.lon) }, |
90 |
|
{ "map_zoom", STORE_INT, OFFSET(map.zoom) }, |
91 |
|
#endif |
92 |
{ NULL, -1, -1 } |
{ NULL, -1, -1 } |
93 |
}; |
}; |
94 |
|
|
161 |
/* store everything listed in the store table */ |
/* store everything listed in the store table */ |
162 |
store_t *st = store; |
store_t *st = store; |
163 |
while(st->key) { |
while(st->key) { |
|
char key[256]; |
|
164 |
void **ptr = ((void*)appdata) + st->offset; |
void **ptr = ((void*)appdata) + st->offset; |
165 |
snprintf(key, sizeof(key), GCONF_PATH "%s", st->key); |
char *key = g_strdup_printf(GCONF_PATH "%s", st->key); |
166 |
|
|
167 |
switch(st->type) { |
switch(st->type) { |
168 |
case STORE_STRING: |
case STORE_STRING: |
180 |
break; |
break; |
181 |
|
|
182 |
case STORE_FLOAT: |
case STORE_FLOAT: |
183 |
gconf_client_set_float(appdata->gconf_client, key, *((float*)ptr), NULL); |
if(!isnan(*((float*)ptr))) |
184 |
|
gconf_client_set_float(appdata->gconf_client, key, *((float*)ptr), NULL); |
185 |
break; |
break; |
186 |
|
|
187 |
default: |
default: |
189 |
break; |
break; |
190 |
} |
} |
191 |
|
|
192 |
|
g_free(key); |
193 |
st++; |
st++; |
194 |
} |
} |
195 |
} |
} |
201 |
|
|
202 |
gpx_dialog_t *dialog = NULL; |
gpx_dialog_t *dialog = NULL; |
203 |
|
|
204 |
|
/* default positions are invalid */ |
205 |
|
appdata->home.lat = appdata->home.lon = NAN; |
206 |
|
appdata->manual_goto.lat = appdata->manual_goto.lon = NAN; |
207 |
|
appdata->gps.lat = appdata->gps.lon = NAN; |
208 |
|
|
209 |
int i, entries = gconf_client_get_int(appdata->gconf_client, |
int i, entries = gconf_client_get_int(appdata->gconf_client, |
210 |
GCONF_KEY_CNT, NULL); |
GCONF_KEY_CNT, NULL); |
211 |
|
|
232 |
else |
else |
233 |
*gpx = gpx_parse(dialog, fname); |
*gpx = gpx_parse(dialog, fname); |
234 |
|
|
235 |
free(fname); |
if(!*gpx) { |
236 |
|
/* restoring the gpx file failed, mark it as unusable, but save */ |
237 |
|
/* its presence for later use */ |
238 |
|
|
239 |
|
/* create fake entry to remember this file for next load attempt */ |
240 |
|
*gpx = g_new0(gpx_t, 1); |
241 |
|
(*gpx)->filename = fname; |
242 |
|
(*gpx)->failed = TRUE; |
243 |
|
} else |
244 |
|
free(fname); |
245 |
} |
} |
246 |
} |
} |
247 |
|
|
248 |
/* use next gpx entry of this was loaded successfully */ |
gpx = &((*gpx)->next); |
|
if(*gpx) |
|
|
gpx = &((*gpx)->next); |
|
249 |
} |
} |
250 |
|
|
251 |
gpx_busy_dialog_destroy(dialog); |
gpx_busy_dialog_destroy(dialog); |
273 |
/* restore everything listed in the store table */ |
/* restore everything listed in the store table */ |
274 |
store_t *st = store; |
store_t *st = store; |
275 |
while(st->key) { |
while(st->key) { |
|
char key[256]; |
|
276 |
void **ptr = ((void*)appdata) + st->offset; |
void **ptr = ((void*)appdata) + st->offset; |
277 |
snprintf(key, sizeof(key), GCONF_PATH "%s", st->key); |
char *key = g_strdup_printf(GCONF_PATH "%s", st->key); |
278 |
|
|
279 |
switch(st->type) { |
/* check if key is present */ |
280 |
case STORE_STRING: { |
GConfValue *value = gconf_client_get(appdata->gconf_client, key, NULL); |
281 |
char **str = (char**)ptr; |
if(value) { |
282 |
*str = gconf_client_get_string(appdata->gconf_client, key, NULL); |
gconf_value_free(value); |
283 |
|
|
284 |
|
switch(st->type) { |
285 |
|
case STORE_STRING: { |
286 |
|
char **str = (char**)ptr; |
287 |
|
*str = gconf_client_get_string(appdata->gconf_client, key, NULL); |
288 |
} break; |
} break; |
289 |
|
|
290 |
case STORE_BOOL: |
case STORE_BOOL: |
291 |
*((int*)ptr) = gconf_client_get_bool(appdata->gconf_client, key, NULL); |
*((int*)ptr) = gconf_client_get_bool(appdata->gconf_client, key, NULL); |
292 |
break; |
break; |
293 |
|
|
294 |
case STORE_INT: |
case STORE_INT: |
295 |
*((int*)ptr) = gconf_client_get_int(appdata->gconf_client, key, NULL); |
*((int*)ptr) = gconf_client_get_int(appdata->gconf_client, key, NULL); |
296 |
break; |
break; |
297 |
|
|
298 |
case STORE_FLOAT: |
case STORE_FLOAT: |
299 |
*((float*)ptr) = gconf_client_get_float(appdata->gconf_client, key, NULL); |
*((float*)ptr) = gconf_client_get_float(appdata->gconf_client, key, NULL); |
300 |
break; |
break; |
301 |
|
|
302 |
default: |
default: |
303 |
printf("Unsupported type %d\n", st->type); |
printf("Unsupported type %d\n", st->type); |
304 |
break; |
break; |
305 |
|
} |
306 |
} |
} |
307 |
|
g_free(key); |
308 |
st++; |
st++; |
309 |
} |
} |
310 |
|
|
311 |
/* ----- set all kinds of defaults ------- */ |
/* ----- set all kinds of defaults ------- */ |
312 |
|
|
|
#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 |
|
|
|
|
313 |
if(!appdata->compass_damping) appdata->compass_damping = 1; |
if(!appdata->compass_damping) appdata->compass_damping = 1; |
314 |
|
|
315 |
if(!appdata->mmpoi_radius) |
if(!appdata->mmpoi_radius) |
337 |
#endif |
#endif |
338 |
appdata->image_path = strdup(DEFAULT_IMAGE_PATH); |
appdata->image_path = strdup(DEFAULT_IMAGE_PATH); |
339 |
|
|
340 |
|
/* check if this path is actually accessible */ |
341 |
|
/* and change it to the current users home if not */ |
342 |
|
/* (this should only happen on scratchbox) */ |
343 |
|
if(!g_file_test(appdata->image_path, G_FILE_TEST_IS_DIR)) { |
344 |
|
if(g_mkdir_with_parents(appdata->image_path, 0700) != 0) { |
345 |
|
char *p = getenv("HOME"); |
346 |
|
if(!p) p = "/tmp/"; |
347 |
|
|
348 |
|
appdata->image_path = |
349 |
|
g_strdup_printf("%s%s%s", p, |
350 |
|
(p[strlen(p)-1]!='/')?"/":"", |
351 |
|
DEFAULT_IMAGE_PATH_HOME); |
352 |
|
printf("using alt path %s\n", appdata->image_path); |
353 |
|
} |
354 |
|
} |
355 |
|
|
356 |
} else { |
} else { |
357 |
/* some versions old versions messed up the path */ |
/* some versions old versions messed up the path */ |
358 |
if(appdata->image_path[strlen(appdata->image_path)-1] != '/') { |
if(appdata->image_path[strlen(appdata->image_path)-1] != '/') { |