Re: Key-value file parser, howto get all groups and create loop from them
- From: rupert <rupertt gmail com>
- To: "Christian Neumair" <chris gnome-de org>
- Cc: gtk-app-devel-list <gtk-app-devel-list gnome org>
- Subject: Re: Key-value file parser, howto get all groups and create loop from them
- Date: Tue, 1 Aug 2006 19:12:03 +0200
On 8/1/06, Christian Neumair <chris gnome-de org> wrote:
Am Dienstag, den 01.08.2006, 12:52 +0200 schrieb rupert:
> Im playing arroung with the Gkeyfile functions and now try to get all
groups
> from the keyfile and create a for loop that than shows me the
> different values, packed into strings, including the group name
> i have something like this in mind:
>
> crpyto_get_keyfile(){
>
> GtkWidget *crypto_keys, *crypto_key_groups;
> gboolean *isfile=FALSE;
> gchar *startgroup;
> gint *groupcounter=0;
Why did you make crypto_key_groups and crypto_keys a GtkWidget, and use
pointers for all the variables? Maybe learning C before learning the GTK
+/GLib API would help? :)
in my book the guy does it all the time, using pointer for the variables,
thought
its done to make some things easier...
The Widget for the keys isnt used anymore, i played arround with it a bit.
crypto_keys = g_key_file_new();
> g_key_file_load_from_file(crypto_keys,
> "/home/Programmierung/GTK_Projects/project_dmaster/src/crypto.ini",
> G_KEY_FILE_NONE, NULL) ;
>
> crypto_key_groups = g_key_file_get_groups(crypto_keys, NULL);
>
> // g_print("%s", crypto_key_groups[0]);
> //startgroup = g_key_file_get_start_group(crypto_keys);
So far, so good (except for the variable types, see below).
> while (g_key_file_get_groups(crypto_keys, NULL))
> {
>
> crypto_key_groups[groupcounter] =
g_key_file_get_groups(crypto_keys,
> NULL);
> // g_key_file_get_string(crypto_keys, "DATEN", "mountpoint",
NULL);
> g_print("%s", g_key_file_get_string(crypto_keys, "DATEN",
> "mountpoint", NULL));
> }
>
> }
Please read the g_key_file_get_groups() documentation, this won't work.
i n my 3rd mail i have a fixed version with for
char **crypto_key_groups;
int i;
crypto_key_groups = g_key_file_get_groups (crypto_keys, NULL);
for (i = 0; crypto_key_groups[i] != NULL; i++) {
g_print("%s", g_key_file_get_string(crypto_keys, crypto_key_groups[i],
"mountpoint", NULL));
}
g_strfreev (crypto_key_groups);
note that this code will execute the for-enclosed block for each group.
But maybe you just want to fetch the "mountpoint" key's value from the
"DATEN" group? If so, you should use
i have more the the DATEN groups, already got it to display all the keys
device = g_key_file_get_string(crypto_keys, groups[i], "device",
NULL);
mapper = g_key_file_get_string(crypto_keys, groups[i],
"mapperdevice", NULL);
mountpoint = g_key_file_get_string(crypto_keys, groups[i],
"mountpoint", NULL);
password = g_key_file_get_string(crypto_keys, groups[i], "password",
NULL);
keyfile = g_key_file_get_string(crypto_keys, groups[i], "keyfile",
NULL);
g_print("\n %s", device);
g_print("\n %s", mapper);
g_print("\n %s", mountpoint);
g_print("\n %s", password);
g_print("\n %s", keyfile);
g_print ("%s", g_key_file_get_string(crypto_keys, "DATEN", "mountpoint",
NULL));
Maybe I'm taken wrong but I think the GKeyFile API and documentation is
quite strong and obvious. If you disagree, please tell us what
particular problem you encountered.
after some more playing arround i got the things good working, the reference
helps often, i have away from programming some time and never been to deep
in, so sometimes i do things wrong that other wouldnt.
Im so far with my code that i want to create a table where each group gets a
row that has labels, buttons and textentries.
right now im using a GtkTable where i create the Widgets in the for loop
that gets the content from the keyfile, is this possible or do I have to use
a treeview?
I can compile the app but get a segfault while running, it looks like this
with one static row http://az-lantech.de/ubuntu/view.png.
thx
--
Christian Neumair <chris gnome-de org>
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]