Commit 6bb62c53021e09c227108283bdd73f26b6b1dbf0

Authored by Perry Werneck
1 parent 8cfde575

GAction Adapter for lib3270 toggles seens ok.

src/actions/abstract.c
... ... @@ -128,8 +128,6 @@
128 128 NULL,
129 129 G_PARAM_READWRITE | G_PARAM_CONSTRUCT |
130 130 G_PARAM_STATIC_STRINGS));
131   -
132   -
133 131 }
134 132  
135 133 void pw3270Action_init(pw3270Action *action) {
... ... @@ -144,19 +142,27 @@
144 142  
145 143 pw3270Action * action = PW3270_ACTION(object);
146 144  
147   - if(action->terminal)
  145 + debug("Finalizing action %p (%s)",object,action->name);
  146 +
  147 + if(action->state) {
  148 + g_variant_unref(action->state);
  149 + action->state = NULL;
  150 + }
  151 +
  152 + if(action->terminal) {
148 153 pw3270_action_set_terminal_widget(G_ACTION(object),NULL);
  154 + action->terminal = NULL;
  155 + }
149 156  
150 157 if(action->name) {
151   -
152   - debug("Finalizing action \"%s\"",action->name);
153 158 g_free(action->name);
154 159 action->name = NULL;
155   -
156 160 }
157 161  
158   - if(action->parameter_type)
  162 + if(action->parameter_type) {
159 163 g_variant_type_free(action->parameter_type);
  164 + action->parameter_type = NULL;
  165 + }
160 166  
161 167 G_OBJECT_CLASS(pw3270Action_parent_class)->finalize(object);
162 168  
... ... @@ -246,8 +252,9 @@
246 252  
247 253 }
248 254  
249   - GVariant * pw3270_action_get_state_property(GAction *action) {
250   - return PW3270_ACTION(action)->state;
  255 + GVariant * pw3270_action_get_state_property(GAction *object) {
  256 + pw3270Action *action = PW3270_ACTION(object);
  257 + return action->state ? g_variant_ref(action->state) : NULL;
251 258 }
252 259  
253 260 const GVariantType * pw3270_action_get_parameter_type(GAction *action) {
... ... @@ -259,10 +266,10 @@
259 266  
260 267 pw3270Action * action = PW3270_ACTION(object);
261 268  
262   - if(action->state != NULL)
  269 + if(action->state)
263 270 return g_variant_get_type(action->state);
264   - else
265   - return NULL;
  271 +
  272 + return NULL;
266 273  
267 274 }
268 275  
... ... @@ -272,15 +279,13 @@
272 279 }
273 280  
274 281 void pw3270_action_change_state(GAction *object, GVariant *value) {
  282 + pw3270_action_set_state(object, value);
  283 + }
275 284  
276   - /*
277   - pw3270Action * action = PW3270_ACTION(object);
278   -
279   - if (g_signal_has_handler_pending(object, pw3270_action_signals[SIGNAL_CHANGE_STATE], 0, TRUE))
280   - g_signal_emit(action, pw3270_action_signals[SIGNAL_CHANGE_STATE], 0, value);
281   - */
  285 + void pw3270_action_change_state_boolean(GAction *action, gboolean state) {
282 286  
283   - pw3270_action_set_state(object, value);
  287 + g_return_if_fail(PW3270_IS_ACTION(action));
  288 + pw3270_action_set_state(action,g_variant_new_boolean(state));
284 289  
285 290 }
286 291  
... ... @@ -300,6 +305,7 @@
300 305 action->state = g_variant_ref(value);
301 306  
302 307 g_object_notify(G_OBJECT(object), "state");
  308 +
303 309 }
304 310  
305 311 g_variant_unref(value);
... ... @@ -325,10 +331,6 @@
325 331  
326 332 }
327 333  
328   - void pw3270_action_change_state_boolean(GAction *action, gboolean state) {
329   - pw3270_action_change_state(action,g_variant_new_boolean(state));
330   - }
331   -
332 334 gboolean pw3270_action_get_enabled(GAction *object) {
333 335  
334 336 pw3270Action * action = PW3270_ACTION(object);
... ... @@ -358,7 +360,7 @@
358 360 }
359 361  
360 362 gboolean get_enabled(GAction *object, GtkWidget *terminal) {
361   - debug("%s",__FUNCTION__);
  363 + debug("%s(%s)",__FUNCTION__,pw3270_action_get_name(object));
362 364 return TRUE;
363 365 }
364 366  
... ...
src/actions/lib3270/toggle.c
... ... @@ -59,6 +59,7 @@
59 59 G_DEFINE_TYPE(Lib3270ToggleAction, Lib3270ToggleAction, PW3270_TYPE_ACTION);
60 60  
61 61 static void change_state(H3270 *hSession, LIB3270_TOGGLE_ID id, char state, void * action) {
  62 + debug("%s: %s",__FUNCTION__,state ? "ON" : "OFF");
62 63 pw3270_action_change_state_boolean((GAction *) action, state == 0 ? FALSE : TRUE);
63 64 }
64 65  
... ... @@ -71,7 +72,7 @@
71 72 }
72 73  
73 74 if(to) {
74   - action->listener = lib3270_register_toggle_listener(v3270_get_session(from),action->definition->id,change_state,object);
  75 + action->listener = lib3270_register_toggle_listener(v3270_get_session(to),action->definition->id,change_state,object);
75 76 pw3270_action_change_state_boolean(object,lib3270_get_toggle(v3270_get_session(to),action->definition->id));
76 77 }
77 78  
... ... @@ -80,7 +81,21 @@
80 81 }
81 82  
82 83 static void activate(GAction *action, GVariant *parameter, GtkWidget *terminal) {
83   - lib3270_toggle(v3270_get_session(terminal),PW3270_LIB3270_TOGGLE_ACTION(action)->definition->id);
  84 +
  85 + debug("Activating \"%s\"",pw3270_action_get_name(action));
  86 +
  87 + if(parameter && g_variant_is_of_type(parameter,G_VARIANT_TYPE_BOOLEAN)) {
  88 +
  89 + lib3270_set_toggle(v3270_get_session(terminal),PW3270_LIB3270_TOGGLE_ACTION(action)->definition->id,g_variant_get_boolean(parameter));
  90 + debug("Toggle set to %s",lib3270_get_toggle(v3270_get_session(terminal),PW3270_LIB3270_TOGGLE_ACTION(action)->definition->id) ? "ON" : "OFF");
  91 +
  92 + } else {
  93 +
  94 + lib3270_toggle(v3270_get_session(terminal),PW3270_LIB3270_TOGGLE_ACTION(action)->definition->id);
  95 + debug("Toggle is %s",lib3270_get_toggle(v3270_get_session(terminal),PW3270_LIB3270_TOGGLE_ACTION(action)->definition->id) ? "ON" : "OFF");
  96 +
  97 + }
  98 +
84 99 }
85 100  
86 101 void Lib3270ToggleAction_class_init(Lib3270ToggleActionClass *klass) {
... ...
src/actions/testprogram/testprogram.c
... ... @@ -32,7 +32,9 @@
32 32 #include <v3270.h>
33 33 #include <v3270/trace.h>
34 34 #include <lib3270/log.h>
  35 + #include <lib3270/toggle.h>
35 36 #include <pw3270/actions.h>
  37 + #include "../private.h"
36 38  
37 39 /*---[ Implement ]----------------------------------------------------------------------------------*/
38 40  
... ...
src/actions/window.c
... ... @@ -53,10 +53,19 @@
53 53 debug("--> \"%s\"",pw3270_action_get_name(action));
54 54 */
55 55  
  56 + /*
  57 + GAction *action = pw3270_toggle_action_new_from_lib3270(lib3270_get_toggles() + LIB3270_TOGGLE_INSERT);
  58 + pw3270_action_set_terminal_widget(action,terminal);
  59 +
  60 + debug("--> \"%s\"",pw3270_action_get_name(action));
  61 +
  62 + g_action_map_add_action(map,action);
  63 +
  64 + debug("--> \"%s\"",pw3270_action_get_name(action));
  65 + */
56 66  
57 67 // Map lib3270 actions
58 68 const LIB3270_ACTION * actions = lib3270_get_actions();
59   -
60 69 for(ix = 0; actions[ix].name; ix++) {
61 70  
62 71 GAction *action = pw3270_action_new_from_lib3270(&actions[ix]);
... ... @@ -66,6 +75,14 @@
66 75 }
67 76  
68 77 // Map toggles
  78 + const LIB3270_TOGGLE * toggles = lib3270_get_toggles();
  79 + for(ix = 0; toggles[ix].name; ix++) {
  80 +
  81 + GAction *action = pw3270_toggle_action_new_from_lib3270(&toggles[ix]);
  82 + pw3270_action_set_terminal_widget(action,terminal);
  83 + g_action_map_add_action(map,action);
  84 +
  85 + }
69 86  
70 87 debug("%s ends",__FUNCTION__);
71 88 }
... ...