Re: GConf and storing GSList - how?
- From: Jukka Alasalmi <jualasal mail student oulu fi>
- To: Cyrille Moureaux <Cyrille Moureaux Sun COM>
- Cc: gconf-list gnome org
- Subject: Re: GConf and storing GSList - how?
- Date: Tue, 28 Mar 2006 16:11:10 +0300
> Hi Jukka,
>
> >I have a problem that I haven't found the answer to, despite looking for
> >source codes.
> >
> >I am using gconf 2.6, and I would like to store a list of integers into the
>
> >gconf (to keep track of bookmarks).
> >
> >I use following kind of code (actually separated into different functions,
> but
> >here for clarity shortened, removed error checks etc):
> >
> >GConfValue *conf_value;
> >gconf_value = gconf_client_get_without_default(gconf_client,
> >KEY_BOOKMARKS_LIST, NULL);
> >GSList *list = gconf_value_get_list(gconf_value);
> >g_slist_foreach(list, add_bookmark_to_list, NULL);
> >
> >void add_bookmark_to_list(gpointer list_data, gpointer user_data)
> >{
> > gint bookmark_id;
> > gint *tmp = list_data;
> > bookmark_id = *tmp; /***/
> >}
> >
> >/***/: If I understand correctly, this should return the numeric value that
>
> >the list item holds. But this always has the value 2. If I put *(tmp + 1)
> >here, it works correctly, but I have no idea why.
> >
> >Now, the same problem occurs when saving the list. But I have no idea in
> what
> >format the numbers should be appended to list. I am using following:
> >
> >[...]
> >g_slist_append(list_copy, GINT_TO_POINTER(bookmark_id))
> >gconf_client_set_list(gconf_client, KEY_BOOKMARKS_LIST, GCONF_VALUE_INT,
> > list_copy, NULL);
> >g_slist_free(list_copy);
> >[...]
> >
> >This, however, saves just random data to the gconf.
> >
> >This all hints that there is some container, for example a struct, used
> >internally in GConf, and those are stored to GSList, but I haven't found any
>
> >clarification to this by searching the source codes.
> >
> >Could someone tell how can I fix this problem?
> >
> >
> The problem is that the GSList which is manipulated by GConf when
> dealing with value lists is a GSList of GConfValue objects (which all
> are expected to have the same GConfValueType), and not a GSList of
> integers, or of pointers to integers (your code above is inconsistent,
> the callback function assumes the GSList contains pointers to bookmark
> ids, while your saving function passes the integer off as a pointer
> directly).
>
> So you need to interpret list_data as GConfValue, and then do a
> gconf_value_get_int on the result, while when saving you need to build
> GConfValue objects with your integers in it, and append these GConfValue
> objects to the GSList you pass to set_list.
>
> The reason your callback code "works" when using *(tmp + 1) is that
> list_data is a GConfValue *, meaning its first word is the
> GConfValueType (the 2 you're consistently getting) and the rest of the
> memory is the union containing the actual value (in your case the
> integer) so if you go over the type you end up pointing to your int.
>
> Cyrille
Hi,
Thank you very much. This is something that I thought it might be, but I was
unable to find it in the documentation of GConf (it might be there, though, but
I may have missed it).
I'll try that out as soon as I have the time for it (I have been moving now so
everything is still a bit hassle).
Jukka
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]