Re: hardcoded values in ~/.gconf



Hi Jody,
	So, I think what I was getting at was that all we need is a convenience
hack rather than actually complicating the value model - i.e. an app
right now could:

  1) Make sure to store $(datadir)/blah in the string value rather than
     the absolute path
  2) Translate $(datadir)/blah to the absolute path when reading that
     value.

	A simple convenience API in GConf for this might be:
	
typedef struct _GConfSymbolMapping GConfSymbolMapping;
struct _GConfSymbolMapping
{
  char *name;
  char *value;
};

char *gconf_map_symbols_in_string   (GConfSymbolMapping  mappings[],
                                     const char         *str); 
char *gconf_unmap_symbols_in_string (GConfSymbolMapping  mappings[],
                                     const char         *str);

	i.e. unmap() for (1) above and map for (2) above.

	This is very similar to the approach taken with enum_to_string(). What
also might be useful would be:

char *gconf_client_get_string_mapped (GConfClient         *client,
                                      const char          *key,
                                      GConfSymbolMapping   mappings[],
                                      GError              **err);

gboolean gconf_client_set_string_unmapped (GConfClient          *client,
                                           const char           *key,
                                           const char           *value,
                                           GConfSymbolMapping    mappings[],
                                           GError              **err);

	(The "mapped"/"unmapped" terminology is confusing here. We'd certainly
want something better.)

	The actual usage of this might look like:

static GConfSymbolMapping sysdir_mappings[] =
{
  { "prefix", PREFIX },
  { "datadir", DATADIR },
  ...
  { NULL, NULL }
};

void
store_plugin_path (GConfClient *client,
                   const char  *path)
{
   if (!gconf_client_set_string_mapped (client,
                                        PLUGIN_PATH_KEY,
                                        path,
                                        sysdir_mappings,
                                        &error)
     {
       ...
     }
}

	How does all that sound?

Cheers,
Mark.




[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]