summaryrefslogtreecommitdiff
path: root/libxklavier/xklavier_config.c
blob: 2dfb695a15b11fea1d36f146723a55fbb127f4cb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
#include <errno.h>
#include <locale.h>
#include <stdio.h>
#include <string.h>
#include <sys/stat.h>

#include "config.h"

#include "xklavier_private.h"

static GObjectClass *parent_class = NULL;

static xmlXPathCompExprPtr models_xpath;
static xmlXPathCompExprPtr layouts_xpath;
static xmlXPathCompExprPtr option_groups_xpath;


#define XKBCR_MODEL_PATH "/xkbConfigRegistry/modelList/model"
#define XKBCR_LAYOUT_PATH "/xkbConfigRegistry/layoutList/layout"
#define XKBCR_VARIANT_PATH XKBCR_LAYOUT_PATH "/variantList/variant"
#define XKBCR_GROUP_PATH "/xkbConfigRegistry/optionList/group"
#define XKBCR_OPTION_PATH XKBCR_GROUP_PATH "/option"

#define LANG_ATTR "lang"

enum {
	PROP_0,
	PROP_ENGINE,
};

#define xkl_config_registry_is_initialized(config) \
  ( xkl_config_registry_priv(config,xpath_context) != NULL )

static xmlChar *
xkl_node_get_xml_lang_attr(xmlNodePtr nptr)
{
	if (nptr->properties != NULL &&
	    !g_ascii_strcasecmp(LANG_ATTR, (char *) nptr->properties[0].name)
	    && nptr->properties[0].ns != NULL
	    && !g_ascii_strcasecmp("xml",
				   (char *) nptr->properties[0].ns->prefix)
	    && nptr->properties[0].children != NULL)
		return nptr->properties[0].children->content;
	else
		return NULL;
}

static gboolean
xkl_read_config_item(XklConfigRegistry * config, xmlNodePtr iptr,
		     XklConfigItem * item)
{
	xmlNodePtr name_element, nptr, ptr;
	xmlNodePtr desc_element = NULL, short_desc_element = NULL;
	xmlNodePtr nt_desc_element = NULL, nt_short_desc_element = NULL;

	gint max_desc_priority = -1;
	gint max_short_desc_priority = -1;

	*item->name = 0;
	*item->short_description = 0;
	*item->description = 0;
	if (iptr->type != XML_ELEMENT_NODE)
		return FALSE;
	ptr = iptr->children;
	while (ptr != NULL) {
		switch (ptr->type) {
		case XML_ELEMENT_NODE:
			if (!g_ascii_strcasecmp
			    ((char *) ptr->name, "configItem"))
				break;
			return FALSE;
		case XML_TEXT_NODE:
		case XML_COMMENT_NODE:
			ptr = ptr->next;
			continue;
		default:
			return FALSE;
		}
		break;
	}
	if (ptr == NULL)
		return FALSE;

	nptr = ptr->children;

	if (nptr->type == XML_TEXT_NODE)
		nptr = nptr->next;
	name_element = nptr;
	nptr = nptr->next;

	while (nptr != NULL) {
		char *node_name = (char *) nptr->name;
		if (nptr->type != XML_TEXT_NODE) {
			xmlChar *lang = xkl_node_get_xml_lang_attr(nptr);

			if (lang != NULL) {
				gint priority =
				    xkl_get_language_priority((gchar *)
							      lang);

				/*
				 * Find desc/shortdesc with highest priority
				 */
				if (!g_ascii_strcasecmp(node_name,
							"description") &&
				    (priority > max_desc_priority)) {
					desc_element = nptr;
					max_desc_priority = priority;
				} else if (!g_ascii_strcasecmp(node_name,
							       "shortDescription")
					   && (priority >
					       max_short_desc_priority)) {
					short_desc_element = nptr;
					max_short_desc_priority = priority;
				}
			} else	// no language specified!
			{
				if (!g_ascii_strcasecmp
				    (node_name, "description"))
					nt_desc_element = nptr;
				else if (!g_ascii_strcasecmp
					 (node_name, "shortDescription"))
					nt_short_desc_element = nptr;
			}
		}
		nptr = nptr->next;
	}

	/* if no language-specific description found - use the ones without lang */
	if (desc_element == NULL)
		desc_element = nt_desc_element;

	if (short_desc_element == NULL)
		short_desc_element = nt_short_desc_element;

	/*
	 * Actually, here we should have some code to find 
	 * the correct localized description...
	 */

	if (name_element != NULL && name_element->children != NULL)
		strncat(item->name,
			(char *) name_element->children->content,
			XKL_MAX_CI_NAME_LENGTH - 1);

	if (short_desc_element != NULL
	    && short_desc_element->children != NULL) {
		gchar *lmsg = xkl_locale_from_utf8(config, (const gchar *)
						   short_desc_element->
						   children->content);
		strncat(item->short_description, lmsg,
			XKL_MAX_CI_SHORT_DESC_LENGTH - 1);
		g_free(lmsg);
	}

	if (desc_element != NULL && desc_element->children != NULL) {
		gchar *lmsg = xkl_locale_from_utf8(config,
						   (const gchar *)
						   desc_element->children->
						   content);
		strncat(item->description, lmsg,
			XKL_MAX_CI_DESC_LENGTH - 1);
		g_free(lmsg);
	}
	return TRUE;
}

static void
xkl_config_registry_foreach_in_nodeset(XklConfigRegistry * config,
				       xmlNodeSetPtr nodes,
				       ConfigItemProcessFunc func,
				       gpointer data)
{
	gint i;
	if (nodes != NULL) {
		xmlNodePtr *pnode = nodes->nodeTab;
		XklConfigItem *ci = xkl_config_item_new();
		for (i = nodes->nodeNr; --i >= 0;) {
			if (xkl_read_config_item(config, *pnode, ci))
				func(config, ci, data);

			pnode++;
		}
		g_object_unref(G_OBJECT(ci));
	}
}

static void
xkl_config_registry_foreach_in_xpath(XklConfigRegistry * config,
				     xmlXPathCompExprPtr xpath_comp_expr,
				     ConfigItemProcessFunc func,
				     gpointer data)
{
	xmlXPathObjectPtr xpath_obj;

	if (!xkl_config_registry_is_initialized(config))
		return;
	xpath_obj = xmlXPathCompiledEval(xpath_comp_expr,
					 xkl_config_registry_priv(config,
								  xpath_context));
	if (xpath_obj != NULL) {
		xkl_config_registry_foreach_in_nodeset(config,
						       xpath_obj->
						       nodesetval, func,
						       data);
		xmlXPathFreeObject(xpath_obj);
	}
}

static void
xkl_config_registry_foreach_in_xpath_with_param(XklConfigRegistry * config,
						const gchar * format,
						const gchar * value,
						ConfigItemProcessFunc func,
						gpointer data)
{
	char xpath_expr[1024];
	xmlXPathObjectPtr xpath_obj;

	if (!xkl_config_registry_is_initialized(config))
		return;
	snprintf(xpath_expr, sizeof xpath_expr, format, value);
	xpath_obj = xmlXPathEval((unsigned char *) xpath_expr,
				 xkl_config_registry_priv(config,
							  xpath_context));
	if (xpath_obj != NULL) {
		xkl_config_registry_foreach_in_nodeset(config,
						       xpath_obj->
						       nodesetval, func,
						       data);
		xmlXPathFreeObject(xpath_obj);
	}
}

static gboolean
xkl_config_registry_find_object(XklConfigRegistry * config,
				const gchar * format, const gchar * arg1,
				XklConfigItem * pitem /* in/out */ ,
				xmlNodePtr * pnode /* out */ )
{
	xmlXPathObjectPtr xpath_obj;
	xmlNodeSetPtr nodes;
	gboolean rv = FALSE;
	gchar xpath_expr[1024];

	if (!xkl_config_registry_is_initialized(config))
		return FALSE;

	snprintf(xpath_expr, sizeof xpath_expr, format, arg1, pitem->name);
	xpath_obj = xmlXPathEval((unsigned char *) xpath_expr,
				 xkl_config_registry_priv(config,
							  xpath_context));
	if (xpath_obj == NULL)
		return FALSE;

	nodes = xpath_obj->nodesetval;
	if (nodes != NULL && nodes->nodeTab != NULL) {
		rv = xkl_read_config_item(config, *nodes->nodeTab, pitem);
		if (pnode != NULL) {
			*pnode = *nodes->nodeTab;
		}
	}

	xmlXPathFreeObject(xpath_obj);
	return rv;
}

gchar *
xkl_config_rec_merge_layouts(const XklConfigRec * data)
{
	return xkl_strings_concat_comma_separated(data->layouts);
}

gchar *
xkl_config_rec_merge_variants(const XklConfigRec * data)
{
	return xkl_strings_concat_comma_separated(data->variants);
}

gchar *
xkl_config_rec_merge_options(const XklConfigRec * data)
{
	return xkl_strings_concat_comma_separated(data->options);
}

gchar *
xkl_strings_concat_comma_separated(gchar ** array)
{
	if (array) {
		return g_strjoinv(",", array);
	} else {
		return g_strdup("");
	}
}

void
xkl_config_rec_split_layouts(XklConfigRec * data, const gchar * merged)
{
	xkl_strings_split_comma_separated(&data->layouts, merged);
}

void
xkl_config_rec_split_variants(XklConfigRec * data, const gchar * merged)
{
	xkl_strings_split_comma_separated(&data->variants, merged);
}

void
xkl_config_rec_split_options(XklConfigRec * data, const gchar * merged)
{
	xkl_strings_split_comma_separated(&data->options, merged);
}

void
xkl_strings_split_comma_separated(gchar *** array, const gchar * merged)
{
	*array = g_strsplit(merged, ",", 0);
}

gchar *
xkl_engine_get_ruleset_name(XklEngine * engine,
			    const gchar default_ruleset[])
{
	static gchar rules_set_name[1024] = "";
	if (!rules_set_name[0]) {
		/* first call */
		gchar *rf = NULL;
		if (!xkl_config_rec_get_from_root_window_property
		    (NULL, xkl_engine_priv(engine, base_config_atom), &rf,
		     engine) || (rf == NULL)) {
			g_strlcpy(rules_set_name, default_ruleset,
				  sizeof rules_set_name);
			xkl_debug(100, "Using default rules set: [%s]\n",
				  rules_set_name);
			return rules_set_name;
		}
		g_strlcpy(rules_set_name, rf, sizeof rules_set_name);
		g_free(rf);
	}
	xkl_debug(100, "Rules set: [%s]\n", rules_set_name);
	return rules_set_name;
}

XklConfigRegistry *
xkl_config_registry_get_instance(XklEngine * engine)
{
	XklConfigRegistry *config;

	if (!engine) {
		xkl_debug(10,
			  "xkl_config_registry_get_instance : engine is NULL ?\n");
		return NULL;
	}

	config =
	    XKL_CONFIG_REGISTRY(g_object_new
				(xkl_config_registry_get_type(), "engine",
				 engine, NULL));

	return config;
}

static void
xkl_config_registry_clean_languages_in_xpath(XklConfigRegistry * config,
					     gchar * xpath_expr)
{
	xmlXPathObjectPtr xpath_obj =
	    xmlXPathEval((unsigned char *) xpath_expr,
			 xkl_config_registry_priv(config,
						  xpath_context));
	if (xpath_obj != NULL && xpath_obj->nodesetval != NULL) {
		xmlNodePtr *pnode = xpath_obj->nodesetval->nodeTab;
		gint i;

		for (i = xpath_obj->nodesetval->nodeNr; --i >= 0;) {
			/* 
			 * TODO - drop description subnodes 
			 * for irrelevant languages
			 */
			pnode++;
		}
		xmlXPathFreeObject(xpath_obj);
	}
}

static void
xkl_config_registry_clean_languages(XklConfigRegistry * config)
{
	xkl_config_registry_clean_languages_in_xpath(config,
						     XKBCR_MODEL_PATH);
	xkl_config_registry_clean_languages_in_xpath(config,
						     XKBCR_LAYOUT_PATH);
	xkl_config_registry_clean_languages_in_xpath(config,
						     XKBCR_VARIANT_PATH);
	xkl_config_registry_clean_languages_in_xpath(config,
						     XKBCR_GROUP_PATH);
	xkl_config_registry_clean_languages_in_xpath(config,
						     XKBCR_OPTION_PATH);
}

gboolean
xkl_config_registry_load_from_file(XklConfigRegistry * config,
				   const gchar * file_name)
{
	xkl_config_registry_priv(config, doc) = xmlParseFile(file_name);
	if (xkl_config_registry_priv(config, doc) == NULL) {
		xkl_config_registry_priv(config, xpath_context) = NULL;
		xkl_last_error_message =
		    "Could not parse XKB configuration registry";
		return FALSE;
	}
	xkl_config_registry_priv(config, xpath_context) =
	    xmlXPathNewContext(xkl_config_registry_priv(config, doc));

	xkl_config_registry_clean_languages(config);

	return TRUE;
}

void
xkl_config_registry_free(XklConfigRegistry * config)
{
	if (xkl_config_registry_is_initialized(config)) {
		xmlXPathFreeContext(xkl_config_registry_priv
				    (config, xpath_context));
		xmlFreeDoc(xkl_config_registry_priv(config, doc));
		xkl_config_registry_priv(config, xpath_context) = NULL;
		xkl_config_registry_priv(config, doc) = NULL;
	}
}

void
xkl_config_registry_foreach_model(XklConfigRegistry * config,
				  ConfigItemProcessFunc func,
				  gpointer data)
{
	xkl_config_registry_foreach_in_xpath(config, models_xpath, func,
					     data);
}

void
xkl_config_registry_foreach_layout(XklConfigRegistry * config,
				   ConfigItemProcessFunc func,
				   gpointer data)
{
	xkl_config_registry_foreach_in_xpath(config, layouts_xpath, func,
					     data);
}

void
xkl_config_registry_foreach_layout_variant(XklConfigRegistry * config,
					   const gchar * layout_name,
					   ConfigItemProcessFunc func,
					   gpointer data)
{
	xkl_config_registry_foreach_in_xpath_with_param
	    (config,
	     XKBCR_VARIANT_PATH "[../../configItem/name = '%s']",
	     layout_name, func, data);
}

void
xkl_config_registry_foreach_option_group(XklConfigRegistry * config,
					 ConfigItemProcessFunc func,
					 gpointer data)
{
	xmlXPathObjectPtr xpath_obj;
	gint i;

	if (!xkl_config_registry_is_initialized(config))
		return;
	xpath_obj =
	    xmlXPathCompiledEval(option_groups_xpath,
				 xkl_config_registry_priv(config,
							  xpath_context));
	if (xpath_obj != NULL) {
		xmlNodeSetPtr nodes = xpath_obj->nodesetval;
		xmlNodePtr *pnode = nodes->nodeTab;
		XklConfigItem *ci = xkl_config_item_new();
		for (i = nodes->nodeNr; --i >= 0;) {

			if (xkl_read_config_item(config, *pnode, ci)) {
				gboolean allow_multisel = TRUE;
				xmlChar *sallow_multisel =
				    xmlGetProp(*pnode,
					       (unsigned char *)
					       XCI_PROP_ALLOW_MULTIPLE_SELECTION);
				if (sallow_multisel != NULL) {
					allow_multisel =
					    !g_ascii_strcasecmp("true",
								(char *)
								sallow_multisel);
					xmlFree(sallow_multisel);
					g_object_set_data(G_OBJECT(ci),
							  XCI_PROP_ALLOW_MULTIPLE_SELECTION,
							  GINT_TO_POINTER
							  (allow_multisel));
				}

				func(config, ci, data);
			}

			pnode++;
		}
		g_object_unref(G_OBJECT(ci));
		xmlXPathFreeObject(xpath_obj);
	}
}

void
xkl_config_registry_foreach_option(XklConfigRegistry * config,
				   const gchar * option_group_name,
				   ConfigItemProcessFunc func,
				   gpointer data)
{
	xkl_config_registry_foreach_in_xpath_with_param
	    (config,
	     XKBCR_OPTION_PATH "[../configItem/name = '%s']",
	     option_group_name, func, data);
}

gboolean
xkl_config_registry_find_model(XklConfigRegistry * config,
			       XklConfigItem * pitem /* in/out */ )
{
	return
	    xkl_config_registry_find_object
	    (config,
	     XKBCR_MODEL_PATH "[configItem/name = '%s%s']",
	     "", pitem, NULL);
}

gboolean
xkl_config_registry_find_layout(XklConfigRegistry * config,
				XklConfigItem * pitem /* in/out */ )
{
	return
	    xkl_config_registry_find_object
	    (config,
	     XKBCR_LAYOUT_PATH "[configItem/name = '%s%s']",
	     "", pitem, NULL);
}

gboolean
xkl_config_registry_find_variant(XklConfigRegistry * config,
				 const char *layout_name,
				 XklConfigItem * pitem /* in/out */ )
{
	return
	    xkl_config_registry_find_object
	    (config,
	     XKBCR_VARIANT_PATH
	     "[../../configItem/name = '%s' and configItem/name = '%s']",
	     layout_name, pitem, NULL);
}

gboolean
xkl_config_registry_find_option_group(XklConfigRegistry * config,
				      XklConfigItem * pitem /* in/out */ )
{
	xmlNodePtr node = NULL;
	gboolean rv = xkl_config_registry_find_object(config,
						      XKBCR_GROUP_PATH
						      "[configItem/name = '%s%s']",
						      "",
						      pitem, &node);

	if (rv) {
		xmlChar *val = xmlGetProp(node,
					  (unsigned char *)
					  XCI_PROP_ALLOW_MULTIPLE_SELECTION);
		if (val != NULL) {
			gboolean allow_multisel =
			    !g_ascii_strcasecmp("true", (char *) val);
			g_object_set_data(G_OBJECT(pitem),
					  XCI_PROP_ALLOW_MULTIPLE_SELECTION,
					  GINT_TO_POINTER(allow_multisel));
			xmlFree(val);
		}
	}
	return rv;
}

gboolean
xkl_config_registry_find_option(XklConfigRegistry * config,
				const char *option_group_name,
				XklConfigItem * pitem /* in/out */ )
{
	return
	    xkl_config_registry_find_object
	    (config, XKBCR_OPTION_PATH
	     "[../configItem/name = '%s' and configItem/name = '%s']",
	     option_group_name, pitem, NULL);
}

/*
 * Calling through vtable
 */
gboolean
xkl_config_rec_activate(const XklConfigRec * data, XklEngine * engine)
{
	xkl_engine_ensure_vtable_inited(engine);
	return xkl_engine_vcall(engine, activate_config_rec) (engine,
							      data);
}

gboolean
xkl_config_registry_load(XklConfigRegistry * config)
{
	XklEngine *engine;

	xkl_config_registry_free(config);
	engine = xkl_config_registry_get_engine(config);
	xkl_engine_ensure_vtable_inited(engine);
	return xkl_engine_vcall(engine, load_config_registry) (config);
}

gboolean
xkl_config_rec_write_to_file(XklEngine * engine, const gchar * file_name,
			     const XklConfigRec * data,
			     const gboolean binary)
{
	if ((!binary &&
	     !(xkl_engine_priv(engine, features) &
	       XKLF_CAN_OUTPUT_CONFIG_AS_ASCII))
	    || (binary
		&& !(xkl_engine_priv(engine, features) &
		     XKLF_CAN_OUTPUT_CONFIG_AS_BINARY))) {
		xkl_last_error_message =
		    "Function not supported at backend";
		return FALSE;
	}
	xkl_engine_ensure_vtable_inited(engine);
	return xkl_engine_vcall(engine, write_config_rec_to_file) (engine,
								   file_name,
								   data,
								   binary);
}

void
xkl_config_rec_dump(FILE * file, XklConfigRec * data)
{
	int j;
	fprintf(file, "  model: [%s]\n", data->model);

	fprintf(file, "  layouts:\n");
#define OUTPUT_ARRZ(arrz) \
  { \
    gchar **p = data->arrz; \
    fprintf( file, "  " #arrz ":\n" ); \
    if ( p != NULL ) \
      for( j = 0; *p != NULL; ) \
        fprintf( file, "  %d: [%s]\n", j++, *p++ ); \
  }
	OUTPUT_ARRZ(layouts);
	OUTPUT_ARRZ(variants);
	OUTPUT_ARRZ(options);

}

G_DEFINE_TYPE(XklConfigRegistry, xkl_config_registry, G_TYPE_OBJECT)
static GObject *
xkl_config_registry_constructor(GType type,
				guint
				n_construct_properties,
				GObjectConstructParam *
				construct_properties)
{
	GObject *obj;
	XklConfigRegistry *config;
	XklEngine *engine;

	{
		/* Invoke parent constructor. */
		XklConfigRegistryClass *klass;
		klass =
		    XKL_CONFIG_REGISTRY_CLASS(g_type_class_peek
					      (XKL_TYPE_CONFIG_REGISTRY));
		obj =
		    parent_class->constructor(type, n_construct_properties,
					      construct_properties);
	}

	config = XKL_CONFIG_REGISTRY(obj);

	engine = XKL_ENGINE(g_value_peek_pointer
			    (construct_properties[0].value));
	xkl_config_registry_get_engine(config) = engine;

	xkl_engine_ensure_vtable_inited(engine);
	xkl_engine_vcall(engine, init_config_registry) (config);

	return obj;
}

static void
xkl_config_registry_init(XklConfigRegistry * config)
{
	config->priv = g_new0(XklConfigRegistryPrivate, 1);
}

static void
xkl_config_registry_set_property(GObject * object,
				 guint property_id,
				 const GValue * value, GParamSpec * pspec)
{
}

static void
xkl_config_registry_get_property(GObject * object,
				 guint property_id,
				 GValue * value, GParamSpec * pspec)
{
	XklConfigRegistry *config = XKL_CONFIG_REGISTRY(object);

	switch (property_id) {
	case PROP_ENGINE:
		g_value_set_pointer(value,
				    xkl_config_registry_get_engine
				    (config));
		break;
	}

}

static void
xkl_config_registry_finalize(GObject * obj)
{
	XklConfigRegistry *config = (XklConfigRegistry *) obj;

	xkl_config_registry_free(config);

	g_free(config->priv);

	G_OBJECT_CLASS(parent_class)->finalize(obj);
}

/* 
 * This function is actually NEVER called.
 * It is 'extern' just to avoid the compilation warnings
 * TODO: add class cleanup
 */
extern void
xkl_config_registry_class_term(XklConfigRegistryClass * klass)
{
	if (models_xpath != NULL) {
		xmlXPathFreeCompExpr(models_xpath);
		models_xpath = NULL;
	}
	if (layouts_xpath != NULL) {
		xmlXPathFreeCompExpr(layouts_xpath);
		layouts_xpath = NULL;
	}
	if (option_groups_xpath != NULL) {
		xmlXPathFreeCompExpr(option_groups_xpath);
		option_groups_xpath = NULL;
	}
}

static void
xkl_config_registry_class_init(XklConfigRegistryClass * klass)
{
	GObjectClass *object_class;
	GParamSpec *engine_param_spec;

	object_class = (GObjectClass *) klass;
	parent_class = g_type_class_peek_parent(object_class);
	object_class->constructor = xkl_config_registry_constructor;
	object_class->finalize = xkl_config_registry_finalize;
	object_class->set_property = xkl_config_registry_set_property;
	object_class->get_property = xkl_config_registry_get_property;

	engine_param_spec = g_param_spec_object("engine",
						"Engine",
						"XklEngine",
						XKL_TYPE_ENGINE,
						G_PARAM_CONSTRUCT_ONLY
						| G_PARAM_READWRITE);

	g_object_class_install_property(object_class,
					PROP_ENGINE, engine_param_spec);

	/* static stuff initialized */

	xmlXPathInit();
	models_xpath = xmlXPathCompile((unsigned char *)
				       XKBCR_MODEL_PATH);
	layouts_xpath = xmlXPathCompile((unsigned char *)
					XKBCR_LAYOUT_PATH);
	option_groups_xpath = xmlXPathCompile((unsigned char *)
					      XKBCR_GROUP_PATH);
	xkl_i18n_init();
}