diff options
author | Sergey Udaltsov <svu@gnome.org> | 2006-02-20 01:24:05 +0000 |
---|---|---|
committer | Sergey Udaltsov <svu@gnome.org> | 2006-02-20 01:24:05 +0000 |
commit | 883773a40a132b68d73d0a563b211c12994bc6b1 (patch) | |
tree | 25a5f42baa47caa6728dc95d9f517813682fac36 | |
parent | ec3712359f42cf1d015c66af286cdeece495aa12 (diff) | |
download | libxklavier-883773a40a132b68d73d0a563b211c12994bc6b1.tar.gz |
started going gobject way
-rw-r--r-- | libxklavier/xklavier_config.c | 22 | ||||
-rw-r--r-- | libxklavier/xklavier_config.h | 39 | ||||
-rw-r--r-- | libxklavier/xklavier_props.c | 67 | ||||
-rw-r--r-- | tests/.indent.pro | 3 | ||||
-rw-r--r-- | tests/test_config.c | 60 | ||||
-rw-r--r-- | tests/test_monitor.c | 10 |
6 files changed, 135 insertions, 66 deletions
diff --git a/libxklavier/xklavier_config.c b/libxklavier/xklavier_config.c index 2ee6799..49691c2 100644 --- a/libxklavier/xklavier_config.c +++ b/libxklavier/xklavier_config.c @@ -136,10 +136,9 @@ xkl_read_config_item(xmlNodePtr iptr, XklConfigItem * item) if (short_desc_element != NULL && short_desc_element->children != NULL) { - gchar *lmsg = - xkl_locale_from_utf8((const gchar *) - short_desc_element->children-> - content); + gchar *lmsg = xkl_locale_from_utf8((const gchar *) + short_desc_element-> + children->content); strncat(item->short_description, lmsg, XKL_MAX_CI_SHORT_DESC_LENGTH - 1); g_free(lmsg); @@ -317,15 +316,12 @@ void xkl_config_init(void) { 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"); + 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_ensure_vtable_inited(); diff --git a/libxklavier/xklavier_config.h b/libxklavier/xklavier_config.h index ee31067..6b4d5e5 100644 --- a/libxklavier/xklavier_config.h +++ b/libxklavier/xklavier_config.h @@ -87,12 +87,27 @@ extern "C" { */ GObjectClass parent_class; }; +/** + * Get type info for XConfigItem + * @return GType for XConfigItem + */ + extern GType xkl_config_item_get_type(void); + +/** + * Create new XklConfigItem + * @return new instance + */ + extern XklConfigItem *xkl_config_item_new(void); /** * Basic configuration params */ struct _XklConfigRec { /** + * The superclass object + */ + GObject parent; +/** * The keyboard model */ gchar *model; @@ -121,6 +136,18 @@ extern "C" { }; /** + * Get type info for XConfigRec + * @return GType for XConfigRec + */ + extern GType xkl_config_rec_get_type(void); + +/** + * Create new XklConfigRec + * @return new instance + */ + extern XklConfigRec *xkl_config_rec_new(void); + +/** * @defgroup xklconfiginitterm XKB configuration handling initialization and termination * @{ */ @@ -381,24 +408,12 @@ extern "C" { */ /** - * Initializes the record (actually, fills it with 0-s) - * @param data is a record to initialize - */ - extern void xkl_config_rec_init(XklConfigRec * data); - -/** * Resets the record (equal to Destroy and Init) * @param data is a record to reset */ extern void xkl_config_rec_reset(XklConfigRec * data); /** - * Cleans the record (frees all the non-null members) - * @param data is a record to clean - */ - extern void xkl_config_rec_destroy(XklConfigRec * data); - -/** * Compares the records * @param data1 is a record to compare * @param data2 is another record diff --git a/libxklavier/xklavier_props.c b/libxklavier/xklavier_props.c index 1a45744..75719fb 100644 --- a/libxklavier/xklavier_props.c +++ b/libxklavier/xklavier_props.c @@ -13,11 +13,55 @@ #include "xklavier_config.h" #include "xklavier_private.h" -void -xkl_config_rec_init(XklConfigRec * data) +static GObjectClass *g_object_class = NULL; + +static void xkl_config_rec_destroy(XklConfigRec * data); + +G_DEFINE_TYPE(XklConfigItem, xkl_config_item, G_TYPE_OBJECT) + +static void +xkl_config_item_init(XklConfigItem * this) { - /* clear the structure VarDefsPtr... */ - memset((void *) data, 0, sizeof(XklConfigRec)); +} + +static void +xkl_config_item_class_init(XklConfigItemClass * klass) +{ +} + +XklConfigItem * +xkl_config_item_new(void) +{ + return + XKL_CONFIG_ITEM(g_object_new + (xkl_config_item_get_type(), NULL)); +} + +G_DEFINE_TYPE(XklConfigRec, xkl_config_rec, G_TYPE_OBJECT) + +static void +xkl_config_rec_finalize(GObject * obj) +{ + XklConfigRec *this = (XklConfigRec *) obj; + xkl_config_rec_destroy(this); + G_OBJECT_CLASS(g_object_class)->finalize(obj); +} + +static void +xkl_config_rec_class_init(XklConfigRecClass * klass) +{ + GObjectClass *object_class; + + object_class = (GObjectClass *) klass; + g_object_class = g_type_class_peek_parent(klass); + object_class->finalize = xkl_config_rec_finalize; +} + +XklConfigRec * +xkl_config_rec_new(void) +{ + return + XKL_CONFIG_REC(g_object_new(xkl_config_rec_get_type(), NULL)); } static gboolean @@ -65,9 +109,8 @@ xkl_get_default_names_prop(char **rules_file_out, XklConfigRec * data) gboolean xkl_config_get_full_from_server(char **rules_file_out, XklConfigRec * data) { - gboolean rv = - xkl_get_names_prop(xkl_vtable->base_config_atom, - rules_file_out, data); + gboolean rv = xkl_get_names_prop(xkl_vtable->base_config_atom, + rules_file_out, data); if (!rv) rv = xkl_get_default_names_prop(rules_file_out, data); @@ -90,6 +133,14 @@ xkl_config_rec_equals(XklConfigRec * data1, XklConfigRec * data2) } void +xkl_config_rec_init(XklConfigRec * data) +{ + /* clear the structure VarDefsPtr... */ + data->model = NULL; + data->layouts = data->variants = data->options = NULL; +} + +void xkl_config_rec_destroy(XklConfigRec * data) { if (data->model != NULL) @@ -289,7 +340,7 @@ xkl_get_names_prop(Atom rules_atom, ((char *) g_realloc(*layout, laylen + 1))[laylen] = - '\0'; + '\0'; } } layout++; diff --git a/tests/.indent.pro b/tests/.indent.pro new file mode 100644 index 0000000..dbec33f --- /dev/null +++ b/tests/.indent.pro @@ -0,0 +1,3 @@ +-kr +-i8 +-psl diff --git a/tests/test_config.c b/tests/test_config.c index e1ddf0d..1a9886c 100644 --- a/tests/test_config.c +++ b/tests/test_config.c @@ -42,6 +42,8 @@ main(int argc, char *const argv[]) int binary = 0; Display *dpy; + g_type_init_with_debug_flags(G_TYPE_DEBUG_OBJECTS | G_TYPE_DEBUG_SIGNALS); + while (1) { c = getopt(argc, argv, "hsgm:l:o:d:w:"); if (c == -1) @@ -93,7 +95,7 @@ main(int argc, char *const argv[]) } printf("opened display: %p\n", dpy); if (!xkl_init(dpy)) { - XklConfigRec current_config, r2; + XklConfigRec *current_config, *r2; if (debug_level != -1) xkl_set_debug_level(debug_level); xkl_debug(0, "Xklavier initialized\n"); @@ -106,26 +108,26 @@ main(int argc, char *const argv[]) xkl_debug(0, "Max number of groups: %d\n", xkl_groups_get_max_num()); - xkl_config_rec_init(¤t_config); - xkl_config_get_from_server(¤t_config); + current_config = xkl_config_rec_new(); + xkl_config_get_from_server(current_config); switch (action) { case ACTION_GET: xkl_debug(0, "Got config from the server\n"); - xkl_config_dump(stdout, ¤t_config); + xkl_config_dump(stdout, current_config); - xkl_config_rec_init(&r2); + r2 = xkl_config_rec_new(); - if (xkl_config_get_from_backup(&r2)) { + if (xkl_config_get_from_backup(r2)) { xkl_debug(0, "Got config from the backup\n"); - xkl_config_dump(stdout, &r2); + xkl_config_dump(stdout, r2); } - if (xkl_config_activate(&r2)) { + if (xkl_config_activate(r2)) { xkl_debug(0, "The backup configuration restored\n"); - if (xkl_config_activate(¤t_config)) { + if (xkl_config_activate(current_config)) { xkl_debug(0, "Reverting the configuration change\n"); } else { @@ -139,42 +141,42 @@ main(int argc, char *const argv[]) xkl_get_last_error()); } - xkl_config_rec_destroy(&r2); + g_object_unref(G_OBJECT(r2)); break; case ACTION_SET: if (model != NULL) { - if (current_config.model != NULL) - g_free(current_config.model); - current_config.model = g_strdup(model); + if (current_config->model != NULL) + g_free(current_config->model); + current_config->model = g_strdup(model); } if (layouts != NULL) { - if (current_config.layouts != NULL) - g_strfreev(current_config.layouts); - if (current_config.variants != NULL) - g_strfreev(current_config. + if (current_config->layouts != NULL) + g_strfreev(current_config->layouts); + if (current_config->variants != NULL) + g_strfreev(current_config-> variants); - current_config.layouts = g_new0(char *, 2); - current_config.layouts[0] = + current_config->layouts = g_new0(char *, 2); + current_config->layouts[0] = g_strdup(layouts); - current_config.variants = + current_config->variants = g_new0(char *, 2); - current_config.variants[0] = g_strdup(""); + current_config->variants[0] = g_strdup(""); } if (options != NULL) { - if (current_config.options != NULL) - g_strfreev(current_config.options); + if (current_config->options != NULL) + g_strfreev(current_config->options); - current_config.options = g_new0(char *, 2); - current_config.options[0] = + current_config->options = g_new0(char *, 2); + current_config->options[0] = g_strdup(options); } xkl_debug(0, "New config:\n"); - xkl_config_dump(stdout, ¤t_config); - if (xkl_config_activate(¤t_config)) + xkl_config_dump(stdout, current_config); + if (xkl_config_activate(current_config)) xkl_debug(0, "Set the config\n"); else xkl_debug(0, @@ -184,13 +186,13 @@ main(int argc, char *const argv[]) case ACTION_WRITE: xkl_config_write_file(binary ? (PACKAGE ".xkm") : (PACKAGE ".xkb"), - ¤t_config, binary); + current_config, binary); xkl_debug(0, "The file " PACKAGE "%s is written\n", binary ? ".xkm" : ".xkb"); break; } - xkl_config_rec_destroy(¤t_config); + g_object_unref(G_OBJECT(current_config)); xkl_config_registry_free(); xkl_config_term(); diff --git a/tests/test_monitor.c b/tests/test_monitor.c index 159c355..4c30528 100644 --- a/tests/test_monitor.c +++ b/tests/test_monitor.c @@ -36,6 +36,8 @@ main(int argc, char *argv[]) XKLL_TRACK_KEYBOARD_STATE }; + g_type_init_with_debug_flags(G_TYPE_DEBUG_OBJECTS | G_TYPE_DEBUG_SIGNALS); + while (1) { c = getopt(argc, argv, "hd:l:"); if (c == -1) @@ -71,7 +73,7 @@ main(int argc, char *argv[]) } printf("opened display: %p\n", dpy); if (!xkl_init(dpy)) { - XklConfigRec current_config; + XklConfigRec *current_config; if (debug_level != -1) xkl_set_debug_level(debug_level); xkl_debug(0, "Xklavier initialized\n"); @@ -79,8 +81,8 @@ main(int argc, char *argv[]) xkl_config_registry_load(); xkl_debug(0, "Xklavier registry loaded\n"); - xkl_config_rec_init(¤t_config); - xkl_config_get_from_server(¤t_config); + current_config = xkl_config_rec_new(); + xkl_config_get_from_server(current_config); xkl_debug(0, "Now, listening...\n"); xkl_listen_start(listener_type); @@ -94,7 +96,7 @@ main(int argc, char *argv[]) xkl_listen_stop(); - xkl_config_rec_destroy(¤t_config); + g_object_unref(G_OBJECT(current_config)); xkl_config_registry_free(); xkl_config_term(); |