Commit dfe42f3a97fefea9aa1e3288518a85e35a5869f5
1 parent
888c8d2a
Exists in
master
and in
4 other branches
Implementing model object.
Showing
6 changed files
with
374 additions
and
0 deletions
Show diff stats
src/include/pw3270/keypad.h
src/objects/keypad/keypad.cbp
| ... | ... | @@ -39,6 +39,13 @@ |
| 39 | 39 | <Add option="`pkg-config --libs libv3270 gtk+-3.0`" /> |
| 40 | 40 | </Linker> |
| 41 | 41 | <Unit filename="../../include/pw3270/keypad.h" /> |
| 42 | + <Unit filename="load.c"> | |
| 43 | + <Option compilerVar="CC" /> | |
| 44 | + </Unit> | |
| 45 | + <Unit filename="model.c"> | |
| 46 | + <Option compilerVar="CC" /> | |
| 47 | + </Unit> | |
| 48 | + <Unit filename="private.h" /> | |
| 42 | 49 | <Unit filename="testprogram/testprogram.c"> |
| 43 | 50 | <Option compilerVar="CC" /> |
| 44 | 51 | </Unit> | ... | ... |
| ... | ... | @@ -0,0 +1,59 @@ |
| 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 | + | |
| 32 | +/*---[ Implement ]----------------------------------------------------------------------------------*/ | |
| 33 | + | |
| 34 | + GObject * pw3270_keypad_model_new_from_xml(const gchar *filename) { | |
| 35 | + | |
| 36 | + GObject * object = g_object_new(PW_TYPE_KEYPAD_MODEL,NULL); | |
| 37 | + GError * error = NULL; | |
| 38 | + g_autofree gchar *text = NULL; | |
| 39 | + | |
| 40 | + if(g_file_get_contents(filename,&text,NULL,&error)) { | |
| 41 | + | |
| 42 | + g_message("Loading keypad from %s",filename); | |
| 43 | + | |
| 44 | + | |
| 45 | + } | |
| 46 | + | |
| 47 | + if(error) { | |
| 48 | + | |
| 49 | + // TODO: Popup with error message. | |
| 50 | + g_error_free(error); | |
| 51 | + error = NULL; | |
| 52 | + g_object_unref(object); | |
| 53 | + object = NULL; | |
| 54 | + | |
| 55 | + } | |
| 56 | + | |
| 57 | + return object; | |
| 58 | + | |
| 59 | + } | ... | ... |
| ... | ... | @@ -0,0 +1,233 @@ |
| 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 | + | |
| 32 | +/*---[ Globals & Object definition ]----------------------------------------------------------------*/ | |
| 33 | + | |
| 34 | + enum { | |
| 35 | + PROP_NONE, | |
| 36 | + PROP_NAME, | |
| 37 | + PROP_LABEL, | |
| 38 | + PROP_POSITION, | |
| 39 | + PROP_WIDTH, | |
| 40 | + PROP_HEIGHT, | |
| 41 | + }; | |
| 42 | + | |
| 43 | + static const char * positions[] = { | |
| 44 | + "up", | |
| 45 | + "down", | |
| 46 | + "left", | |
| 47 | + "right" | |
| 48 | + }; | |
| 49 | + | |
| 50 | + static void get_property(GObject *object, guint prop_id, GValue *value, GParamSpec *pspec); | |
| 51 | + static void set_property(GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec); | |
| 52 | + | |
| 53 | + G_DEFINE_TYPE(KeypadModel, KeypadModel, G_TYPE_OBJECT) | |
| 54 | + | |
| 55 | +/*---[ Implement ]----------------------------------------------------------------------------------*/ | |
| 56 | + | |
| 57 | + static void finalize(GObject *object) { | |
| 58 | + | |
| 59 | + KeypadModel * model = PW_KEYPAD_MODEL(object); | |
| 60 | + | |
| 61 | + if(model->name) { | |
| 62 | + g_free(model->name); | |
| 63 | + model->name = NULL; | |
| 64 | + } | |
| 65 | + | |
| 66 | + if(model->label) { | |
| 67 | + g_free(model->label); | |
| 68 | + model->label = NULL; | |
| 69 | + } | |
| 70 | + | |
| 71 | + } | |
| 72 | + | |
| 73 | + static void KeypadModel_class_init(KeypadModelClass *klass) { | |
| 74 | + | |
| 75 | + GObjectClass *object_class = G_OBJECT_CLASS(klass); | |
| 76 | + | |
| 77 | + klass->domain = g_quark_from_static_string("keypad"); | |
| 78 | + | |
| 79 | + object_class->finalize = finalize; | |
| 80 | + object_class->get_property = get_property; | |
| 81 | + object_class->set_property = set_property; | |
| 82 | + | |
| 83 | + // Install properties | |
| 84 | + g_object_class_install_property(object_class, PROP_NAME, | |
| 85 | + g_param_spec_string ( | |
| 86 | + "name", | |
| 87 | + N_("Keypad Name"), | |
| 88 | + N_("The name used to identify the keypad"), | |
| 89 | + NULL, | |
| 90 | + G_PARAM_STATIC_STRINGS | G_PARAM_READABLE | G_PARAM_WRITABLE | |
| 91 | + ) | |
| 92 | + ); | |
| 93 | + | |
| 94 | + g_object_class_install_property(object_class, PROP_LABEL, | |
| 95 | + g_param_spec_string ( | |
| 96 | + "label", | |
| 97 | + N_("Keypad Label"), | |
| 98 | + N_("The Label of the keypad"), | |
| 99 | + NULL, | |
| 100 | + G_PARAM_STATIC_STRINGS | G_PARAM_READABLE | G_PARAM_WRITABLE | |
| 101 | + ) | |
| 102 | + ); | |
| 103 | + | |
| 104 | + g_object_class_install_property(object_class, PROP_POSITION, | |
| 105 | + g_param_spec_string ( | |
| 106 | + "position", | |
| 107 | + N_("Keypad position"), | |
| 108 | + N_("The position of the keypad"), | |
| 109 | + NULL, | |
| 110 | + G_PARAM_STATIC_STRINGS | G_PARAM_READABLE | G_PARAM_WRITABLE | |
| 111 | + ) | |
| 112 | + ); | |
| 113 | + | |
| 114 | + g_object_class_install_property(object_class, PROP_WIDTH, | |
| 115 | + g_param_spec_uint( | |
| 116 | + "width", | |
| 117 | + "width", | |
| 118 | + _("Keypad width in columns"), | |
| 119 | + 1, | |
| 120 | + 10, | |
| 121 | + 3, | |
| 122 | + G_PARAM_STATIC_STRINGS | G_PARAM_READABLE | G_PARAM_WRITABLE | |
| 123 | + ) | |
| 124 | + ); | |
| 125 | + | |
| 126 | + g_object_class_install_property(object_class, PROP_WIDTH, | |
| 127 | + g_param_spec_uint( | |
| 128 | + "height", | |
| 129 | + "height", | |
| 130 | + _("Keypad height in rows"), | |
| 131 | + 0, | |
| 132 | + 100, | |
| 133 | + 0, | |
| 134 | + G_PARAM_STATIC_STRINGS | G_PARAM_READABLE | G_PARAM_WRITABLE | |
| 135 | + ) | |
| 136 | + ); | |
| 137 | + } | |
| 138 | + | |
| 139 | + static void KeypadModel_init(KeypadModel *object) { | |
| 140 | + | |
| 141 | + | |
| 142 | + } | |
| 143 | + | |
| 144 | + static void get_property(GObject *object, guint prop_id, GValue *value, GParamSpec *pspec) { | |
| 145 | + | |
| 146 | + KeypadModel * model = PW_KEYPAD_MODEL(object); | |
| 147 | + | |
| 148 | + switch (prop_id) { | |
| 149 | + case PROP_NAME: | |
| 150 | + g_value_set_string(value, model->name); | |
| 151 | + break; | |
| 152 | + | |
| 153 | + case PROP_LABEL: | |
| 154 | + g_value_set_string(value, model->label); | |
| 155 | + break; | |
| 156 | + | |
| 157 | + case PROP_POSITION: | |
| 158 | + g_value_set_static_string(value,keypad_model_get_position(object)); | |
| 159 | + break; | |
| 160 | + | |
| 161 | + case PROP_HEIGHT: | |
| 162 | + g_value_set_uint(value, model->height); | |
| 163 | + break; | |
| 164 | + | |
| 165 | + case PROP_WIDTH: | |
| 166 | + g_value_set_uint(value, model->width); | |
| 167 | + break; | |
| 168 | + | |
| 169 | + default: | |
| 170 | + g_assert_not_reached (); | |
| 171 | + } | |
| 172 | + | |
| 173 | + } | |
| 174 | + | |
| 175 | + static void set_property(GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec) { | |
| 176 | + | |
| 177 | + KeypadModel * model = PW_KEYPAD_MODEL(object); | |
| 178 | + | |
| 179 | + switch (prop_id) { | |
| 180 | + case PROP_NAME: | |
| 181 | + | |
| 182 | + if(model->name) { | |
| 183 | + g_free(model->name); | |
| 184 | + model->name = g_value_dup_string(value); | |
| 185 | + } | |
| 186 | + break; | |
| 187 | + | |
| 188 | + case PROP_LABEL: | |
| 189 | + | |
| 190 | + if(model->label) { | |
| 191 | + g_free(model->label); | |
| 192 | + model->label = g_value_dup_string(value); | |
| 193 | + } | |
| 194 | + break; | |
| 195 | + | |
| 196 | + case PROP_POSITION: | |
| 197 | + keypad_model_set_position(object,g_value_get_string(value)); | |
| 198 | + break; | |
| 199 | + | |
| 200 | + case PROP_HEIGHT: | |
| 201 | + model->height = (unsigned short) g_value_get_uint(value); | |
| 202 | + break; | |
| 203 | + | |
| 204 | + case PROP_WIDTH: | |
| 205 | + model->width = (unsigned short) g_value_get_uint(value); | |
| 206 | + break; | |
| 207 | + | |
| 208 | + default: | |
| 209 | + g_assert_not_reached(); | |
| 210 | + } | |
| 211 | + } | |
| 212 | + | |
| 213 | + void keypad_model_set_position(GObject *model, const gchar *position) { | |
| 214 | + | |
| 215 | + size_t ix; | |
| 216 | + for(ix = 0; ix < G_N_ELEMENTS(positions); ix++) { | |
| 217 | + if(!g_ascii_strcasecmp(positions[ix],position)) { | |
| 218 | + PW_KEYPAD_MODEL(model)->position = (unsigned short) ix; | |
| 219 | + break; | |
| 220 | + } | |
| 221 | + } | |
| 222 | + | |
| 223 | + } | |
| 224 | + | |
| 225 | + const gchar * keypad_model_get_position(GObject *model) { | |
| 226 | + | |
| 227 | + size_t ix = (size_t) PW_KEYPAD_MODEL(model)->position; | |
| 228 | + | |
| 229 | + if(ix < G_N_ELEMENTS(positions)) | |
| 230 | + return positions[ix]; | |
| 231 | + | |
| 232 | + return "undefined"; | |
| 233 | + } | ... | ... |
| ... | ... | @@ -0,0 +1,71 @@ |
| 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 | +#ifndef PRIVATE_H_INCLUDED | |
| 31 | + | |
| 32 | + #define PRIVATE_H_INCLUDED | |
| 33 | + | |
| 34 | + #include <config.h> | |
| 35 | + | |
| 36 | + #ifndef GETTEXT_PACKAGE | |
| 37 | + #define GETTEXT_PACKAGE PACKAGE_NAME | |
| 38 | + #endif | |
| 39 | + | |
| 40 | + #include <libintl.h> | |
| 41 | + #include <glib/gi18n.h> | |
| 42 | + #include <gtk/gtk.h> | |
| 43 | + | |
| 44 | + #include <lib3270.h> | |
| 45 | + #include <lib3270/log.h> | |
| 46 | + | |
| 47 | + #include <pw3270/keypad.h> | |
| 48 | + | |
| 49 | + struct _KeypadModel { | |
| 50 | + GObject parent; | |
| 51 | + | |
| 52 | + unsigned short width; | |
| 53 | + unsigned short height; | |
| 54 | + unsigned short position; | |
| 55 | + | |
| 56 | + gchar *name; | |
| 57 | + gchar *label; | |
| 58 | + | |
| 59 | + | |
| 60 | + }; | |
| 61 | + | |
| 62 | + struct _KeypadModelClass { | |
| 63 | + GObjectClass parent; | |
| 64 | + GQuark domain; | |
| 65 | + | |
| 66 | + }; | |
| 67 | + | |
| 68 | + void keypad_model_set_position(GObject *model, const gchar *position); | |
| 69 | + const gchar * keypad_model_get_position(GObject *mode); | |
| 70 | + | |
| 71 | +#endif // PRIVATE_H_INCLUDED | ... | ... |
src/objects/keypad/testprogram/testprogram.c