Commit 3aa05438fe66a5f63039e3a8a118513464a3777f
1 parent
89bb30e8
Exists in
master
and in
4 other branches
Playing with property actions.
Showing
8 changed files
with
160 additions
and
88 deletions
Show diff stats
src/objects/actions/abstract.c
... | ... | @@ -63,6 +63,7 @@ |
63 | 63 | PROP_STATE |
64 | 64 | }; |
65 | 65 | |
66 | + /* | |
66 | 67 | enum { |
67 | 68 | SIGNAL_CHANGE_STATE, |
68 | 69 | NR_SIGNALS |
... | ... | @@ -70,6 +71,9 @@ |
70 | 71 | |
71 | 72 | static guint action_signals[NR_SIGNALS]; |
72 | 73 | |
74 | + */ | |
75 | + | |
76 | + | |
73 | 77 | G_DEFINE_TYPE_WITH_CODE(pw3270Action, pw3270Action, G_TYPE_OBJECT, G_IMPLEMENT_INTERFACE(G_TYPE_ACTION, pw3270_action_iface_init)) |
74 | 78 | |
75 | 79 | void pw3270_action_iface_init(GActionInterface *iface) { |
... | ... | @@ -123,8 +127,7 @@ |
123 | 127 | N_("State Type"), |
124 | 128 | N_("The type of the state kept by the action"), |
125 | 129 | G_TYPE_VARIANT_TYPE, |
126 | - G_PARAM_READABLE | | |
127 | - G_PARAM_STATIC_STRINGS)); | |
130 | + G_PARAM_READABLE | G_PARAM_STATIC_STRINGS)); | |
128 | 131 | |
129 | 132 | // Enabled property |
130 | 133 | klass->properties.enabled = |
... | ... | @@ -146,12 +149,12 @@ |
146 | 149 | N_("The state the action is in"), |
147 | 150 | G_VARIANT_TYPE_ANY, |
148 | 151 | NULL, |
149 | - G_PARAM_READWRITE | G_PARAM_CONSTRUCT | | |
150 | - G_PARAM_STATIC_STRINGS | |
152 | + G_PARAM_READWRITE | G_PARAM_CONSTRUCT | G_PARAM_STATIC_STRINGS | |
151 | 153 | ); |
152 | 154 | |
153 | 155 | g_object_class_install_property (object_class, PROP_STATE, klass->properties.state); |
154 | 156 | |
157 | + /* | |
155 | 158 | // Install signals |
156 | 159 | action_signals[SIGNAL_CHANGE_STATE] = |
157 | 160 | g_signal_new( |
... | ... | @@ -163,6 +166,7 @@ |
163 | 166 | G_TYPE_NONE, 1, |
164 | 167 | G_TYPE_VARIANT |
165 | 168 | ); |
169 | + */ | |
166 | 170 | } |
167 | 171 | |
168 | 172 | void pw3270Action_init(pw3270Action *action) { |
... | ... | @@ -304,19 +308,37 @@ |
304 | 308 | debug("%s",__FUNCTION__) |
305 | 309 | } |
306 | 310 | |
307 | - void pw3270_action_notify_enabled(GAction *object) { | |
308 | - g_object_notify(G_OBJECT (object), "enabled"); | |
311 | + static gboolean bg_notify_enabled(GObject *action) { | |
312 | + g_object_notify(action, "enabled"); | |
313 | + return FALSE; | |
309 | 314 | } |
310 | 315 | |
311 | - void pw3270_action_notify_state(GAction *object) { | |
312 | - g_object_notify(G_OBJECT (object), "state"); | |
316 | + void pw3270_action_notify_enabled(GAction *action) { | |
317 | + g_idle_add((GSourceFunc) bg_notify_enabled, G_OBJECT(action)); | |
318 | + } | |
319 | + | |
320 | + static gboolean bg_notify_state(GObject *action) { | |
321 | + g_object_notify(action, "state"); | |
322 | + return FALSE; | |
323 | + } | |
324 | + | |
325 | + void pw3270_action_notify_state(GAction *action) { | |
326 | + g_idle_add((GSourceFunc) bg_notify_state, G_OBJECT(action)); | |
313 | 327 | } |
314 | 328 | |
315 | 329 | static void change_widget(GAction *action, GtkWidget *from, GtkWidget *to) { |
316 | 330 | |
317 | 331 | if(from != to) { |
318 | - PW3270_ACTION(action)->terminal = to; | |
332 | + | |
333 | + pw3270Action *pAction = PW3270_ACTION(action); | |
334 | + | |
335 | + pAction->terminal = to; | |
336 | + | |
319 | 337 | pw3270_action_notify_enabled(action); |
338 | + | |
339 | + if(pAction->types.state) | |
340 | + pw3270_action_notify_state(action); | |
341 | + | |
320 | 342 | } |
321 | 343 | |
322 | 344 | } | ... | ... |
src/objects/actions/lib3270/action.c
... | ... | @@ -133,14 +133,8 @@ |
133 | 133 | return G_ACTION(action); |
134 | 134 | } |
135 | 135 | |
136 | - static gboolean bg_notify_enabled(GAction *action) { | |
137 | -// debug("Action %s was notified (%s)",g_action_get_name(action),g_action_get_enabled(action) ? "Enabled" : "Disabled"); | |
138 | - pw3270_action_notify_enabled(action); | |
139 | - return FALSE; | |
140 | - } | |
141 | - | |
142 | 136 | static void event_listener(H3270 G_GNUC_UNUSED(*hSession), void *object) { |
143 | - g_idle_add((GSourceFunc) bg_notify_enabled, G_ACTION(object)); | |
137 | + pw3270_action_notify_enabled(G_ACTION(object)); | |
144 | 138 | } |
145 | 139 | |
146 | 140 | void change_widget(GAction *object, GtkWidget *from, GtkWidget *to) { |
... | ... | @@ -160,10 +154,5 @@ |
160 | 154 | action->listener = lib3270_register_action_group_listener(pw3270_action_get_session(object),action->definition->group,event_listener,object); |
161 | 155 | } |
162 | 156 | |
163 | - // Does the "enabled" state has changed? If yes notify customers. | |
164 | - gboolean enabled = get_enabled(object,to); | |
165 | - if(get_enabled(object,from) != enabled) | |
166 | - pw3270_action_notify_enabled(object); | |
167 | - | |
168 | 157 | } |
169 | 158 | ... | ... |
src/objects/actions/lib3270/pakey.c
... | ... | @@ -51,7 +51,6 @@ |
51 | 51 | |
52 | 52 | static void Lib3270PaAction_class_init(Lib3270PaActionClass *klass); |
53 | 53 | static void Lib3270PaAction_init(Lib3270PaAction *action); |
54 | - static void change_widget(GAction *object, GtkWidget *from, GtkWidget *to); | |
55 | 54 | |
56 | 55 | G_DEFINE_TYPE(Lib3270PaAction, Lib3270PaAction, PW3270_TYPE_ACTION); |
57 | 56 | |
... | ... | @@ -97,7 +96,6 @@ |
97 | 96 | void Lib3270PaAction_class_init(Lib3270PaActionClass *klass) { |
98 | 97 | |
99 | 98 | klass->parent_class.get_enabled = get_enabled; |
100 | - klass->parent_class.change_widget = change_widget; | |
101 | 99 | |
102 | 100 | } |
103 | 101 | |
... | ... | @@ -113,14 +111,3 @@ |
113 | 111 | return G_ACTION(g_object_new(PW3270_TYPE_PAKEY_ACTION, NULL)); |
114 | 112 | } |
115 | 113 | |
116 | - void change_widget(GAction *object, GtkWidget *from, GtkWidget *to) { | |
117 | - | |
118 | - PW3270_ACTION_CLASS(Lib3270PaAction_parent_class)->change_widget(object,from,to); | |
119 | - | |
120 | - // Does the "enabled" state has changed? If yes notify customers. | |
121 | - gboolean enabled = get_enabled(object,to); | |
122 | - if(get_enabled(object,from) != enabled) | |
123 | - pw3270_action_notify_enabled(object); | |
124 | - | |
125 | - } | |
126 | - | ... | ... |
src/objects/actions/lib3270/pfkey.c
... | ... | @@ -51,7 +51,6 @@ |
51 | 51 | |
52 | 52 | static void Lib3270PfAction_class_init(Lib3270PfActionClass *klass); |
53 | 53 | static void Lib3270PfAction_init(Lib3270PfAction *action); |
54 | - static void change_widget(GAction *object, GtkWidget *from, GtkWidget *to); | |
55 | 54 | |
56 | 55 | G_DEFINE_TYPE(Lib3270PfAction, Lib3270PfAction, PW3270_TYPE_ACTION); |
57 | 56 | |
... | ... | @@ -97,17 +96,6 @@ |
97 | 96 | void Lib3270PfAction_class_init(Lib3270PfActionClass *klass) { |
98 | 97 | |
99 | 98 | klass->parent_class.get_enabled = get_enabled; |
100 | - klass->parent_class.change_widget = change_widget; | |
101 | - | |
102 | - /* | |
103 | - pw3270ActionClass * action = PW3270_ACTION_CLASS(klass); | |
104 | - | |
105 | - action->get_enabled = get_enabled; | |
106 | - action->change_widget = change_widget; | |
107 | - | |
108 | - action-> | |
109 | - action->get_parameter_type = get_parameter_type; | |
110 | -*/ | |
111 | 99 | |
112 | 100 | } |
113 | 101 | |
... | ... | @@ -122,14 +110,4 @@ |
122 | 110 | return G_ACTION(g_object_new(PW3270_TYPE_PFKEY_ACTION, NULL)); |
123 | 111 | } |
124 | 112 | |
125 | - void change_widget(GAction *object, GtkWidget *from, GtkWidget *to) { | |
126 | - | |
127 | - PW3270_ACTION_CLASS(Lib3270PfAction_parent_class)->change_widget(object,from,to); | |
128 | - | |
129 | - // Does the "enabled" state has changed? If yes notify customers. | |
130 | - gboolean enabled = get_enabled(object,to); | |
131 | - if(get_enabled(object,from) != enabled) | |
132 | - pw3270_action_notify_enabled(object); | |
133 | - | |
134 | - } | |
135 | 113 | ... | ... |
src/objects/actions/lib3270/toggle.c
... | ... | @@ -58,18 +58,8 @@ |
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 | - | |
66 | - static void change_state(H3270 G_GNUC_UNUSED(*hSession), LIB3270_TOGGLE_ID G_GNUC_UNUSED(id), char state, void * action) { | |
67 | - debug("%s: State on action %s is %s", | |
68 | - __FUNCTION__, | |
69 | - g_action_get_name(G_ACTION(action)), | |
70 | - state ? "ON" : "OFF" | |
71 | - ); | |
72 | - g_idle_add((GSourceFunc) bg_notify_state, G_ACTION(action)); | |
61 | + static void change_state(H3270 G_GNUC_UNUSED(*hSession), LIB3270_TOGGLE_ID G_GNUC_UNUSED(id), char G_GNUC_UNUSED(state), void G_GNUC_UNUSED(*action)) { | |
62 | + pw3270_action_notify_state(G_ACTION(action)); | |
73 | 63 | } |
74 | 64 | |
75 | 65 | static void change_widget(GAction *object, GtkWidget *from, GtkWidget *to) { |
... | ... | @@ -84,8 +74,6 @@ |
84 | 74 | |
85 | 75 | PW3270_ACTION_CLASS(Lib3270ToggleAction_parent_class)->change_widget(object,from,to); |
86 | 76 | |
87 | - bg_notify_state(G_ACTION(object)); | |
88 | - | |
89 | 77 | } |
90 | 78 | |
91 | 79 | static void activate(GAction *action, GVariant *parameter, GtkWidget *terminal) { |
... | ... | @@ -130,7 +118,7 @@ |
130 | 118 | |
131 | 119 | action->parent.name = "toggle"; |
132 | 120 | |
133 | - action->parent.get_state_property = get_state_property; | |
121 | + action->parent.get_state_property = get_state_property; | |
134 | 122 | action->parent.activate = activate; |
135 | 123 | |
136 | 124 | action->parent.types.state = G_VARIANT_TYPE_BOOLEAN; | ... | ... |
src/objects/actions/v3270/property.c
... | ... | @@ -42,6 +42,8 @@ |
42 | 42 | |
43 | 43 | static void v3270PropertyAction_class_init(v3270PropertyActionClass *klass); |
44 | 44 | static void v3270PropertyAction_init(v3270PropertyAction *action); |
45 | + static GVariant * get_state(GAction *action, GtkWidget *terminal); | |
46 | + | |
45 | 47 | |
46 | 48 | G_DEFINE_TYPE(v3270PropertyAction, v3270PropertyAction, PW3270_TYPE_ACTION); |
47 | 49 | |
... | ... | @@ -51,17 +53,72 @@ |
51 | 53 | |
52 | 54 | static void v3270PropertyAction_init(v3270PropertyAction *action) { |
53 | 55 | |
56 | + action->parent.get_state_property = get_state; | |
57 | + | |
54 | 58 | } |
55 | 59 | |
56 | - v3270PropertyAction * v3270_property_action_new(GtkWidget *widget, const gchar *property_name) { | |
60 | + GVariant * get_state(GAction *action, GtkWidget *terminal) { | |
57 | 61 | |
58 | - v3270PropertyAction * action = (v3270PropertyAction *) g_object_new(V3270_TYPE_PROPERTY_ACTION, NULL); | |
62 | + if(!terminal) | |
63 | + return NULL; | |
64 | + | |
65 | + debug("%s",__FUNCTION__); | |
66 | + | |
67 | + v3270PropertyAction * paction = V3270_PROPERTY_ACTION(action); | |
68 | + | |
69 | + GValue value = G_VALUE_INIT; | |
70 | + GVariant *result = NULL; | |
71 | + | |
72 | + g_value_init(&value, paction->pspec->value_type); | |
73 | + g_object_get_property(G_OBJECT(terminal), paction->pspec->name, &value); | |
74 | + | |
75 | + switch(paction->pspec->value_type) { | |
76 | + case G_TYPE_BOOLEAN: | |
77 | + result = g_variant_new_boolean(g_value_get_boolean(&value)); | |
78 | + break; | |
79 | + | |
80 | + case G_TYPE_INT: | |
81 | + result = g_variant_new_int32(g_value_get_int(&value)); | |
82 | + break; | |
83 | + | |
84 | + case G_TYPE_UINT: | |
85 | + result = g_variant_new_uint32(g_value_get_uint(&value)); | |
86 | + debug("state of %s is %u",g_action_get_name(action),g_value_get_uint(&value)); | |
87 | + break; | |
88 | + | |
89 | + case G_TYPE_DOUBLE: | |
90 | + result = g_variant_new_double(g_value_get_double(&value)); | |
91 | + break; | |
92 | + | |
93 | + case G_TYPE_FLOAT: | |
94 | + result = g_variant_new_double(g_value_get_float(&value)); | |
95 | + break; | |
96 | + | |
97 | + case G_TYPE_STRING: | |
98 | + result = g_variant_new_string(g_value_get_string(&value)); | |
99 | + break; | |
100 | + | |
101 | + } | |
102 | + | |
103 | + g_value_unset (&value); | |
104 | + | |
105 | + return result; | |
106 | + | |
107 | + } | |
108 | + | |
109 | + static void activate(GAction *action, GVariant *parameter, GtkWidget *terminal) { | |
110 | + | |
111 | + debug("%s(%s,%p,%p)",__FUNCTION__,g_action_get_name(action),parameter,terminal); | |
112 | + | |
113 | + } | |
59 | 114 | |
60 | - action->pspec = g_object_class_find_property(G_OBJECT_GET_CLASS(widget), property_name); | |
115 | + v3270PropertyAction * v3270_property_action_new(GtkWidget *widget, const gchar *property_name) { | |
116 | + | |
117 | + GParamSpec *pspec = g_object_class_find_property(G_OBJECT_GET_CLASS(widget), property_name); | |
61 | 118 | |
62 | - if(~action->pspec->flags & G_PARAM_READABLE || ~action->pspec->flags & G_PARAM_WRITABLE || action->pspec->flags & G_PARAM_CONSTRUCT_ONLY) { | |
119 | + if(~pspec->flags & G_PARAM_READABLE || ~pspec->flags & G_PARAM_WRITABLE || pspec->flags & G_PARAM_CONSTRUCT_ONLY) { | |
63 | 120 | |
64 | - g_critical( | |
121 | + g_warning( | |
65 | 122 | "Property '%s::%s' must be readable, writable, and not construct-only", |
66 | 123 | G_OBJECT_TYPE_NAME(G_OBJECT(widget)), |
67 | 124 | property_name |
... | ... | @@ -70,5 +127,52 @@ |
70 | 127 | return NULL; |
71 | 128 | } |
72 | 129 | |
130 | + // Get state type | |
131 | + const GVariantType * type; | |
132 | + | |
133 | + switch(pspec->value_type) { | |
134 | + case G_TYPE_BOOLEAN: | |
135 | + type = G_VARIANT_TYPE_BOOLEAN; | |
136 | + debug("%s: Type of \"%s\" is %s",__FUNCTION__,property_name,"boolean"); | |
137 | + break; | |
138 | + | |
139 | + case G_TYPE_INT: | |
140 | + type = G_VARIANT_TYPE_INT32; | |
141 | + debug("%s: Type of \"%s\" is %s",__FUNCTION__,property_name,"int32"); | |
142 | + break; | |
143 | + | |
144 | + case G_TYPE_UINT: | |
145 | + type = G_VARIANT_TYPE_UINT32; | |
146 | + debug("%s: Type of \"%s\" is %s",__FUNCTION__,property_name,"uint32"); | |
147 | + break; | |
148 | + | |
149 | + case G_TYPE_DOUBLE: | |
150 | + case G_TYPE_FLOAT: | |
151 | + type = G_VARIANT_TYPE_DOUBLE; | |
152 | + break; | |
153 | + | |
154 | + case G_TYPE_STRING: | |
155 | + type = G_VARIANT_TYPE_STRING; | |
156 | + break; | |
157 | + | |
158 | + default: | |
159 | + g_warning( | |
160 | + "Unable to create action for property '%s::%s' of type '%s'", | |
161 | + g_type_name(pspec->owner_type), | |
162 | + pspec->name, | |
163 | + g_type_name(pspec->value_type) | |
164 | + ); | |
165 | + return NULL; | |
166 | + } | |
167 | + | |
168 | + v3270PropertyAction * action = (v3270PropertyAction *) g_object_new(V3270_TYPE_PROPERTY_ACTION, NULL); | |
169 | + | |
170 | + action->parent.name = pspec->name; | |
171 | + action->parent.types.state = type; | |
172 | + action->parent.types.parameter = type; | |
173 | + action->parent.activate = activate; | |
174 | + action->pspec = pspec; | |
175 | + | |
176 | + pw3270_action_set_terminal_widget(G_ACTION(action), widget); | |
73 | 177 | return action; |
74 | 178 | } | ... | ... |
src/objects/application/application.c
... | ... | @@ -33,6 +33,7 @@ |
33 | 33 | |
34 | 34 | #include "private.h" |
35 | 35 | #include <pw3270/application.h> |
36 | + #include <pw3270/actions.h> | |
36 | 37 | |
37 | 38 | enum { |
38 | 39 | PROP_ZERO, |
... | ... | @@ -272,11 +273,18 @@ |
272 | 273 | |
273 | 274 | GtkWidget * window = pw3270_application_window_new(GTK_APPLICATION(application)); |
274 | 275 | |
275 | - // Create terminal widget | |
276 | - pw3270_terminal_new(window); | |
277 | - pw3270_window_set_current_page(window,0); | |
276 | + // Create terminal widget & associated widget | |
277 | + GtkWidget * terminal = pw3270_terminal_new(window); | |
278 | + | |
279 | + GAction * action = G_ACTION(v3270_property_action_new(terminal,"model_number")); | |
280 | + | |
281 | + if(action) { | |
282 | + debug("Adding window action \"%s\"",g_action_get_name(action)); | |
283 | + g_action_map_add_action(G_ACTION_MAP(window),action); | |
284 | + } | |
278 | 285 | |
279 | 286 | // Present the new window |
287 | + pw3270_window_set_current_page(window,0); | |
280 | 288 | gtk_window_present(GTK_WINDOW(window)); |
281 | 289 | |
282 | 290 | } | ... | ... |
ui/application.xml
... | ... | @@ -245,19 +245,20 @@ |
245 | 245 | <attribute name="label" translatable="yes">Screen size</attribute> |
246 | 246 | <item> |
247 | 247 | <attribute name="label" translatable="yes">Model 2 - 80x24</attribute> |
248 | - <attribute name="action">win.set-model</attribute> | |
248 | + <attribute name="action">win.model-number</attribute> | |
249 | + <attribute name="state">2</attribute> | |
249 | 250 | </item> |
250 | 251 | <item> |
251 | 252 | <attribute name="label" translatable="yes">Model 3 - 80x32</attribute> |
252 | - <attribute name="action">win.set-model</attribute> | |
253 | + <attribute name="action">win.model-number</attribute> | |
253 | 254 | </item> |
254 | 255 | <item> |
255 | 256 | <attribute name="label" translatable="yes">Model 4 - 80x43</attribute> |
256 | - <attribute name="action">win.set-model</attribute> | |
257 | + <attribute name="action">win.model-number</attribute> | |
257 | 258 | </item> |
258 | 259 | <item> |
259 | 260 | <attribute name="label" translatable="yes">Model 5 - 132x27</attribute> |
260 | - <attribute name="action">win.set-model</attribute> | |
261 | + <attribute name="action">win.model-number</attribute> | |
261 | 262 | </item> |
262 | 263 | |
263 | 264 | </submenu> |
... | ... | @@ -266,11 +267,6 @@ |
266 | 267 | <attribute name="label" translatable="yes">Select font</attribute> |
267 | 268 | </submenu> |
268 | 269 | |
269 | - <item> | |
270 | - <attribute name="label" translatable="yes">Screen sizes</attribute> | |
271 | - <attribute name="action">win.screen.sizes</attribute> | |
272 | - </item> | |
273 | - | |
274 | 270 | <submenu> |
275 | 271 | |
276 | 272 | <attribute name='label' translatable='yes'>Options</attribute> | ... | ... |