2
Copyright © 2007 Dennis Kasprzyk
3
Copyright © 2011 Canonical Ltd.
5
Permission to use, copy, modify, distribute, and sell this software
6
and its documentation for any purpose is hereby granted without
7
fee, provided that the above copyright notice appear in all copies
8
and that both that copyright notice and this permission notice
9
appear in supporting documentation, and that the name of
10
Dennis Kasprzyk not be used in advertising or publicity pertaining to
11
distribution of the software without specific, written prior permission.
12
Dennis Kasprzyk makes no representations about the suitability of this
13
software for any purpose. It is provided "as is" without express or
16
DENNIS KASPRZYK DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
17
INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN
18
NO EVENT SHALL DENNIS KASPRZYK BE LIABLE FOR ANY SPECIAL, INDIRECT OR
19
CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
20
OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
21
NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
22
WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
24
Authors: Dennis Kasprzyk <onestone@deltatauchi.de>
25
Authors: Sam Spilsbury <sam.spilsbury@canonical.com>
28
<xsl:stylesheet version='1.0' xmlns:xsl='http://www.w3.org/1999/XSL/Transform' >
29
<xsl:output method="xml" indent="yes"/>
31
<xsl:param name="appName">/apps/compiz-1</xsl:param>
33
<xsl:template match="/compiz">
34
<xsl:element name="schemalist">
35
<xsl:for-each select="/compiz/plugin/options">
36
<xsl:call-template name="genGSettingsSchema"/>
41
<xsl:template name="genGSettingsSchema">
42
<!--xsl:param name="schemaPath">
43
<xsl:call-template name="printPath"/>
45
<xsl:param name="schemaId">
46
<xsl:call-template name="printId"/>
48
<!-- two levels of indentation: group and subgroup>= -->
49
<xsl:element name="schema">
50
<xsl:attribute name="id">
51
<xsl:value-of select="$schemaId"/>
53
<!--xsl:attribute name="path">
54
<xsl:value-of select="$schemaPath"/>
56
<xsl:attribute name="gettext-domain">
57
<xsl:text>@GETTEXT_PACKAGE@</xsl:text>
59
<xsl:for-each select="/compiz//options//option[not(@read_only='true') and not(@type='action')]">
60
<xsl:call-template name="dumpOption"/>
65
<!-- generates the schema for an option -->
66
<xsl:template name="dumpOption">
67
<xsl:param name="keyType">
68
<xsl:call-template name="printType"/>
70
<xsl:param name="keyKeyName">
71
<xsl:call-template name="printKeyName"/>
73
<xsl:param name="keySummary">
74
<xsl:call-template name="printSummary"/>
76
<xsl:param name="keyDescription">
77
<xsl:call-template name="printDescription"/>
79
<xsl:element name="key">
80
<xsl:attribute name="type">
81
<xsl:value-of select="$keyType"/>
83
<xsl:attribute name="name">
84
<xsl:value-of select="$keyKeyName"/>
87
<!-- color values need a special handling -->
88
<xsl:when test="@type = 'color'">
89
<xsl:element name="default">
91
<xsl:when test="default">
92
<xsl:for-each select="default[1]">
93
<xsl:call-template name="printColor"/>
97
<xsl:text>'#000000ff'</xsl:text>
102
<xsl:when test="@type = 'edge'">
103
<xsl:element name="default">
104
<xsl:call-template name="printEdgeList"/>
107
<xsl:when test="@type = 'list'">
109
<xsl:when test="type/text() = 'color'">
110
<xsl:element name="default">
111
<xsl:text>[</xsl:text>
112
<xsl:call-template name="printColorList"/>
113
<xsl:text>]</xsl:text>
117
<xsl:element name="default">
118
<xsl:text>[</xsl:text>
119
<xsl:call-template name="printValueList">
120
<xsl:with-param name="listType" select="type/text()"/>
122
<xsl:text>]</xsl:text>
127
<!-- for most option types we can use the default value directly -->
129
<xsl:element name="default">
130
<!-- for non int and double option types we need to have
133
<xsl:when test="contains('int,float,bool,bell', @type)"/>
135
<xsl:text>'</xsl:text>
139
<xsl:when test="default/text()">
140
<xsl:value-of select="default/text()"/>
143
<!-- if no default value was specified we need to generate one -->
145
<xsl:when test="contains('bool,bell',@type)">
146
<xsl:text>false</xsl:text>
148
<xsl:when test="@type = 'int'">
149
<xsl:variable name="num">
150
<xsl:call-template name="printNumFallback"/>
152
<xsl:value-of select="floor($num)"/>
154
<xsl:when test="@type = 'float'">
155
<xsl:call-template name="printNumFallback"/>
157
<xsl:when test="contains('key,button',@type)">
158
<xsl:text>Disabled</xsl:text>
163
<!-- for non int and double option types we need to have
166
<xsl:when test="contains('int,float,bool,bell', @type)"/>
168
<xsl:text>'</xsl:text>
174
<!-- add the short and long descriptions -->
175
<xsl:element name="summary">
176
<xsl:value-of select="$keySummary"/>
178
<xsl:element name="description">
179
<xsl:value-of select="$keyDescription"/>
184
<!-- converts a compiz type to a gvariant type -->
185
<xsl:template name="printType">
186
<xsl:param name="type">
187
<xsl:value-of select="@type"/>
190
<xsl:when test="$type = 'int'">
191
<xsl:text>i</xsl:text>
193
<xsl:when test="$type = 'float'">
194
<xsl:text>d</xsl:text>
196
<xsl:when test="$type = 'bool'">
197
<xsl:text>b</xsl:text>
199
<xsl:when test="$type = 'bell'">
200
<xsl:text>b</xsl:text>
202
<xsl:when test="$type = 'list'">
203
<!-- convert list type to array type -->
204
<xsl:text>a</xsl:text>
205
<xsl:call-template name="printType">
206
<xsl:with-param name="type" select="type/text()"/>
210
<xsl:text>s</xsl:text>
215
<!-- prints the option long and short descriptions of an option -->
216
<xsl:template name="printSummary">
217
<xsl:value-of select="short/text()"/>
220
<xsl:template name="printDescription">
221
<xsl:param name="info">
222
<xsl:call-template name="printInfo"/>
224
<!-- get the long description from the xml and also any additional info
225
about this setting -->
226
<xsl:value-of select="long/text()"/>
227
<xsl:value-of select="$info"/>
230
<!-- generates the additional info for the long option description -->
231
<xsl:template name="printInfo">
232
<!-- save all of this in 'info' -->
233
<xsl:variable name="info">
234
<xsl:text> (</xsl:text>
236
<xsl:when test="contains('int,float',@type) and not(desc/value/text())">
237
<xsl:value-of select="min/text()"/> - <xsl:value-of select="max/text()"/>
239
<xsl:when test="@type='int' and desc/value/text()">
240
<xsl:call-template name="printIntDescList"/>
242
<xsl:when test="@type = 'match'">
243
<xsl:text>match</xsl:text>
246
<xsl:text>)</xsl:text>
248
<xsl:if test="not(contains($info,' ()'))">
249
<xsl:value-of select="$info"/>
253
<!-- generates a list of int descriptions -->
254
<xsl:template name="printIntDescList">
255
<xsl:variable name="list">
256
<xsl:for-each select="desc">
257
<xsl:value-of select="value/text()"/>
258
<xsl:text> = </xsl:text>
259
<xsl:value-of select="name/text()"/>
260
<xsl:text>, </xsl:text>
263
<xsl:value-of select="substring($list,1,string-length($list) - 2)"/>
266
<!-- generates a default number out of the min and max values -->
267
<xsl:template name="printNumFallback">
269
<xsl:when test="max/text() and min/text()">
270
<xsl:value-of select="(max/text() + min/text()) div 2"/>
272
<xsl:when test="max/text() and not(min/text())">
273
<xsl:value-of select="max/text()"/>
275
<xsl:when test="not(max/text()) and min/text()">
276
<xsl:value-of select="min/text()"/>
278
<xsl:otherwise>0</xsl:otherwise>
282
<!-- generates a list of values -->
283
<xsl:template name="printValueList">
284
<xsl:param name="listType"/>
285
<xsl:variable name="list">
286
<xsl:for-each select="default/value">
288
<xsl:when test="contains ('int,float,bool,bell', $listType)">
289
<xsl:value-of select="text()"/>
290
<xsl:text>,</xsl:text>
293
<xsl:text>'</xsl:text>
294
<xsl:value-of select="text()"/>
295
<xsl:text>'</xsl:text>
296
<xsl:text>,</xsl:text>
301
<xsl:value-of select="substring($list,1,string-length($list) - 1)"/>
304
<!-- generates a list of color string values -->
305
<xsl:template name="printColorList">
306
<xsl:variable name="list">
307
<xsl:for-each select="default/value">
308
<xsl:call-template name="printColor"/>
309
<xsl:text>,</xsl:text>
312
<xsl:value-of select="substring($list,1,string-length($list) - 1)"/>
316
generates the #00aabbcc color value out of the compiz
317
metadata color description
319
<xsl:template name="printColor">
320
<xsl:variable name="red">
321
<xsl:call-template name="getHexNum">
322
<xsl:with-param name="value" select="red/text()"/>
325
<xsl:variable name="green">
326
<xsl:call-template name="getHexNum">
327
<xsl:with-param name="value" select="green/text()"/>
330
<xsl:variable name="blue">
331
<xsl:call-template name="getHexNum">
332
<xsl:with-param name="value" select="blue/text()"/>
335
<xsl:variable name="alpha">
337
<xsl:when test="alpha/text()">
338
<xsl:call-template name="getHexNum">
339
<xsl:with-param name="value" select="alpha/text()"/>
343
<xsl:text>ff</xsl:text>
347
<xsl:text>'</xsl:text>
348
<xsl:value-of select="concat('#',concat($red,concat($green,concat($blue,$alpha))))"/>
349
<xsl:text>'</xsl:text>
353
converts a decimal number in the range of 0-65535 or
354
a hex number in the range of 0x0000 - 0xffff to a hex number in the
357
<xsl:template name="getHexNum">
358
<xsl:param name="value"/>
360
<xsl:when test="starts-with($value,'0x')">
361
<xsl:variable name="number">
362
<xsl:text>0000</xsl:text>
363
<xsl:value-of select="substring-after($value,'0x')"/>
365
<xsl:value-of select="substring(concat('000',$number),string-length($number),2)"/>
367
<xsl:when test="string-length($value)">
368
<xsl:variable name="number">
369
<xsl:call-template name="toHex">
370
<xsl:with-param name="decimalNumber" select="$value"/>
373
<xsl:value-of select="substring(concat('000',$number),string-length($number),2)"/>
376
<xsl:text>00</xsl:text>
381
<!-- generates a list of selected edges -->
382
<xsl:template name="printEdgeList">
383
<xsl:variable name="list">
384
<xsl:for-each select="default/edge">
385
<xsl:value-of select="@name"/>
386
<xsl:text> | </xsl:text>
389
<xsl:text>'</xsl:text>
390
<xsl:value-of select="substring($list,1,string-length($list) - 3)"/>
391
<xsl:text>'</xsl:text>
394
<!-- prints the path for an option -->
395
<xsl:template name="printPath">
396
<xsl:value-of select="$appName"/>
398
<xsl:when test="ancestor::plugin">
399
<xsl:text>/plugins/</xsl:text>
400
<xsl:value-of select="ancestor::plugin/@name"/>
403
<xsl:text>/general</xsl:text>
406
<xsl:text>/screen0/options/</xsl:text>
409
<!-- prints the schema id (in d-bus style) -->
410
<xsl:template name="printId">
411
<xsl:text>org.freedesktop.compiz</xsl:text>
413
<xsl:when test="ancestor::plugin">
414
<xsl:text>.</xsl:text>
415
<xsl:value-of select="ancestor::plugin/@name"/>
420
<!-- prints the key name -->
421
<xsl:template name="printKeyName">
422
<!-- not allowed to have underscores, key names > 32 chars and upper case characters -->
423
<xsl:param name="ASCIIUpper" >ABCDEFGHIJKLMNOPQRSTUVWXYZ</xsl:param>
424
<xsl:param name="ASCIILower" >abcdefghijklmnopqrstuvwxyz</xsl:param>
425
<xsl:value-of select="translate(substring(translate(@name, '_', '-'), 0, 32), $ASCIIUpper, $ASCIILower)"/>
428
<!-- converts a decimal number to a hex number -->
429
<xsl:variable name="hexDigits" select="'0123456789abcdef'" />
431
<xsl:template name="toHex">
432
<xsl:param name="decimalNumber" />
433
<xsl:if test="$decimalNumber >= 16">
434
<xsl:call-template name="toHex">
435
<xsl:with-param name="decimalNumber" select="floor($decimalNumber div 16)" />
438
<xsl:value-of select="substring($hexDigits, ($decimalNumber mod 16) + 1, 1)" />