From 0b4d159597161b73681330400f43f3bd473d0360 Mon Sep 17 00:00:00 2001 From: Perry Werneck Date: Tue, 7 Jan 2020 11:41:38 -0300 Subject: [PATCH] Adding methods to get translated properties. --- src/core/properties/get.c | 24 +++++++++++++++--------- src/core/toggles/getset.c | 49 ++++++++++++++++++++++++++++++++++++++++--------- src/core/toggles/table.c | 15 +++++++-------- src/include/lib3270/properties.h | 6 ++++++ src/include/lib3270/toggle.h | 8 ++++++++ 5 files changed, 76 insertions(+), 26 deletions(-) diff --git a/src/core/properties/get.c b/src/core/properties/get.c index be40a5b..6263f21 100644 --- a/src/core/properties/get.c +++ b/src/core/properties/get.c @@ -34,24 +34,30 @@ #include #include - LIB3270_EXPORT const char * lib3270_property_get_description(const LIB3270_PROPERTY * property) { + LIB3270_EXPORT const char * lib3270_property_get_label(const LIB3270_PROPERTY * property) { + + if(property && property->label) + return dgettext(GETTEXT_PACKAGE,property->label); + + return ""; - if(property->description) - return property->description; + } + + LIB3270_EXPORT const char * lib3270_property_get_description(const LIB3270_PROPERTY * property) { - if(property->summary) - return property->summary; + if(property && property->description) + return dgettext(GETTEXT_PACKAGE,property->description); - return property->name; + return ""; } LIB3270_EXPORT const char * lib3270_property_get_summary(const LIB3270_PROPERTY * property) { - if(property->summary) - return property->summary; + if(property && property->summary) + return dgettext(GETTEXT_PACKAGE,property->summary); - return property->name; + return ""; } diff --git a/src/core/toggles/getset.c b/src/core/toggles/getset.c index e9b3756..5ec1921 100644 --- a/src/core/toggles/getset.c +++ b/src/core/toggles/getset.c @@ -30,7 +30,7 @@ /** * @file toggles/getset.c - * @brief This module handles toggle changes. + * @brief This module handles toggle changes and properties. */ #include @@ -41,8 +41,7 @@ /*---[ Implement ]------------------------------------------------------------------------------------------------------------*/ -LIB3270_EXPORT unsigned char lib3270_get_toggle(const H3270 *hSession, LIB3270_TOGGLE_ID ix) -{ +LIB3270_EXPORT unsigned char lib3270_get_toggle(const H3270 *hSession, LIB3270_TOGGLE_ID ix) { if(ix < 0 || ix >= LIB3270_TOGGLE_COUNT) { errno = EINVAL; @@ -55,8 +54,7 @@ LIB3270_EXPORT unsigned char lib3270_get_toggle(const H3270 *hSession, LIB3270_T /** * @brief Call the internal update routine and listeners. */ -static void toggle_notify(H3270 *session, struct lib3270_toggle *t, LIB3270_TOGGLE_ID ix) -{ +static void toggle_notify(H3270 *session, struct lib3270_toggle *t, LIB3270_TOGGLE_ID ix) { trace("%s: ix=%d upcall=%p",__FUNCTION__,ix,t->upcall); t->upcall(session, t, LIB3270_TOGGLE_TYPE_INTERACTIVE); @@ -89,8 +87,7 @@ static void toggle_notify(H3270 *session, struct lib3270_toggle *t, LIB3270_TOGG * * @returns 0 if the toggle is already at the state, 1 if the toggle was changed; < 0 on error (sets errno). */ -LIB3270_EXPORT int lib3270_set_toggle(H3270 *session, LIB3270_TOGGLE_ID ix, int value) -{ +LIB3270_EXPORT int lib3270_set_toggle(H3270 *session, LIB3270_TOGGLE_ID ix, int value) { char v = value ? True : False; struct lib3270_toggle * t; @@ -110,8 +107,7 @@ LIB3270_EXPORT int lib3270_set_toggle(H3270 *session, LIB3270_TOGGLE_ID ix, int return 1; } -LIB3270_EXPORT int lib3270_toggle(H3270 *session, LIB3270_TOGGLE_ID ix) -{ +LIB3270_EXPORT int lib3270_toggle(H3270 *session, LIB3270_TOGGLE_ID ix) { struct lib3270_toggle *t; CHECK_SESSION_HANDLE(session); @@ -128,3 +124,38 @@ LIB3270_EXPORT int lib3270_toggle(H3270 *session, LIB3270_TOGGLE_ID ix) return (int) t->value; } +LIB3270_EXPORT const char * lib3270_toggle_get_name(const LIB3270_TOGGLE *toggle) { + + if(toggle && toggle->name) + return dgettext(GETTEXT_PACKAGE,toggle->name); + + return ""; + +} + +LIB3270_EXPORT const char * lib3270_toggle_get_label(const LIB3270_TOGGLE *toggle) { + + if(toggle && toggle->label) + return dgettext(GETTEXT_PACKAGE,toggle->label); + + return ""; + +} + +LIB3270_EXPORT const char * lib3270_toggle_get_summary(const LIB3270_TOGGLE *toggle) { + + if(toggle && toggle->summary) + return dgettext(GETTEXT_PACKAGE,toggle->summary); + + return ""; + +} + +LIB3270_EXPORT const char * lib3270_toggle_get_description(const LIB3270_TOGGLE *toggle) { + + if(toggle && toggle->description) + return dgettext(GETTEXT_PACKAGE,toggle->description); + + return ""; + +} diff --git a/src/core/toggles/table.c b/src/core/toggles/table.c index 315979b..7b1861d 100644 --- a/src/core/toggles/table.c +++ b/src/core/toggles/table.c @@ -29,8 +29,8 @@ /** - * @file toggles/init.c - * @brief Toggle description table. + * @file toggles/table.c + * @brief Toggle description table and associated methods. */ #include @@ -342,14 +342,14 @@ LIB3270_EXPORT const LIB3270_TOGGLE * lib3270_get_toggle_list() LIB3270_EXPORT const char * lib3270_get_toggle_summary(LIB3270_TOGGLE_ID ix) { if(ix < LIB3270_TOGGLE_COUNT) - return toggle_descriptor[ix].summary; + return lib3270_toggle_get_summary(toggle_descriptor+ix); return ""; } LIB3270_EXPORT const char * lib3270_get_toggle_label(LIB3270_TOGGLE_ID ix) { if(ix < LIB3270_TOGGLE_COUNT) - return toggle_descriptor[ix].label; + return lib3270_toggle_get_label(toggle_descriptor+ix); return ""; } @@ -357,14 +357,13 @@ LIB3270_EXPORT const char * lib3270_get_toggle_label(LIB3270_TOGGLE_ID ix) LIB3270_EXPORT const char * lib3270_get_toggle_description(LIB3270_TOGGLE_ID ix) { if(ix < LIB3270_TOGGLE_COUNT) - return toggle_descriptor[ix].description; + return lib3270_toggle_get_description(toggle_descriptor+ix); return ""; } -LIB3270_EXPORT const char * lib3270_get_toggle_name(LIB3270_TOGGLE_ID ix) -{ +LIB3270_EXPORT const char * lib3270_get_toggle_name(LIB3270_TOGGLE_ID ix) { if(ix < LIB3270_TOGGLE_COUNT) - return toggle_descriptor[ix].name; + return lib3270_toggle_get_name(toggle_descriptor+ix); return ""; } diff --git a/src/include/lib3270/properties.h b/src/include/lib3270/properties.h index 2e04876..37f31fb 100644 --- a/src/include/lib3270/properties.h +++ b/src/include/lib3270/properties.h @@ -181,6 +181,12 @@ LIB3270_EXPORT int lib3270_set_oversize(H3270 *hSession, const char *value); /** + * @brief Get property label. + * + */ + LIB3270_EXPORT const char * lib3270_property_get_label(const LIB3270_PROPERTY * property); + + /** * @brief Get property description. * */ diff --git a/src/include/lib3270/toggle.h b/src/include/lib3270/toggle.h index 31167fe..a53a639 100644 --- a/src/include/lib3270/toggle.h +++ b/src/include/lib3270/toggle.h @@ -162,6 +162,8 @@ */ LIB3270_EXPORT const char * lib3270_get_toggle_name(LIB3270_TOGGLE_ID ix); + + /** * @brief Get a long description of the toggle. * @@ -212,6 +214,12 @@ */ LIB3270_EXPORT const LIB3270_TOGGLE * lib3270_toggle_get_from_id(LIB3270_TOGGLE_ID id); + LIB3270_EXPORT const char * lib3270_toggle_get_name(const LIB3270_TOGGLE *toggle); + LIB3270_EXPORT const char * lib3270_toggle_get_label(const LIB3270_TOGGLE *toggle); + LIB3270_EXPORT const char * lib3270_toggle_get_summary(const LIB3270_TOGGLE *toggle); + LIB3270_EXPORT const char * lib3270_toggle_get_description(const LIB3270_TOGGLE *toggle); + + #ifdef __cplusplus } #endif -- libgit2 0.21.2