This page was last modified 13:13, 4 July 2008.
Maemo: Using GConf
From Forum Nokia Wiki
GConf is a configuration data storage system providing a simple interface to GNOME applications. the aim of the GConf library is to provide a consistent method for applications to access configuration settings as well as to provide tools for administrators to distribute software settings in a centralized manner.
The GConf database may consist of multiple databases, configured by the system admin. Typically at least one database engine uses XML to store the settings. This keeps the database still in a very human-readable form (compared to binary databases). However, client-side interface is always the same, irrespective of the database backend.
One of the features of GConf is the capability of notifying its clients about their settings being changed. This allows the client to react to changes originating from another process in (almost) real-time.
GConf consist of client library and the GConf server daemon. In Maemo, client-server communications is done using D-Bus.
Each application will specify its own directory under /apps/Maemo/application_name/ (in GConf's namespace).
The following data types are supported in GConf:
* gint * gchar [ASCII/ISO 8859-1/UTF-8] * gboolean * gfloat (with limited precision) * pair of values (useful for key-value pairs) * list of values of same type
Note that storing binary data is not supported by GConf.
SDK includes a tool gconftool-2 for setting/unsetting keys and displaying contents of keys stored in GConf:
Setting an integer key:
[sbox-CHINOOK_X86: ~] > run-standalone.sh gconftool-2 --set \ /apps/Maemo/myapp/mykey --type=int 42
Unsetting a key:
[sbox-CHINOOK_X86: ~] > run-standalone.sh gconftool-2 --unset /apps/Maemo/myapp/mykey
Listing all keys under /apps:
[sbox-CHINOOK_X86: ~] > run-standalone.sh gconftool-2 -R /apps
Sample code
#include <gconf/gconf-client.h> #define APPLICATION_NAME "myapp" #define GCONF_DIR "/apps/Maemo/" APPLICATION_NAME "/" /** * Store an integer key "mykey" with a specified value to gconf database */ static void StoreMykey( gint value ) { GConfClient* gconfClient = gconf_client_get_default(); g_assert(GCONF_IS_CLIENT(gcClient)); if(!gconf_client_set_int(gconfClient, GCONF_DIR "mykey", value, NULL)) { g_warning(" failed to set %smykey (%d)\n", GCONF_DIR, value); } /* release GConf client */ g_object_unref(gconfClient); } /** * Get an integer value from key "mykey" */ static void GetMykey( gint* value ) { GConfClient* gconfClient = gconf_client_get_default(); g_assert(GCONF_IS_CLIENT(gcClient)); GConfValue* gcValue = NULL; gcValue = gconf_client_get_without_default(GConfClient, "mykey", NULL); /* if value pointer remains NULL, the key was not found */ if(gcValue == NULL) { g_warning(" key %smykey not found\n", GCONF_DIR); g_object_unref(gconfClient); return; } /* Check if value type is integer */ if(gcValue->type == GCONF_VALUE_INT) { *value = gconf_value_get_int(gcValue); } else { g_warning(" key %smykey is not integer\n", GCONF_DIR); } /* Release resources */ gconf_value_free(gcValue); g_object_unref(gconfClient); }
See also
GConf Reference Manual in maemo.org
| Related Discussions | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Python on S60 (GPS, camera, UI). Python or C | N800Fun | Python | 13 | 2008-09-16 09:12 |
| Does Nokia N800 has Java? | mikeaf | Mobile Java General | 2 | 2007-01-11 12:42 |
| [anounce] Tracker.py GPS mapping application | hurenkam | Python | 77 | 2008-10-08 00:27 |
| Looking for a platform for my application | kazuma6666 | Mobile Java General | 2 | 2008-02-11 15:09 |
| Python on N91, 90, 70 | imiten | Python | 2 | 2005-05-28 16:19 |
