Commit 92d516aaab9b2ab2aac3b3a452c786d146400b5d
1 parent
0b69e655
Exists in
master
and in
4 other branches
Fixing GAction<->lib3270 adapters.
Showing
7 changed files
with
175 additions
and
88 deletions
Show diff stats
src/actions/abstract.c
... | ... | @@ -28,6 +28,7 @@ |
28 | 28 | */ |
29 | 29 | |
30 | 30 | #include "private.h" |
31 | + #include <v3270.h> | |
31 | 32 | |
32 | 33 | static void pw3270_action_iface_init(GActionInterface *iface); |
33 | 34 | static void pw3270Action_class_init(pw3270ActionClass *klass); |
... | ... | @@ -35,6 +36,12 @@ |
35 | 36 | static void pw3270_action_get_property(GObject *object, guint prop_id, GValue *value, GParamSpec *pspec); |
36 | 37 | static void pw3270_action_set_property(GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec); |
37 | 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); | |
44 | + static void change_widget(GAction *action, GtkWidget *from, GtkWidget *to); | |
38 | 45 | |
39 | 46 | static void finalize(GObject *object); |
40 | 47 | |
... | ... | @@ -66,20 +73,18 @@ |
66 | 73 | iface->activate = pw3270_action_activate; |
67 | 74 | } |
68 | 75 | |
69 | - static gboolean return_false(GAction G_GNUC_UNUSED(*action), GtkWidget G_GNUC_UNUSED(*window)) { | |
70 | - return FALSE; | |
71 | - } | |
72 | - | |
73 | 76 | void pw3270Action_class_init(pw3270ActionClass *klass) { |
74 | 77 | |
75 | 78 | GObjectClass *object_class = G_OBJECT_CLASS(klass); |
76 | 79 | |
80 | + klass->change_widget = change_widget; | |
81 | + klass->get_enabled = get_enabled; | |
82 | + klass->activate = activate; | |
83 | + | |
77 | 84 | object_class->finalize = finalize; |
78 | 85 | object_class->set_property = pw3270_action_set_property; |
79 | 86 | object_class->get_property = pw3270_action_get_property; |
80 | 87 | |
81 | - klass->get_enabled = return_false; | |
82 | - | |
83 | 88 | // Install properties |
84 | 89 | g_object_class_install_property(object_class, PROP_NAME, |
85 | 90 | g_param_spec_string ("name", |
... | ... | @@ -129,9 +134,9 @@ |
129 | 134 | |
130 | 135 | void pw3270Action_init(pw3270Action *action) { |
131 | 136 | |
132 | - action->name = NULL; | |
133 | - action->window = NULL; | |
134 | - action->state = NULL; | |
137 | + action->name = NULL; | |
138 | + action->terminal = NULL; | |
139 | + action->state = NULL; | |
135 | 140 | |
136 | 141 | } |
137 | 142 | |
... | ... | @@ -139,6 +144,9 @@ |
139 | 144 | |
140 | 145 | pw3270Action * action = PW3270_ACTION(object); |
141 | 146 | |
147 | + if(action->terminal) | |
148 | + pw3270_action_set_terminal_widget(G_ACTION(object),NULL); | |
149 | + | |
142 | 150 | if(action->name) { |
143 | 151 | |
144 | 152 | debug("Finalizing action \"%s\"",action->name); |
... | ... | @@ -242,23 +250,6 @@ |
242 | 250 | return PW3270_ACTION(action)->state; |
243 | 251 | } |
244 | 252 | |
245 | - gboolean pw3270_action_get_enabled(GAction *action) { | |
246 | - GtkWidget *window = PW3270_ACTION(action)->window; | |
247 | - | |
248 | - if(window) | |
249 | - return PW3270_ACTION_GET_CLASS(action)->get_enabled(action,window); | |
250 | - | |
251 | - return FALSE; | |
252 | - } | |
253 | - | |
254 | - void pw3270_action_activate(GAction *action, GVariant *parameter) { | |
255 | - GtkWidget *window = PW3270_ACTION(action)->window; | |
256 | - | |
257 | - if(window) | |
258 | - PW3270_ACTION_GET_CLASS(action)->activate(action,window); | |
259 | - | |
260 | - } | |
261 | - | |
262 | 253 | const GVariantType * pw3270_action_get_parameter_type(GAction *action) { |
263 | 254 | debug("%s",__FUNCTION__); |
264 | 255 | return NULL; |
... | ... | @@ -280,11 +271,97 @@ |
280 | 271 | return NULL; |
281 | 272 | } |
282 | 273 | |
283 | - void pw3270_action_change_state(GAction *action, GVariant *value) { | |
284 | - debug("%s",__FUNCTION__); | |
285 | - pw3270_action_set_state (action, value); | |
274 | + void pw3270_action_change_state(GAction *object, GVariant *value) { | |
275 | + | |
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 | + */ | |
282 | + | |
283 | + pw3270_action_set_state(object, value); | |
284 | + | |
286 | 285 | } |
287 | 286 | |
288 | - void pw3270_action_set_state(GAction *action, GVariant *value) { | |
287 | + void pw3270_action_set_state(GAction *object, GVariant *value) { | |
288 | + | |
289 | + if(value) { | |
290 | + | |
291 | + pw3270Action * action = PW3270_ACTION(object); | |
292 | + | |
293 | + g_variant_ref_sink(value); | |
294 | + | |
295 | + if (!action->state || !g_variant_equal(action->state, value)) { | |
296 | + | |
297 | + if(action->state) | |
298 | + g_variant_unref(action->state); | |
299 | + | |
300 | + action->state = g_variant_ref(value); | |
301 | + | |
302 | + g_object_notify(G_OBJECT(object), "state"); | |
303 | + } | |
304 | + | |
305 | + g_variant_unref(value); | |
306 | + | |
307 | + } | |
308 | + | |
309 | + } | |
310 | + | |
311 | + static void change_widget(GAction *action, GtkWidget G_GNUC_UNUSED(*from), GtkWidget *to) { | |
312 | + PW3270_ACTION(action)->terminal = to; | |
313 | + } | |
314 | + | |
315 | + void pw3270_action_set_terminal_widget(GAction *object, GtkWidget *widget) { | |
316 | + | |
317 | + g_return_if_fail(PW3270_IS_ACTION(object) && GTK_IS_V3270(widget)); | |
318 | + | |
319 | + pw3270Action * action = PW3270_ACTION(object); | |
320 | + | |
321 | + if(action->terminal != widget) { | |
322 | + PW3270_ACTION_GET_CLASS(object)->change_widget(object,action->terminal,widget); | |
323 | + action->terminal = widget; | |
324 | + } | |
325 | + | |
326 | + } | |
327 | + | |
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 | + gboolean pw3270_action_get_enabled(GAction *object) { | |
333 | + | |
334 | + pw3270Action * action = PW3270_ACTION(object); | |
335 | + | |
336 | + debug("%s: terminal=%p",__FUNCTION__,action->terminal); | |
337 | + | |
338 | + if(action && action->terminal) { | |
339 | + | |
340 | + return PW3270_ACTION_GET_CLASS(object)->get_enabled(object,action->terminal); | |
341 | + | |
342 | + } | |
343 | + | |
344 | + return FALSE; | |
345 | + | |
346 | + } | |
347 | + | |
348 | + void pw3270_action_activate(GAction *object, GVariant *parameter) { | |
349 | + | |
350 | + pw3270Action * action = PW3270_ACTION(object); | |
351 | + | |
352 | + debug("%s: terminal=%p",__FUNCTION__,action->terminal); | |
353 | + | |
354 | + if(action && action->terminal) { | |
355 | + return PW3270_ACTION_GET_CLASS(object)->activate(object,parameter,action->terminal); | |
356 | + } | |
357 | + | |
358 | + } | |
359 | + | |
360 | + gboolean get_enabled(GAction *object, GtkWidget *terminal) { | |
289 | 361 | debug("%s",__FUNCTION__); |
362 | + return TRUE; | |
363 | + } | |
364 | + | |
365 | + void activate(GAction *action, GVariant G_GNUC_UNUSED(*parameter), GtkWidget G_GNUC_UNUSED(*terminal)) { | |
366 | + g_message("Action %s can't be activated",pw3270_action_get_name(action)); | |
290 | 367 | } | ... | ... |
src/actions/lib3270/action.c
... | ... | @@ -33,7 +33,7 @@ |
33 | 33 | */ |
34 | 34 | |
35 | 35 | #include "../private.h" |
36 | - #include <pw3270/window.h> | |
36 | + #include <v3270.h> | |
37 | 37 | |
38 | 38 | #define PW3270_TYPE_LIB3270_ACTION (Lib3270Action_get_type()) |
39 | 39 | #define PW3270_LIB3270_ACTION(inst) (G_TYPE_CHECK_INSTANCE_CAST ((inst), PW3270_TYPE_LIB3270_ACTION, Lib3270Action)) |
... | ... | @@ -56,48 +56,33 @@ |
56 | 56 | |
57 | 57 | G_DEFINE_TYPE(Lib3270Action, Lib3270Action, PW3270_TYPE_ACTION); |
58 | 58 | |
59 | - static gboolean action_enabled(GAction *action, GtkWidget *window) { | |
60 | - | |
61 | - H3270 * hSession = pw3270_window_get_session_handle(window); | |
62 | - | |
63 | - if(hSession) | |
64 | - return PW3270_LIB3270_ACTION(action)->definition->activatable(hSession) > 0 ? TRUE : FALSE; | |
65 | - | |
66 | - return FALSE; | |
59 | + static gboolean get_enabled(GAction *action, GtkWidget *terminal) { | |
60 | + return PW3270_LIB3270_ACTION(action)->definition->activatable(v3270_get_session(terminal)) > 0 ? TRUE : FALSE; | |
67 | 61 | } |
68 | 62 | |
69 | - static void action_activate(GAction *action, GtkWidget *window) { | |
70 | - | |
71 | - H3270 * hSession = pw3270_window_get_session_handle(window); | |
72 | - | |
73 | - debug("Activating action %s on hSession %p", pw3270_action_get_name(action), hSession); | |
74 | - | |
75 | - if(hSession) | |
76 | - PW3270_LIB3270_ACTION(action)->definition->activate(hSession); | |
77 | - else | |
78 | - g_message("Action \"%s\" requires a lib3270 session", pw3270_action_get_name(action)); | |
79 | - | |
63 | + static void activate(GAction *action, GVariant *parameter, GtkWidget *terminal) { | |
64 | + PW3270_LIB3270_ACTION(action)->definition->activate(v3270_get_session(terminal)); | |
80 | 65 | } |
81 | 66 | |
82 | 67 | void Lib3270Action_class_init(Lib3270ActionClass *klass) { |
83 | 68 | |
84 | - pw3270ActionClass * action = PW3270_ACTION_CLASS(klass); | |
69 | + pw3270ActionClass * action = PW3270_ACTION_CLASS(klass); | |
85 | 70 | |
86 | - action->get_enabled = action_enabled; | |
87 | - action->activate = action_activate; | |
71 | + action->activate = activate; | |
72 | + action->get_enabled = get_enabled; | |
88 | 73 | |
89 | 74 | } |
90 | 75 | |
91 | 76 | void Lib3270Action_init(Lib3270Action *action) { |
92 | 77 | } |
93 | 78 | |
94 | - GAction * pw3270_action_new_from_lib3270(const LIB3270_ACTION * definition, GtkWidget *window) { | |
79 | + GAction * pw3270_action_new_from_lib3270(const LIB3270_ACTION * definition) { | |
95 | 80 | |
96 | 81 | Lib3270Action * action = (Lib3270Action *) g_object_new(PW3270_TYPE_LIB3270_ACTION, NULL); |
97 | - pw3270Action * abstract = PW3270_ACTION(action); | |
98 | - | |
99 | 82 | action->definition = definition; |
100 | - abstract->window = window; | |
83 | + | |
84 | + // Setup the default name. | |
85 | + pw3270Action * abstract = PW3270_ACTION(action); | |
101 | 86 | |
102 | 87 | if(abstract->name) |
103 | 88 | g_free(abstract->name); | ... | ... |
src/actions/lib3270/toggle.c
... | ... | @@ -34,9 +34,10 @@ |
34 | 34 | |
35 | 35 | #include "../private.h" |
36 | 36 | #include <pw3270/window.h> |
37 | + #include <v3270.h> | |
37 | 38 | |
38 | 39 | #define PW3270_TYPE_LIB3270_TOGGLE_ACTION (Lib3270ToggleAction_get_type()) |
39 | - #define PW3270_LIB3270_TOGGLE_ACTION(inst) (G_TYPE_CHECK_INSTANCE_CAST ((inst), PW3270_TYPE_LIB3270_TOGGLE_ACTION, Lib3270Action)) | |
40 | + #define PW3270_LIB3270_TOGGLE_ACTION(inst) (G_TYPE_CHECK_INSTANCE_CAST ((inst), PW3270_TYPE_LIB3270_TOGGLE_ACTION, Lib3270ToggleAction)) | |
40 | 41 | #define PW3270_IS_LIB3270_TOGGLE_ACTION(inst) (G_TYPE_CHECK_INSTANCE_TYPE ((inst), PW3270_TYPE_LIB3270_TOGGLE_ACTION)) |
41 | 42 | |
42 | 43 | typedef struct _Lib3270ToggleActionClass { |
... | ... | @@ -47,45 +48,54 @@ |
47 | 48 | typedef struct _Lib3270ToggleAction { |
48 | 49 | pw3270Action parent; |
49 | 50 | |
50 | - const LIB3270_TOGGLE_ENTRY * definition; | |
51 | + const LIB3270_TOGGLE * definition; | |
52 | + const void * listener; | |
51 | 53 | |
52 | 54 | } Lib3270ToggleAction; |
53 | 55 | |
54 | - static void Lib3270ToggleAction_class_init(Lib3270ActionClass *klass); | |
55 | - static void Lib3270ToggleAction_init(Lib3270Action *action); | |
56 | + static void Lib3270ToggleAction_class_init(Lib3270ToggleActionClass *klass); | |
57 | + static void Lib3270ToggleAction_init(Lib3270ToggleAction *action); | |
56 | 58 | |
57 | 59 | G_DEFINE_TYPE(Lib3270ToggleAction, Lib3270ToggleAction, PW3270_TYPE_ACTION); |
58 | 60 | |
59 | - static gboolean action_enabled(GAction *action, GtkWidget *window) { | |
60 | - | |
61 | - | |
62 | - return FALSE; | |
61 | + static void change_state(H3270 *hSession, LIB3270_TOGGLE_ID id, char state, void * action) { | |
62 | + pw3270_action_change_state_boolean(PW3270_ACTION(action), state == 0 ? FALSE : TRUE); | |
63 | 63 | } |
64 | 64 | |
65 | - static void action_activate(GAction *action, GtkWidget *window) { | |
65 | + static void change_widget(GAction *object, GtkWidget *from, GtkWidget *to) { | |
66 | 66 | |
67 | + Lib3270ToggleAction * action = PW3270_LIB3270_TOGGLE_ACTION(object); | |
67 | 68 | |
68 | - } | |
69 | + if(action->listener) { | |
70 | + lib3270_unregister_toggle_listener(v3270_get_session(from),action->definition->id,object); | |
71 | + } | |
69 | 72 | |
70 | - void Lib3270Action_class_init(Lib3270ActionClass *klass) { | |
73 | + if(to) { | |
74 | + action->listener = lib3270_register_toggle_listener(v3270_get_session(from),action->definition->id,change_state,object); | |
75 | + pw3270_action_change_state_boolean(object,lib3270_get_toggle(v3270_get_session(to),action->definition->id)); | |
76 | + } | |
71 | 77 | |
72 | - pw3270ActionClass * action = PW3270_TOGGLE_ACTION_CLASS(klass); | |
78 | + PW3270_ACTION_CLASS(Lib3270ToggleAction_parent_class)->change_widget(object,from,to); | |
73 | 79 | |
74 | - action->get_enabled = action_enabled; | |
75 | - action->activate = action_activate; | |
80 | + } | |
76 | 81 | |
82 | + void Lib3270ToggleAction_class_init(Lib3270ToggleActionClass *klass) { | |
77 | 83 | } |
78 | 84 | |
79 | - void Lib3270Action_init(Lib3270Action *action) { | |
85 | + void Lib3270ToggleAction_init(Lib3270ToggleAction *action) { | |
86 | + | |
87 | + action->definition = NULL; | |
88 | + action->listener = NULL; | |
89 | + | |
80 | 90 | } |
81 | 91 | |
82 | - GAction * pw3270_toggle_action_new_from_lib3270(const LIB3270_TOGGLE_ENTRY * definition, GtkWidget *window) { | |
92 | + GAction * pw3270_toggle_action_new_from_lib3270(const LIB3270_TOGGLE * definition) { | |
83 | 93 | |
84 | - Lib3270Action * action = (Lib3270Action *) g_object_new(PW3270_TYPE_LIB3270_TOGGLE_ACTION, NULL); | |
85 | - pw3270Action * abstract = PW3270_ACTION(action); | |
94 | + Lib3270ToggleAction * action = (Lib3270ToggleAction *) g_object_new(PW3270_TYPE_LIB3270_TOGGLE_ACTION, NULL); | |
95 | + action->definition = definition; | |
86 | 96 | |
87 | - action->definition = definition; | |
88 | - abstract->window = window; | |
97 | + // Setup the default name. | |
98 | + pw3270Action * abstract = PW3270_ACTION(action); | |
89 | 99 | |
90 | 100 | if(abstract->name) |
91 | 101 | g_free(abstract->name); |
... | ... | @@ -93,6 +103,7 @@ |
93 | 103 | abstract->name = g_strconcat("win.",definition->name,NULL); |
94 | 104 | |
95 | 105 | return G_ACTION(action); |
106 | + | |
96 | 107 | } |
97 | 108 | |
98 | 109 | ... | ... |
src/actions/private.h
... | ... | @@ -42,6 +42,10 @@ |
42 | 42 | #include <gtk/gtk.h> |
43 | 43 | |
44 | 44 | #include <pw3270/actions.h> |
45 | + | |
46 | + #include <lib3270/actions.h> | |
47 | + #include <lib3270/toggle.h> | |
48 | + | |
45 | 49 | #include <lib3270/log.h> |
46 | 50 | |
47 | 51 | struct _pw3270Action { |
... | ... | @@ -49,7 +53,7 @@ |
49 | 53 | |
50 | 54 | GVariantType * parameter_type; |
51 | 55 | GVariant * state; |
52 | - GtkWidget * window; | |
56 | + GtkWidget * terminal; | |
53 | 57 | gchar * name; |
54 | 58 | |
55 | 59 | }; |
... | ... | @@ -57,9 +61,16 @@ |
57 | 61 | struct _pw3270ActionClass { |
58 | 62 | GObjectClass parent_class; |
59 | 63 | |
60 | - gboolean (*get_enabled)(GAction *action, GtkWidget *window); | |
61 | - void (*activate)(GAction *action, GtkWidget *window); | |
64 | + void (*change_widget)(GAction *action, GtkWidget *from, GtkWidget *to); | |
65 | + gboolean (*get_enabled)(GAction *action, GtkWidget *terminal); | |
66 | + void (*activate)(GAction *action, GVariant *parameter, GtkWidget *terminal); | |
62 | 67 | |
63 | 68 | }; |
64 | 69 | |
70 | + G_GNUC_INTERNAL GAction * pw3270_action_new_from_lib3270(const LIB3270_ACTION * definition); | |
71 | + G_GNUC_INTERNAL GAction * pw3270_toggle_action_new_from_lib3270(const LIB3270_TOGGLE * definition); | |
72 | + | |
73 | + G_GNUC_INTERNAL void pw3270_action_change_state_boolean(GAction *action, gboolean state); | |
74 | + | |
75 | + | |
65 | 76 | #endif // PRIVATE_H_INCLUDED | ... | ... |
src/actions/testprogram/testprogram.c
... | ... | @@ -40,9 +40,11 @@ |
40 | 40 | return g_object_get_data(G_OBJECT(window), "v3270_terminal"); |
41 | 41 | } |
42 | 42 | |
43 | + /* | |
43 | 44 | H3270 * pw3270_window_get_session_handle(GtkWidget *window) { |
44 | 45 | return v3270_get_session(pw3270_window_get_terminal_widget(window)); |
45 | 46 | } |
47 | + */ | |
46 | 48 | |
47 | 49 | static gboolean handle_command(GtkWidget *trace, const gchar *cmd, const gchar *args, GtkWidget *window) { |
48 | 50 | ... | ... |
src/actions/window.c
... | ... | @@ -37,11 +37,13 @@ |
37 | 37 | |
38 | 38 | void pw3270_window_add_actions(GtkWidget * appwindow) { |
39 | 39 | |
40 | - GActionMap *map = G_ACTION_MAP(appwindow); | |
40 | + GActionMap * map = G_ACTION_MAP(appwindow); | |
41 | + GtkWidget * terminal = pw3270_window_get_terminal_widget(appwindow); | |
41 | 42 | |
42 | 43 | // g_action_map_add_action(map,pw3270_action_new_from_lib3270(lib3270_action_get_by_name("testpattern"), appwindow)); |
43 | 44 | |
44 | - GAction *action = pw3270_action_new_from_lib3270(lib3270_action_get_by_name("testpattern"), appwindow); | |
45 | + GAction *action = pw3270_action_new_from_lib3270(lib3270_action_get_by_name("testpattern")); | |
46 | + pw3270_action_set_terminal_widget(action,terminal); | |
45 | 47 | |
46 | 48 | debug("--> \"%s\"",pw3270_action_get_name(action)); |
47 | 49 | ... | ... |
src/include/pw3270/actions.h
... | ... | @@ -38,7 +38,6 @@ |
38 | 38 | |
39 | 39 | #include <gio/gio.h> |
40 | 40 | #include <lib3270.h> |
41 | - #include <lib3270/actions.h> | |
42 | 41 | |
43 | 42 | G_BEGIN_DECLS |
44 | 43 | |
... | ... | @@ -54,14 +53,14 @@ |
54 | 53 | |
55 | 54 | GType pw3270Action_get_type(void) G_GNUC_CONST; |
56 | 55 | |
57 | - GAction * pw3270_action_new_from_lib3270(const LIB3270_ACTION * definition, GtkWidget *window); | |
58 | - GAction * pw3270_toggle_action_new_from_lib3270(const LIB3270_TOGGLE_ENTRY * definition, GtkWidget *window); | |
59 | - | |
60 | 56 | const gchar * pw3270_action_get_name(GAction *action); |
61 | 57 | void pw3270_action_set_name(GAction *action, const gchar *name); |
62 | 58 | |
63 | - gboolean pw3270_action_get_enabled(GAction *action); | |
64 | - void pw3270_action_activate(GAction *action, GVariant *parameter); | |
59 | + /// @brief Associate action with the terminal widget. | |
60 | + void pw3270_action_set_terminal_widget(GAction *action, GtkWidget *terminal); | |
61 | + | |
62 | + /// @brief Get lib3270 session handle. | |
63 | + H3270 * pw3270_action_get_session(GAction *action); | |
65 | 64 | |
66 | 65 | /// @brief Add lib3270 actions to an application window. |
67 | 66 | void pw3270_window_add_actions(GtkWidget * appwindow); | ... | ... |