Diff of /trunk/src/gconf.c

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

revision 12 by harbaum, Fri Jun 26 20:07:33 2009 UTC revision 89 by harbaum, Tue Sep 1 11:16:30 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 83  static store_t store[] = { Line 84  static store_t store[] = {
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    
# Line 156  void gconf_save_state(appdata_t *appdata Line 162  void gconf_save_state(appdata_t *appdata
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:
# Line 176  void gconf_save_state(appdata_t *appdata Line 181  void gconf_save_state(appdata_t *appdata
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:
# Line 184  void gconf_save_state(appdata_t *appdata Line 190  void gconf_save_state(appdata_t *appdata
190        break;        break;
191      }      }
192    
193        g_free(key);
194      st++;      st++;
195    }    }
196  }  }
# Line 195  void gconf_load_state(appdata_t *appdata Line 202  void gconf_load_state(appdata_t *appdata
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    
# Line 221  void gconf_load_state(appdata_t *appdata Line 233  void gconf_load_state(appdata_t *appdata
233          else          else
234            *gpx = gpx_parse(dialog, fname);            *gpx = gpx_parse(dialog, fname);
235    
236          free(fname);          if(!*gpx) {
237              /* restoring the gpx file failed, mark it as unusable, but save */
238              /* its presence for later use */
239    
240              /* create fake entry to remember this file for next load attempt */
241              *gpx = g_new0(gpx_t, 1);
242              (*gpx)->filename = fname;
243              (*gpx)->failed = TRUE;
244            } else
245              free(fname);
246        }        }
247      }      }
248    
249      /* use next gpx entry of this was loaded successfully */      gpx = &((*gpx)->next);
     if(*gpx)  
       gpx = &((*gpx)->next);  
250    }    }
251    
252    gpx_busy_dialog_destroy(dialog);    gpx_busy_dialog_destroy(dialog);
# Line 255  void gconf_load_state(appdata_t *appdata Line 274  void gconf_load_state(appdata_t *appdata
274    /* restore everything listed in the store table */    /* restore everything listed in the store table */
275    store_t *st = store;    store_t *st = store;
276    while(st->key) {    while(st->key) {
     char key[256];  
277      void **ptr = ((void*)appdata) + st->offset;      void **ptr = ((void*)appdata) + st->offset;
278      snprintf(key, sizeof(key), GCONF_PATH "%s", st->key);      char *key = g_strdup_printf(GCONF_PATH "%s", st->key);
279    
280      switch(st->type) {      /* check if key is present */
281      case STORE_STRING: {      GConfValue *value = gconf_client_get(appdata->gconf_client, key, NULL);
282        char **str = (char**)ptr;      if(value) {
283        *str = gconf_client_get_string(appdata->gconf_client, key, NULL);        gconf_value_free(value);
284    
285          switch(st->type) {
286          case STORE_STRING: {
287            char **str = (char**)ptr;
288            *str = gconf_client_get_string(appdata->gconf_client, key, NULL);
289        } break;        } break;
290    
291      case STORE_BOOL:        case STORE_BOOL:
292        *((int*)ptr) = gconf_client_get_bool(appdata->gconf_client, key, NULL);          *((int*)ptr) = gconf_client_get_bool(appdata->gconf_client, key, NULL);
293        break;          break;
294    
295      case STORE_INT:        case STORE_INT:
296        *((int*)ptr) = gconf_client_get_int(appdata->gconf_client, key, NULL);          *((int*)ptr) = gconf_client_get_int(appdata->gconf_client, key, NULL);
297        break;          break;
298    
299      case STORE_FLOAT:        case STORE_FLOAT:
300        *((float*)ptr) = gconf_client_get_float(appdata->gconf_client, key, NULL);          *((float*)ptr) = gconf_client_get_float(appdata->gconf_client, key, NULL);
301        break;          break;
302    
303      default:        default:
304        printf("Unsupported type %d\n", st->type);          printf("Unsupported type %d\n", st->type);
305        break;          break;
306          }
307      }      }
308        g_free(key);
309      st++;      st++;
310    }    }
311    
312    /* ----- set all kinds of defaults ------- */    /* ----- set all kinds of defaults ------- */
313    
 #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  
   
314    if(!appdata->compass_damping) appdata->compass_damping = 1;    if(!appdata->compass_damping) appdata->compass_damping = 1;
315    
316    if(!appdata->mmpoi_radius)    if(!appdata->mmpoi_radius)
# Line 314  void gconf_load_state(appdata_t *appdata Line 321  void gconf_load_state(appdata_t *appdata
321    
322    if(!appdata->image_path) {    if(!appdata->image_path) {
323    
324        /* use gps by default */
325        appdata->use_gps = TRUE;
326    
327  #ifndef USE_MAEMO  #ifndef USE_MAEMO
328      char *p = getenv("HOME");      char *p = getenv("HOME");
329      if(p) {      if(p) {
# Line 328  void gconf_load_state(appdata_t *appdata Line 338  void gconf_load_state(appdata_t *appdata
338  #endif  #endif
339      appdata->image_path = strdup(DEFAULT_IMAGE_PATH);      appdata->image_path = strdup(DEFAULT_IMAGE_PATH);
340    
341        /* check if this path is actually accessible */
342        /* and change it to the current users home if not */
343        /* (this should only happen on scratchbox) */
344        if(!g_file_test(appdata->image_path, G_FILE_TEST_IS_DIR)) {
345          if(g_mkdir_with_parents(appdata->image_path, 0700) != 0) {
346            char *p = getenv("HOME");
347            if(!p) p = "/tmp/";
348    
349            appdata->image_path =
350              g_strdup_printf("%s%s%s", p,
351                              (p[strlen(p)-1]!='/')?"/":"",
352                              DEFAULT_IMAGE_PATH_HOME);
353            printf("using alt path %s\n", appdata->image_path);
354          }
355        }
356    
357    } else {    } else {
358      /* some versions old versions messed up the path */      /* some versions old versions messed up the path */
359      if(appdata->image_path[strlen(appdata->image_path)-1] != '/') {      if(appdata->image_path[strlen(appdata->image_path)-1] != '/') {
# Line 389  void gconf_load_state(appdata_t *appdata Line 415  void gconf_load_state(appdata_t *appdata
415    if(!appdata->cachelist_items)    if(!appdata->cachelist_items)
416      appdata->cachelist_items = CACHELIST_ITEM_DEFAULT;      appdata->cachelist_items = CACHELIST_ITEM_DEFAULT;
417    
418      /* if there are no entries in the main list, try to add the */
419      /* "welcome" one */
420      if(!appdata->gpx) {
421        char *name = g_strdup(ICONPATH "welcome.gpx");
422        dialog = gpx_busy_dialog_new(GTK_WIDGET(appdata->window));
423        printf("No GPX file loaded, trying to load demo\n");
424        appdata->gpx = gpx_parse(dialog, name);
425        gpx_busy_dialog_destroy(dialog);
426        g_free(name);
427      }
428  }  }
429    

Legend:
Removed from v.12  
changed lines
  Added in v.89