Commit ad2421a16713e688db910d9b3a787bd092b4ba95

Authored by Perry Werneck
1 parent fc343827

Fixing toggle action.

src/objects/actions/abstract.c
... ... @@ -33,14 +33,11 @@
33 33 static void pw3270_action_iface_init(GActionInterface *iface);
34 34 static void pw3270Action_class_init(pw3270ActionClass *klass);
35 35 static void pw3270Action_init(pw3270Action *action);
36   - static void pw3270_action_get_property(GObject *object, guint prop_id, GValue *value, GParamSpec *pspec);
37   - static void pw3270_action_set_property(GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec);
38   - static void pw3270_action_set_state(GAction *action, GVariant *value);
39   - static gboolean pw3270_action_get_enabled(GAction *action);
40   - static void pw3270_action_activate(GAction *action, GVariant *parameter);
41   -
42   - static gboolean get_enabled(GAction *action, GtkWidget *terminal);
43   - static void activate(GAction *action, GVariant *parameter, GtkWidget *terminal);
  36 + static void get_property(GObject *object, guint prop_id, GValue *value, GParamSpec *pspec);
  37 + static void set_property(GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec);
  38 + static gboolean get_enabled(GAction *action);
  39 + static void activate(GAction *action, GVariant *parameter);
  40 +
44 41 static void change_widget(GAction *action, GtkWidget *from, GtkWidget *to);
45 42 static const gchar *get_null(GAction *action);
46 43  
... ... @@ -50,10 +47,12 @@
50 47 static GVariant * get_state_property(GAction *action);
51 48  
52 49 static GVariant * internal_get_state_property(GAction *action, GtkWidget *terminal);
  50 + static gboolean internal_get_enabled(GAction *action, GtkWidget *terminal);
  51 + static void internal_activate(GAction *action, GVariant *parameter, GtkWidget *terminal);
53 52  
54 53 static const GVariantType * get_parameter_type(GAction *action);
55   - static GVariant * pw3270_action_get_state_hint(GAction *action);
56   - static void pw3270_action_change_state(GAction *action, GVariant *value);
  54 + static GVariant * get_state_hint(GAction *action);
  55 + static void change_state(GAction *action, GVariant *value);
57 56  
58 57 enum {
59 58 PROP_NONE,
... ... @@ -77,11 +76,11 @@
77 76 iface->get_name = pw3270_action_get_name;
78 77 iface->get_parameter_type = get_parameter_type;
79 78 iface->get_state_type = get_state_type;
80   - iface->get_state_hint = pw3270_action_get_state_hint;
81   - iface->get_enabled = pw3270_action_get_enabled;
  79 + iface->get_state_hint = get_state_hint;
  80 + iface->get_enabled = get_enabled;
82 81 iface->get_state = get_state_property;
83   - iface->change_state = pw3270_action_change_state;
84   - iface->activate = pw3270_action_activate;
  82 + iface->change_state = change_state;
  83 + iface->activate = activate;
85 84 }
86 85  
87 86 void pw3270Action_class_init(pw3270ActionClass *klass) {
... ... @@ -91,14 +90,14 @@
91 90 debug("%s",__FUNCTION__);
92 91  
93 92 klass->change_widget = change_widget;
94   - klass->get_enabled = get_enabled;
  93 + klass->get_enabled = internal_get_enabled;
95 94 klass->get_icon_name = get_null;
96 95 klass->get_label = get_null;
97 96 klass->get_tooltip = get_null;
98 97  
99 98 object_class->finalize = finalize;
100   - object_class->set_property = pw3270_action_set_property;
101   - object_class->get_property = pw3270_action_get_property;
  99 + object_class->set_property = set_property;
  100 + object_class->get_property = get_property;
102 101  
103 102 // Install properties
104 103 g_object_class_install_property(object_class, PROP_NAME,
... ... @@ -171,7 +170,7 @@
171 170 action->terminal = NULL;
172 171 action->types.parameter = NULL;
173 172  
174   - action->activate = activate;
  173 + action->activate = internal_activate;
175 174 action->get_state_property = internal_get_state_property;
176 175  
177 176 }
... ... @@ -189,7 +188,7 @@
189 188  
190 189 }
191 190  
192   - void pw3270_action_get_property(GObject *object, guint prop_id, GValue *value, GParamSpec G_GNUC_UNUSED(*pspec)) {
  191 + void get_property(GObject *object, guint prop_id, GValue *value, GParamSpec G_GNUC_UNUSED(*pspec)) {
193 192  
194 193 GAction *action = G_ACTION(object);
195 194  
... ... @@ -205,7 +204,7 @@
205 204 break;
206 205  
207 206 case PROP_ENABLED:
208   - g_value_set_boolean(value, pw3270_action_get_enabled(action));
  207 + g_value_set_boolean(value, get_enabled(action));
209 208 break;
210 209  
211 210 case PROP_STATE_TYPE:
... ... @@ -222,7 +221,7 @@
222 221  
223 222 }
224 223  
225   - void pw3270_action_set_property(GObject *object, guint prop_id, const GValue *value, GParamSpec G_GNUC_UNUSED(*pspec)) {
  224 + void set_property(GObject *object, guint prop_id, const GValue *value, GParamSpec G_GNUC_UNUSED(*pspec)) {
226 225  
227 226 // debug("%s(%d)",__FUNCTION__,prop_id);
228 227  
... ... @@ -243,7 +242,7 @@
243 242 break;
244 243  
245 244 case PROP_STATE:
246   - pw3270_action_set_state(action, g_value_get_variant(value));
  245 +// pw3270_action_set_state(action, g_value_get_variant(value));
247 246 break;
248 247  
249 248 default:
... ... @@ -268,7 +267,7 @@
268 267 pw3270Action * action = PW3270_ACTION(object);
269 268  
270 269 if(action->types.state == G_VARIANT_TYPE_BOOLEAN)
271   - return g_variant_new_boolean(TRUE);
  270 + return g_variant_new_boolean(FALSE);
272 271  
273 272 return NULL;
274 273 }
... ... @@ -297,57 +296,20 @@
297 296 return PW3270_ACTION(object)->types.state;
298 297 }
299 298  
300   - GVariant * pw3270_action_get_state_hint(GAction G_GNUC_UNUSED(*action)) {
  299 + GVariant * get_state_hint(GAction G_GNUC_UNUSED(*action)) {
301 300 return NULL;
302 301 }
303 302  
304   - void pw3270_action_change_state(GAction *object, GVariant *value) {
305   - pw3270_action_set_state(object, value);
306   - }
307   -
308   - void pw3270_action_change_state_boolean(GAction *action, gboolean state) {
309   -
310   - g_return_if_fail(PW3270_IS_ACTION(action));
311   - pw3270_action_set_state(action,g_variant_new_boolean(state));
312   -
313   - }
314   -
315   - void pw3270_action_set_state(GAction *object, GVariant *value) {
316   -
317   - /*
318   - if(value) {
319   -
320   - pw3270Action * action = PW3270_ACTION(object);
321   -
322   - g_variant_ref_sink(value);
323   -
324   - if (!action->state || !g_variant_equal(action->state, value)) {
325   -
326   - if(action->state)
327   - g_variant_unref(action->state);
328   -
329   - action->state = g_variant_ref(value);
330   -
331   - if (g_signal_has_handler_pending(object, action_signals[SIGNAL_CHANGE_STATE], 0, TRUE)) {
332   - g_signal_emit(object, action_signals[SIGNAL_CHANGE_STATE], 0, value);
333   - }
334   -
335   - g_object_notify_by_pspec(G_OBJECT(object), PW3270_ACTION_GET_CLASS(object)->properties.state);
336   -
337   - }
338   -
339   - g_variant_unref(value);
340   -
341   - }
342   - */
343   -
  303 + void change_state(GAction *object, GVariant *value) {
  304 + debug("%s",__FUNCTION__)
344 305 }
345 306  
346 307 void pw3270_action_notify_enabled(GAction *object) {
347   -
348   - // g_object_notify_by_pspec(G_OBJECT(object), PW3270_ACTION_GET_CLASS(object)->properties.enabled);
349 308 g_object_notify(G_OBJECT (object), "enabled");
  309 + }
350 310  
  311 + void pw3270_action_notify_state(GAction *object) {
  312 + g_object_notify(G_OBJECT (object), "state");
351 313 }
352 314  
353 315 static void change_widget(GAction *action, GtkWidget *from, GtkWidget *to) {
... ... @@ -376,7 +338,7 @@
376 338  
377 339 }
378 340  
379   - gboolean pw3270_action_get_enabled(GAction *object) {
  341 + gboolean get_enabled(GAction *object) {
380 342  
381 343 gboolean enabled = FALSE;
382 344  
... ... @@ -391,7 +353,7 @@
391 353  
392 354 }
393 355  
394   - void pw3270_action_activate(GAction *object, GVariant *parameter) {
  356 + void activate(GAction *object, GVariant *parameter) {
395 357  
396 358 pw3270Action * action = PW3270_ACTION(object);
397 359  
... ... @@ -403,11 +365,11 @@
403 365  
404 366 }
405 367  
406   - gboolean get_enabled(GAction G_GNUC_UNUSED(*object), GtkWidget *terminal) {
  368 + gboolean internal_get_enabled(GAction G_GNUC_UNUSED(*object), GtkWidget *terminal) {
407 369 return terminal != NULL;
408 370 }
409 371  
410   - void activate(GAction *action, GVariant G_GNUC_UNUSED(*parameter), GtkWidget G_GNUC_UNUSED(*terminal)) {
  372 + void internal_activate(GAction *action, GVariant G_GNUC_UNUSED(*parameter), GtkWidget G_GNUC_UNUSED(*terminal)) {
411 373 g_message("Action %s can't be activated",pw3270_action_get_name(action));
412 374 }
413 375  
... ...
src/objects/actions/lib3270/toggle.c
... ... @@ -58,30 +58,34 @@
58 58  
59 59 G_DEFINE_TYPE(Lib3270ToggleAction, Lib3270ToggleAction, PW3270_TYPE_ACTION);
60 60  
  61 + static gboolean bg_notify_state(GAction *action) {
  62 + pw3270_action_notify_state(action);
  63 + return FALSE;
  64 + }
  65 +
61 66 static void change_state(H3270 G_GNUC_UNUSED(*hSession), LIB3270_TOGGLE_ID G_GNUC_UNUSED(id), char state, void * action) {
62 67 debug("%s: State on action %s is %s",
63 68 __FUNCTION__,
64 69 g_action_get_name(G_ACTION(action)),
65 70 state ? "ON" : "OFF"
66 71 );
67   - pw3270_action_change_state_boolean((GAction *) action, state == 0 ? FALSE : TRUE);
  72 + g_idle_add((GSourceFunc) bg_notify_state, G_ACTION(action));
68 73 }
69 74  
70 75 static void change_widget(GAction *object, GtkWidget *from, GtkWidget *to) {
71 76  
72 77 Lib3270ToggleAction * action = PW3270_LIB3270_TOGGLE_ACTION(object);
73 78  
74   - if(action->listener) {
  79 + if(action->listener)
75 80 lib3270_unregister_toggle_listener(v3270_get_session(from),action->definition->id,object);
76   - }
77 81  
78   - if(to) {
  82 + if(to)
79 83 action->listener = lib3270_register_toggle_listener(v3270_get_session(to),action->definition->id,change_state,object);
80   - pw3270_action_change_state_boolean(object,lib3270_get_toggle(v3270_get_session(to),action->definition->id));
81   - }
82 84  
83 85 PW3270_ACTION_CLASS(Lib3270ToggleAction_parent_class)->change_widget(object,from,to);
84 86  
  87 + bg_notify_state(G_ACTION(object));
  88 +
85 89 }
86 90  
87 91 static void activate(GAction *action, GVariant *parameter, GtkWidget *terminal) {
... ...
src/objects/actions/private.h
... ... @@ -55,10 +55,11 @@
55 55 G_GNUC_INTERNAL GAction * pw3270_action_new_pfkey(void);
56 56 G_GNUC_INTERNAL GAction * pw3270_action_new_pakey(void);
57 57  
58   - G_GNUC_INTERNAL void pw3270_action_change_state_boolean(GAction *action, gboolean state);
59   - G_GNUC_INTERNAL void pw3270_action_notify_enabled(GAction *action);
60 58 G_GNUC_INTERNAL void pw3270_action_set_name(GAction *object, const gchar *name);
61 59  
  60 + G_GNUC_INTERNAL void pw3270_action_notify_enabled(GAction *action);
  61 + G_GNUC_INTERNAL void pw3270_action_notify_state(GAction *object);
  62 +
62 63 // Internal actions
63 64 G_GNUC_INTERNAL GAction * pw3270_connect_action_new(void);
64 65 G_GNUC_INTERNAL GAction * pw3270_copy_action_new(void);
... ...