Gsettings and GConf 介绍、侧重点比较

原创 2011年10月14日 14:28:56

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 /





Ubuntu 中 gconf, dconf, gsettings 和 dconf-editor 的功能与使用

GConf 是在基于 GNOME2 的 Linux 操作系统中实现对应用程序的配置及管理功能的工具。我们可以把 GConf 理解为 Linux 操作系统中的注册表。然而,它克服了 Windows 注册...
  • O_O___O_O
  • O_O___O_O
  • 2016年07月24日 01:42
  • 5268


GConf was a system used by the GNOME desktop environment for storing configuration settings for the...
  • yygydjkthh
  • yygydjkthh
  • 2014年12月11日 19:32
  • 2427


命令行获取屏幕锁定超时时间 命令行 屏幕锁定 超时时间 电源管理 锁定 挂起...
  • yygydjkthh
  • yygydjkthh
  • 2016年06月12日 18:37
  • 898


  • chuangjinweilai
  • chuangjinweilai
  • 2016年11月21日 10:13
  • 2338

GSettings 稍长一点的简介和用法

GSettings 稍长一点的简介和用法 NOV 28TH, 2011 | COMMENTS 从wpblog中备份。 GSettings 是什么? 简单地说,GSettin...
  • zhgn2
  • zhgn2
  • 2013年04月22日 14:23
  • 5904


       *引用本文请注明来自              昨天在看代码的时候,遇到了gconf这个陌生的对象,陌生只是相对我而言。然后花了一天的时间对...
  • wtz1985
  • wtz1985
  • 2008年09月10日 12:33
  • 2579

linux GSettings 和设置字体

GSettings 提供方便的借口用来设置或查询应用程序的设置。 GSettings 会把设置写入到~/.config/dconf/user文件中, 可用工具dconf-editor或dconf-...
  • hobertony_7
  • hobertony_7
  • 2015年03月05日 17:04
  • 416

unbuntu 运行时遇到的问题

问题1与解决方法 wgb@wgb:~$ spyder GLib-GIO-Message: Using the 'memory' GSettings backend. Your settings wi...
  • wuguangbin1230
  • wuguangbin1230
  • 2017年08月24日 10:02
  • 1526


GIO Reference Manual gsettings gsettings — GSettings configuration tool   ...
  • txgc1009
  • txgc1009
  • 2011年08月30日 15:39
  • 872


  • dongyy
  • dongyy
  • 2008年01月18日 13:32
  • 4002
您举报文章:Gsettings and GConf 介绍、侧重点比较