Commit e459184ea2465ff3039a9e629a673c5727485e62
1 parent
f50da19d
Exists in
master
and in
1 other branch
Refactoring standard V3270 action object.
Showing
3 changed files
with
123 additions
and
137 deletions
Show diff stats
src/include/v3270/actions.h
... | ... | @@ -120,11 +120,6 @@ |
120 | 120 | const LIB3270_PROPERTY * info; ///> @brief Action info. |
121 | 121 | const void * listener; ///> @brief Signal listener for the action group. |
122 | 122 | |
123 | - struct { | |
124 | - const GVariantType * state; ///> @brief State type type. | |
125 | - const GVariantType * parameter; ///> @brief Parameter type. | |
126 | - } types; | |
127 | - | |
128 | 123 | /// @brief Activation method. |
129 | 124 | void (*activate)(GAction *action, GVariant *parameter, GtkWidget *terminal); |
130 | 125 | |
... | ... | @@ -139,11 +134,14 @@ |
139 | 134 | GParamSpec * enabled; |
140 | 135 | } properties; |
141 | 136 | |
137 | + struct { | |
138 | + const GVariantType * type; ///> @brief State type. | |
139 | + } state; | |
140 | + | |
142 | 141 | void (*change_widget)(GAction *action, GtkWidget *from, GtkWidget *to); |
143 | - gboolean (*get_enabled)(GAction *action, GtkWidget *terminal); | |
144 | 142 | |
145 | - GVariant * (*get_state)(GAction *action, GtkWidget *terminal); | |
146 | - GVariant * (*get_state_hint)(GAction *action, GtkWidget *terminal); | |
143 | + gboolean (*get_enabled)(GAction *action, GtkWidget *terminal); | |
144 | + GVariant * (*get_state)(GAction *action, GtkWidget *terminal); | |
147 | 145 | |
148 | 146 | } V3270ActionClass; |
149 | 147 | ... | ... |
src/terminal/actions/action.c
... | ... | @@ -43,27 +43,22 @@ |
43 | 43 | static void get_property(GObject *object, guint prop_id, GValue *value, GParamSpec *pspec); |
44 | 44 | static void set_property(GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec); |
45 | 45 | |
46 | - static gboolean get_enabled(GAction *action); | |
47 | - static void activate(GAction *action, GVariant *parameter); | |
48 | - | |
49 | 46 | static void change_widget(GAction *action, GtkWidget *from, GtkWidget *to); |
50 | - | |
51 | 47 | static void finalize(GObject *object); |
52 | 48 | |
53 | - static const GVariantType * get_state_type(GAction *action); | |
54 | - static GVariant * get_state_property(GAction *action); | |
55 | - | |
56 | - static gboolean internal_get_enabled(GAction *action, GtkWidget *terminal); | |
57 | - static void internal_activate(GAction *action, GVariant *parameter, GtkWidget *terminal); | |
58 | - | |
59 | - static GVariant * internal_get_state(GAction *action, GtkWidget *terminal); | |
60 | - static GVariant * internal_get_state_hint(GAction *action, GtkWidget *terminal); | |
49 | + static gboolean get_enabled(GAction *action, GtkWidget *terminal); | |
50 | + static void activate(GAction *action, GVariant *parameter, GtkWidget *terminal); | |
51 | + static GVariant * get_state(GAction *action, GtkWidget *terminal); | |
61 | 52 | |
62 | - static const GVariantType * get_parameter_type(GAction *action); | |
63 | - static GVariant * get_state_hint(GAction *action); | |
64 | - static const gchar * get_name(GAction *action); | |
65 | - | |
66 | - static void change_state(GAction *action, GVariant *value); | |
53 | + static const gchar * iface_get_name(GAction *action); | |
54 | + static const GVariantType * iface_get_parameter_type(GAction *action); | |
55 | + static GVariant * iface_get_state_hint(GAction *action); | |
56 | + static const GVariantType * iface_get_state_type(GAction *action); | |
57 | + static GVariant * iface_get_state(GAction *action); | |
58 | + static gboolean iface_get_enabled(GAction *action); | |
59 | + static GVariant * iface_get_state(GAction *object); | |
60 | + static void iface_change_state(GAction *object, GVariant *value); | |
61 | + static void iface_activate(GAction *object, GVariant *parameter); | |
67 | 62 | |
68 | 63 | enum { |
69 | 64 | PROP_NONE, |
... | ... | @@ -79,17 +74,6 @@ |
79 | 74 | |
80 | 75 | G_DEFINE_TYPE_WITH_CODE(V3270Action, V3270Action, G_TYPE_OBJECT, G_IMPLEMENT_INTERFACE(G_TYPE_ACTION, V3270_action_iface_init)) |
81 | 76 | |
82 | - void V3270_action_iface_init(GActionInterface *iface) { | |
83 | - iface->get_name = get_name; | |
84 | - iface->get_parameter_type = get_parameter_type; | |
85 | - iface->get_state_type = get_state_type; | |
86 | - iface->get_state_hint = get_state_hint; | |
87 | - iface->get_enabled = get_enabled; | |
88 | - iface->get_state = get_state_property; | |
89 | - iface->change_state = change_state; | |
90 | - iface->activate = activate; | |
91 | - } | |
92 | - | |
93 | 77 | void V3270Action_class_init(V3270ActionClass *klass) { |
94 | 78 | |
95 | 79 | GObjectClass *object_class = G_OBJECT_CLASS(klass); |
... | ... | @@ -97,10 +81,10 @@ |
97 | 81 | debug("%s",__FUNCTION__); |
98 | 82 | |
99 | 83 | klass->change_widget = change_widget; |
100 | - klass->get_enabled = internal_get_enabled; | |
101 | - klass->get_state = internal_get_state; | |
102 | - klass->get_state_hint = internal_get_state_hint; | |
84 | + klass->get_enabled = get_enabled; | |
85 | + klass->get_state = get_state; | |
103 | 86 | |
87 | + klass->state.type = NULL; | |
104 | 88 | |
105 | 89 | object_class->finalize = finalize; |
106 | 90 | object_class->get_property = get_property; |
... | ... | @@ -188,11 +172,7 @@ |
188 | 172 | |
189 | 173 | action->terminal = NULL; |
190 | 174 | action->info = &default_info; |
191 | - action->types.parameter = NULL; | |
192 | - | |
193 | - action->activate = internal_activate; | |
194 | -// action->get_state_property = internal_get_state_property; | |
195 | -// action->get_state_hint = internal_get_state_hint; | |
175 | + action->activate = activate; | |
196 | 176 | |
197 | 177 | } |
198 | 178 | |
... | ... | @@ -217,7 +197,7 @@ |
217 | 197 | |
218 | 198 | switch (prop_id) { |
219 | 199 | case PROP_NAME: |
220 | - g_value_set_string(value, get_name(action)); | |
200 | + g_value_set_string(value, g_action_get_name(action)); | |
221 | 201 | break; |
222 | 202 | |
223 | 203 | case PROP_ICON_NAME: |
... | ... | @@ -233,19 +213,19 @@ |
233 | 213 | break; |
234 | 214 | |
235 | 215 | case PROP_PARAMETER_TYPE: |
236 | - g_value_set_boxed(value, get_parameter_type(action)); | |
216 | + g_value_set_boxed(value, g_action_get_parameter_type(action)); | |
237 | 217 | break; |
238 | 218 | |
239 | 219 | case PROP_ENABLED: |
240 | - g_value_set_boolean(value, get_enabled(action)); | |
220 | + g_value_set_boolean(value, g_action_get_enabled(action)); | |
241 | 221 | break; |
242 | 222 | |
243 | 223 | case PROP_STATE_TYPE: |
244 | - g_value_set_boxed(value, get_state_type(action)); | |
224 | + g_value_set_boxed(value, g_action_get_state_type(action)); | |
245 | 225 | break; |
246 | 226 | |
247 | 227 | case PROP_STATE: |
248 | - g_value_take_variant(value, get_state_property(action)); | |
228 | + g_value_take_variant(value, g_action_get_state(action)); | |
249 | 229 | break; |
250 | 230 | |
251 | 231 | default: |
... | ... | @@ -254,46 +234,8 @@ |
254 | 234 | |
255 | 235 | } |
256 | 236 | |
257 | - void set_property(GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec) { | |
258 | - g_message("Action property \"%s\" is read-only",pspec->name); | |
259 | - } | |
260 | - | |
261 | - const gchar * get_name(GAction *action) { | |
262 | - return V3270_ACTION_GET_DESCRIPTOR(action)->name; | |
263 | - } | |
264 | - | |
265 | - GVariant * internal_get_state_hint(GAction G_GNUC_UNUSED(*action), GtkWidget G_GNUC_UNUSED(*terminal)) { | |
266 | - return NULL; | |
267 | - } | |
268 | - | |
269 | - GVariant * internal_get_state(GAction *object, GtkWidget G_GNUC_UNUSED(*terminal)) { | |
270 | - | |
271 | - V3270Action * action = V3270_ACTION(object); | |
272 | - | |
273 | - if(action->types.state == G_VARIANT_TYPE_BOOLEAN) | |
274 | - return g_variant_new_boolean(FALSE); | |
275 | - | |
276 | - return NULL; | |
277 | - } | |
278 | - | |
279 | - GVariant * get_state_property(GAction *object) { | |
280 | - return V3270_ACTION_GET_CLASS(object)->get_state(object,V3270_ACTION(object)->terminal); | |
281 | - } | |
282 | - | |
283 | - const GVariantType * get_parameter_type(GAction *action) { | |
284 | - return V3270_ACTION(action)->types.parameter; | |
285 | - } | |
286 | - | |
287 | - const GVariantType * get_state_type(GAction *object) { | |
288 | - return V3270_ACTION(object)->types.state; | |
289 | - } | |
290 | - | |
291 | - GVariant * get_state_hint(GAction *object) { | |
292 | - return V3270_ACTION_GET_CLASS(object)->get_state_hint(object,V3270_ACTION(object)->terminal); | |
293 | - } | |
294 | - | |
295 | - void change_state(GAction G_GNUC_UNUSED(*object), GVariant G_GNUC_UNUSED(*value)) { | |
296 | - debug("%s",__FUNCTION__); | |
237 | + void set_property(GObject *object, guint G_GNUC_UNUSED(prop_id), const GValue G_GNUC_UNUSED(*value), GParamSpec *pspec) { | |
238 | + g_message("Action %s property %s is read-only",g_action_get_name(G_ACTION(object)),pspec->name); | |
297 | 239 | } |
298 | 240 | |
299 | 241 | static gboolean bg_notify_enabled(GObject *action) { |
... | ... | @@ -338,7 +280,7 @@ |
338 | 280 | |
339 | 281 | g_idle_add((GSourceFunc) bg_notify_enabled, G_OBJECT(action)); |
340 | 282 | |
341 | - if(action->types.state) | |
283 | + if(V3270_ACTION_GET_CLASS(action)->state.type) | |
342 | 284 | g_idle_add((GSourceFunc) bg_notify_state, G_OBJECT(action)); |
343 | 285 | |
344 | 286 | } |
... | ... | @@ -367,43 +309,11 @@ |
367 | 309 | return V3270_ACTION(object)->terminal; |
368 | 310 | } |
369 | 311 | |
370 | - gboolean get_enabled(GAction *object) { | |
371 | - | |
372 | - V3270Action * action = V3270_ACTION(object); | |
373 | - | |
374 | - if(action && action->terminal) { | |
375 | - | |
376 | - if(action->info->group != LIB3270_ACTION_GROUP_NONE) { | |
377 | - | |
378 | - if(!lib3270_action_group_get_activatable(v3270_get_session(action->terminal),action->info->group)) | |
379 | - return FALSE; | |
380 | - | |
381 | - } | |
382 | - | |
383 | - return V3270_ACTION_GET_CLASS(object)->get_enabled(object,action->terminal); | |
384 | - } | |
385 | - | |
386 | - return FALSE; | |
387 | - | |
388 | - } | |
389 | - | |
390 | - void activate(GAction *object, GVariant *parameter) { | |
391 | - | |
392 | - V3270Action * action = V3270_ACTION(object); | |
393 | - | |
394 | - debug("%s: terminal=%p",__FUNCTION__,action->terminal); | |
395 | - | |
396 | - if(action && action->terminal) { | |
397 | - action->activate(object,parameter,action->terminal); | |
398 | - } | |
399 | - | |
400 | - } | |
401 | - | |
402 | - gboolean internal_get_enabled(GAction G_GNUC_UNUSED(*object), GtkWidget *terminal) { | |
312 | + gboolean get_enabled(GAction G_GNUC_UNUSED(*object), GtkWidget *terminal) { | |
403 | 313 | return terminal != NULL; |
404 | 314 | } |
405 | 315 | |
406 | - void internal_activate(GAction *action, GVariant G_GNUC_UNUSED(*parameter), GtkWidget G_GNUC_UNUSED(*terminal)) { | |
316 | + void activate(GAction *action, GVariant G_GNUC_UNUSED(*parameter), GtkWidget G_GNUC_UNUSED(*terminal)) { | |
407 | 317 | g_message("Action %s can't be activated",g_action_get_name(action)); |
408 | 318 | } |
409 | 319 | |
... | ... | @@ -421,14 +331,23 @@ |
421 | 331 | } |
422 | 332 | |
423 | 333 | const gchar * v3270_action_get_tooltip(GAction *action) { |
424 | - const gchar * tooltip = V3270_ACTION_GET_DESCRIPTOR(action)->description; | |
425 | 334 | |
335 | + const gchar * tooltip; | |
336 | + | |
337 | + tooltip = V3270_ACTION_GET_DESCRIPTOR(action)->description; | |
338 | + if(tooltip) | |
339 | + return gettext(tooltip); | |
340 | + | |
341 | + tooltip = V3270_ACTION_GET_DESCRIPTOR(action)->summary; | |
426 | 342 | if(tooltip) |
427 | 343 | return gettext(tooltip); |
428 | 344 | |
429 | 345 | return NULL; |
430 | 346 | } |
431 | 347 | |
348 | + // | |
349 | + // Action methods. | |
350 | + // | |
432 | 351 | H3270 * v3270_action_get_session(GAction *action) { |
433 | 352 | g_return_val_if_fail(V3270_IS_ACTION(action),NULL); |
434 | 353 | return v3270_get_session(V3270_ACTION(action)->terminal); |
... | ... | @@ -438,17 +357,6 @@ |
438 | 357 | return G_ACTION(g_object_new(V3270_TYPE_ACTION, NULL)); |
439 | 358 | } |
440 | 359 | |
441 | - /* | |
442 | - static GdkPixbuf * pixbuf_from_icon_name(GValue *value, GtkIconSize icon_size) { | |
443 | - | |
444 | - const gchar * icon_name = g_value_get_string(value); | |
445 | - | |
446 | - if(!icon_name) | |
447 | - return NULL; | |
448 | - | |
449 | - } | |
450 | - */ | |
451 | - | |
452 | 360 | GdkPixbuf * v3270_action_get_pixbuf(GAction *action, GtkIconSize icon_size, GtkIconLookupFlags flags) { |
453 | 361 | |
454 | 362 | const gchar * icon_name = v3270_action_get_icon_name(action); |
... | ... | @@ -466,3 +374,84 @@ |
466 | 374 | |
467 | 375 | } |
468 | 376 | |
377 | +// | |
378 | +// Default methods. | |
379 | +// | |
380 | + GVariant * get_state(GAction G_GNUC_UNUSED(*object), GtkWidget *terminal) { | |
381 | + return g_variant_new_boolean(terminal != NULL); | |
382 | + } | |
383 | + | |
384 | +// | |
385 | +// Interface Methods. | |
386 | +// | |
387 | + void V3270_action_iface_init(GActionInterface *iface) { | |
388 | + iface->get_name = iface_get_name; | |
389 | + iface->get_parameter_type = iface_get_parameter_type; | |
390 | + iface->get_state_type = iface_get_state_type; | |
391 | + iface->get_state_hint = iface_get_state_hint; | |
392 | + iface->get_enabled = iface_get_enabled; | |
393 | + iface->get_state = iface_get_state; | |
394 | + iface->change_state = iface_change_state; | |
395 | + iface->activate = iface_activate; | |
396 | + } | |
397 | + | |
398 | + const gchar * iface_get_name(GAction *action) { | |
399 | + return V3270_ACTION_GET_DESCRIPTOR(action)->name; | |
400 | + } | |
401 | + | |
402 | + GVariant * iface_get_state(GAction *object) { | |
403 | + | |
404 | + GtkWidget * terminal = V3270_ACTION(object)->terminal; | |
405 | + | |
406 | + if(!terminal) | |
407 | + g_variant_new_boolean(FALSE); | |
408 | + | |
409 | + return V3270_ACTION_GET_CLASS(object)->get_state(object,terminal); | |
410 | + } | |
411 | + | |
412 | + const GVariantType * iface_get_parameter_type(GAction G_GNUC_UNUSED(*action)) { | |
413 | + return NULL; | |
414 | + } | |
415 | + | |
416 | + const GVariantType * iface_get_state_type(GAction *object) { | |
417 | + return V3270_ACTION_GET_CLASS(object)->state.type; | |
418 | + } | |
419 | + | |
420 | + GVariant * iface_get_state_hint(GAction G_GNUC_UNUSED(*object)) { | |
421 | + return NULL; | |
422 | + } | |
423 | + | |
424 | + void iface_change_state(GAction G_GNUC_UNUSED(*object), GVariant G_GNUC_UNUSED(*value)) { | |
425 | + debug("%s",__FUNCTION__); | |
426 | + } | |
427 | + | |
428 | + gboolean iface_get_enabled(GAction *object) { | |
429 | + | |
430 | + V3270Action * action = V3270_ACTION(object); | |
431 | + | |
432 | + if(action && action->terminal) { | |
433 | + | |
434 | + if(action->info->group != LIB3270_ACTION_GROUP_NONE) { | |
435 | + | |
436 | + if(!lib3270_action_group_get_activatable(v3270_get_session(action->terminal),action->info->group)) | |
437 | + return FALSE; | |
438 | + | |
439 | + } | |
440 | + | |
441 | + return V3270_ACTION_GET_CLASS(object)->get_enabled(object,action->terminal); | |
442 | + } | |
443 | + | |
444 | + return FALSE; | |
445 | + | |
446 | + } | |
447 | + | |
448 | + void iface_activate(GAction *object, GVariant *parameter) { | |
449 | + | |
450 | + V3270Action * action = V3270_ACTION(object); | |
451 | + | |
452 | + if(action && action->terminal) { | |
453 | + action->activate(object,parameter,action->terminal); | |
454 | + } | |
455 | + | |
456 | + } | |
457 | + | ... | ... |
v3270.cbp
... | ... | @@ -171,7 +171,6 @@ |
171 | 171 | <Option compilerVar="CC" /> |
172 | 172 | </Unit> |
173 | 173 | <Unit filename="src/include/clipboard.h" /> |
174 | - <Unit filename="src/include/config.h" /> | |
175 | 174 | <Unit filename="src/include/config.h.in" /> |
176 | 175 | <Unit filename="src/include/hostselect.h" /> |
177 | 176 | <Unit filename="src/include/internals.h" /> | ... | ... |