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 |
|
{ "map_source", STORE_INT, OFFSET(map.source) }, |
92 |
|
#endif |
93 |
{ NULL, -1, -1 } |
{ NULL, -1, -1 } |
94 |
}; |
}; |
95 |
|
|
162 |
/* store everything listed in the store table */ |
/* store everything listed in the store table */ |
163 |
store_t *st = store; |
store_t *st = store; |
164 |
while(st->key) { |
while(st->key) { |
|
char key[256]; |
|
165 |
void **ptr = ((void*)appdata) + st->offset; |
void **ptr = ((void*)appdata) + st->offset; |
166 |
snprintf(key, sizeof(key), GCONF_PATH "%s", st->key); |
char *key = g_strdup_printf(GCONF_PATH "%s", st->key); |
167 |
|
|
168 |
switch(st->type) { |
switch(st->type) { |
169 |
case STORE_STRING: |
case STORE_STRING: |
181 |
break; |
break; |
182 |
|
|
183 |
case STORE_FLOAT: |
case STORE_FLOAT: |
184 |
gconf_client_set_float(appdata->gconf_client, key, *((float*)ptr), NULL); |
if(!isnan(*((float*)ptr))) |
185 |
|
gconf_client_set_float(appdata->gconf_client, key, *((float*)ptr), NULL); |
186 |
break; |
break; |
187 |
|
|
188 |
default: |
default: |
190 |
break; |
break; |
191 |
} |
} |
192 |
|
|
193 |
|
g_free(key); |
194 |
st++; |
st++; |
195 |
} |
} |
196 |
} |
} |
202 |
|
|
203 |
gpx_dialog_t *dialog = NULL; |
gpx_dialog_t *dialog = NULL; |
204 |
|
|
205 |
|
/* default positions are invalid */ |
206 |
|
appdata->home.lat = appdata->home.lon = NAN; |
207 |
|
appdata->manual_goto.lat = appdata->manual_goto.lon = NAN; |
208 |
|
appdata->gps.lat = appdata->gps.lon = NAN; |
209 |
|
|
210 |
int i, entries = gconf_client_get_int(appdata->gconf_client, |
int i, entries = gconf_client_get_int(appdata->gconf_client, |
211 |
GCONF_KEY_CNT, NULL); |
GCONF_KEY_CNT, NULL); |
212 |
|
|
217 |
char str[128]; |
char str[128]; |
218 |
snprintf(str, sizeof(str), GCONF_KEY_GPX, i); |
snprintf(str, sizeof(str), GCONF_KEY_GPX, i); |
219 |
char *fname = gconf_client_get_string(appdata->gconf_client, str, NULL); |
char *fname = gconf_client_get_string(appdata->gconf_client, str, NULL); |
|
|
|
220 |
if(fname) { |
if(fname) { |
221 |
/* check if there's a valid name stored for this file. */ |
/* check if there's a valid name stored for this file. */ |
222 |
/* if yes it's a "closed" file */ |
/* if yes it's a "closed" file */ |
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 |
} |
} |
|
} |
|
|
|
|
|
/* use next gpx entry of this was loaded successfully */ |
|
|
if(*gpx) |
|
246 |
gpx = &((*gpx)->next); |
gpx = &((*gpx)->next); |
247 |
|
} |
248 |
} |
} |
249 |
|
|
250 |
gpx_busy_dialog_destroy(dialog); |
gpx_busy_dialog_destroy(dialog); |
272 |
/* restore everything listed in the store table */ |
/* restore everything listed in the store table */ |
273 |
store_t *st = store; |
store_t *st = store; |
274 |
while(st->key) { |
while(st->key) { |
|
char key[256]; |
|
275 |
void **ptr = ((void*)appdata) + st->offset; |
void **ptr = ((void*)appdata) + st->offset; |
276 |
snprintf(key, sizeof(key), GCONF_PATH "%s", st->key); |
char *key = g_strdup_printf(GCONF_PATH "%s", st->key); |
277 |
|
|
278 |
switch(st->type) { |
/* check if key is present */ |
279 |
case STORE_STRING: { |
GConfValue *value = gconf_client_get(appdata->gconf_client, key, NULL); |
280 |
char **str = (char**)ptr; |
if(value) { |
281 |
*str = gconf_client_get_string(appdata->gconf_client, key, NULL); |
gconf_value_free(value); |
282 |
|
|
283 |
|
switch(st->type) { |
284 |
|
case STORE_STRING: { |
285 |
|
char **str = (char**)ptr; |
286 |
|
*str = gconf_client_get_string(appdata->gconf_client, key, NULL); |
287 |
} break; |
} break; |
288 |
|
|
289 |
case STORE_BOOL: |
case STORE_BOOL: |
290 |
*((int*)ptr) = gconf_client_get_bool(appdata->gconf_client, key, NULL); |
*((int*)ptr) = gconf_client_get_bool(appdata->gconf_client, key, NULL); |
291 |
break; |
break; |
292 |
|
|
293 |
case STORE_INT: |
case STORE_INT: |
294 |
*((int*)ptr) = gconf_client_get_int(appdata->gconf_client, key, NULL); |
*((int*)ptr) = gconf_client_get_int(appdata->gconf_client, key, NULL); |
295 |
break; |
break; |
296 |
|
|
297 |
case STORE_FLOAT: |
case STORE_FLOAT: |
298 |
*((float*)ptr) = gconf_client_get_float(appdata->gconf_client, key, NULL); |
*((float*)ptr) = gconf_client_get_float(appdata->gconf_client, key, NULL); |
299 |
break; |
break; |
300 |
|
|
301 |
default: |
default: |
302 |
printf("Unsupported type %d\n", st->type); |
printf("Unsupported type %d\n", st->type); |
303 |
break; |
break; |
304 |
|
} |
305 |
} |
} |
306 |
|
g_free(key); |
307 |
st++; |
st++; |
308 |
} |
} |
309 |
|
|
310 |
/* ----- set all kinds of defaults ------- */ |
/* ----- set all kinds of defaults ------- */ |
311 |
|
|
|
#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 |
|
|
|
|
312 |
if(!appdata->compass_damping) appdata->compass_damping = 1; |
if(!appdata->compass_damping) appdata->compass_damping = 1; |
313 |
|
|
314 |
if(!appdata->mmpoi_radius) |
if(!appdata->mmpoi_radius) |
336 |
#endif |
#endif |
337 |
appdata->image_path = strdup(DEFAULT_IMAGE_PATH); |
appdata->image_path = strdup(DEFAULT_IMAGE_PATH); |
338 |
|
|
339 |
|
/* check if this path is actually accessible */ |
340 |
|
/* and change it to the current users home if not */ |
341 |
|
/* (this should only happen on scratchbox) */ |
342 |
|
if(!g_file_test(appdata->image_path, G_FILE_TEST_IS_DIR)) { |
343 |
|
if(g_mkdir_with_parents(appdata->image_path, 0700) != 0) { |
344 |
|
char *p = getenv("HOME"); |
345 |
|
if(!p) p = "/tmp/"; |
346 |
|
|
347 |
|
appdata->image_path = |
348 |
|
g_strdup_printf("%s%s%s", p, |
349 |
|
(p[strlen(p)-1]!='/')?"/":"", |
350 |
|
DEFAULT_IMAGE_PATH_HOME); |
351 |
|
printf("using alt path %s\n", appdata->image_path); |
352 |
|
} |
353 |
|
} |
354 |
|
|
355 |
} else { |
} else { |
356 |
/* some versions old versions messed up the path */ |
/* some versions old versions messed up the path */ |
357 |
if(appdata->image_path[strlen(appdata->image_path)-1] != '/') { |
if(appdata->image_path[strlen(appdata->image_path)-1] != '/') { |
416 |
/* if there are no entries in the main list, try to add the */ |
/* if there are no entries in the main list, try to add the */ |
417 |
/* "welcome" one */ |
/* "welcome" one */ |
418 |
if(!appdata->gpx) { |
if(!appdata->gpx) { |
419 |
char *name = g_strdup("/usr/share/gpxview/welcome.gpx"); |
char *name = g_strdup(ICONPATH "welcome.gpx"); |
420 |
dialog = gpx_busy_dialog_new(GTK_WIDGET(appdata->window)); |
dialog = gpx_busy_dialog_new(GTK_WIDGET(appdata->window)); |
421 |
printf("No GPX file loaded, trying to load demo\n"); |
printf("No GPX file loaded, trying to load demo\n"); |
422 |
appdata->gpx = gpx_parse(dialog, name); |
appdata->gpx = gpx_parse(dialog, name); |