Commit 828fe62163e23dea55f8ec57ab779c7fe7e9ec01

Authored by Perry Werneck
1 parent 7632ef36
Exists in master and in 1 other branch develop

Rewriting getter/setters to use lib3270 internal tables.

src/testprogram/testprogram.c
... ... @@ -92,12 +92,21 @@ static void activate(GtkApplication* app, gpointer user_data) {
92 92 GtkWidget * window = gtk_application_window_new(app);
93 93 GtkWidget * terminal = v3270_new();
94 94 gchar * filename = NULL;
  95 + GValue val = G_VALUE_INIT;
95 96  
96 97 const gchar *url = getenv("LIB3270_DEFAULT_HOST");
97 98 if(url) {
98 99  
  100 + /*
99 101 v3270_set_url(terminal,url);
100 102 v3270_connect(terminal);
  103 + */
  104 +
  105 + g_value_init (&val, G_TYPE_STRING);
  106 + g_value_set_string(&val,url);
  107 + g_object_set_property(G_OBJECT(terminal), "url", &val);
  108 + g_value_unset(&val);
  109 +
101 110 gchar * title = g_strdup_printf("%s - %s", v3270_get_session_name(terminal), url);
102 111 gtk_window_set_title(GTK_WINDOW(window), title);
103 112 g_free(title);
... ... @@ -106,6 +115,11 @@ static void activate(GtkApplication* app, gpointer user_data) {
106 115 gtk_window_set_title(GTK_WINDOW(window), v3270_get_session_name(terminal));
107 116 }
108 117  
  118 + g_value_init(&val, G_TYPE_STRING);
  119 + g_object_get_property(G_OBJECT(terminal),"url",&val);
  120 + g_message("URL=%s",g_value_get_string(&val));
  121 + g_value_unset(&val);
  122 +
109 123 g_signal_connect(terminal,"popup",G_CALLBACK(popup_menu),NULL);
110 124  
111 125 // Setup and show window
... ...
src/v3270/oia.c
... ... @@ -711,11 +711,7 @@ void v3270_update_luname(GtkWidget *widget,const gchar *name)
711 711 v3270_queue_draw_area(GTK_WIDGET(terminal),rect->x,rect->y,rect->width,rect->height);
712 712 }
713 713  
714   -#if GTK_CHECK_VERSION(2,26,0)
715   - g_object_notify_by_pspec(G_OBJECT(widget), v3270_properties[PROP_LUNAME]);
716   -#else
717   - g_object_notify(G_OBJECT(widget),"luname");
718   -#endif // GTK_CHECK_VERSION
  714 +// g_object_notify_by_pspec(G_OBJECT(widget), v3270_properties[PROP_LUNAME]);
719 715  
720 716 }
721 717  
... ...
src/v3270/private.h
... ... @@ -201,15 +201,15 @@ G_BEGIN_DECLS
201 201  
202 202 /*--[ Properties ]-----------------------------------------------------------------------------------*/
203 203  
  204 + /*
204 205 enum
205 206 {
206 207 PROP_0,
207 208  
208   - /* Construct */
  209 + // Construct
209 210 PROP_TYPE,
210 211  
211   -
212   - /* Widget properties */
  212 + // Widget properties
213 213 PROP_ONLINE,
214 214 PROP_SELECTION,
215 215 PROP_MODEL,
... ... @@ -218,21 +218,37 @@ G_BEGIN_DECLS
218 218 PROP_URL,
219 219 PROP_SESSION_NAME,
220 220  
221   - /* Toggles - always the last one, the real values are PROP_TOGGLE+LIB3270_TOGGLE */
  221 + // Toggles - always the last one, the real values are PROP_TOGGLE+LIB3270_TOGGLE
222 222 PROP_TOGGLE
223 223 };
224 224  
225 225 #define PROP_LAST (PROP_TOGGLE+LIB3270_TOGGLE_COUNT)
226   -
  226 + */
227 227  
228 228 /*--[ Globals ]--------------------------------------------------------------------------------------*/
229 229  
230 230 G_GNUC_INTERNAL guint v3270_widget_signal[LAST_SIGNAL];
231 231 G_GNUC_INTERNAL GdkCursor * v3270_cursor[LIB3270_POINTER_COUNT];
232   - G_GNUC_INTERNAL GParamSpec * v3270_properties[PROP_LAST];
  232 +// G_GNUC_INTERNAL GParamSpec * v3270_properties[PROP_LAST];
233 233 G_GNUC_INTERNAL const gchar * v3270_default_colors;
234 234 G_GNUC_INTERNAL const gchar * v3270_default_font;
235 235  
  236 + G_GNUC_INTERNAL struct _v3270_properties
  237 + {
  238 + size_t count; // Number of properties.
  239 + GParamSpec **toggle; // Toggle properties.
  240 +
  241 + struct
  242 + {
  243 + guint toggle;
  244 + guint boolean;
  245 + guint integer;
  246 + guint str;
  247 + } type;
  248 +
  249 + } v3270_properties;
  250 +
  251 +
236 252 /*--[ Prototipes ]-----------------------------------------------------------------------------------*/
237 253  
238 254 const GtkWidgetClass * v3270_get_parent_class(void);
... ...
src/v3270/properties.c
... ... @@ -34,28 +34,74 @@
34 34 #endif // WIN32
35 35  
36 36 #include <gtk/gtk.h>
  37 + #include <limits.h>
37 38 #include <lib3270.h>
38 39 #include <lib3270/session.h>
39 40 #include <lib3270/actions.h>
40 41 #include <lib3270/log.h>
41   - #include <lib3270/macros.h>
  42 + #include <lib3270/properties.h>
42 43 #include <stdlib.h>
43 44 #include <errno.h>
44 45 #include <v3270.h>
45 46 #include "private.h"
46 47  
  48 + #define PROP_BEGIN 2
  49 +
47 50 /*--[ Globals ]--------------------------------------------------------------------------------------*/
48 51  
49   - GParamSpec * v3270_properties[PROP_LAST] = { 0 };
  52 +// GParamSpec * v3270_properties[PROP_LAST] = { 0 };
50 53  
51 54 /*--[ Implement ]------------------------------------------------------------------------------------*/
52 55  
53 56 static void v3270_set_property(GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec)
54 57 {
55   - debug("%s(%u)",__FUNCTION__,prop_id);
56   -
57 58 v3270 *window = GTK_V3270(object);
58 59  
  60 + debug("%s(%u,%s)",__FUNCTION__,prop_id,g_param_spec_get_name(pspec));
  61 +
  62 + if(prop_id < v3270_properties.type.toggle)
  63 + {
  64 + G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
  65 + }
  66 + else if(prop_id >= v3270_properties.type.str)
  67 + {
  68 + const LIB3270_STRING_PROPERTY * prop = (lib3270_get_string_properties_list()+(prop_id - v3270_properties.type.str));
  69 + debug("%s.%s.%s=%s",__FUNCTION__,"string",prop->name,g_value_get_string(value));
  70 +
  71 + if(prop->set)
  72 + prop->set(window->host,g_value_get_string(value));
  73 +
  74 + }
  75 + else if(prop_id >= v3270_properties.type.integer)
  76 + {
  77 + const LIB3270_INT_PROPERTY * prop = (lib3270_get_int_properties_list()+(prop_id - v3270_properties.type.integer));
  78 + debug("%s.%s.%s",__FUNCTION__,"integer",prop->name);
  79 +
  80 + if(prop->set)
  81 + prop->set(window->host,g_value_get_int(value));
  82 +
  83 + }
  84 + else if(prop_id >= v3270_properties.type.boolean)
  85 + {
  86 + const LIB3270_INT_PROPERTY * prop = (lib3270_get_boolean_properties_list()+(prop_id - v3270_properties.type.boolean));
  87 + debug("%s.%s.%s",__FUNCTION__,"boolean",prop->name);
  88 +
  89 + if(prop->set)
  90 + prop->set(window->host,g_value_get_boolean(value) ? 1 : 0);
  91 +
  92 + }
  93 + else if(prop_id >= v3270_properties.type.toggle)
  94 + {
  95 + debug("%s.%s",__FUNCTION__,"toggle");
  96 +
  97 + }
  98 + else
  99 + {
  100 + G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
  101 + }
  102 +
  103 + /*
  104 +
59 105 switch (prop_id)
60 106 {
61 107 case PROP_MODEL:
... ... @@ -82,13 +128,54 @@
82 128 }
83 129 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
84 130 }
  131 + */
85 132  
86 133 }
87 134  
88 135 static void v3270_get_property(GObject *object,guint prop_id, GValue *value, GParamSpec *pspec)
89 136 {
90   - debug("%s(%u)",__FUNCTION__,prop_id);
  137 + v3270 *window = GTK_V3270(object);
  138 +
  139 + debug("%s(%u,%s)",__FUNCTION__,prop_id,g_param_spec_get_name(pspec));
  140 +
  141 + if(prop_id < v3270_properties.type.toggle)
  142 + {
  143 + G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
  144 + }
  145 + else if(prop_id >= v3270_properties.type.str)
  146 + {
  147 + const LIB3270_STRING_PROPERTY * prop = (lib3270_get_string_properties_list()+(prop_id - v3270_properties.type.str));
  148 + debug("%s.%s.%s",__FUNCTION__,"string",prop->name);
  149 +
  150 + if(prop->get)
  151 + g_value_set_string(value,prop->get(window->host));
  152 +
  153 + }
  154 + else if(prop_id >= v3270_properties.type.integer)
  155 + {
  156 + const LIB3270_INT_PROPERTY * prop = (lib3270_get_int_properties_list()+(prop_id - v3270_properties.type.integer));
  157 + debug("%s.%s.%s",__FUNCTION__,"integer",prop->name);
  158 +
  159 +
  160 + }
  161 + else if(prop_id >= v3270_properties.type.boolean)
  162 + {
  163 + const LIB3270_INT_PROPERTY * prop = (lib3270_get_boolean_properties_list()+(prop_id - v3270_properties.type.boolean));
  164 + debug("%s.%s.%s",__FUNCTION__,"boolean",prop->name);
  165 +
91 166  
  167 + }
  168 + else if(prop_id >= v3270_properties.type.toggle)
  169 + {
  170 + debug("%s.%s",__FUNCTION__,"toggle");
  171 +
  172 + }
  173 + else
  174 + {
  175 + G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
  176 + }
  177 +
  178 + /*
92 179 v3270 *window = GTK_V3270(object);
93 180  
94 181 switch (prop_id)
... ... @@ -129,17 +216,96 @@
129 216 }
130 217 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
131 218 }
  219 + */
132 220 }
133 221  
134 222 void v3270_init_properties(GObjectClass * gobject_class)
135 223 {
  224 + size_t ix;
  225 + GParamSpec * spec;
  226 +
136 227 debug("%s",__FUNCTION__);
137 228  
138   - memset(v3270_properties,0,sizeof(v3270_properties));
  229 + memset(&v3270_properties,0,sizeof(v3270_properties));
  230 + v3270_properties.count = LIB3270_TOGGLE_COUNT;
  231 + v3270_properties.type.toggle = PROP_BEGIN;
139 232  
140 233 gobject_class->set_property = v3270_set_property;
141 234 gobject_class->get_property = v3270_get_property;
142 235  
  236 + // Get property tables
  237 + const LIB3270_INT_PROPERTY * bool_props = lib3270_get_boolean_properties_list();
  238 + const LIB3270_INT_PROPERTY * int_props = lib3270_get_int_properties_list();
  239 + const LIB3270_STRING_PROPERTY * str_props = lib3270_get_string_properties_list();
  240 +
  241 + v3270_properties.type.boolean = v3270_properties.count + PROP_BEGIN;
  242 + for(ix = 0; bool_props[ix].name; ix++)
  243 + {
  244 + v3270_properties.count++;
  245 + }
  246 +
  247 + v3270_properties.type.integer = v3270_properties.count + PROP_BEGIN;
  248 + for(ix = 0; int_props[ix].name; ix++)
  249 + {
  250 + v3270_properties.count++;
  251 + }
  252 +
  253 + v3270_properties.type.str = v3270_properties.count + PROP_BEGIN;
  254 + for(ix = 0; str_props[ix].name; ix++)
  255 + {
  256 + v3270_properties.count++;
  257 + }
  258 +
  259 + debug("Creating %u properties", (unsigned int) v3270_properties.count);
  260 +
  261 + // Creating toggle properties.
  262 + for(ix = 0; ix < LIB3270_TOGGLE_COUNT; ix++)
  263 + {
  264 + debug("Property %u=%s (Toggle)",(unsigned int) v3270_properties.type.toggle + ix, lib3270_get_toggle_name(ix));
  265 + spec = g_param_spec_boolean(lib3270_get_toggle_name(ix),lib3270_get_toggle_name(ix),lib3270_get_toggle_description(ix),FALSE,G_PARAM_WRITABLE|G_PARAM_READABLE);
  266 + g_object_class_install_property(gobject_class, v3270_properties.type.toggle + ix, spec);
  267 + }
  268 +
  269 +
  270 + // Creating boolean properties.
  271 + for(ix = 0; bool_props[ix].name; ix++)
  272 + {
  273 + debug("Property %u=%s (Boolean)",(unsigned int) v3270_properties.type.boolean + ix, bool_props[ix].name);
  274 + spec = g_param_spec_boolean(bool_props[ix].name, bool_props[ix].name, bool_props[ix].description, FALSE,(bool_props[ix].set == NULL ? G_PARAM_READABLE : (G_PARAM_READABLE|G_PARAM_WRITABLE)));
  275 + g_object_class_install_property(gobject_class, v3270_properties.type.boolean + ix, spec);
  276 +
  277 + }
  278 +
  279 + // Creating integer properties.
  280 + for(ix = 0; int_props[ix].name; ix++)
  281 + {
  282 + debug("Property %u=%s (Integer)",(unsigned int) v3270_properties.type.integer + ix, int_props[ix].name);
  283 +
  284 + spec = g_param_spec_int(
  285 + int_props[ix].name,
  286 + int_props[ix].name,
  287 + int_props[ix].description,
  288 + 0, // Minimo
  289 + INT_MAX, // Máximo
  290 + 0, // Default
  291 + (int_props[ix].set == NULL ? G_PARAM_READABLE : (G_PARAM_READABLE|G_PARAM_WRITABLE))
  292 + );
  293 +
  294 + g_object_class_install_property(gobject_class, v3270_properties.type.integer + ix, spec);
  295 +
  296 + }
  297 +
  298 + // Creating string properties.
  299 + for(ix = 0; str_props[ix].name; ix++)
  300 + {
  301 + debug("Property %u=%s (String)",(unsigned int) v3270_properties.type.str + ix, str_props[ix].name);
  302 + spec = g_param_spec_string(str_props[ix].name, str_props[ix].name, str_props[ix].description, FALSE,(str_props[ix].set == NULL ? G_PARAM_READABLE : (G_PARAM_READABLE|G_PARAM_WRITABLE)));
  303 + g_object_class_install_property(gobject_class, v3270_properties.type.str + ix, spec);
  304 +
  305 + }
  306 +
  307 +
  308 + /*
143 309 v3270_properties[PROP_ONLINE] = g_param_spec_boolean(
144 310 "online",
145 311 "online",
... ... @@ -206,6 +372,7 @@
206 372 g_object_class_install_property(gobject_class,PROP_TOGGLE+f,v3270_properties[PROP_TOGGLE+f]);
207 373 }
208 374 debug("%s",__FUNCTION__);
  375 + */
209 376 }
210 377  
211 378 void v3270_set_auto_disconnect(GtkWidget *widget, guint minutes)
... ...
src/v3270/widget.c
... ... @@ -718,13 +718,10 @@ static void update_toggle(H3270 *session, LIB3270_TOGGLE ix, unsigned char value
718 718 break;
719 719  
720 720 }
721   -#if GTK_CHECK_VERSION(2,26,0)
722   - g_object_notify_by_pspec(G_OBJECT(widget), v3270_properties[PROP_TOGGLE+ix]);
723   -#else
724   - g_object_notify(G_OBJECT(widget),name);
725   -#endif // GTK_CHECK_VERSION
726 721  
  722 + g_object_notify_by_pspec(G_OBJECT(widget), v3270_properties.toggle[ix]);
727 723 g_signal_emit(widget, v3270_widget_signal[SIGNAL_TOGGLE_CHANGED], 0, (guint) ix, (gboolean) (value != 0), (gchar *) name);
  724 +
728 725 }
729 726  
730 727 static void update_message(H3270 *session, LIB3270_MESSAGE id)
... ... @@ -785,11 +782,7 @@ static void update_connect(H3270 *session, unsigned char connected)
785 782 g_signal_emit(GTK_WIDGET(widget), v3270_widget_signal[SIGNAL_DISCONNECTED], 0);
786 783 }
787 784  
788   -#if GTK_CHECK_VERSION(2,26,0)
789   - g_object_notify_by_pspec(G_OBJECT(widget), v3270_properties[PROP_ONLINE]);
790   -#else
791   - g_object_notify(G_OBJECT(widget),"online");
792   -#endif // GTK_CHECK_VERSION
  785 + // g_object_notify_by_pspec(G_OBJECT(widget), v3270_properties[PROP_ONLINE]);
793 786  
794 787 widget->activity.timestamp = time(0);
795 788  
... ... @@ -804,11 +797,7 @@ static void update_screen_size(H3270 *session,unsigned short rows, unsigned shor
804 797  
805 798 static void update_model(H3270 *session, const char *name, int model, int rows, int cols)
806 799 {
807   -#if GTK_CHECK_VERSION(2,26,0)
808   - g_object_notify_by_pspec(G_OBJECT(lib3270_get_user_data(session)), v3270_properties[PROP_MODEL]);
809   -#else
810   - g_object_notify(G_OBJECT(lib3270_get_user_data(session)),"model");
811   -#endif // GTK_CHECK_VERSION
  800 +// g_object_notify_by_pspec(G_OBJECT(lib3270_get_user_data(session)), v3270_properties[PROP_MODEL]);
812 801 g_signal_emit(GTK_WIDGET(lib3270_get_user_data(session)),v3270_widget_signal[SIGNAL_MODEL_CHANGED], 0, (guint) model, name);
813 802 }
814 803  
... ... @@ -863,13 +852,9 @@ static void set_selection(H3270 *session, unsigned char status)
863 852 {
864 853 GtkWidget * widget = GTK_WIDGET(lib3270_get_user_data(session));
865 854  
866   -#if GTK_CHECK_VERSION(2,26,0)
867   - g_object_notify_by_pspec(G_OBJECT(widget), v3270_properties[PROP_SELECTION]);
868   -#else
869   - g_object_notify(G_OBJECT(widget),"selection");
870   -#endif // GTK_CHECK_VERSION
871   -
  855 +// g_object_notify_by_pspec(G_OBJECT(widget), v3270_properties[PROP_SELECTION]);
872 856 g_signal_emit(widget,v3270_widget_signal[SIGNAL_SELECTING], 0, status ? TRUE : FALSE);
  857 +
873 858 }
874 859  
875 860 static void update_selection(H3270 *session, int start, int end)
... ...