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/" |
67 |
{ "compass_locked", STORE_BOOL, OFFSET(compass_locked) }, |
{ "compass_locked", STORE_BOOL, OFFSET(compass_locked) }, |
68 |
{ "latitude", STORE_FLOAT, OFFSET(home.lat) }, |
{ "latitude", STORE_FLOAT, OFFSET(home.lat) }, |
69 |
{ "longitude", STORE_FLOAT, OFFSET(home.lon) }, |
{ "longitude", STORE_FLOAT, OFFSET(home.lon) }, |
|
{ "manual_goto_lat", STORE_FLOAT, OFFSET(manual_goto.lat) }, |
|
|
{ "manual_goto_lon", STORE_FLOAT, OFFSET(manual_goto.lon) }, |
|
70 |
{ "gps_lat", STORE_FLOAT, OFFSET(gps.lat) }, |
{ "gps_lat", STORE_FLOAT, OFFSET(gps.lat) }, |
71 |
{ "gps_lon", STORE_FLOAT, OFFSET(gps.lon) }, |
{ "gps_lon", STORE_FLOAT, OFFSET(gps.lon) }, |
72 |
{ "search_in", STORE_INT, OFFSET(search) }, |
{ "search_in", STORE_INT, OFFSET(search) }, |
76 |
{ "cachelist_items", STORE_INT, OFFSET(cachelist_items) }, |
{ "cachelist_items", STORE_INT, OFFSET(cachelist_items) }, |
77 |
{ "compass_damping", STORE_INT, OFFSET(compass_damping) }, |
{ "compass_damping", STORE_INT, OFFSET(compass_damping) }, |
78 |
{ "cachelist_hide_found", STORE_BOOL, OFFSET(cachelist_hide_found) }, |
{ "cachelist_hide_found", STORE_BOOL, OFFSET(cachelist_hide_found) }, |
79 |
|
{ "cachelist_update", STORE_BOOL, OFFSET(cachelist_update) }, |
80 |
|
{ "disable_gcvote", STORE_BOOL, OFFSET(disable_gcvote) }, |
81 |
|
{ "username", STORE_STRING, OFFSET(username) }, |
82 |
#ifdef USE_MAEMO |
#ifdef USE_MAEMO |
83 |
{ "mmpoi_dontlaunch", STORE_BOOL, OFFSET(mmpoi_dontlaunch) }, |
{ "mmpoi_dontlaunch", STORE_BOOL, OFFSET(mmpoi_dontlaunch) }, |
84 |
{ "cachelist_dss", STORE_BOOL, OFFSET(cachelist_disable_screensaver) }, |
{ "cachelist_dss", STORE_BOOL, OFFSET(cachelist_disable_screensaver) }, |
85 |
{ "goto_dss", STORE_BOOL, OFFSET(goto_disable_screensaver) }, |
{ "goto_dss", STORE_BOOL, OFFSET(goto_disable_screensaver) }, |
86 |
{ "cachelist_update", STORE_BOOL, OFFSET(cachelist_update) }, |
#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 |
#endif |
93 |
|
|
94 |
|
{ "geotoad/password", STORE_STRING, OFFSET(gt.password) }, |
95 |
|
{ "geotoad/filename", STORE_STRING, OFFSET(gt.filename) }, |
96 |
|
{ "geotoad/distance", STORE_FLOAT, OFFSET(gt.distance) }, |
97 |
|
{ "geotoad/lat", STORE_FLOAT, OFFSET(gt.lat) }, |
98 |
|
{ "geotoad/lon", STORE_FLOAT, OFFSET(gt.lon) }, |
99 |
|
{ "geotoad/flags", STORE_INT, OFFSET(gt.flags) }, |
100 |
|
|
101 |
{ NULL, -1, -1 } |
{ NULL, -1, -1 } |
102 |
}; |
}; |
103 |
|
|
119 |
} |
} |
120 |
|
|
121 |
void gconf_remove_closed_name(appdata_t *appdata, char *filename) { |
void gconf_remove_closed_name(appdata_t *appdata, char *filename) { |
122 |
|
if(!filename || !strlen(filename)) return; |
123 |
|
|
124 |
char *key = g_strdup_printf(GCONF_KEY_CLOSED, get_basename(filename)); |
char *key = g_strdup_printf(GCONF_KEY_CLOSED, get_basename(filename)); |
125 |
gconf_client_unset(appdata->gconf_client, key, NULL); |
gconf_client_unset(appdata->gconf_client, key, NULL); |
126 |
g_free(key); |
g_free(key); |
127 |
} |
} |
128 |
|
|
129 |
void gconf_save_closed_name(appdata_t *appdata, char *filename, char *name) { |
void gconf_save_closed_name(appdata_t *appdata, char *filename, char *name) { |
130 |
|
if(!filename || !strlen(filename)) return; |
131 |
|
|
132 |
char *key = g_strdup_printf(GCONF_KEY_CLOSED, get_basename(filename)); |
char *key = g_strdup_printf(GCONF_KEY_CLOSED, get_basename(filename)); |
133 |
gconf_client_set_string(appdata->gconf_client, key, name, NULL); |
gconf_client_set_string(appdata->gconf_client, key, name, NULL); |
134 |
g_free(key); |
g_free(key); |
135 |
} |
} |
136 |
|
|
137 |
char *gconf_restore_closed_name(appdata_t *appdata, char *filename) { |
char *gconf_restore_closed_name(appdata_t *appdata, char *filename) { |
138 |
|
if(!filename || !strlen(filename)) return NULL; |
139 |
|
|
140 |
char *key = g_strdup_printf(GCONF_KEY_CLOSED, get_basename(filename)); |
char *key = g_strdup_printf(GCONF_KEY_CLOSED, get_basename(filename)); |
141 |
char *ret = gconf_client_get_string(appdata->gconf_client, key, NULL); |
char *ret = gconf_client_get_string(appdata->gconf_client, key, NULL); |
142 |
g_free(key); |
g_free(key); |
146 |
void gconf_save_state(appdata_t *appdata) { |
void gconf_save_state(appdata_t *appdata) { |
147 |
int entries = 0; |
int entries = 0; |
148 |
|
|
149 |
|
printf("saving gconf state\n"); |
150 |
|
|
151 |
|
/* free proxy settings */ |
152 |
|
if(appdata->proxy) { |
153 |
|
proxy_t *proxy = appdata->proxy; |
154 |
|
|
155 |
|
if(proxy->authentication_password) g_free(proxy->authentication_password); |
156 |
|
if(proxy->authentication_user) g_free(proxy->authentication_user); |
157 |
|
if(proxy->host) g_free(proxy->host); |
158 |
|
if(proxy->ignore_hosts) g_free(proxy->ignore_hosts); |
159 |
|
|
160 |
|
g_free(proxy); |
161 |
|
appdata->proxy = NULL; |
162 |
|
} |
163 |
|
|
164 |
gpx_t *gpx = appdata->gpx; |
gpx_t *gpx = appdata->gpx; |
165 |
while(gpx) { |
while(gpx) { |
166 |
char str[128]; |
char str[128]; |
191 |
/* store everything listed in the store table */ |
/* store everything listed in the store table */ |
192 |
store_t *st = store; |
store_t *st = store; |
193 |
while(st->key) { |
while(st->key) { |
|
char key[256]; |
|
194 |
void **ptr = ((void*)appdata) + st->offset; |
void **ptr = ((void*)appdata) + st->offset; |
195 |
snprintf(key, sizeof(key), GCONF_PATH "%s", st->key); |
char *key = g_strdup_printf(GCONF_PATH "%s", st->key); |
196 |
|
|
197 |
switch(st->type) { |
switch(st->type) { |
198 |
case STORE_STRING: |
case STORE_STRING: |
199 |
if((char*)(*ptr)) { |
if((char*)(*ptr)) { |
200 |
gconf_client_set_string(appdata->gconf_client, key, (char*)(*ptr), NULL); |
gconf_client_set_string(appdata->gconf_client, key, (char*)(*ptr), NULL); |
201 |
} |
} |
202 |
|
g_free((char*)(*ptr)); |
203 |
|
*ptr = NULL; |
204 |
break; |
break; |
205 |
|
|
206 |
case STORE_BOOL: |
case STORE_BOOL: |
212 |
break; |
break; |
213 |
|
|
214 |
case STORE_FLOAT: |
case STORE_FLOAT: |
215 |
gconf_client_set_float(appdata->gconf_client, key, *((float*)ptr), NULL); |
if(!isnan(*((float*)ptr))) |
216 |
|
gconf_client_set_float(appdata->gconf_client, key, *((float*)ptr), NULL); |
217 |
break; |
break; |
218 |
|
|
219 |
default: |
default: |
221 |
break; |
break; |
222 |
} |
} |
223 |
|
|
224 |
|
g_free(key); |
225 |
st++; |
st++; |
226 |
} |
} |
227 |
} |
} |
233 |
|
|
234 |
gpx_dialog_t *dialog = NULL; |
gpx_dialog_t *dialog = NULL; |
235 |
|
|
236 |
|
/* default positions are invalid */ |
237 |
|
appdata->home.lat = appdata->home.lon = NAN; |
238 |
|
appdata->gps.lat = appdata->gps.lon = NAN; |
239 |
|
appdata->geomath.lat = appdata->geomath.lon = NAN; |
240 |
|
|
241 |
|
appdata->gt.lat = appdata->gt.lon = NAN; |
242 |
|
appdata->gt.distance = 1.0; // in km/mil |
243 |
|
|
244 |
|
/* ------------- get proxy settings -------------------- */ |
245 |
|
if(gconf_client_get_bool(appdata->gconf_client, |
246 |
|
PROXY_KEY "use_http_proxy", NULL)) { |
247 |
|
proxy_t *proxy = appdata->proxy = g_new0(proxy_t, 1); |
248 |
|
|
249 |
|
/* get basic settings */ |
250 |
|
proxy->host = gconf_client_get_string(appdata->gconf_client, |
251 |
|
PROXY_KEY "host", NULL); |
252 |
|
proxy->port = gconf_client_get_int(appdata->gconf_client, |
253 |
|
PROXY_KEY "port", NULL); |
254 |
|
proxy->ignore_hosts = |
255 |
|
gconf_client_get_string(appdata->gconf_client, |
256 |
|
PROXY_KEY "ignore_hosts", NULL); |
257 |
|
|
258 |
|
/* check for authentication */ |
259 |
|
proxy->use_authentication = |
260 |
|
gconf_client_get_bool(appdata->gconf_client, |
261 |
|
PROXY_KEY "use_authentication", NULL); |
262 |
|
|
263 |
|
if(proxy->use_authentication) { |
264 |
|
proxy->authentication_user = |
265 |
|
gconf_client_get_string(appdata->gconf_client, |
266 |
|
PROXY_KEY "authentication_user", NULL); |
267 |
|
proxy->authentication_password = |
268 |
|
gconf_client_get_string(appdata->gconf_client, |
269 |
|
PROXY_KEY "authentication_password", NULL); |
270 |
|
} |
271 |
|
} |
272 |
|
|
273 |
|
/* restore everything listed in the store table */ |
274 |
|
store_t *st = store; |
275 |
|
while(st->key) { |
276 |
|
void **ptr = ((void*)appdata) + st->offset; |
277 |
|
char *key = g_strdup_printf(GCONF_PATH "%s", st->key); |
278 |
|
|
279 |
|
/* check if key is present */ |
280 |
|
GConfValue *value = gconf_client_get(appdata->gconf_client, key, NULL); |
281 |
|
if(value) { |
282 |
|
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; |
289 |
|
|
290 |
|
case STORE_BOOL: |
291 |
|
*((int*)ptr) = gconf_client_get_bool(appdata->gconf_client, key, NULL); |
292 |
|
break; |
293 |
|
|
294 |
|
case STORE_INT: |
295 |
|
*((int*)ptr) = gconf_client_get_int(appdata->gconf_client, key, NULL); |
296 |
|
break; |
297 |
|
|
298 |
|
case STORE_FLOAT: |
299 |
|
*((float*)ptr) = gconf_client_get_float(appdata->gconf_client, key, NULL); |
300 |
|
break; |
301 |
|
|
302 |
|
default: |
303 |
|
printf("Unsupported type %d\n", st->type); |
304 |
|
break; |
305 |
|
} |
306 |
|
} |
307 |
|
g_free(key); |
308 |
|
st++; |
309 |
|
} |
310 |
|
|
311 |
int i, entries = gconf_client_get_int(appdata->gconf_client, |
int i, entries = gconf_client_get_int(appdata->gconf_client, |
312 |
GCONF_KEY_CNT, NULL); |
GCONF_KEY_CNT, NULL); |
313 |
|
|
318 |
char str[128]; |
char str[128]; |
319 |
snprintf(str, sizeof(str), GCONF_KEY_GPX, i); |
snprintf(str, sizeof(str), GCONF_KEY_GPX, i); |
320 |
char *fname = gconf_client_get_string(appdata->gconf_client, str, NULL); |
char *fname = gconf_client_get_string(appdata->gconf_client, str, NULL); |
|
|
|
321 |
if(fname) { |
if(fname) { |
322 |
/* check if there's a valid name stored for this file. */ |
/* check if there's a valid name stored for this file. */ |
323 |
/* if yes it's a "closed" file */ |
/* if yes it's a "closed" file */ |
329 |
(*gpx)->closed = TRUE; |
(*gpx)->closed = TRUE; |
330 |
} else { |
} else { |
331 |
if(g_file_test(fname, G_FILE_TEST_IS_DIR)) |
if(g_file_test(fname, G_FILE_TEST_IS_DIR)) |
332 |
*gpx = gpx_parse_dir(dialog, fname); |
*gpx = gpx_parse_dir(dialog, fname, appdata->username); |
333 |
else |
else |
334 |
*gpx = gpx_parse(dialog, fname); |
*gpx = gpx_parse(dialog, fname, appdata->username); |
335 |
|
|
336 |
free(fname); |
if(!*gpx) { |
337 |
|
/* restoring the gpx file failed, mark it as unusable, but save */ |
338 |
|
/* its presence for later use */ |
339 |
|
|
340 |
|
/* create "closed" entry to remember this file for next */ |
341 |
|
/* load attempt */ |
342 |
|
*gpx = g_new0(gpx_t, 1); |
343 |
|
(*gpx)->filename = fname; |
344 |
|
char *p = fname; |
345 |
|
if(strrchr(fname, '/')) |
346 |
|
p = strrchr(fname, '/')+1; |
347 |
|
|
348 |
|
(*gpx)->name = g_strdup_printf(_("Failed to load: %s"), p); |
349 |
|
(*gpx)->closed = TRUE; |
350 |
|
} else |
351 |
|
free(fname); |
352 |
} |
} |
|
} |
|
|
|
|
|
/* use next gpx entry of this was loaded successfully */ |
|
|
if(*gpx) |
|
353 |
gpx = &((*gpx)->next); |
gpx = &((*gpx)->next); |
354 |
|
} |
355 |
} |
} |
356 |
|
|
357 |
gpx_busy_dialog_destroy(dialog); |
gpx_busy_dialog_destroy(dialog); |
376 |
} |
} |
377 |
} |
} |
378 |
|
|
|
/* 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); |
|
|
|
|
|
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; |
|
|
} |
|
|
|
|
|
st++; |
|
|
} |
|
|
|
|
379 |
/* ----- set all kinds of defaults ------- */ |
/* ----- set all kinds of defaults ------- */ |
380 |
|
|
|
#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 |
|
|
|
|
381 |
if(!appdata->compass_damping) appdata->compass_damping = 1; |
if(!appdata->compass_damping) appdata->compass_damping = 1; |
382 |
|
|
383 |
if(!appdata->mmpoi_radius) |
if(!appdata->mmpoi_radius) |
387 |
appdata->search = SEARCH_NAME | SEARCH_ID; |
appdata->search = SEARCH_NAME | SEARCH_ID; |
388 |
|
|
389 |
if(!appdata->image_path) { |
if(!appdata->image_path) { |
390 |
|
#ifdef USE_MAEMO |
391 |
|
/* update cachelist by default */ |
392 |
|
appdata->cachelist_update = TRUE; |
393 |
|
#endif |
394 |
|
|
395 |
/* use gps by default */ |
/* use gps by default */ |
396 |
appdata->use_gps = TRUE; |
appdata->use_gps = TRUE; |
409 |
#endif |
#endif |
410 |
appdata->image_path = strdup(DEFAULT_IMAGE_PATH); |
appdata->image_path = strdup(DEFAULT_IMAGE_PATH); |
411 |
|
|
412 |
|
/* check if this path is actually accessible */ |
413 |
|
/* and change it to the current users home if not */ |
414 |
|
/* (this should only happen on scratchbox) */ |
415 |
|
if(!g_file_test(appdata->image_path, G_FILE_TEST_IS_DIR)) { |
416 |
|
if(g_mkdir_with_parents(appdata->image_path, 0700) != 0) { |
417 |
|
char *p = getenv("HOME"); |
418 |
|
if(!p) p = "/tmp/"; |
419 |
|
|
420 |
|
appdata->image_path = |
421 |
|
g_strdup_printf("%s%s%s", p, |
422 |
|
(p[strlen(p)-1]!='/')?"/":"", |
423 |
|
DEFAULT_IMAGE_PATH_HOME); |
424 |
|
printf("using alt path %s\n", appdata->image_path); |
425 |
|
} |
426 |
|
} |
427 |
|
|
428 |
} else { |
} else { |
429 |
/* some versions old versions messed up the path */ |
/* some versions old versions messed up the path */ |
430 |
if(appdata->image_path[strlen(appdata->image_path)-1] != '/') { |
if(appdata->image_path[strlen(appdata->image_path)-1] != '/') { |
489 |
/* 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 */ |
490 |
/* "welcome" one */ |
/* "welcome" one */ |
491 |
if(!appdata->gpx) { |
if(!appdata->gpx) { |
492 |
char *name = g_strdup("/usr/share/gpxview/welcome.gpx"); |
char *name = g_strdup(ICONPATH "welcome.gpx"); |
493 |
dialog = gpx_busy_dialog_new(GTK_WIDGET(appdata->window)); |
dialog = gpx_busy_dialog_new(GTK_WIDGET(appdata->window)); |
494 |
printf("No GPX file loaded, trying to load demo\n"); |
printf("No GPX file loaded, trying to load demo\n"); |
495 |
appdata->gpx = gpx_parse(dialog, name); |
appdata->gpx = gpx_parse(dialog, name, appdata->username); |
496 |
gpx_busy_dialog_destroy(dialog); |
gpx_busy_dialog_destroy(dialog); |
497 |
g_free(name); |
g_free(name); |
498 |
} |
} |