grim/guifications3

added the install prefix to gflib-genheader
cmake
2010-12-13, Gary Kramlich
999ee3e165df
added the install prefix to gflib-genheader
/*
* Guifications - The end-all, be-all notification framework
* Copyright (C) 2003-2009 Gary Kramlich <grim@reaperworld.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
/*
* This test create a GfPreferenceEngineXML, adds and removes some preferences,
* then writes to a file, and tries to load the file.
*/
#include <gflib/gf_lib.h>
static void
query(GfPreferenceEngine *engine, const gchar *path) {
GfPreference **query;
gint i = 0;
guint len = 0;
gf_log_info("testxmlprefs", "querying '%s'\n", path);
query = gf_preference_engine_query(engine, path, &len);
if(!query) {
gf_log_info("testxmlprefs", "'%s' does not exist!\n\n", path);
return;
}
gf_log_info("textxmlprefs", "found %u prefs\n", len);
for(i = 0; query[i]; i++) {
GfPreference *pref = query[i];
gchar *value, *fullname;
switch(pref->type) {
case GF_PREFERENCE_TYPE_STRING:
value = g_strdup(g_value_get_string(pref->value));
break;
case GF_PREFERENCE_TYPE_INT:
value = g_strdup_printf("%d", g_value_get_int(pref->value));
break;
case GF_PREFERENCE_TYPE_BOOL:
value = g_strdup_printf("%d", g_value_get_boolean(pref->value));
break;
case GF_PREFERENCE_TYPE_UNKNOWN:
case GF_PREFERENCE_TYPE_SECTION:
default:
value = NULL;
break;
}
fullname = gf_preference_get_full_name(pref);
gf_log_info("testxmlprefs", "query: type: %s, name: %s, value: %s\n",
gf_preference_type_to_string(pref->type, TRUE),
fullname, value ? value : "(none)");
g_free(fullname);
g_free(value);
}
gf_preference_freev(query);
gf_log_info("testxmlprefs", "done querying '%s'\n\n", path);
}
static void
changed_cb(GfPreferenceEngine *engine, const gchar *fullname,
GfPreference *pref, gpointer data)
{
gf_log_info("testxmlprefs", "changed_cb: %s changed\n", fullname);
}
static void
renamed_cb(GfPreferenceEngine *engine, const gchar *oldname,
GfPreference *newpref, gpointer data)
{
gf_log_info("testxmlprefs", "renamed_cb: renamed %s to %s\n",
oldname, newpref->name);
}
static void
removed_cb(GfPreferenceEngine *engine, GfPreference *pref, gpointer data) {
gf_log_info("textxmlprefs", "removed_cb: removed %s/%s\n",
pref->path, pref->name);
}
gint
main(gint argc, gchar **argv) {
GfPreferenceEngine *engine;
GfPreferenceEngineXML *xml_engine;
gf_lib_init();
/* create the engine */
engine = gf_preference_engine_xml_new("prefs.xml");
g_signal_connect(G_OBJECT(engine), "changed",
G_CALLBACK(changed_cb), NULL);
g_signal_connect(G_OBJECT(engine), "renamed",
G_CALLBACK(renamed_cb), NULL);
g_signal_connect(G_OBJECT(engine), "removed",
G_CALLBACK(removed_cb), NULL);
xml_engine = GF_PREFERENCE_ENGINE_XML(engine);
gf_log_info("testxmlprefs",
"Created xml preference engine %p\n\n", engine);
/* query '/' to check if it loaded */
query(engine, "/");
/* add some test preferences */
gf_preference_engine_add_string(engine, "/string", "1.0.0");
gf_preference_engine_add_int(engine, "/int", 10);
gf_preference_engine_add_bool(engine, "/on", FALSE);
gf_preference_engine_add_section(engine, "/foo");
gf_preference_engine_add_string(engine, "/foo/bar", "yep");
gf_preference_engine_add_int(engine, "/foo/baz", 8);
gf_preference_engine_add_bool(engine, "/foo/insane", TRUE);
// gf_preference_engine_set_string(engine, "/string", "1.0.1");
/* save to the file */
gf_preference_engine_save(engine);
gf_log_info("testxmlprefs", "saved preferences to %s\n\n",
gf_preference_engine_xml_get_filename(xml_engine));
/* query '/' */
query(engine, "/");
/* change a pref of each type */
// gf_preference_engine_set_string(engine, "/string", "1.0.2");
gf_preference_engine_set_int(engine, "/int", 12);
gf_preference_engine_set_bool(engine, "/on", TRUE);
/* query a single pref */
query(engine, "/int");
/* try an inner query */
query(engine, "/foo");
/* reload preferences */
gf_preference_engine_reload(engine);
gf_log_info("testxmlprefs", "reloaded preferences\n\n");
/* query '/' */
query(engine, "/");
/* done */
/* rename a pref */
gf_log_info("testxmlprefs",
"renaming \"/foo/baz\" to \"/foo/bazzar\"\n");
if(gf_preference_engine_rename(engine, "/foo/baz", "/foo/bazzar")) {
gf_log_info("testxmlprefs",
"renamed \"/foo/baz\" to \"/foo/bazzar\"\n\n");
} else {
gf_log_info("testxmlprefs",
"failed to rename \"/foo/baz/\" to \"/foo/bazzar\"\n\n");
}
/* query /foo */
query(engine, "/foo");
/* delete a pref */
gf_log_info("testxmlprefs", "deleting \"/foo/bazzar\"\n");
if(gf_preference_engine_remove(engine, "/foo/bazzar") == 1) {
gf_log_info("testxmlprefs", "removed \"/foo/bazzar/\"\n\n");
} else {
gf_log_info("testxmlprefs",
"failed to remove \"/foo/bazzar\"\n\n");
}
/* query /foo */
query(engine, "/foo");
/* delete a section */
if(gf_preference_engine_remove(engine, "/foo") > 0) {
gf_log_info("testxmlprefs", "removed \"/foo\"\n\n");
} else {
gf_log_info("testxmlprefs", "failed to remove \"/foo\"\n\n");
}
/* query / */
query(engine, "/");
/* save */
gf_preference_engine_save(engine);
return 0;
}