1 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
4 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
5 <title>Schema conversion</title>
6 <meta name="generator" content="DocBook XSL Stylesheets V1.76.1">
7 <link rel="home" href="index.html" title="GIO Reference Manual">
8 <link rel="up" href="ch29.html" title="Migrating from GConf to GSettings">
9 <link rel="prev" href="ch29s05.html" title="Change sets">
10 <link rel="next" href="ch29s07.html" title="Data conversion">
11 <meta name="generator" content="GTK-Doc V1.18 (XML mode)">
12 <link rel="stylesheet" href="style.css" type="text/css">
14 <body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
15 <table class="navigation" id="top" width="100%" summary="Navigation header" cellpadding="2" cellspacing="2"><tr valign="middle">
16 <td><a accesskey="p" href="ch29s05.html"><img src="left.png" width="24" height="24" border="0" alt="Prev"></a></td>
17 <td><a accesskey="u" href="ch29.html"><img src="up.png" width="24" height="24" border="0" alt="Up"></a></td>
18 <td><a accesskey="h" href="index.html"><img src="home.png" width="24" height="24" border="0" alt="Home"></a></td>
19 <th width="100%" align="center">GIO Reference Manual</th>
20 <td><a accesskey="n" href="ch29s07.html"><img src="right.png" width="24" height="24" border="0" alt="Next"></a></td>
23 <div class="titlepage"><div><div><h2 class="title" style="clear: both">
24 <a name="id1005963"></a>Schema conversion</h2></div></div></div>
26 If you are porting your application from GConf, most likely you already
27 have a GConf schema. GConf comes with a commandline tool
28 gsettings-schema-convert that can help with the task of converting
29 a GConf schema into an equivalent GSettings schema. The tool is not
30 perfect and may need assistence in some cases.
33 <a name="id573133"></a><p class="title"><b>Example 22. An example for using gsettings-schema-convert</b></p>
34 <div class="example-contents">
35 <p>Running <strong class="userinput"><code>gsettings-schema-convert --gconf --xml --schema-id "org.gnome.font-rendering" --output org.gnome.font-rendering.gschema.xml destop_gnome_font_rendering.schemas</code></strong> on the following <code class="filename">desktop_gnome_font_rendering.schemas</code> file:
37 <pre class="programlisting">
39 <?xml version="1.0"?>
40 <gconfschemafile>
43 <key>/schemas/desktop/gnome/font_rendering/dpi</key>
44 <applyto>/desktop/gnome/font_rendering/dpi</applyto>
45 <owner>gnome</owner>
46 <type>int</type>
47 <default>96</default>
48 <locale name="C">
49 <short>DPI</short>
50 <long>The resolution used for converting font sizes to pixel sizes, in dots per inch.</long>
54 </gconfschemafile>
58 produces a <code class="filename">org.gnome.font-rendering.gschema.xml</code> file with the following content:
60 <pre class="programlisting">
63 <schema id="org.gnome.font-rendering" path="/desktop/gnome/font_rendering/">
64 <key name="dpi" type="i">
65 <default>96</default>
66 <summary>DPI</summary>
67 <description>The resolution used for converting font sizes to pixel sizes, in dots per inch.</description>
77 <br class="example-break"><p>
78 GSettings schemas are identified at runtime by their id (as specified
79 in the XML source file). It is recommended to use a dotted name as schema
80 id, similar in style to a D-Bus bus name, e.g. "org.gnome.SessionManager".
81 In cases where the settings are general and not specific to one application,
82 the id should not use StudlyCaps, e.g. "org.gnome.font-rendering".
83 The filename used for the XML schema source is immaterial, but
84 schema compiler expects the files to have the extension
85 <code class="filename">.gschema.xml</code>. It is recommended to simply
86 use the schema id as the filename, followed by this extension,
87 e.g. <code class="filename">org.gnome.SessionManager.gschema.xml</code>.
90 The XML source file for your GSettings schema needs to get installed
91 into <code class="filename">$datadir/glib-2.0/schemas</code>, and needs to be
92 compiled into a binary form. At runtime, GSettings looks for compiled
93 schemas in the <code class="filename">glib-2.0/schemas</code> subdirectories
94 of all <code class="envar">XDG_DATA_DIRS</code> directories, so if you install
95 your schema in a different location, you need to set the
96 <code class="envar">XDG_DATA_DIRS</code> environment variable appropriately.
99 Schemas are compiled into binary form by the
100 <a href="glib-compile-schemas.html">glib-compile-schemas</a> utility.
101 GIO provides a <code class="literal">glib_compile_schemas</code>
102 variable for the schema compiler.
105 You can ignore all of this by using the provided m4 macros. To
106 do this, add to your <code class="filename">configure.ac</code>:
108 <pre class="programlisting">
112 The corresponding <code class="filename">Makefile.am</code> fragment looks like
115 <pre class="programlisting">
116 # gsettings_SCHEMAS is a list of all the schemas you want to install
117 gsettings_SCHEMAS = my.app.gschema.xml
119 # include the appropriate makefile rules for schema handling
125 This is not sufficient on its own. You need to mention what the source
126 of the <code class="filename">my.app.gschema.xml</code> file is. If the schema
127 file is distributed directly with your project's tarball then a mention
128 in <code class="varname">EXTRA_DIST</code> is appropriate. If the schema file is
129 generated from another source then you will need the appropriate rule
130 for that, plus probably an item in <code class="varname">EXTRA_DIST</code> for the
131 source files used by that rule.
134 One possible pitfall in doing schema conversion is that the default
135 values in GSettings schemas are parsed by the <a href="./../glib/glib/glib-GVariant.html#GVariant"><span class="type">GVariant</span></a> parser.
136 This means that strings need to include quotes in the XML. Also note
137 that the types are now specified as <a href="./../glib/glib/glib-GVariant.html#GVariant"><span class="type">GVariant</span></a> type strings.
139 <pre class="programlisting">
141 <type>string</type>
142 <default>rgb</default>
148 <pre class="programlisting">
150 <key name="rgba-order" type="s">
151 <default>'rgb'</default> <!-- note quotes -->
158 Another possible complication is that GConf specifies full paths
159 for each key, while a GSettings schema has a 'path' attribute that
160 contains the prefix for all the keys in the schema, and individual
161 keys just have a simple name. So
163 <pre class="programlisting">
165 <key>/schemas/desktop/gnome/font_rendering/antialiasing</key>
171 <pre class="programlisting">
173 <schema id="org.gnome.font" path="/desktop/gnome/font_rendering/">
174 <key name="antialiasing" type="s">
180 Default values can be localized in both GConf and GSettings schemas,
181 but GSettings uses gettext for the localization. You can specify
182 the gettext domain to use in the <code class="sgmltag-attribute">gettext-domain</code>
183 attribute. Therefore, when converting localized defaults in GConf,
185 <pre class="programlisting">
187 <key>/schemas/apps/my_app/font_size</key>
188 <locale name="C">
189 <default>18</default>
191 <locale name="be">
192 <default>24</default>
200 <pre class="programlisting">
202 <schema id="..." gettext-domain="your-domain">
204 <key name="font-size" type="i">
205 <default l10n="messages" context="font_size">18</default>
212 GSettings uses gettext for translation of default values.
213 The string that is translated is exactly the string that appears
214 inside of the <code class="sgmltag-starttag"><default></code> element. This
215 includes the quotation marks that appear around strings.
216 Default values must be marked with the <code class="varname">l10n</code>
217 attribute in the <code class="sgmltag-starttag"><default></code> tag, which
218 should be set as equal to <code class="literal">'messages'</code> or
219 <code class="literal">'time'</code> depending on the desired category. An
220 optional translation context can also be specified with the
221 <code class="varname">context</code> attribute, as in the example. This
222 is usually recommended, since the string "<code class="literal">18</code>"
223 is not particularly easy to translate without context. The
224 translated version of the default value should be stored in the
225 specified <code class="varname">gettext-domain</code>. Care must be taken
226 during translation to ensure that all translated values remain
227 syntactically valid; mistakes here will cause runtime errors.
230 GSettings schemas have optional <code class="sgmltag-starttag"><summary></code> and
231 <code class="sgmltag-starttag"><description></code> elements for each key which
232 correspond to the <code class="sgmltag-starttag"><short></code> and
233 <code class="sgmltag-starttag"><long></code> elements in the GConf schema and
234 will be used in similar ways by a future gsettings-editor, so you
235 should use the same conventions for them: The summary is just a short
236 label with no punctuation, the description can be one or more complete
237 sentences. If multiple paragraphs are desired for the description, the
238 paragraphs should be separated by a completely empty line.
241 Translations for these strings will also be handled
242 via gettext, so you should arrange for these strings to be
243 extracted into your gettext catalog. One way to do that is to use
244 intltool. For that, you use <code class="sgmltag-starttag"><_summary></code>
245 and <code class="sgmltag-starttag"><_description></code> elements in a
246 .gschema.xml.in file and use
247 <code class="literal">@INTLTOOL_XML_NOMERGE_RULE@</code>
248 in your Makefile.am to produce the .gschema.xml file. The
249 <code class="literal">NOMERGE</code> part of the rule instructs intltool
250 to extract translatable strings, but not merge the translations
251 back into the generated xml file.
254 GSettings is a bit more restrictive about key names than GConf. Key
255 names in GSettings can be at most 32 characters long, and must only
256 consist of lowercase characters, numbers and dashes, with no
257 consecutive dashes. The first character must not be a number or dash,
258 and the last character cannot be '-'.
261 If you are using the GConf backend for GSettings during the
262 transition, you may want to keep your key names the same they
263 were in GConf, so that existing settings in the users GConf
264 database are preserved. You can achieve this by using the
265 <code class="option">--allow-any-name</code> with the
266 <a href="glib-compile-schemas.html">glib-compile-schemas</a> schema
267 compiler. Note that this option is only meant
268 to ease the process of porting your application, allowing parts
269 of your application to continue to access GConf and parts to use
270 GSettings. By the time you have finished porting your application
271 you must ensure that all key names are valid.
276 Generated by GTK-Doc V1.18</div>