Gsettings and GConf 介绍、侧重点比较

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


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


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


1.2.4 Schemas saved in XML format

Evolution schema:
<locale name="C">
<short>Log filter actions</short>
<long>Log filter actions to the specified log file.</long>

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:
include /etc/gconf/2/local-mandatory.path
include "$(HOME)/.gconf.path"
include /etc/gconf/2/local-defaults.path

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:

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){
//Free the value
//Unref this gobject
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


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


[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


//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


//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:

Here,Extract a piece of code as follows from dockbar :

Dockbar can be show at left or right through users:
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 position


[alex@alex schemas]$ gsettings set position 'right'

[alex@alex schemas]$ gsettings get position


3 Migrating from GConf to GSettings

The details can be linked:

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 /





个人分类: Linux
想对作者说点什么? 我来说一句