2
Copyright © 2007 Dennis Kasprzyk
4
Permission to use, copy, modify, distribute, and sell this software
5
and its documentation for any purpose is hereby granted without
6
fee, provided that the above copyright notice appear in all copies
7
and that both that copyright notice and this permission notice
8
appear in supporting documentation, and that the name of
9
Dennis Kasprzyk not be used in advertising or publicity pertaining to
10
distribution of the software without specific, written prior permission.
11
Dennis Kasprzyk makes no representations about the suitability of this
12
software for any purpose. It is provided "as is" without express or
15
DENNIS KASPRZYK DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
16
INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN
17
NO EVENT SHALL DENNIS KASPRZYK BE LIABLE FOR ANY SPECIAL, INDIRECT OR
18
CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
19
OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
20
NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
21
WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
23
Authors: Dennis Kasprzyk <onestone@deltatauchi.de>
26
<xsl:stylesheet version='1.0' xmlns:xsl='http://www.w3.org/1999/XSL/Transform' >
27
<xsl:output method="xml" indent="yes"/>
29
<xsl:param name="appName">/apps/compiz-1</xsl:param>
31
<xsl:template match="/compiz">
34
<!-- two levels of indentation: group and subgroup>= -->
35
<xsl:for-each select="/compiz//options//option[not(@read_only='true') and not(@type='action')]">
36
<xsl:call-template name="dumpOption"/>
42
<!-- generates the schema for an option -->
43
<xsl:template name="dumpOption">
45
<key>/schemas<xsl:call-template name="printKey"/></key>
46
<applyto><xsl:call-template name="printKey"/></applyto>
47
<owner>compiz-1</owner>
48
<type><xsl:call-template name="printType"/></type>
50
<!-- color values need a special handling -->
51
<xsl:when test="@type = 'color'">
54
<xsl:when test="default">
55
<xsl:for-each select="default[1]">
56
<xsl:call-template name="printColor"/>
60
<xsl:text>#000000ff</xsl:text>
65
<xsl:when test="@type = 'edge'">
67
<xsl:call-template name="printEdgeList"/>
70
<xsl:when test="@type = 'list'">
72
<xsl:call-template name="printType">
73
<xsl:with-param name="type" select="type/text()"/>
77
<xsl:when test="type/text() = 'color'">
78
<default>[<xsl:call-template name="printColorList"/>]</default>
81
<default>[<xsl:call-template name="printValueList"/>]</default>
85
<!-- for most option types we can use the default value directly -->
89
<xsl:when test="default/text()">
90
<xsl:value-of select="default/text()"/>
93
<!-- if no default value was specified we need to generate one -->
95
<xsl:when test="contains('bool,bell',@type)">
96
<xsl:text>false</xsl:text>
98
<xsl:when test="@type = 'int'">
99
<xsl:variable name="num">
100
<xsl:call-template name="printNumFallback"/>
102
<xsl:value-of select="floor($num)"/>
104
<xsl:when test="@type = 'float'">
105
<xsl:call-template name="printNumFallback"/>
107
<xsl:when test="contains('key,button',@type)">
108
<xsl:text>Disabled</xsl:text>
116
<!-- add the short and long descriptions -->
117
<xsl:call-template name="printDescription"/>
121
<!-- converts a compiz type to a gconf type -->
122
<xsl:template name="printType">
123
<xsl:param name="type">
124
<xsl:value-of select="@type"/>
127
<xsl:when test="$type = 'int'">
128
<xsl:text>int</xsl:text>
130
<xsl:when test="$type = 'float'">
131
<xsl:text>float</xsl:text>
133
<xsl:when test="$type = 'bool'">
134
<xsl:text>bool</xsl:text>
136
<xsl:when test="$type = 'list'">
137
<xsl:text>list</xsl:text>
139
<xsl:when test="$type = 'bell'">
140
<xsl:text>bool</xsl:text>
143
<xsl:text>string</xsl:text>
148
<!-- prints the option long and short descriptions of an option -->
149
<xsl:template name="printDescription">
150
<xsl:param name="info">
151
<xsl:call-template name="printInfo"/>
154
<short><xsl:value-of select="short[not(@xml:lang)]/text()"/></short>
156
<xsl:value-of select="long[not(@xml:lang)]/text()"/>
157
<xsl:value-of select="$info"/>
160
<xsl:for-each select="short[@xml:lang]">
161
<xsl:variable name="language" select="@xml:lang"/>
162
<xsl:variable name="infoTrans">
163
<xsl:call-template name="printInfoTrans">
164
<xsl:with-param name="language" select="$language"/>
168
<xsl:attribute name='name'>
169
<xsl:value-of select="@xml:lang"/>
171
<short><xsl:value-of select="text()"/></short>
174
<xsl:when test="parent::option/long[lang($language)]">
175
<xsl:value-of select="parent::option/long[lang($language)]/text()"/>
178
<xsl:value-of select="parent::option/long[not(@xml:lang)]/text()"/>
181
<xsl:value-of select="$infoTrans"/>
187
<!-- generates the additional info for the long option description -->
188
<xsl:template name="printInfo">
189
<xsl:variable name="info">
190
<xsl:text> (</xsl:text>
192
<xsl:when test="contains('int,float',@type) and not(desc/value/text())">
193
<xsl:value-of select="min/text()"/> - <xsl:value-of select="max/text()"/>
195
<xsl:when test="@type='int' and desc/value/text()">
196
<xsl:call-template name="printIntDescList"/>
198
<xsl:when test="@type = 'match'">
199
<xsl:text>match</xsl:text>
202
<xsl:text>)</xsl:text>
204
<xsl:if test="not(contains($info,' ()'))">
205
<xsl:value-of select="$info"/>
209
<!-- generates a list of int descriptions -->
210
<xsl:template name="printIntDescList">
211
<xsl:variable name="list">
212
<xsl:for-each select="desc">
213
<xsl:value-of select="value/text()"/>
214
<xsl:text> = </xsl:text>
215
<xsl:value-of select="name/text()"/>
216
<xsl:text>, </xsl:text>
219
<xsl:value-of select="substring($list,1,string-length($list) - 2)"/>
222
<!-- generates the additional info for the long option description -->
223
<xsl:template name="printInfoTrans">
224
<xsl:param name="language"/>
225
<xsl:variable name="info">
226
<xsl:text> (</xsl:text>
228
<xsl:when test="contains('int,float',parent::option/@type) and not(parent::option/desc/value/text())">
229
<xsl:value-of select="parent::option/min/text()"/> - <xsl:value-of select="parent::option/max/text()"/>
231
<xsl:when test="parent::option/@type='int' and parent::option/desc/value/text()">
232
<xsl:call-template name="printIntDescListTrans">
233
<xsl:with-param name="language" select="$language"/>
236
<xsl:when test="parent::option/@type = 'match'">
237
<xsl:text>match</xsl:text>
240
<xsl:text>)</xsl:text>
242
<xsl:if test="not(contains($info,' ()'))">
243
<xsl:value-of select="$info"/>
247
<!-- generates a list of int descriptions -->
248
<xsl:template name="printIntDescListTrans">
249
<xsl:param name="language"/>
250
<xsl:variable name="list">
251
<xsl:for-each select="parent::option/desc">
252
<xsl:value-of select="value/text()"/>
253
<xsl:text> = </xsl:text>
255
<xsl:when test="name[lang($language)]/text()">
256
<xsl:value-of select="name[lang($language)]/text()"/>
259
<xsl:value-of select="name[not(@xml:lang)]/text()"/>
262
<xsl:text>, </xsl:text>
265
<xsl:value-of select="substring($list,1,string-length($list) - 2)"/>
268
<!-- generates a default number out of the min and max values -->
269
<xsl:template name="printNumFallback">
271
<xsl:when test="max/text() and min/text()">
272
<xsl:value-of select="(max/text() + min/text()) div 2"/>
274
<xsl:when test="max/text() and not(min/text())">
275
<xsl:value-of select="max/text()"/>
277
<xsl:when test="not(max/text()) and min/text()">
278
<xsl:value-of select="min/text()"/>
280
<xsl:otherwise>0</xsl:otherwise>
284
<!-- generates a list of values -->
285
<xsl:template name="printValueList">
286
<xsl:variable name="list">
287
<xsl:for-each select="default/value">
288
<xsl:value-of select="text()"/>
289
<xsl:text>,</xsl:text>
292
<xsl:value-of select="substring($list,1,string-length($list) - 1)"/>
295
<!-- generates a list of color string values -->
296
<xsl:template name="printColorList">
297
<xsl:variable name="list">
298
<xsl:for-each select="default/value">
299
<xsl:call-template name="printColor"/>
300
<xsl:text>,</xsl:text>
303
<xsl:value-of select="substring($list,1,string-length($list) - 1)"/>
307
generates the #00aabbcc color value out of the compiz
308
metadata color description
310
<xsl:template name="printColor">
311
<xsl:variable name="red">
312
<xsl:call-template name="getHexNum">
313
<xsl:with-param name="value" select="red/text()"/>
316
<xsl:variable name="green">
317
<xsl:call-template name="getHexNum">
318
<xsl:with-param name="value" select="green/text()"/>
321
<xsl:variable name="blue">
322
<xsl:call-template name="getHexNum">
323
<xsl:with-param name="value" select="blue/text()"/>
326
<xsl:variable name="alpha">
328
<xsl:when test="alpha/text()">
329
<xsl:call-template name="getHexNum">
330
<xsl:with-param name="value" select="alpha/text()"/>
334
<xsl:text>ff</xsl:text>
338
<xsl:value-of select="concat('#',concat($red,concat($green,concat($blue,$alpha))))"/>
342
converts a decimal number in the range of 0-65535 or
343
a hex number in the range of 0x0000 - 0xffff to a hex number in the
346
<xsl:template name="getHexNum">
347
<xsl:param name="value"/>
349
<xsl:when test="starts-with($value,'0x')">
350
<xsl:variable name="number">
351
<xsl:text>0000</xsl:text>
352
<xsl:value-of select="substring-after($value,'0x')"/>
354
<xsl:value-of select="substring(concat('000',$number),string-length($number),2)"/>
356
<xsl:when test="string-length($value)">
357
<xsl:variable name="number">
358
<xsl:call-template name="toHex">
359
<xsl:with-param name="decimalNumber" select="$value"/>
362
<xsl:value-of select="substring(concat('000',$number),string-length($number),2)"/>
365
<xsl:text>00</xsl:text>
370
<!-- generates a list of selected edges -->
371
<xsl:template name="printEdgeList">
372
<xsl:variable name="list">
373
<xsl:for-each select="default/edge">
374
<xsl:value-of select="@name"/>
375
<xsl:text> | </xsl:text>
378
<xsl:value-of select="substring($list,1,string-length($list) - 3)"/>
381
<!-- prints the key path for an option -->
382
<xsl:template name="printKey">
383
<xsl:value-of select="$appName"/>
385
<xsl:when test="ancestor::plugin">
386
<xsl:text>/plugins/</xsl:text>
387
<xsl:value-of select="ancestor::plugin/@name"/>
390
<xsl:text>/general</xsl:text>
393
<xsl:text>/screen0/options/</xsl:text>
394
<xsl:value-of select="@name"/>
397
<!-- converts a decimal number to a hex number -->
398
<xsl:variable name="hexDigits" select="'0123456789abcdef'" />
400
<xsl:template name="toHex">
401
<xsl:param name="decimalNumber" />
402
<xsl:if test="$decimalNumber >= 16">
403
<xsl:call-template name="toHex">
404
<xsl:with-param name="decimalNumber" select="floor($decimalNumber div 16)" />
407
<xsl:value-of select="substring($hexDigits, ($decimalNumber mod 16) + 1, 1)" />