DConf Overview
05 Jan 2015DConf
Links:
- Dconf overview - gnome
- Dconf mer-package
- Using GSettings with Python/PyGObject
- Gio.Settings documentation
- GSettings C Documentation
dconf is a simple key/value storage system. dconf has a partial client/server architecture. It uses D-Bus. The server is only involved in writes (and is not activated in the user session until the user modifies a preference). The list of paths that each process is watching is stored within the D-Bus daemon itself (as D-Bus signal match rules).
A profile is a list of configuration databases that dconf consults to find the value for a key. The user’s personal database always takes the highest priority, followed by the system databases in the order prescribed by the profile. Profile file is stored in /etc/dconf/profile/user
. It defines 3 databases:
- A read only system database called “nemo” which is used to store configuration for packages coming from nemo. (
/etc/dconf/db/nemo
) - A read only system database called “vendor”. This allows vendors to override and customize stuff. (
/etc/dconf/db/vendor
). An example is the theme. Nemo has its theme and the nemo database contains the name of it. A vendor (like Jolla can override it with its own theme and store that info in the vendor db). - A read/write db called user which contains the configuration (
/home/nemo/.config/dconf/user
)
Adding an app
According to mer. But, harbour doesn’t allow this
Create a key file with your defaults in /etc/dconf/db/nemo.d/<package-name>.txt
:
[apps/harbour-my-nice-app]
miValue='a value'
anotherValue=1
boolValue=false
Call dconf-update
via a oneshot
(%{_bindir}/add-oneshot dconf-update
) in %post
.
DConf command line utility
[nemo@SailfishEmul ~]$ dconf help
Usage:
dconf COMMAND [ARGS...]
Commands:
help Show this information
read Read the value of a key
list List the contents of a dir
write Change the value of a key
reset Reset the value of a key or dir
update Update the system databases
watch Watch a path for changes
dump Dump an entire subpath to stdout
load Populate a subpath from stdin
The basic ussage is simple:
* Reading values: dconf read /my/app/key
the value will be printed.
* Writing values: dconf write /my/app/key <value>
, <value>
is the value that is going to be saved on that key. Remember, that it has to have GVariant format. Ie, if you want to write a string: dconf write /my/app/key '"this is the value"'
(yes, it has quotes in the quoted value). For booleans <value>
will be true
or false
.
Using dconf in python through GSettings
This is only intended if you are developing a python app which is allowed in harbour.
In Qt/C++ you are encorage to use the MGConfItem provided by the nemomobile/mlite package, and in qml the nemomobile/configuration qml plugin, although it has not been harbour-whitelisted). The problem of using python is that there are not bindings. The work arround is using GSettings
of the gi.repository
packages which uses dconf
as backend.
In order to use GSettings
a configuration schema has to be declared and compiled.
Generate <app>.gschema.xml
-> /usr/share/glib-2.0/schemas/
Harbour doesn’t allow to write files in /usr/share/glib-2.0/schemas
. If targeting harbour, a workaround could be writing the file in /usr/share/<HARBOUR_APP_NAME>
compile the file, and in runtime change XDG_DATA_DIRS
in order to make GSettings
to look for the custom schema.
id
is the schema id, while path
is the dconf key.
<?xml version="1.0" encoding="UTF-8"?>
<schemalist>
<schema id="apps.harbour-my-nice-app" path="/apps/harbour-my-nice-app/">
<key type="s" name="miValue">
<default>'a value'</default>
<summary>My string value</summary>
<description>This is an example of a string setting.</description>
</key>
<key type="i" name="anotherValue">
<default>1</default>
<summary>My number value</summary>
<description>This is an example of a number setting.</description>
</key>
<key type="b" name="boolValue">
<default>false</default>
<summary>My bool value</summary>
<description>This is an example of a bool setting.</description>
</key>
</schema>
</schemalist>
Compile Schemas
[root@SailfishEmul ~]# glib-compile-schemas /usr/share/glib-2.0/schemas/
Example code:
from gi.repository import Gio
if __name__ == "__main__":
gsettings = Gio.Settings.new("apps.harbour-my-nice-app")
print(gsettings.get_string("miValue"))
gsettings.set_string("miValue", "another value")
gsettings.apply()
See the Gio.Settings documentation for full information about how to set/get values. Remember that if you change values, .apply()
method must be called!.
You can check that both the python script and dconf read
command utility return the same values for the same paths.
Using dconf in QML org.nemomobile.configuration
nemomobile/nemo-qml-plugin-configuration.
The plugin has to be included: import org.nemomobile.configuration 1.0
. It provides two components:
ConfigurationValue
: It is used to configurate un value, it has two propertieskey
andvalue
. First thekey
has to be setted, then if thevalue
property is queryed, it will return thedconf
value. If this property is setted, it will set the dconf value, as simple as that.ConfigurationGroup
: TODO
Example:
ApplicationWindow {
initialPage: Component {
Page {
ConfigurationValue {
id: configurationValue
}
SilicaFlickable {
anchors.fill: parent
contentHeight: column.height
Column {
id: column
width: parent.width
height: childRect.height
PageHeader { title: "Qml DConf Client" }
TextField {
id: key
width: parent.width
inputMethodHints: Qt.ImhNoPredictiveText
label: "Key"
placeholderText: "Key"
focus: true
EnterKey.onClicked: {
configurationValue.key = key.text
value.text = configurationValue.value
}
}
TextField {
id: value
width: parent.width
inputMethodHints: Qt.ImhNoPredictiveText
label: "Value"
placeholderText: "Value"
EnterKey.onClicked: {
configurationValue.value = value.text
}
}
}
}
}
}
}
In this example, when the key field is setted and the enter key is hit, the value field will be filled with the dconf value. If in the value TextField is chaged, and the enter key is pressed, the value will be saved.
TODO: