1 GConf
1.1 GConf introduce
Each preference in the GConf repository is expressed as a key-value pair. The default key-value pairs are installed on the system, and are known as schemas. The GConf preference keys are stored and managed by the GConf daemon (gconfd-2). These keys are cached in memory,and saved to disk in XML format.
1.2 Schemas
Conventionally, schema files are also placed in etc/gconf/schemas.Application developers create files called schema files, traditionally ending in the .schemas extension,a nice human-readable format.Take evolution app as an example:
1.2.1 Inspect key/value pair
[alex@alex schemas]$ gconftool-2 -R /apps/evolution
/apps/evolution/mail/filters:
log = false
logfile =
flush-outbox = false……
1.2.2 get value of a key
[alex@alex schemas]$ gconftool-2 –get /apps/evolution/mail/filters/log
false
1.2.3 Set value of a key,using with –type
[alex@alex schemas]$ gconftool-2 –set –type bool /apps/evolution/mail/filters/log true
[alex@alex schemas]$ gconftool-2 –get /apps/evolution/mail/filters/log
true
1.2.4 Schemas saved in XML format
Evolution schema: |
---|
<schema> |
<key>/schemas/apps/evolution/mail/filters/log</key> |
<applyto>/apps/evolution/mail/filters/log</applyto> |
<owner>evolution-mail</owner> |
<type>bool</type> |
<default>false</default> |
<gettext_domain>evolution-3.0</gettext_domain> |
<locale name="C"> |
<short>Log filter actions</short> |
<long>Log filter actions to the specified log file.</long> |
</locale> |
</schema> |
1.3 Procedures of GConf Reading
The details lie in path: /etc/gconf/2/path. This file stores the addresses of config sources for GConf.When a value is stored or requested, the sources are scanned from top to bottom.Now,on Fedora15,we can see the details of GConf reading app preference.
Configuration sources in GConf: |
---|
xml:readonly:/etc/gconf/gconf.xml.mandatory |
include /etc/gconf/2/local-mandatory.path |
include "$(HOME)/.gconf.path" |
xml:readwrite:$(HOME)/.gconf |
xml:readonly:/etc/gconf/gconf.xml.system |
include /etc/gconf/2/local-defaults.path |
xml:readonly:/etc/gconf/gconf.xml.defaults |
The order above is exactly that the source reading application configuration GConf system property values in the order.That is preference stored in a mandatory source of the property will be given priority access, even if the source of the custom configuration attributed by users will be ignored.
1.4 GConf API
The details can be linked:http://developer.gnome.org/gconf/stable/ch01.html
GConf system itself provides a number of APIs for the user to use, so the user can use the APIs to complete the management of the GConf.Now a sample about GConf API from network is as follows:
GConf API Sample: |
---|
#include <string.h> |
#include <stdio.h> |
#include <gconf/gconf-client.h> |
int main (){ |
//Get Gconf client |
GConfClient* gConfClient = gconf_client_get_default(); |
if (!gConfClient) return 1 ; |
//Get the value |
gchar * str = gconf_client_get_string(gConfClient, |
"/desktop/gnome/url-handlers/ftp/command", NULL); |
if (str){ |
printf("%s\n",str); |
//Free the value |
g_free(str); |
} |
//Unref this gobject |
g_object_unref(gConfClient); |
return 0; |
} |
2 Gsettings
2.1 Gsettings introduce
GNOME 3 contains some major changes with respect to persistent application settings data.The GConf CORBA-based configuration system is no longer used; it has been replaced by GSettings.GSettings stores its schemas in a binary format, unlike GConf which uses XML files.
2.2 Schemas
Conventionally, schema files are placed in /usr/share/glib-2.0/schemas,ending in .gschema.xml extension.
Take power-manager as an example:
2.2.1 Get value of a key
[alex@alex schemas]$ gsettings get org.gnome.power-manager lock-hibernate
true
2.2.2 Set value of a key
[alex@alex schemas]$ gsettings set org.gnome.power-manager lock-hibernate false
[alex@alex schemas]$ gsettings get org.gnome.power-manager lock-hibernate
false
[alex@alex schemas]$ gsettings reset org.gnome.power-manager lock-hibernate
2.2.3 Convert .xml to binary to store
GSettings uses schemas in a compact binary form that is created by the glib-compile-schemas utility.The command glib-compile-schemas expects schema files to have the extension .gschema.xml
[root@alex schemas]# gsettings get org.gnome.power-manager time-action
120
//The default value of time-action key is 120,changed to 122 with vim. Then exe the glib-compile-schemas command:
[root@alex schemas]# glib-compile-schemas .
//Now,the modified value of time-action key is stored.
[root@alex schemas]# gsettings get org.gnome.power-manager time-action
122
//Note,I try to gsettings reset,but the value of time-action key is still 122,already compiled into binary.
2.3 Gsettings API
The details can be linked:http://developer.gnome.org/gio/2.28/GSettings.html
Here,Extract a piece of code as follows from dockbar :
Dockbar can be show at left or right through users: |
---|
const DOCK_SETTINGS_SCHEMA = 'org.gnome.shell.extensions.dock'; |
const DOCK_POSITION_KEY = 'position'; |
this._settings = new Gio.Settings({ schema: DOCK_SETTINGS_SCHEMA }); |
position =this._settings.get_enum(DOCK_POSITION_KEY); |
Test the setting about 'position':
[alex@alex schemas]$ gsettings get org.gnome.shell.extensions.dock position
'left'
[alex@alex schemas]$ gsettings set org.gnome.shell.extensions.dock position 'right'
[alex@alex schemas]$ gsettings get org.gnome.shell.extensions.dock position
'right'
3 Migrating from GConf to GSettings
The details can be linked:http://developer.gnome.org/gio/stable/ch28.html
At present,GConf still exists on Gnome3, So do not throw away gconftool-2 just yet. There are a whole range of settings that gsettings does not have access to,like window customizing.But Converting individual applications and their settings from GConf to GSettings can be done at will.
4 Tips
GConf provides a preferences database, which is like a simple filesystem,consisting of /system,/desktop,/schemas,/apps.
[alex@alex ~]$ gconftool-2 –all-dirs /
/system
/desktop
/schemas
/apps