Diff of /trunk/src/gconf.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 14 by harbaum, Sat Jun 27 19:18:40 2009 UTC revision 158 by harbaum, Wed Nov 4 14:54:52 2009 UTC
# Line 20  Line 20 
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/"
# Line 77  static store_t store[] = { Line 78  static store_t store[] = {
78    { "cachelist_items",  STORE_INT,    OFFSET(cachelist_items) },    { "cachelist_items",  STORE_INT,    OFFSET(cachelist_items) },
79    { "compass_damping",  STORE_INT,    OFFSET(compass_damping) },    { "compass_damping",  STORE_INT,    OFFSET(compass_damping) },
80    { "cachelist_hide_found", STORE_BOOL, OFFSET(cachelist_hide_found) },    { "cachelist_hide_found", STORE_BOOL, OFFSET(cachelist_hide_found) },
81      { "cachelist_update", STORE_BOOL,   OFFSET(cachelist_update) },
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) },
   { "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    
# Line 126  char *gconf_restore_closed_name(appdata_ Line 132  char *gconf_restore_closed_name(appdata_
132  void gconf_save_state(appdata_t *appdata) {  void gconf_save_state(appdata_t *appdata) {
133    int entries = 0;    int entries = 0;
134    
135      /* free proxy settings */
136      if(appdata->proxy) {
137        proxy_t *proxy = appdata->proxy;
138    
139        if(proxy->authentication_password) g_free(proxy->authentication_password);
140        if(proxy->authentication_user)     g_free(proxy->authentication_user);
141        if(proxy->host)                    g_free(proxy->host);
142        if(proxy->ignore_hosts)            g_free(proxy->ignore_hosts);
143    
144        g_free(proxy);
145        appdata->proxy = NULL;
146      }
147    
148    gpx_t *gpx = appdata->gpx;    gpx_t *gpx = appdata->gpx;
149    while(gpx) {    while(gpx) {
150      char str[128];      char str[128];
# Line 156  void gconf_save_state(appdata_t *appdata Line 175  void gconf_save_state(appdata_t *appdata
175    /* store everything listed in the store table */    /* store everything listed in the store table */
176    store_t *st = store;    store_t *st = store;
177    while(st->key) {    while(st->key) {
     char key[256];  
178      void **ptr = ((void*)appdata) + st->offset;      void **ptr = ((void*)appdata) + st->offset;
179      snprintf(key, sizeof(key), GCONF_PATH "%s", st->key);      char *key = g_strdup_printf(GCONF_PATH "%s", st->key);
180    
181      switch(st->type) {      switch(st->type) {
182      case STORE_STRING:      case STORE_STRING:
# Line 176  void gconf_save_state(appdata_t *appdata Line 194  void gconf_save_state(appdata_t *appdata
194        break;        break;
195    
196      case STORE_FLOAT:      case STORE_FLOAT:
197        gconf_client_set_float(appdata->gconf_client, key, *((float*)ptr), NULL);        if(!isnan(*((float*)ptr)))
198            gconf_client_set_float(appdata->gconf_client, key, *((float*)ptr), NULL);
199        break;        break;
200    
201      default:      default:
# Line 184  void gconf_save_state(appdata_t *appdata Line 203  void gconf_save_state(appdata_t *appdata
203        break;        break;
204      }      }
205    
206        g_free(key);
207      st++;      st++;
208    }    }
209  }  }
# Line 195  void gconf_load_state(appdata_t *appdata Line 215  void gconf_load_state(appdata_t *appdata
215    
216    gpx_dialog_t *dialog = NULL;    gpx_dialog_t *dialog = NULL;
217    
218      /* default positions are invalid */
219      appdata->home.lat = appdata->home.lon = NAN;
220      appdata->manual_goto.lat = appdata->manual_goto.lon = NAN;
221      appdata->gps.lat = appdata->gps.lon = NAN;
222    
223      /* ------------- get proxy settings -------------------- */
224      if(gconf_client_get_bool(appdata->gconf_client,
225                               PROXY_KEY "use_http_proxy", NULL)) {
226        proxy_t *proxy = appdata->proxy = g_new0(proxy_t, 1);
227    
228        /* get basic settings */
229        proxy->host = gconf_client_get_string(appdata->gconf_client,
230                                              PROXY_KEY "host", NULL);
231        proxy->port = gconf_client_get_int(appdata->gconf_client,
232                                           PROXY_KEY "port", NULL);
233        proxy->ignore_hosts =
234          gconf_client_get_string(appdata->gconf_client,
235                                  PROXY_KEY "ignore_hosts", NULL);
236    
237        /* check for authentication */
238        proxy->use_authentication =
239          gconf_client_get_bool(appdata->gconf_client,
240                                PROXY_KEY "use_authentication", NULL);
241    
242        if(proxy->use_authentication) {
243          proxy->authentication_user =
244            gconf_client_get_string(appdata->gconf_client,
245                                    PROXY_KEY "authentication_user", NULL);
246          proxy->authentication_password =
247            gconf_client_get_string(appdata->gconf_client,
248                                    PROXY_KEY "authentication_password", NULL);
249        }
250      }
251    
252    int i, entries = gconf_client_get_int(appdata->gconf_client,    int i, entries = gconf_client_get_int(appdata->gconf_client,
253                                   GCONF_KEY_CNT, NULL);                                   GCONF_KEY_CNT, NULL);
254    
# Line 205  void gconf_load_state(appdata_t *appdata Line 259  void gconf_load_state(appdata_t *appdata
259      char str[128];      char str[128];
260      snprintf(str, sizeof(str), GCONF_KEY_GPX, i);      snprintf(str, sizeof(str), GCONF_KEY_GPX, i);
261      char *fname = gconf_client_get_string(appdata->gconf_client, str, NULL);      char *fname = gconf_client_get_string(appdata->gconf_client, str, NULL);
   
262      if(fname) {      if(fname) {
263        /* check if there's a valid name stored for this file. */        /* check if there's a valid name stored for this file. */
264        /* if yes it's a "closed" file */        /* if yes it's a "closed" file */
# Line 221  void gconf_load_state(appdata_t *appdata Line 274  void gconf_load_state(appdata_t *appdata
274          else          else
275            *gpx = gpx_parse(dialog, fname);            *gpx = gpx_parse(dialog, fname);
276    
277          free(fname);          if(!*gpx) {
278              /* restoring the gpx file failed, mark it as unusable, but save */
279              /* its presence for later use */
280    
281              /* create "closed" entry to remember this file for next */
282              /* load attempt */
283              *gpx = g_new0(gpx_t, 1);
284              (*gpx)->filename = fname;
285              char *p = fname;
286              if(strrchr(fname, '/'))
287                p = strrchr(fname, '/')+1;
288    
289              (*gpx)->name = g_strdup_printf(_("Failed to load: %s"), p);
290              (*gpx)->closed = TRUE;
291            } else
292              free(fname);
293        }        }
     }  
   
     /* use next gpx entry of this was loaded successfully */  
     if(*gpx)  
294        gpx = &((*gpx)->next);        gpx = &((*gpx)->next);
295        }
296    }    }
297    
298    gpx_busy_dialog_destroy(dialog);    gpx_busy_dialog_destroy(dialog);
# Line 255  void gconf_load_state(appdata_t *appdata Line 320  void gconf_load_state(appdata_t *appdata
320    /* restore everything listed in the store table */    /* restore everything listed in the store table */
321    store_t *st = store;    store_t *st = store;
322    while(st->key) {    while(st->key) {
     char key[256];  
323      void **ptr = ((void*)appdata) + st->offset;      void **ptr = ((void*)appdata) + st->offset;
324      snprintf(key, sizeof(key), GCONF_PATH "%s", st->key);      char *key = g_strdup_printf(GCONF_PATH "%s", st->key);
325    
326      switch(st->type) {      /* check if key is present */
327      case STORE_STRING: {      GConfValue *value = gconf_client_get(appdata->gconf_client, key, NULL);
328        char **str = (char**)ptr;      if(value) {
329        *str = gconf_client_get_string(appdata->gconf_client, key, NULL);        gconf_value_free(value);
330    
331          switch(st->type) {
332          case STORE_STRING: {
333            char **str = (char**)ptr;
334            *str = gconf_client_get_string(appdata->gconf_client, key, NULL);
335        } break;        } break;
336    
337      case STORE_BOOL:        case STORE_BOOL:
338        *((int*)ptr) = gconf_client_get_bool(appdata->gconf_client, key, NULL);          *((int*)ptr) = gconf_client_get_bool(appdata->gconf_client, key, NULL);
339        break;          break;
340    
341      case STORE_INT:        case STORE_INT:
342        *((int*)ptr) = gconf_client_get_int(appdata->gconf_client, key, NULL);          *((int*)ptr) = gconf_client_get_int(appdata->gconf_client, key, NULL);
343        break;          break;
344    
345      case STORE_FLOAT:        case STORE_FLOAT:
346        *((float*)ptr) = gconf_client_get_float(appdata->gconf_client, key, NULL);          *((float*)ptr) = gconf_client_get_float(appdata->gconf_client, key, NULL);
347        break;          break;
348    
349      default:        default:
350        printf("Unsupported type %d\n", st->type);          printf("Unsupported type %d\n", st->type);
351        break;          break;
352          }
353      }      }
354        g_free(key);
355      st++;      st++;
356    }    }
357    
358    /* ----- set all kinds of defaults ------- */    /* ----- set all kinds of defaults ------- */
359    
 #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  
   
360    if(!appdata->compass_damping) appdata->compass_damping = 1;    if(!appdata->compass_damping) appdata->compass_damping = 1;
361    
362    if(!appdata->mmpoi_radius)    if(!appdata->mmpoi_radius)
# Line 313  void gconf_load_state(appdata_t *appdata Line 366  void gconf_load_state(appdata_t *appdata
366      appdata->search = SEARCH_NAME | SEARCH_ID;      appdata->search = SEARCH_NAME | SEARCH_ID;
367    
368    if(!appdata->image_path) {    if(!appdata->image_path) {
369    #ifdef USE_MAEMO
370        /* update cachelist by default */
371        appdata->cachelist_update = TRUE;
372    #endif
373    
374      /* use gps by default */      /* use gps by default */
375      appdata->use_gps = TRUE;      appdata->use_gps = TRUE;
# Line 331  void gconf_load_state(appdata_t *appdata Line 388  void gconf_load_state(appdata_t *appdata
388  #endif  #endif
389      appdata->image_path = strdup(DEFAULT_IMAGE_PATH);      appdata->image_path = strdup(DEFAULT_IMAGE_PATH);
390    
391        /* check if this path is actually accessible */
392        /* and change it to the current users home if not */
393        /* (this should only happen on scratchbox) */
394        if(!g_file_test(appdata->image_path, G_FILE_TEST_IS_DIR)) {
395          if(g_mkdir_with_parents(appdata->image_path, 0700) != 0) {
396            char *p = getenv("HOME");
397            if(!p) p = "/tmp/";
398    
399            appdata->image_path =
400              g_strdup_printf("%s%s%s", p,
401                              (p[strlen(p)-1]!='/')?"/":"",
402                              DEFAULT_IMAGE_PATH_HOME);
403            printf("using alt path %s\n", appdata->image_path);
404          }
405        }
406    
407    } else {    } else {
408      /* some versions old versions messed up the path */      /* some versions old versions messed up the path */
409      if(appdata->image_path[strlen(appdata->image_path)-1] != '/') {      if(appdata->image_path[strlen(appdata->image_path)-1] != '/') {
# Line 395  void gconf_load_state(appdata_t *appdata Line 468  void gconf_load_state(appdata_t *appdata
468    /* 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 */
469    /* "welcome" one */    /* "welcome" one */
470    if(!appdata->gpx) {    if(!appdata->gpx) {
471      char *name = g_strdup("/usr/share/gpxview/welcome.gpx");      char *name = g_strdup(ICONPATH "welcome.gpx");
472      dialog = gpx_busy_dialog_new(GTK_WIDGET(appdata->window));      dialog = gpx_busy_dialog_new(GTK_WIDGET(appdata->window));
473      printf("No GPX file loaded, trying to load demo\n");      printf("No GPX file loaded, trying to load demo\n");
474      appdata->gpx = gpx_parse(dialog, name);      appdata->gpx = gpx_parse(dialog, name);

Legend:
Removed from v.14  
changed lines
  Added in v.158