Diff of /trunk/src/gconf.c

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

revision 17 by harbaum, Mon Jun 29 08:24:41 2009 UTC revision 34 by harbaum, Wed Jul 29 19:24:15 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 156  void gconf_save_state(appdata_t *appdata Line 157  void gconf_save_state(appdata_t *appdata
157    /* store everything listed in the store table */    /* store everything listed in the store table */
158    store_t *st = store;    store_t *st = store;
159    while(st->key) {    while(st->key) {
     char key[256];  
160      void **ptr = ((void*)appdata) + st->offset;      void **ptr = ((void*)appdata) + st->offset;
161      snprintf(key, sizeof(key), GCONF_PATH "%s", st->key);      char *key = g_strdup_printf(GCONF_PATH "%s", st->key);
162    
163      switch(st->type) {      switch(st->type) {
164      case STORE_STRING:      case STORE_STRING:
# Line 176  void gconf_save_state(appdata_t *appdata Line 176  void gconf_save_state(appdata_t *appdata
176        break;        break;
177    
178      case STORE_FLOAT:      case STORE_FLOAT:
179        gconf_client_set_float(appdata->gconf_client, key, *((float*)ptr), NULL);        if(!isnan(*((float*)ptr)))
180            gconf_client_set_float(appdata->gconf_client, key, *((float*)ptr), NULL);
181        break;        break;
182    
183      default:      default:
# Line 184  void gconf_save_state(appdata_t *appdata Line 185  void gconf_save_state(appdata_t *appdata
185        break;        break;
186      }      }
187    
188        g_free(key);
189      st++;      st++;
190    }    }
191  }  }
# Line 195  void gconf_load_state(appdata_t *appdata Line 197  void gconf_load_state(appdata_t *appdata
197    
198    gpx_dialog_t *dialog = NULL;    gpx_dialog_t *dialog = NULL;
199    
200      /* default positions are invalid */
201      appdata->home.lat = appdata->home.lon = NAN;
202      appdata->manual_goto.lat = appdata->manual_goto.lon = NAN;
203      appdata->gps.lat = appdata->gps.lon = NAN;
204    
205    int i, entries = gconf_client_get_int(appdata->gconf_client,    int i, entries = gconf_client_get_int(appdata->gconf_client,
206                                   GCONF_KEY_CNT, NULL);                                   GCONF_KEY_CNT, NULL);
207    
# Line 255  void gconf_load_state(appdata_t *appdata Line 262  void gconf_load_state(appdata_t *appdata
262    /* restore everything listed in the store table */    /* restore everything listed in the store table */
263    store_t *st = store;    store_t *st = store;
264    while(st->key) {    while(st->key) {
     char key[256];  
265      void **ptr = ((void*)appdata) + st->offset;      void **ptr = ((void*)appdata) + st->offset;
266      snprintf(key, sizeof(key), GCONF_PATH "%s", st->key);      char *key = g_strdup_printf(GCONF_PATH "%s", st->key);
267    
268      switch(st->type) {      /* check if key is present */
269      case STORE_STRING: {      GConfValue *value = gconf_client_get(appdata->gconf_client, key, NULL);
270        char **str = (char**)ptr;      if(value) {
271        *str = gconf_client_get_string(appdata->gconf_client, key, NULL);        gconf_value_free(value);
272    
273          switch(st->type) {
274          case STORE_STRING: {
275            char **str = (char**)ptr;
276            *str = gconf_client_get_string(appdata->gconf_client, key, NULL);
277        } break;        } break;
278    
279      case STORE_BOOL:        case STORE_BOOL:
280        *((int*)ptr) = gconf_client_get_bool(appdata->gconf_client, key, NULL);          *((int*)ptr) = gconf_client_get_bool(appdata->gconf_client, key, NULL);
281        break;          break;
282    
283      case STORE_INT:        case STORE_INT:
284        *((int*)ptr) = gconf_client_get_int(appdata->gconf_client, key, NULL);          *((int*)ptr) = gconf_client_get_int(appdata->gconf_client, key, NULL);
285        break;          break;
286    
287      case STORE_FLOAT:        case STORE_FLOAT:
288        *((float*)ptr) = gconf_client_get_float(appdata->gconf_client, key, NULL);          *((float*)ptr) = gconf_client_get_float(appdata->gconf_client, key, NULL);
289        break;          break;
290    
291      default:        default:
292        printf("Unsupported type %d\n", st->type);          printf("Unsupported type %d\n", st->type);
293        break;          break;
294          }
295      }      }
296        g_free(key);
297      st++;      st++;
298    }    }
299    
300    /* ----- set all kinds of defaults ------- */    /* ----- set all kinds of defaults ------- */
301    
 #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  
   
302    if(!appdata->compass_damping) appdata->compass_damping = 1;    if(!appdata->compass_damping) appdata->compass_damping = 1;
303    
304    if(!appdata->mmpoi_radius)    if(!appdata->mmpoi_radius)

Legend:
Removed from v.17  
changed lines
  Added in v.34