~compiz-team/compiz-core/compiz-core.stack_sync_fix

« back to all changes in this revision

Viewing changes to xslt/compiz_gsettings_schemas.xslt.in

Merge:  lp:~andyrock/compiz-core/fix-832631

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
<!--
 
2
  Copyright © 2007 Dennis Kasprzyk
 
3
  Copyright © 2011 Canonical Ltd.
 
4
 
 
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
 
14
  implied warranty.
 
15
 
 
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.
 
23
 
 
24
  Authors: Dennis Kasprzyk <onestone@deltatauchi.de>
 
25
  Authors: Sam Spilsbury <sam.spilsbury@canonical.com>
 
26
-->
 
27
 
 
28
<xsl:stylesheet version='1.0' xmlns:xsl='http://www.w3.org/1999/XSL/Transform' >
 
29
  <xsl:output method="xml" indent="yes"/>
 
30
 
 
31
  <xsl:param name="appName">/apps/compiz-1</xsl:param>
 
32
 
 
33
  <xsl:template  match="/compiz">
 
34
    <xsl:element name="schemalist">
 
35
    <xsl:for-each select="/compiz/plugin/options">
 
36
      <xsl:call-template name="genGSettingsSchema"/>
 
37
    </xsl:for-each>
 
38
    </xsl:element>
 
39
  </xsl:template>
 
40
 
 
41
  <xsl:template name="genGSettingsSchema">
 
42
    <!--xsl:param name="schemaPath">
 
43
      <xsl:call-template name="printPath"/>
 
44
    </xsl:param-->
 
45
    <xsl:param name="schemaId">
 
46
      <xsl:call-template name="printId"/>
 
47
    </xsl:param>
 
48
    <!-- two levels of indentation: group and subgroup>= -->
 
49
    <xsl:element name="schema">
 
50
      <xsl:attribute name="id">
 
51
          <xsl:value-of select="$schemaId"/>
 
52
      </xsl:attribute>
 
53
      <!--xsl:attribute name="path">
 
54
        <xsl:value-of select="$schemaPath"/>
 
55
      </xsl:attribute-->
 
56
      <xsl:attribute name="gettext-domain">
 
57
        <xsl:text>@GETTEXT_PACKAGE@</xsl:text>
 
58
      </xsl:attribute>
 
59
      <xsl:for-each select="/compiz//options//option[not(@read_only='true') and not(@type='action')]">
 
60
        <xsl:call-template name="dumpOption"/>
 
61
      </xsl:for-each>
 
62
    </xsl:element>
 
63
  </xsl:template>
 
64
 
 
65
  <!-- generates the schema for an option -->
 
66
  <xsl:template name="dumpOption">
 
67
    <xsl:param name="keyType">
 
68
      <xsl:call-template name="printType"/>
 
69
    </xsl:param>
 
70
    <xsl:param name="keyKeyName">
 
71
      <xsl:call-template name="printKeyName"/>
 
72
    </xsl:param>
 
73
    <xsl:param name="keySummary">
 
74
      <xsl:call-template name="printSummary"/>
 
75
    </xsl:param>
 
76
    <xsl:param name="keyDescription">
 
77
      <xsl:call-template name="printDescription"/>
 
78
    </xsl:param>
 
79
    <xsl:element name="key">
 
80
      <xsl:attribute name="type">
 
81
        <xsl:value-of select="$keyType"/>
 
82
      </xsl:attribute>
 
83
      <xsl:attribute name="name">
 
84
        <xsl:value-of select="$keyKeyName"/>
 
85
      </xsl:attribute>
 
86
      <xsl:choose>
 
87
        <!-- color values need a special handling -->
 
88
        <xsl:when test="@type = 'color'">
 
89
          <xsl:element name="default">
 
90
            <xsl:choose>
 
91
              <xsl:when test="default">
 
92
                <xsl:for-each select="default[1]">
 
93
                  <xsl:call-template name="printColor"/>
 
94
                </xsl:for-each>
 
95
              </xsl:when>
 
96
              <xsl:otherwise>
 
97
                <xsl:text>'#000000ff'</xsl:text>
 
98
              </xsl:otherwise>
 
99
            </xsl:choose>
 
100
          </xsl:element>
 
101
        </xsl:when>
 
102
        <xsl:when test="@type = 'edge'">
 
103
          <xsl:element name="default">
 
104
            <xsl:call-template name="printEdgeList"/>
 
105
          </xsl:element>
 
106
        </xsl:when>
 
107
        <xsl:when test="@type = 'list'">
 
108
          <xsl:choose>
 
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>
 
114
              </xsl:element>
 
115
            </xsl:when>
 
116
            <xsl:otherwise>
 
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()"/>
 
121
                </xsl:call-template>
 
122
                <xsl:text>]</xsl:text>
 
123
              </xsl:element>
 
124
            </xsl:otherwise>
 
125
          </xsl:choose>
 
126
        </xsl:when>
 
127
        <!-- for most option types we can use the default value directly -->
 
128
        <xsl:otherwise>
 
129
          <xsl:element name="default">
 
130
            <!-- for non int and double option types we need to have
 
131
                 string markers -->
 
132
            <xsl:choose>
 
133
              <xsl:when test="contains('int,float,bool,bell', @type)"/>
 
134
              <xsl:otherwise>
 
135
                <xsl:text>'</xsl:text>
 
136
              </xsl:otherwise>
 
137
            </xsl:choose>
 
138
            <xsl:choose>
 
139
              <xsl:when test="default/text()">
 
140
                <xsl:value-of select="default/text()"/>
 
141
              </xsl:when>
 
142
              <xsl:otherwise>
 
143
                <!-- if no default value was specified we need to generate one -->
 
144
                <xsl:choose>
 
145
                  <xsl:when test="contains('bool,bell',@type)">
 
146
                    <xsl:text>false</xsl:text>
 
147
                  </xsl:when>
 
148
                  <xsl:when test="@type = 'int'">
 
149
                    <xsl:variable name="num">
 
150
                      <xsl:call-template name="printNumFallback"/>
 
151
                    </xsl:variable>
 
152
                    <xsl:value-of select="floor($num)"/>
 
153
                  </xsl:when>
 
154
                  <xsl:when test="@type = 'float'">
 
155
                    <xsl:call-template name="printNumFallback"/>
 
156
                  </xsl:when>
 
157
                  <xsl:when test="contains('key,button',@type)">
 
158
                    <xsl:text>Disabled</xsl:text>
 
159
                  </xsl:when>
 
160
                </xsl:choose>
 
161
              </xsl:otherwise>
 
162
            </xsl:choose>
 
163
            <!-- for non int and double option types we need to have
 
164
                 string markers -->
 
165
            <xsl:choose>
 
166
              <xsl:when test="contains('int,float,bool,bell', @type)"/>
 
167
              <xsl:otherwise>
 
168
                <xsl:text>'</xsl:text>
 
169
              </xsl:otherwise>
 
170
            </xsl:choose>
 
171
          </xsl:element>
 
172
        </xsl:otherwise>
 
173
      </xsl:choose>
 
174
      <!-- add the short and long descriptions -->
 
175
      <xsl:element name="summary">
 
176
        <xsl:value-of select="$keySummary"/>
 
177
      </xsl:element>
 
178
      <xsl:element name="description">
 
179
        <xsl:value-of select="$keyDescription"/>
 
180
      </xsl:element>
 
181
    </xsl:element>
 
182
  </xsl:template>
 
183
 
 
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"/>
 
188
    </xsl:param>
 
189
    <xsl:choose>
 
190
      <xsl:when test="$type = 'int'">
 
191
        <xsl:text>i</xsl:text>
 
192
      </xsl:when>
 
193
      <xsl:when test="$type = 'float'">
 
194
        <xsl:text>d</xsl:text>
 
195
      </xsl:when>
 
196
      <xsl:when test="$type = 'bool'">
 
197
        <xsl:text>b</xsl:text>
 
198
      </xsl:when>
 
199
      <xsl:when test="$type = 'bell'">
 
200
        <xsl:text>b</xsl:text>
 
201
      </xsl:when>
 
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()"/>
 
207
        </xsl:call-template>
 
208
      </xsl:when>
 
209
      <xsl:otherwise>
 
210
        <xsl:text>s</xsl:text>
 
211
      </xsl:otherwise>
 
212
    </xsl:choose>
 
213
  </xsl:template>
 
214
 
 
215
  <!-- prints the option long and short descriptions of an option -->
 
216
  <xsl:template name="printSummary">
 
217
    <xsl:value-of select="short/text()"/>
 
218
  </xsl:template>
 
219
 
 
220
  <xsl:template name="printDescription">
 
221
    <xsl:param name="info">
 
222
      <xsl:call-template name="printInfo"/>
 
223
    </xsl:param>
 
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"/>
 
228
  </xsl:template>
 
229
 
 
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>
 
235
      <xsl:choose>
 
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()"/>
 
238
        </xsl:when>
 
239
        <xsl:when test="@type='int' and desc/value/text()">
 
240
          <xsl:call-template name="printIntDescList"/>
 
241
        </xsl:when>
 
242
        <xsl:when test="@type = 'match'">
 
243
          <xsl:text>match</xsl:text>
 
244
        </xsl:when>
 
245
      </xsl:choose>
 
246
      <xsl:text>)</xsl:text>
 
247
    </xsl:variable>
 
248
    <xsl:if test="not(contains($info,' ()'))">
 
249
      <xsl:value-of select="$info"/>
 
250
    </xsl:if>
 
251
  </xsl:template>
 
252
 
 
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>
 
261
      </xsl:for-each>
 
262
    </xsl:variable>
 
263
    <xsl:value-of select="substring($list,1,string-length($list) - 2)"/>
 
264
  </xsl:template>
 
265
 
 
266
  <!-- generates a default number out of the min and max values -->
 
267
  <xsl:template name="printNumFallback">
 
268
    <xsl:choose>
 
269
      <xsl:when test="max/text() and min/text()">
 
270
        <xsl:value-of select="(max/text() + min/text()) div 2"/>
 
271
      </xsl:when>
 
272
      <xsl:when test="max/text() and not(min/text())">
 
273
        <xsl:value-of select="max/text()"/>
 
274
      </xsl:when>
 
275
      <xsl:when test="not(max/text()) and min/text()">
 
276
        <xsl:value-of select="min/text()"/>
 
277
      </xsl:when>
 
278
      <xsl:otherwise>0</xsl:otherwise>
 
279
    </xsl:choose>
 
280
  </xsl:template>
 
281
 
 
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">
 
287
        <xsl:choose>
 
288
          <xsl:when test="contains ('int,float,bool,bell', $listType)">
 
289
            <xsl:value-of select="text()"/>
 
290
            <xsl:text>,</xsl:text>
 
291
          </xsl:when>
 
292
          <xsl:otherwise>
 
293
            <xsl:text>'</xsl:text>
 
294
            <xsl:value-of select="text()"/>
 
295
            <xsl:text>'</xsl:text>
 
296
            <xsl:text>,</xsl:text>
 
297
          </xsl:otherwise>
 
298
        </xsl:choose>
 
299
      </xsl:for-each>
 
300
    </xsl:variable>
 
301
    <xsl:value-of select="substring($list,1,string-length($list) - 1)"/>
 
302
  </xsl:template>
 
303
 
 
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>
 
310
      </xsl:for-each>
 
311
    </xsl:variable>
 
312
    <xsl:value-of select="substring($list,1,string-length($list) - 1)"/>
 
313
  </xsl:template>
 
314
 
 
315
  <!--
 
316
    generates the #00aabbcc color value out of the compiz
 
317
    metadata color description
 
318
  -->
 
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()"/>
 
323
      </xsl:call-template>
 
324
    </xsl:variable>
 
325
    <xsl:variable name="green">
 
326
      <xsl:call-template name="getHexNum">
 
327
        <xsl:with-param name="value" select="green/text()"/>
 
328
      </xsl:call-template>
 
329
    </xsl:variable>
 
330
    <xsl:variable name="blue">
 
331
      <xsl:call-template name="getHexNum">
 
332
        <xsl:with-param name="value" select="blue/text()"/>
 
333
      </xsl:call-template>
 
334
    </xsl:variable>
 
335
    <xsl:variable name="alpha">
 
336
      <xsl:choose>
 
337
        <xsl:when test="alpha/text()">
 
338
          <xsl:call-template name="getHexNum">
 
339
            <xsl:with-param name="value" select="alpha/text()"/>
 
340
          </xsl:call-template>
 
341
        </xsl:when>
 
342
        <xsl:otherwise>
 
343
          <xsl:text>ff</xsl:text>
 
344
        </xsl:otherwise>
 
345
      </xsl:choose>
 
346
    </xsl:variable>
 
347
    <xsl:text>'</xsl:text>
 
348
    <xsl:value-of select="concat('#',concat($red,concat($green,concat($blue,$alpha))))"/>
 
349
    <xsl:text>'</xsl:text>
 
350
  </xsl:template>
 
351
 
 
352
  <!--
 
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
 
355
    range of 00 - ff
 
356
  -->
 
357
  <xsl:template name="getHexNum">
 
358
    <xsl:param name="value"/>
 
359
    <xsl:choose>
 
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')"/>
 
364
        </xsl:variable>
 
365
        <xsl:value-of select="substring(concat('000',$number),string-length($number),2)"/>
 
366
      </xsl:when>
 
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"/>
 
371
          </xsl:call-template>
 
372
        </xsl:variable>
 
373
        <xsl:value-of select="substring(concat('000',$number),string-length($number),2)"/>
 
374
      </xsl:when>
 
375
      <xsl:otherwise>
 
376
        <xsl:text>00</xsl:text>
 
377
      </xsl:otherwise>
 
378
    </xsl:choose>
 
379
  </xsl:template>
 
380
 
 
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>
 
387
      </xsl:for-each>
 
388
    </xsl:variable>
 
389
    <xsl:text>'</xsl:text>
 
390
    <xsl:value-of select="substring($list,1,string-length($list) - 3)"/>
 
391
    <xsl:text>'</xsl:text>
 
392
  </xsl:template>
 
393
 
 
394
  <!-- prints the path for an option -->
 
395
  <xsl:template name="printPath">
 
396
    <xsl:value-of select="$appName"/>
 
397
    <xsl:choose>
 
398
      <xsl:when test="ancestor::plugin">
 
399
        <xsl:text>/plugins/</xsl:text>
 
400
        <xsl:value-of select="ancestor::plugin/@name"/>
 
401
      </xsl:when>
 
402
      <xsl:otherwise>
 
403
        <xsl:text>/general</xsl:text>
 
404
      </xsl:otherwise>
 
405
    </xsl:choose>
 
406
    <xsl:text>/screen0/options/</xsl:text>
 
407
  </xsl:template>
 
408
 
 
409
  <!-- prints the schema id (in d-bus style) -->
 
410
  <xsl:template name="printId">
 
411
    <xsl:text>org.freedesktop.compiz</xsl:text>
 
412
    <xsl:choose>
 
413
      <xsl:when test="ancestor::plugin">
 
414
        <xsl:text>.</xsl:text>
 
415
        <xsl:value-of select="ancestor::plugin/@name"/>
 
416
      </xsl:when>
 
417
    </xsl:choose>
 
418
  </xsl:template>
 
419
 
 
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)"/>
 
426
  </xsl:template>
 
427
 
 
428
  <!-- converts a decimal number to a hex number -->
 
429
  <xsl:variable name="hexDigits" select="'0123456789abcdef'" />
 
430
 
 
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)" />
 
436
      </xsl:call-template>
 
437
    </xsl:if>
 
438
    <xsl:value-of select="substring($hexDigits, ($decimalNumber mod 16) + 1, 1)" />
 
439
  </xsl:template>
 
440
 
 
441
</xsl:stylesheet>