dconf-editor和gsettings不应该访问同一个数据库吗?

这是一个基本的“学术”问题 – 试图更好地理解配置系统内部。

据我所知, dconf系统是gnome3中的新配置系统,它取代了(已弃用的) gconf ; 从Gconf,Dconf,Gsettings以及它们之间的关系可以清楚地看出这一点。

在我看来,程序gsettingsdconf-editor只有两种不同的方式来访问相同的dconf数据库,这在
什么是dconf,它的function是什么,我该如何使用它?

编辑:我发现有人注意到它在某些模式名称中的区别,请参见此处— dconf模式名称区分大小写? ; 但似乎差异不仅限于此。 在其中一个答案中有一个不匹配的例子,但我没有找到原因的解释。

但最近我发现gsettingsdconf-editor访问的密钥不一样。 例如, vino设置在org.gnome.desktop.remote-access下的dconf-editor (见下面的截图),而在gsettings中它们位于org.gnome.Vino下。 有一些文件可以解释这种差异吗?

gsettings

 (0)samsung-romano:~/tmp/try% gsettings list-recursively org.gnome.Vino org.gnome.Vino alternative-port uint16 5900 org.gnome.Vino authentication-methods ['none'] org.gnome.Vino disable-background false [...] 

和:

 (0)samsung-romano:~/tmp/try% gsettings list-recursively org.gnome.desktop.remote-access No such schema 'org.gnome.desktop.remote-access' 

但是在dconf-editor中

dconf编辑器

  • dconf-editor使用schema path显示设置数据树。 用于在GVariant数据库中存储数据的相同结构。

  • gsettings (来自glib-2.0)使用schema id来显示/获取设置数据。 与使用GSetttings API的任何其他应用程序相同的方式。

  • 应用程序开发人员可以根据需要进行设置。 (对规范命名有一些限制)。 因此path可能与id不同,但大多数应用程序开发人员更喜欢使用相同的单词序列/组合。 有些不保留相同的大小写。 来自Gnome的示例跟踪器项目

      

    除此之外,一些替代应用程序共享属于Gnome桌面的相同设置。 示例: input-sources


  • 首先, 应用程序不应该dconf

    dconf项目页面介绍:

    dconf是一个低级配置系统。 其主要目的是在尚未配置存储系统的平台上为GSettings提供后端。

  • 数据存储在哪里? (参考: https : //wiki.gnome.org/Projects/dconf/SystemAdministrators )

    配置文件是配置数据库的列表。 看起来Gnome和Unity使用相同的配置文件。

     $ cat /etc/dconf/profile/gdm user-db:user system-db:gdm 
    1. user-db:user :配置文件中的第一个数据库是读写rw ,它在用户的主目录中创建。

       $ file ~/.config/dconf/user /home/sneetsher/.config/dconf/user: GVariant Database file, version 0 
    2. system-db:gdm :只读

       $ file /etc/dconf/db/gdm /etc/dconf/db/gdm: GVariant Database file, version 0 

      除了db.d/*文件夹中的GVariant数据库之外,dconf dconf可以绑定文本样式存储。 示例(注意文件路径,因此它是system-db:gdm ):

        $ cat /etc/dconf/db/gdm.d/00-upstream-settings # This file is part of the GDM packaging and should not be changed. # # Instead create your own file next to it with a higher numbered prefix, # and run # # dconf update # [org/gnome/desktop/a11y/keyboard] enable=true [org/gnome/desktop/background] show-desktop-icons=false ... 
  • 架构文件: schema idschema path之间的关系*.gschema.xml

    我的Quickly应用程序的data / glib-2.0文件夹中的架构XML文件是什么? 通过trent显示了在Quickly应用程序中使用GSettings API的一个很好的例子,以及他根据他的经验得出的结论。

    回到Vino。 每个使用GSsettings的应用程序都应定义其架构,并应将它们存储/安装在/usr/share/glib-2.0/schemas/ (它是一个glib目录):

     $ dpkg -L vino | grep -i glib-2.0 /usr/share/glib-2.0 /usr/share/glib-2.0/schemas /usr/share/glib-2.0/schemas/org.gnome.Vino.enums.xml /usr/share/glib-2.0/schemas/org.gnome.Vino.gschema.xml $ more /usr/share/glib-2.0/schemas/org.gnome.Vino.gschema.xml    Enable remote access to the desktop  If true, allows remote access to the desktop via the RFB protocol. Users on remote machines may then connect to the desktop using a VNC viewer.  false   Prompt the user before completing a connection  If true, remote users accessing the desktop are not allowed access until the user on the host machine approves the connection. Recommended especially when access is not password protected.  true  ... 

    如果您注意到,架构使用idpath定义。 模式文件名遵循id值。

      
  • *.enums.xml文件用于自定义枚举声明,用作具有相同schema id *.gschema.xml新数据类型。

     $ cat /usr/share/glib-2.0/schemas/org.gnome.Vino.enums.xml          $ gsettings range org.gnome.Vino icon-visibility enum 'never' 'always' 'client' $ gsettings get org.gnome.Vino icon-visibility 'client' 
  • 编译Schema (参考: 使用dconf和gnome-tweak-tool )

    作为安装过程的一部分(它有一个dpkg触发器),使用glib-compile-schemas工具(来自glib) glib-compile-schemas

     sudo glib-compile-schemas /usr/share/glib-2.0/schemas 

    *.gschema.xml将编译为二进制文件/usr/share/glib-2.0/schemas/gschemas.compiled

  • 供应商覆盖文件*.gschema.override

    除了模式文件之外, glib-compile-schemas读取供应商覆盖文件,这些文件是可以覆盖模式中密钥的默认值的关键文件(参考: man glib-compile-schemas )。 它们包含Ubuntu发行版所做的更改,以覆盖上游模式默认值。

     $ ls /usr/share/glib-2.0/schemas/*.gschema.override /usr/share/glib-2.0/schemas/10_compiz-gnome.gschema.override /usr/share/glib-2.0/schemas/10_desktop-base.gschema.override /usr/share/glib-2.0/schemas/10_evolution-common.gschema.override /usr/share/glib-2.0/schemas/10_gnome-settings-daemon.gschema.override /usr/share/glib-2.0/schemas/10_gnome-shell.gschema.override /usr/share/glib-2.0/schemas/10_gnome-system-log.gschema.override /usr/share/glib-2.0/schemas/10_gsettings-desktop-schemas.gschema.override /usr/share/glib-2.0/schemas/10_libgtk-3-common.gschema.override /usr/share/glib-2.0/schemas/10_ubuntu-settings.gschema.override /usr/share/glib-2.0/schemas/20_ubuntu-gnome-default-settings.gschema.override $ cat /usr/share/glib-2.0/schemas/10_gnome-settings-daemon.gschema.override [org.gnome.desktop.wm.keybindings] switch-input-source=['space'] switch-input-source-backward=['space'] 

    使用覆盖文件的示例,请参阅如何自定义Ubuntu Live CD? (5.定制2:背景和主题)。

  • 锁定文件

    目前,dconf仅支持按键锁定,不支持子路径锁定。 用户定义的值仍将存储在user-db但不会对应用程序产生任何影响。 dconf / gsettings为这些锁定的密钥返回默认值。 锁文件存储在db.d/locks/ 。 例:

     $ cat /etc/dconf/db/gdm.d/locks/00-upstream-settings-locks /org/gnome/desktop/a11y/keyboard/enable /org/gnome/desktop/background/show-desktop-icons /org/gnome/desktop/lockdown/disable-application-handlers /org/gnome/desktop/lockdown/disable-command-line /org/gnome/desktop/lockdown/disable-lock-screen /org/gnome/desktop/lockdown/disable-log-out /org/gnome/desktop/lockdown/disable-printing /org/gnome/desktop/lockdown/disable-print-setup /org/gnome/desktop/lockdown/disable-save-to-disk /org/gnome/desktop/lockdown/disable-user-switching ... 

    锁定修改后,要有效运行:

     sudo dconf update 

    一个很好的展示: dconf设置:默认和锁定

  • 更改全局设置

    gsettings / dconf-editor的默认设置是编辑user-db 。 要更改system-db ,请编写新的覆盖文件并重新编译模式。

    我无法让这个工作:

     sudo su gdm -c 'gsettings ...' 

    这里没有其他答案设置默认/全局Gnome首选项(Gnome 3) ,可能是旧版本。