From 8b7ab225ea52b7cf2666a7253512f8996481dd1c Mon Sep 17 00:00:00 2001 From: Martin Pitt Date: Sun, 8 Jan 2012 14:27:40 +0100 Subject: [PATCH 3/6] Add xkl_config_item_new_with_data() constructor. This makes it much easier (or even possible at all) to set the data fields of an XklConfigItem through GI bindings. E. g. Python has a hard time assigning to a fixed-length static gchar array. --- libxklavier/xkl_config_item.h | 17 ++++++++++++++++- libxklavier/xklavier_props.c | 16 ++++++++++++++++ 2 files changed, 32 insertions(+), 1 deletions(-) diff --git a/libxklavier/xkl_config_item.h b/libxklavier/xkl_config_item.h index 0095c70..49ff6e1 100644 --- a/libxklavier/xkl_config_item.h +++ b/libxklavier/xkl_config_item.h @@ -126,13 +126,28 @@ extern "C" { /** * xkl_config_item_new: * - * Create new XklConfigItem + * Create new empty XklConfigItem * * Returns: new instance */ extern XklConfigItem *xkl_config_item_new(void); /** + * xkl_config_item_new_with_data: + * + * Create new XklConfigItem with data. + * @name: (allow-none): Name (max. 32 characters); can be NULL. + * @short_description: (allow-none): Short description (max. 10 characters); + * can be NULL. + * @description: (allow-none): Description (max. 192 characters); can be NULL. + * + * Returns: new instance + */ + extern XklConfigItem *xkl_config_item_new_with_data(const gchar * name, + const gchar * short_description, + const gchar * description); + +/** * xkl_get_country_name: * @code: ISO 3166 Alpha 2 code: 2 chars, uppercase (US, RU, FR, ...) * diff --git a/libxklavier/xklavier_props.c b/libxklavier/xklavier_props.c index 2abe6bc..160e847 100644 --- a/libxklavier/xklavier_props.c +++ b/libxklavier/xklavier_props.c @@ -54,6 +54,22 @@ xkl_config_item_new(void) (xkl_config_item_get_type(), NULL)); } +XklConfigItem * +xkl_config_item_new_with_data(const gchar * name, + const gchar * short_description, + const gchar * description) +{ + XklConfigItem * this = xkl_config_item_new (); + if (name != NULL) + strncpy (this->name, name, XKL_MAX_CI_NAME_LENGTH-1); + if (short_description != NULL) + strncpy (this->short_description, short_description, XKL_MAX_CI_SHORT_DESC_LENGTH-1); + if (description != NULL) + strncpy (this->description, description, XKL_MAX_CI_DESC_LENGTH-1); + + return this; +} + G_DEFINE_TYPE(XklConfigRec, xkl_config_rec, G_TYPE_OBJECT) static void -- 1.7.7.3