diff options
author | Sergey Udaltsov <svu@gnome.org> | 2006-03-04 01:52:17 +0000 |
---|---|---|
committer | Sergey Udaltsov <svu@gnome.org> | 2006-03-04 01:52:17 +0000 |
commit | 8a21e56ad75b3a42cdf21e571ce24f564c0c9ec8 (patch) | |
tree | 6273bd853f66b873cad9e5a1331e78715f3dafa5 | |
parent | 9139a74836fe34b3a494868943c2add6f28dbbbb (diff) | |
download | libxklavier-8a21e56ad75b3a42cdf21e571ce24f564c0c9ec8.tar.gz |
XklConfigRegistry constructor is proper now - with parameters
-rw-r--r-- | libxklavier/xkl_config_registry.h | 2 | ||||
-rw-r--r-- | libxklavier/xklavier.c | 19 | ||||
-rw-r--r-- | libxklavier/xklavier_config.c | 137 | ||||
-rw-r--r-- | libxklavier/xklavier_private.h | 2 |
4 files changed, 118 insertions, 42 deletions
diff --git a/libxklavier/xkl_config_registry.h b/libxklavier/xkl_config_registry.h index b13d24b..9c9ba1f 100644 --- a/libxklavier/xkl_config_registry.h +++ b/libxklavier/xkl_config_registry.h @@ -21,7 +21,7 @@ extern "C" { #define XKL_TYPE_CONFIG_REGISTRY (xkl_config_registry_get_type ()) #define XKL_CONFIG_REGISTRY(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), XKL_TYPE_CONFIG_REGISTRY, XklConfigRegistry)) -#define XKL_CONFIG_REGISTRY_CLASS(obj) (G_TYPE_CHECK_CLASS_CAST ((obj), XKL_CONFIG_REGISTRY, XklConfigRegistryClass)) +#define XKL_CONFIG_REGISTRY_CLASS(obj) (G_TYPE_CHECK_CLASS_CAST ((obj), XKL_TYPE_CONFIG_REGISTRY, XklConfigRegistryClass)) #define XKL_IS_CONFIG_REGISTRY(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), XKL_TYPE_CONFIG_REGISTRY)) #define XKL_IS_CONFIG_REGISTRY_CLASS(obj) (G_TYPE_CHECK_CLASS_TYPE ((obj), XKL_TYPE_CONFIG_REGISTRY)) #define XKL_CONFIG_REGISTRY_GET_CLASS (G_TYPE_INSTANCE_GET_CLASS ((obj), XKL_TYPE_CONFIG_REGISTRY, XklConfigRegistryClass)) diff --git a/libxklavier/xklavier.c b/libxklavier/xklavier.c index cbe8ab6..1c4d42d 100644 --- a/libxklavier/xklavier.c +++ b/libxklavier/xklavier.c @@ -674,13 +674,6 @@ static void xkl_engine_init(XklEngine * engine) { engine->priv = g_new0(XklEnginePrivate, 1); - - const gchar *sdl = g_getenv("XKL_DEBUG"); - - if (sdl != NULL) { - xkl_set_debug_level(atoi(sdl)); - } - } static void @@ -695,9 +688,7 @@ xkl_engine_get_property(GObject * object, guint property_id, GValue * value, GParamSpec * pspec) { - XklEngine *engine; - - engine = XKL_ENGINE(object); + XklEngine *engine = XKL_ENGINE(object); switch (property_id) { case PROP_DISPLAY: @@ -840,4 +831,12 @@ xkl_engine_class_init(XklEngineClass * klass) g_object_class_install_property(object_class, PROP_INDICATORS_HANDLING, indicators_handling_param_spec); + + /* static stuff initialized */ + + const gchar *sdl = g_getenv("XKL_DEBUG"); + + if (sdl != NULL) { + xkl_set_debug_level(atoi(sdl)); + } } diff --git a/libxklavier/xklavier_config.c b/libxklavier/xklavier_config.c index bd63fab..d9acd47 100644 --- a/libxklavier/xklavier_config.c +++ b/libxklavier/xklavier_config.c @@ -16,8 +16,13 @@ static xmlXPathCompExprPtr models_xpath; static xmlXPathCompExprPtr layouts_xpath; static xmlXPathCompExprPtr option_groups_xpath; +enum { + PROP_0, + PROP_ENGINE, +}; + #define xkl_config_registry_is_initialized(config) \ - ( xkl_config_priv(config,xpath_context) != NULL ) + ( xkl_config_registry_priv(config,xpath_context) != NULL ) static xmlChar * xkl_node_get_xml_lang_attr(xmlNodePtr nptr) @@ -179,8 +184,8 @@ xkl_config_registry_enum_simple(XklConfigRegistry * config, if (!xkl_config_registry_is_initialized(config)) return; xpath_obj = xmlXPathCompiledEval(xpath_comp_expr, - xkl_config_priv(config, - xpath_context)); + xkl_config_registry_priv(config, + xpath_context)); if (xpath_obj != NULL) { xkl_config_registry_enum_from_node_set(config, xpath_obj-> @@ -202,7 +207,8 @@ xkl_config_registry_enum_direct(XklConfigRegistry * config, return; snprintf(xpath_expr, sizeof xpath_expr, format, value); xpath_obj = xmlXPathEval((unsigned char *) xpath_expr, - xkl_config_priv(config, xpath_context)); + xkl_config_registry_priv(config, + xpath_context)); if (xpath_obj != NULL) { xkl_config_registry_enum_from_node_set(config, xpath_obj-> @@ -228,7 +234,8 @@ xkl_config_registry_find_object(XklConfigRegistry * config, snprintf(xpath_expr, sizeof xpath_expr, format, arg1, pitem->name); xpath_obj = xmlXPathEval((unsigned char *) xpath_expr, - xkl_config_priv(config, xpath_context)); + xkl_config_registry_priv(config, + xpath_context)); if (xpath_obj == NULL) return FALSE; @@ -333,21 +340,8 @@ xkl_config_registry_get_instance(XklEngine * engine) the_config = XKL_CONFIG_REGISTRY(g_object_new - (xkl_config_registry_get_type(), NULL)); - - xkl_config_priv(the_config, engine) = engine; - - xmlXPathInit(); - models_xpath = xmlXPathCompile((unsigned char *) - "/xkbConfigRegistry/modelList/model"); - layouts_xpath = xmlXPathCompile((unsigned char *) - "/xkbConfigRegistry/layoutList/layout"); - option_groups_xpath = xmlXPathCompile((unsigned char *) - "/xkbConfigRegistry/optionList/group"); - xkl_i18n_init(); - - xkl_engine_ensure_vtable_inited(engine); - xkl_engine_vcall(engine, init_config_registry) (the_config); + (xkl_config_registry_get_type(), "engine", + engine, NULL)); return the_config; } @@ -356,14 +350,15 @@ gboolean xkl_config_registry_load_from_file(XklConfigRegistry * config, const gchar * file_name) { - xkl_config_priv(config, doc) = xmlParseFile(file_name); - if (xkl_config_priv(config, doc) == NULL) { - xkl_config_priv(config, xpath_context) = NULL; + 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"; } else - xkl_config_priv(config, xpath_context) = - xmlXPathNewContext(xkl_config_priv(config, doc)); + xkl_config_registry_priv(config, xpath_context) = + xmlXPathNewContext(xkl_config_registry_priv + (config, doc)); return xkl_config_registry_is_initialized(config); } @@ -371,11 +366,11 @@ void xkl_config_registry_free(XklConfigRegistry * config) { if (xkl_config_registry_is_initialized(config)) { - xmlXPathFreeContext(xkl_config_priv + xmlXPathFreeContext(xkl_config_registry_priv (config, xpath_context)); - xmlFreeDoc(xkl_config_priv(config, doc)); - xkl_config_priv(config, xpath_context) = NULL; - xkl_config_priv(config, doc) = NULL; + xmlFreeDoc(xkl_config_registry_priv(config, doc)); + xkl_config_registry_priv(config, xpath_context) = NULL; + xkl_config_registry_priv(config, doc) = NULL; } } @@ -417,7 +412,8 @@ xkl_config_registry_enum_option_groups(XklConfigRegistry * config, return; xpath_obj = xmlXPathCompiledEval(option_groups_xpath, - xkl_config_priv(config, xpath_context)); + xkl_config_registry_priv(config, + xpath_context)); if (xpath_obj != NULL) { xmlNodeSetPtr nodes = xpath_obj->nodesetval; xmlNodePtr *pnode = nodes->nodeTab; @@ -595,6 +591,38 @@ xkl_config_rec_dump(FILE * file, XklConfigRec * data) 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; + + { + /* 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); + } + + XklConfigRegistry *config = XKL_CONFIG_REGISTRY(obj); + + XklEngine *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) { @@ -602,6 +630,30 @@ xkl_config_registry_init(XklConfigRegistry * config) } 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; @@ -631,5 +683,30 @@ xkl_config_registry_class_init(XklConfigRegistryClass * klass) 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; + + GParamSpec *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 *) + "/xkbConfigRegistry/modelList/model"); + layouts_xpath = xmlXPathCompile((unsigned char *) + "/xkbConfigRegistry/layoutList/layout"); + option_groups_xpath = xmlXPathCompile((unsigned char *) + "/xkbConfigRegistry/optionList/group"); + xkl_i18n_init(); } diff --git a/libxklavier/xklavier_private.h b/libxklavier/xklavier_private.h index eb9eb2c..c027ff8 100644 --- a/libxklavier/xklavier_private.h +++ b/libxklavier/xklavier_private.h @@ -375,7 +375,7 @@ extern void xkl_engine_one_switch_to_secondary_group_performed(XklEngine * #define xkl_engine_get_display(engine) (xkl_engine_priv(engine,display)) #define xkl_engine_vcall(engine,func) (*(engine)->priv->func) -#define xkl_config_priv(config,member) (config)->priv->member +#define xkl_config_registry_priv(config,member) (config)->priv->member #define xkl_config_registry_get_engine(config) ((config)->priv->engine) extern gint xkl_debug_level; |