geany/doc/stash-example.c
Nick Treleaven 201b595b51 Rename Stash data types to be independently named from Geany (so
Stash can be reused for other projects).
Rename GeanyPrefGroup to StashGroup.



git-svn-id: https://geany.svn.sourceforge.net/svnroot/geany/trunk@4776 ea778897-0a13-0410-b9d1-a72fbfd435f5
2010-03-18 17:04:17 +00:00

34 lines
1005 B
C

StashGroup *group;
gboolean china_enabled;
gchar *potter_name = NULL; /* strings must be initialised */
GKeyFile *keyfile;
const gchar filename[] = "/path/to/data.conf";
gchar *data;
/* setup the group */
group = stash_group_new("cups");
stash_group_add_boolean(group, &china_enabled, "china", TRUE);
stash_group_add_string(group, &potter_name, "potter_name", "Miss Clay");
/* load the settings from a file */
keyfile = g_key_file_new();
g_key_file_load_from_file(keyfile, filename, G_KEY_FILE_NONE, NULL);
stash_group_load_from_key_file(group, keyfile);
g_key_file_free(keyfile);
/* now use settings china_enabled and potter_name */
...
/* save settings to file */
keyfile = g_key_file_new();
stash_group_save_to_key_file(group, keyfile);
data = g_key_file_to_data(keyfile, NULL, NULL);
if (utils_write_file(filename, data) != 0)
dialogs_show_msgbox(GTK_MESSAGE_ERROR,
_("Could not save keyfile %s!"), filename);
g_free(data);
g_key_file_free(keyfile);
/* free memory */
stash_group_free(group);