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 74 by harbaum, Mon Aug 24 09:23:36 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    #endif
92    { NULL, -1, -1 }    { NULL, -1, -1 }
93  };  };
94    
# Line 156  void gconf_save_state(appdata_t *appdata Line 161  void gconf_save_state(appdata_t *appdata
161    /* store everything listed in the store table */    /* store everything listed in the store table */
162    store_t *st = store;    store_t *st = store;
163    while(st->key) {    while(st->key) {
     char key[256];  
164      void **ptr = ((void*)appdata) + st->offset;      void **ptr = ((void*)appdata) + st->offset;
165      snprintf(key, sizeof(key), GCONF_PATH "%s", st->key);      char *key = g_strdup_printf(GCONF_PATH "%s", st->key);
166    
167      switch(st->type) {      switch(st->type) {
168      case STORE_STRING:      case STORE_STRING:
# Line 176  void gconf_save_state(appdata_t *appdata Line 180  void gconf_save_state(appdata_t *appdata
180        break;        break;
181    
182      case STORE_FLOAT:      case STORE_FLOAT:
183        gconf_client_set_float(appdata->gconf_client, key, *((float*)ptr), NULL);        if(!isnan(*((float*)ptr)))
184            gconf_client_set_float(appdata->gconf_client, key, *((float*)ptr), NULL);
185        break;        break;
186    
187      default:      default:
# Line 184  void gconf_save_state(appdata_t *appdata Line 189  void gconf_save_state(appdata_t *appdata
189        break;        break;
190      }      }
191    
192        g_free(key);
193      st++;      st++;
194    }    }
195  }  }
# Line 195  void gconf_load_state(appdata_t *appdata Line 201  void gconf_load_state(appdata_t *appdata
201    
202    gpx_dialog_t *dialog = NULL;    gpx_dialog_t *dialog = NULL;
203    
204      /* default positions are invalid */
205      appdata->home.lat = appdata->home.lon = NAN;
206      appdata->manual_goto.lat = appdata->manual_goto.lon = NAN;
207      appdata->gps.lat = appdata->gps.lon = NAN;
208    
209    int i, entries = gconf_client_get_int(appdata->gconf_client,    int i, entries = gconf_client_get_int(appdata->gconf_client,
210                                   GCONF_KEY_CNT, NULL);                                   GCONF_KEY_CNT, NULL);
211    
# Line 221  void gconf_load_state(appdata_t *appdata Line 232  void gconf_load_state(appdata_t *appdata
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        }        }
246      }      }
247    
248      /* use next gpx entry of this was loaded successfully */      gpx = &((*gpx)->next);
     if(*gpx)  
       gpx = &((*gpx)->next);  
249    }    }
250    
251    gpx_busy_dialog_destroy(dialog);    gpx_busy_dialog_destroy(dialog);
# Line 255  void gconf_load_state(appdata_t *appdata Line 273  void gconf_load_state(appdata_t *appdata
273    /* restore everything listed in the store table */    /* restore everything listed in the store table */
274    store_t *st = store;    store_t *st = store;
275    while(st->key) {    while(st->key) {
     char key[256];  
276      void **ptr = ((void*)appdata) + st->offset;      void **ptr = ((void*)appdata) + st->offset;
277      snprintf(key, sizeof(key), GCONF_PATH "%s", st->key);      char *key = g_strdup_printf(GCONF_PATH "%s", st->key);
278    
279      switch(st->type) {      /* check if key is present */
280      case STORE_STRING: {      GConfValue *value = gconf_client_get(appdata->gconf_client, key, NULL);
281        char **str = (char**)ptr;      if(value) {
282        *str = gconf_client_get_string(appdata->gconf_client, key, NULL);        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;        } break;
289    
290      case STORE_BOOL:        case STORE_BOOL:
291        *((int*)ptr) = gconf_client_get_bool(appdata->gconf_client, key, NULL);          *((int*)ptr) = gconf_client_get_bool(appdata->gconf_client, key, NULL);
292        break;          break;
293    
294      case STORE_INT:        case STORE_INT:
295        *((int*)ptr) = gconf_client_get_int(appdata->gconf_client, key, NULL);          *((int*)ptr) = gconf_client_get_int(appdata->gconf_client, key, NULL);
296        break;          break;
297    
298      case STORE_FLOAT:        case STORE_FLOAT:
299        *((float*)ptr) = gconf_client_get_float(appdata->gconf_client, key, NULL);          *((float*)ptr) = gconf_client_get_float(appdata->gconf_client, key, NULL);
300        break;          break;
301    
302      default:        default:
303        printf("Unsupported type %d\n", st->type);          printf("Unsupported type %d\n", st->type);
304        break;          break;
305          }
306      }      }
307        g_free(key);
308      st++;      st++;
309    }    }
310    
311    /* ----- set all kinds of defaults ------- */    /* ----- set all kinds of defaults ------- */
312    
 #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  
   
313    if(!appdata->compass_damping) appdata->compass_damping = 1;    if(!appdata->compass_damping) appdata->compass_damping = 1;
314    
315    if(!appdata->mmpoi_radius)    if(!appdata->mmpoi_radius)
# Line 314  void gconf_load_state(appdata_t *appdata Line 320  void gconf_load_state(appdata_t *appdata
320    
321    if(!appdata->image_path) {    if(!appdata->image_path) {
322    
323        /* use gps by default */
324        appdata->use_gps = TRUE;
325    
326  #ifndef USE_MAEMO  #ifndef USE_MAEMO
327      char *p = getenv("HOME");      char *p = getenv("HOME");
328      if(p) {      if(p) {
# Line 328  void gconf_load_state(appdata_t *appdata Line 337  void gconf_load_state(appdata_t *appdata
337  #endif  #endif
338      appdata->image_path = strdup(DEFAULT_IMAGE_PATH);      appdata->image_path = strdup(DEFAULT_IMAGE_PATH);
339    
340        /* check if this path is actually accessible */
341        /* and change it to the current users home if not */
342        /* (this should only happen on scratchbox) */
343        if(!g_file_test(appdata->image_path, G_FILE_TEST_IS_DIR)) {
344          if(g_mkdir_with_parents(appdata->image_path, 0700) != 0) {
345            char *p = getenv("HOME");
346            if(!p) p = "/tmp/";
347    
348            appdata->image_path =
349              g_strdup_printf("%s%s%s", p,
350                              (p[strlen(p)-1]!='/')?"/":"",
351                              DEFAULT_IMAGE_PATH_HOME);
352            printf("using alt path %s\n", appdata->image_path);
353          }
354        }
355    
356    } else {    } else {
357      /* some versions old versions messed up the path */      /* some versions old versions messed up the path */
358      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 414  void gconf_load_state(appdata_t *appdata
414    if(!appdata->cachelist_items)    if(!appdata->cachelist_items)
415      appdata->cachelist_items = CACHELIST_ITEM_DEFAULT;      appdata->cachelist_items = CACHELIST_ITEM_DEFAULT;
416    
417      /* if there are no entries in the main list, try to add the */
418      /* "welcome" one */
419      if(!appdata->gpx) {
420        char *name = g_strdup(ICONPATH "welcome.gpx");
421        dialog = gpx_busy_dialog_new(GTK_WIDGET(appdata->window));
422        printf("No GPX file loaded, trying to load demo\n");
423        appdata->gpx = gpx_parse(dialog, name);
424        gpx_busy_dialog_destroy(dialog);
425        g_free(name);
426      }
427  }  }
428    

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