Commit 880509beece11b1b673073cb283c9b605def4344
1 parent
de046ba0
Exists in
master
and in
4 other branches
Setting element properties from xml definition.
Showing
4 changed files
with
179 additions
and
6 deletions
Show diff stats
| @@ -0,0 +1,139 @@ | @@ -0,0 +1,139 @@ | ||
| 1 | +/* | ||
| 2 | + * "Software pw3270, desenvolvido com base nos códigos fontes do WC3270 e X3270 | ||
| 3 | + * (Paul Mattes Paul.Mattes@usa.net), de emulação de terminal 3270 para acesso a | ||
| 4 | + * aplicativos mainframe. Registro no INPI sob o nome G3270. | ||
| 5 | + * | ||
| 6 | + * Copyright (C) <2008> <Banco do Brasil S.A.> | ||
| 7 | + * | ||
| 8 | + * Este programa é software livre. Você pode redistribuí-lo e/ou modificá-lo sob | ||
| 9 | + * os termos da GPL v.2 - Licença Pública Geral GNU, conforme publicado pela | ||
| 10 | + * Free Software Foundation. | ||
| 11 | + * | ||
| 12 | + * Este programa é distribuído na expectativa de ser útil, mas SEM QUALQUER | ||
| 13 | + * GARANTIA; sem mesmo a garantia implícita de COMERCIALIZAÇÃO ou de ADEQUAÇÃO | ||
| 14 | + * A QUALQUER PROPÓSITO EM PARTICULAR. Consulte a Licença Pública Geral GNU para | ||
| 15 | + * obter mais detalhes. | ||
| 16 | + * | ||
| 17 | + * Você deve ter recebido uma cópia da Licença Pública Geral GNU junto com este | ||
| 18 | + * programa; se não, escreva para a Free Software Foundation, Inc., 51 Franklin | ||
| 19 | + * St, Fifth Floor, Boston, MA 02110-1301 USA | ||
| 20 | + * | ||
| 21 | + * Este programa está nomeado como - e possui - linhas de código. | ||
| 22 | + * | ||
| 23 | + * Contatos: | ||
| 24 | + * | ||
| 25 | + * perry.werneck@gmail.com (Alexandre Perry de Souza Werneck) | ||
| 26 | + * erico.mendonca@gmail.com (Erico Mascarenhas Mendonça) | ||
| 27 | + * | ||
| 28 | + */ | ||
| 29 | + | ||
| 30 | + #include "private.h" | ||
| 31 | + #include <stdlib.h> | ||
| 32 | + | ||
| 33 | +/*---[ Globals & Object definition ]----------------------------------------------------------------*/ | ||
| 34 | + | ||
| 35 | + struct Attribute { | ||
| 36 | + GObject * object; | ||
| 37 | + gboolean translatable; | ||
| 38 | + GParamSpec *spec; | ||
| 39 | + }; | ||
| 40 | + | ||
| 41 | +/*---[ Implement ]----------------------------------------------------------------------------------*/ | ||
| 42 | + | ||
| 43 | + | ||
| 44 | + static void parse_error (GMarkupParseContext *context, GError *error, gpointer data) { | ||
| 45 | + g_free(data); | ||
| 46 | + } | ||
| 47 | + | ||
| 48 | + static void parse_text(GMarkupParseContext *context, const gchar *text, gsize text_len, gpointer user_data, GError **error) { | ||
| 49 | + | ||
| 50 | + if( ((struct Attribute *) user_data)->translatable ) { | ||
| 51 | + text = gettext(text); | ||
| 52 | + } | ||
| 53 | + | ||
| 54 | + GParamSpec *spec = ((struct Attribute *) user_data)->spec; | ||
| 55 | + | ||
| 56 | + debug("%s=\"%s\"",spec->name,text); | ||
| 57 | + | ||
| 58 | + GValue value = G_VALUE_INIT; | ||
| 59 | + g_value_init(&value,spec->value_type); | ||
| 60 | + | ||
| 61 | + switch(spec->value_type) { | ||
| 62 | + case G_TYPE_STRING: | ||
| 63 | + g_value_set_string(&value,text); | ||
| 64 | + break; | ||
| 65 | + | ||
| 66 | + case G_TYPE_UINT: | ||
| 67 | + g_value_set_uint(&value,(unsigned int) atoi(text)); | ||
| 68 | + break; | ||
| 69 | + | ||
| 70 | + case G_TYPE_INT: | ||
| 71 | + g_value_set_int(&value, atoi(text)); | ||
| 72 | + break; | ||
| 73 | + | ||
| 74 | + default: | ||
| 75 | + g_set_error_literal( | ||
| 76 | + error, | ||
| 77 | + g_quark_from_static_string("keypad"), | ||
| 78 | + ENOENT, | ||
| 79 | + _( "Invalid or unknown property type" ) | ||
| 80 | + ); | ||
| 81 | + | ||
| 82 | + g_value_unset(&value); | ||
| 83 | + return; | ||
| 84 | + | ||
| 85 | + } | ||
| 86 | + | ||
| 87 | + g_object_set_property(((struct Attribute *) user_data)->object,spec->name,&value); | ||
| 88 | + g_value_unset(&value); | ||
| 89 | + } | ||
| 90 | + | ||
| 91 | + void attribute_element_start(GMarkupParseContext *context,const gchar **names,const gchar **values, GObject *parent, GError **error) { | ||
| 92 | + | ||
| 93 | + struct Attribute * data = g_new0(struct Attribute,1); | ||
| 94 | + const gchar *name; | ||
| 95 | + | ||
| 96 | + data->object = parent; | ||
| 97 | + | ||
| 98 | + if(!g_markup_collect_attributes( | ||
| 99 | + "attribute",names,values,error, | ||
| 100 | + G_MARKUP_COLLECT_BOOLEAN|G_MARKUP_COLLECT_OPTIONAL, "translatable", &data->translatable, | ||
| 101 | + G_MARKUP_COLLECT_STRING, "name", &name, | ||
| 102 | + G_MARKUP_COLLECT_INVALID | ||
| 103 | + )) { | ||
| 104 | + | ||
| 105 | + g_free(data); | ||
| 106 | + return; | ||
| 107 | + | ||
| 108 | + } | ||
| 109 | + | ||
| 110 | + data->spec = g_object_class_find_property(G_OBJECT_GET_CLASS(parent),name); | ||
| 111 | + if(!data->spec) { | ||
| 112 | + g_set_error_literal( | ||
| 113 | + error, | ||
| 114 | + g_quark_from_static_string("keypad"), | ||
| 115 | + ENOENT, | ||
| 116 | + _( "Invalid or unknown property name" ) | ||
| 117 | + ); | ||
| 118 | + g_free(data); | ||
| 119 | + return; | ||
| 120 | + } | ||
| 121 | + | ||
| 122 | + static const GMarkupParser parser = { | ||
| 123 | + NULL, | ||
| 124 | + NULL, | ||
| 125 | + parse_text, | ||
| 126 | + NULL, | ||
| 127 | + parse_error | ||
| 128 | + }; | ||
| 129 | + | ||
| 130 | + g_markup_parse_context_push(context, &parser, data); | ||
| 131 | + | ||
| 132 | + } | ||
| 133 | + | ||
| 134 | + void attribute_element_end(GMarkupParseContext *context, GObject *parent, GError **error) { | ||
| 135 | + | ||
| 136 | + struct Attribute * data = g_markup_parse_context_pop(context); | ||
| 137 | + g_free(data); | ||
| 138 | + | ||
| 139 | + } |
src/objects/keypad/element.c
| @@ -89,6 +89,16 @@ | @@ -89,6 +89,16 @@ | ||
| 89 | ) | 89 | ) |
| 90 | ); | 90 | ); |
| 91 | 91 | ||
| 92 | + g_object_class_install_property(object_class, PROP_ACTION, | ||
| 93 | + g_param_spec_string ( | ||
| 94 | + I_("action"), | ||
| 95 | + I_("action"), | ||
| 96 | + N_("The name of associated action"), | ||
| 97 | + NULL, | ||
| 98 | + G_PARAM_STATIC_STRINGS | G_PARAM_READABLE | G_PARAM_WRITABLE | ||
| 99 | + ) | ||
| 100 | + ); | ||
| 101 | + | ||
| 92 | g_object_class_install_property(object_class, PROP_LABEL, | 102 | g_object_class_install_property(object_class, PROP_LABEL, |
| 93 | g_param_spec_string ( | 103 | g_param_spec_string ( |
| 94 | I_("label"), | 104 | I_("label"), |
| @@ -206,6 +216,14 @@ | @@ -206,6 +216,14 @@ | ||
| 206 | } | 216 | } |
| 207 | break; | 217 | break; |
| 208 | 218 | ||
| 219 | + case PROP_ICON_NAME: | ||
| 220 | + | ||
| 221 | + if(element->icon_name) { | ||
| 222 | + g_free(element->icon_name); | ||
| 223 | + element->icon_name = g_value_dup_string(value); | ||
| 224 | + } | ||
| 225 | + break; | ||
| 226 | + | ||
| 209 | case PROP_ACTION: | 227 | case PROP_ACTION: |
| 210 | 228 | ||
| 211 | if(element->action) { | 229 | if(element->action) { |
| @@ -235,13 +253,23 @@ | @@ -235,13 +253,23 @@ | ||
| 235 | } | 253 | } |
| 236 | } | 254 | } |
| 237 | 255 | ||
| 238 | - static void element_start(GMarkupParseContext *context, const gchar *element_name, const gchar **names,const gchar **values, GList *keypads, GError **error) { | 256 | + static void element_start(GMarkupParseContext *context, const gchar *element_name, const gchar **names,const gchar **values, GObject *element, GError **error) { |
| 257 | + | ||
| 258 | + if(!g_ascii_strcasecmp(element_name,"attribute")) { | ||
| 259 | + attribute_element_start(context,names,values,element,error); | ||
| 260 | + return; | ||
| 261 | + } | ||
| 239 | 262 | ||
| 240 | debug("%s(%s)",__FUNCTION__,element_name); | 263 | debug("%s(%s)",__FUNCTION__,element_name); |
| 241 | 264 | ||
| 242 | } | 265 | } |
| 243 | 266 | ||
| 244 | - static void element_end(GMarkupParseContext *context, const gchar *element_name, GList *keypads, GError **error) { | 267 | + static void element_end(GMarkupParseContext *context, const gchar *element_name, GObject *element, GError **error) { |
| 268 | + | ||
| 269 | + if(!g_ascii_strcasecmp(element_name,"attribute")) { | ||
| 270 | + attribute_element_end(context,element,error); | ||
| 271 | + return; | ||
| 272 | + } | ||
| 245 | 273 | ||
| 246 | debug("%s(%s)",__FUNCTION__,element_name); | 274 | debug("%s(%s)",__FUNCTION__,element_name); |
| 247 | 275 |
src/objects/keypad/keypad.cbp
| @@ -39,6 +39,9 @@ | @@ -39,6 +39,9 @@ | ||
| 39 | <Add option="`pkg-config --libs libv3270 gtk+-3.0`" /> | 39 | <Add option="`pkg-config --libs libv3270 gtk+-3.0`" /> |
| 40 | </Linker> | 40 | </Linker> |
| 41 | <Unit filename="../../include/pw3270/keypad.h" /> | 41 | <Unit filename="../../include/pw3270/keypad.h" /> |
| 42 | + <Unit filename="attribute.c"> | ||
| 43 | + <Option compilerVar="CC" /> | ||
| 44 | + </Unit> | ||
| 42 | <Unit filename="element.c"> | 45 | <Unit filename="element.c"> |
| 43 | <Option compilerVar="CC" /> | 46 | <Option compilerVar="CC" /> |
| 44 | </Unit> | 47 | </Unit> |
src/objects/keypad/private.h
| @@ -103,12 +103,15 @@ | @@ -103,12 +103,15 @@ | ||
| 103 | 103 | ||
| 104 | }; | 104 | }; |
| 105 | 105 | ||
| 106 | - void keypad_model_set_position(GObject *model, const gchar *position); | ||
| 107 | - void keypad_model_parse_context(GObject *model, GMarkupParseContext *context); | 106 | + G_GNUC_INTERNAL void keypad_model_set_position(GObject *model, const gchar *position); |
| 107 | + G_GNUC_INTERNAL void keypad_model_parse_context(GObject *model, GMarkupParseContext *context); | ||
| 108 | 108 | ||
| 109 | - const gchar * keypad_model_get_position(GObject *mode); | 109 | + G_GNUC_INTERNAL const gchar * keypad_model_get_position(GObject *mode); |
| 110 | 110 | ||
| 111 | - void keypad_model_element_parse_context(GObject *element, GMarkupParseContext *context); | 111 | + G_GNUC_INTERNAL void keypad_model_element_parse_context(GObject *element, GMarkupParseContext *context); |
| 112 | + | ||
| 113 | + G_GNUC_INTERNAL void attribute_element_start(GMarkupParseContext *context,const gchar **names,const gchar **values, GObject *parent, GError **error); | ||
| 114 | + G_GNUC_INTERNAL void attribute_element_end(GMarkupParseContext *context, GObject *parent, GError **error); | ||
| 112 | 115 | ||
| 113 | G_END_DECLS | 116 | G_END_DECLS |
| 114 | 117 |