Commit 8629b749db9bad880ff8c53c9c880d870bd58028
1 parent
6c0b2b00
Exists in
master
and in
4 other branches
Fixing action engine.
Showing
7 changed files
with
206 additions
and
52 deletions
Show diff stats
src/objects/actions/abstract.c
| @@ -171,7 +171,6 @@ | @@ -171,7 +171,6 @@ | ||
| 171 | 171 | ||
| 172 | void pw3270Action_init(pw3270Action *action) { | 172 | void pw3270Action_init(pw3270Action *action) { |
| 173 | 173 | ||
| 174 | - action->name = NULL; | ||
| 175 | action->terminal = NULL; | 174 | action->terminal = NULL; |
| 176 | action->state = NULL; | 175 | action->state = NULL; |
| 177 | action->activate = activate; | 176 | action->activate = activate; |
| @@ -182,7 +181,7 @@ | @@ -182,7 +181,7 @@ | ||
| 182 | 181 | ||
| 183 | pw3270Action * action = PW3270_ACTION(object); | 182 | pw3270Action * action = PW3270_ACTION(object); |
| 184 | 183 | ||
| 185 | - debug("Finalizing action %p (%s)",object,action->name); | 184 | +// debug("Finalizing action %p (%s)",object,action->name); |
| 186 | 185 | ||
| 187 | if(action->state) { | 186 | if(action->state) { |
| 188 | g_variant_unref(action->state); | 187 | g_variant_unref(action->state); |
| @@ -194,10 +193,12 @@ | @@ -194,10 +193,12 @@ | ||
| 194 | action->terminal = NULL; | 193 | action->terminal = NULL; |
| 195 | } | 194 | } |
| 196 | 195 | ||
| 196 | + /* | ||
| 197 | if(action->name) { | 197 | if(action->name) { |
| 198 | g_free(action->name); | 198 | g_free(action->name); |
| 199 | action->name = NULL; | 199 | action->name = NULL; |
| 200 | } | 200 | } |
| 201 | + */ | ||
| 201 | 202 | ||
| 202 | if(action->parameter_type) { | 203 | if(action->parameter_type) { |
| 203 | g_variant_type_free(action->parameter_type); | 204 | g_variant_type_free(action->parameter_type); |
| @@ -250,7 +251,7 @@ | @@ -250,7 +251,7 @@ | ||
| 250 | switch (prop_id) | 251 | switch (prop_id) |
| 251 | { | 252 | { |
| 252 | case PROP_NAME: | 253 | case PROP_NAME: |
| 253 | - pw3270_action_set_name(action, g_value_get_string(value)); | 254 | +// pw3270_action_set_name(action, g_value_get_string(value)); |
| 254 | break; | 255 | break; |
| 255 | 256 | ||
| 256 | case PROP_PARAMETER_TYPE: | 257 | case PROP_PARAMETER_TYPE: |
| @@ -272,11 +273,12 @@ | @@ -272,11 +273,12 @@ | ||
| 272 | } | 273 | } |
| 273 | 274 | ||
| 274 | const gchar * pw3270_action_get_name(GAction *action) { | 275 | const gchar * pw3270_action_get_name(GAction *action) { |
| 275 | - return PW3270_ACTION(action)->name; | 276 | + return PW3270_ACTION(action)->get_name(action); |
| 276 | } | 277 | } |
| 277 | 278 | ||
| 278 | void pw3270_action_set_name(GAction *object, const gchar *name) { | 279 | void pw3270_action_set_name(GAction *object, const gchar *name) { |
| 279 | 280 | ||
| 281 | +/* | ||
| 280 | pw3270Action * action = PW3270_ACTION(object); | 282 | pw3270Action * action = PW3270_ACTION(object); |
| 281 | 283 | ||
| 282 | // debug("%s %s -> %s", __FUNCTION__, action->name, name); | 284 | // debug("%s %s -> %s", __FUNCTION__, action->name, name); |
| @@ -288,6 +290,7 @@ | @@ -288,6 +290,7 @@ | ||
| 288 | action->name = g_strdup(name); | 290 | action->name = g_strdup(name); |
| 289 | else | 291 | else |
| 290 | action->name = NULL; | 292 | action->name = NULL; |
| 293 | +*/ | ||
| 291 | 294 | ||
| 292 | } | 295 | } |
| 293 | 296 | ||
| @@ -357,12 +360,6 @@ | @@ -357,12 +360,6 @@ | ||
| 357 | 360 | ||
| 358 | void pw3270_action_notify_enabled(GAction *object) { | 361 | void pw3270_action_notify_enabled(GAction *object) { |
| 359 | 362 | ||
| 360 | - debug("%s(%s) = %s", | ||
| 361 | - __FUNCTION__, | ||
| 362 | - g_action_get_name(G_ACTION(object)), | ||
| 363 | - (g_action_get_enabled(G_ACTION(object)) ? "Enabled" : "Disabled") | ||
| 364 | - ); | ||
| 365 | - | ||
| 366 | // g_object_notify_by_pspec(G_OBJECT(object), PW3270_ACTION_GET_CLASS(object)->properties.enabled); | 363 | // g_object_notify_by_pspec(G_OBJECT(object), PW3270_ACTION_GET_CLASS(object)->properties.enabled); |
| 367 | g_object_notify(G_OBJECT (object), "enabled"); | 364 | g_object_notify(G_OBJECT (object), "enabled"); |
| 368 | 365 |
src/objects/actions/lib3270/action.c
| @@ -114,9 +114,16 @@ | @@ -114,9 +114,16 @@ | ||
| 114 | 114 | ||
| 115 | } | 115 | } |
| 116 | 116 | ||
| 117 | - void Lib3270Action_init(Lib3270Action *action) { | ||
| 118 | -// debug("%s",__FUNCTION__); | ||
| 119 | - PW3270_ACTION(action)->activate = activate; | 117 | + static const gchar * get_name(GAction *action) { |
| 118 | + return PW3270_LIB3270_ACTION(action)->definition->name; | ||
| 119 | + } | ||
| 120 | + | ||
| 121 | + void Lib3270Action_init(Lib3270Action *object) { | ||
| 122 | + pw3270Action * action = PW3270_ACTION(object); | ||
| 123 | + | ||
| 124 | + action->activate = activate; | ||
| 125 | + action->get_name = get_name; | ||
| 126 | + | ||
| 120 | } | 127 | } |
| 121 | 128 | ||
| 122 | GAction * pw3270_action_new_from_lib3270(const LIB3270_ACTION * definition) { | 129 | GAction * pw3270_action_new_from_lib3270(const LIB3270_ACTION * definition) { |
| @@ -127,14 +134,6 @@ | @@ -127,14 +134,6 @@ | ||
| 127 | action->definition = definition; | 134 | action->definition = definition; |
| 128 | action->listener = NULL; | 135 | action->listener = NULL; |
| 129 | 136 | ||
| 130 | - // Setup the default name. | ||
| 131 | - pw3270Action * abstract = PW3270_ACTION(action); | ||
| 132 | - | ||
| 133 | - if(abstract->name) | ||
| 134 | - g_free(abstract->name); | ||
| 135 | - | ||
| 136 | - abstract->name = g_strdup(definition->name); | ||
| 137 | - | ||
| 138 | return G_ACTION(action); | 137 | return G_ACTION(action); |
| 139 | } | 138 | } |
| 140 | 139 |
src/objects/actions/lib3270/pakey.c
| @@ -109,23 +109,20 @@ | @@ -109,23 +109,20 @@ | ||
| 109 | 109 | ||
| 110 | } | 110 | } |
| 111 | 111 | ||
| 112 | - void Lib3270PaAction_init(Lib3270PaAction *action) { | ||
| 113 | - PW3270_ACTION(action)->activate = activate; | 112 | + static const gchar * get_name(GAction G_GNUC_UNUSED(*action)) { |
| 113 | + return "pakey"; | ||
| 114 | } | 114 | } |
| 115 | 115 | ||
| 116 | - GAction * pw3270_action_new_pakey(void) { | ||
| 117 | - | ||
| 118 | - Lib3270PaAction * action = (Lib3270PaAction *) g_object_new(PW3270_TYPE_PAKEY_ACTION, NULL); | ||
| 119 | - | ||
| 120 | - // Setup the default name. | ||
| 121 | - pw3270Action * abstract = PW3270_ACTION(action); | 116 | + void Lib3270PaAction_init(Lib3270PaAction *object) { |
| 117 | + pw3270Action * action = PW3270_ACTION(object); | ||
| 122 | 118 | ||
| 123 | - if(abstract->name) | ||
| 124 | - g_free(abstract->name); | 119 | + action->activate = activate; |
| 120 | + action->get_name = get_name; | ||
| 121 | + } | ||
| 125 | 122 | ||
| 126 | - abstract->name = g_strdup("pakey"); | ||
| 127 | 123 | ||
| 128 | - return G_ACTION(action); | 124 | + GAction * pw3270_action_new_pakey(void) { |
| 125 | + return G_ACTION(g_object_new(PW3270_TYPE_PAKEY_ACTION, NULL)); | ||
| 129 | } | 126 | } |
| 130 | 127 | ||
| 131 | void change_widget(GAction *object, GtkWidget *from, GtkWidget *to) { | 128 | void change_widget(GAction *object, GtkWidget *from, GtkWidget *to) { |
src/objects/actions/lib3270/pfkey.c
| @@ -108,24 +108,19 @@ | @@ -108,24 +108,19 @@ | ||
| 108 | 108 | ||
| 109 | } | 109 | } |
| 110 | 110 | ||
| 111 | - void Lib3270PfAction_init(Lib3270PfAction *action) { | ||
| 112 | - PW3270_ACTION(action)->activate = activate; | 111 | + static const gchar * get_name(GAction *action) { |
| 112 | + return "pakey"; | ||
| 113 | } | 113 | } |
| 114 | 114 | ||
| 115 | - GAction * pw3270_action_new_pfkey(void) { | ||
| 116 | - | ||
| 117 | - Lib3270PfAction * action = (Lib3270PfAction *) g_object_new(PW3270_TYPE_PFKEY_ACTION, NULL); | ||
| 118 | - | ||
| 119 | - // Setup the default name. | ||
| 120 | - pw3270Action * abstract = PW3270_ACTION(action); | ||
| 121 | - | ||
| 122 | - if(abstract->name) | ||
| 123 | - g_free(abstract->name); | 115 | + void Lib3270PfAction_init(Lib3270PfAction *object) { |
| 116 | + pw3270Action * action = PW3270_ACTION(object); | ||
| 124 | 117 | ||
| 125 | - abstract->name = g_strdup("pfkey"); | ||
| 126 | - | ||
| 127 | - return G_ACTION(action); | 118 | + action->activate = activate; |
| 119 | + action->get_name = get_name; | ||
| 120 | + } | ||
| 128 | 121 | ||
| 122 | + GAction * pw3270_action_new_pfkey(void) { | ||
| 123 | + return G_ACTION(g_object_new(PW3270_TYPE_PFKEY_ACTION, NULL)); | ||
| 129 | } | 124 | } |
| 130 | 125 | ||
| 131 | void change_widget(GAction *object, GtkWidget *from, GtkWidget *to) { | 126 | void change_widget(GAction *object, GtkWidget *from, GtkWidget *to) { |
src/objects/actions/lib3270/toggle.c
| @@ -105,12 +105,18 @@ | @@ -105,12 +105,18 @@ | ||
| 105 | 105 | ||
| 106 | } | 106 | } |
| 107 | 107 | ||
| 108 | - void Lib3270ToggleAction_init(Lib3270ToggleAction *action) { | 108 | + static const gchar * get_name(GAction *action) { |
| 109 | + return PW3270_LIB3270_TOGGLE_ACTION(action)->definition->name; | ||
| 110 | + } | ||
| 111 | + | ||
| 112 | + void Lib3270ToggleAction_init(Lib3270ToggleAction *toggle) { | ||
| 109 | 113 | ||
| 110 | - action->definition = NULL; | ||
| 111 | - action->listener = NULL; | 114 | + toggle->definition = NULL; |
| 115 | + toggle->listener = NULL; | ||
| 112 | 116 | ||
| 113 | - PW3270_ACTION(action)->activate = activate; | 117 | + pw3270Action * action = PW3270_ACTION(toggle); |
| 118 | + action->activate = activate; | ||
| 119 | + action->get_name = get_name; | ||
| 114 | 120 | ||
| 115 | } | 121 | } |
| 116 | 122 | ||
| @@ -122,10 +128,12 @@ | @@ -122,10 +128,12 @@ | ||
| 122 | // Setup the default name. | 128 | // Setup the default name. |
| 123 | pw3270Action * abstract = PW3270_ACTION(action); | 129 | pw3270Action * abstract = PW3270_ACTION(action); |
| 124 | 130 | ||
| 131 | + /* | ||
| 125 | if(abstract->name) | 132 | if(abstract->name) |
| 126 | g_free(abstract->name); | 133 | g_free(abstract->name); |
| 127 | 134 | ||
| 128 | abstract->name = g_strconcat("win.",definition->name,NULL); | 135 | abstract->name = g_strconcat("win.",definition->name,NULL); |
| 136 | + */ | ||
| 129 | 137 | ||
| 130 | return G_ACTION(action); | 138 | return G_ACTION(action); |
| 131 | 139 |
src/objects/actions/private.h
| @@ -57,9 +57,9 @@ | @@ -57,9 +57,9 @@ | ||
| 57 | GVariantType * parameter_type; | 57 | GVariantType * parameter_type; |
| 58 | GVariant * state; | 58 | GVariant * state; |
| 59 | GtkWidget * terminal; | 59 | GtkWidget * terminal; |
| 60 | - gchar * name; | ||
| 61 | 60 | ||
| 62 | void (*activate)(GAction *action, GVariant *parameter, GtkWidget *terminal); | 61 | void (*activate)(GAction *action, GVariant *parameter, GtkWidget *terminal); |
| 62 | + const gchar * (*get_name)(GAction *action); | ||
| 63 | 63 | ||
| 64 | }; | 64 | }; |
| 65 | 65 |
| @@ -0,0 +1,158 @@ | @@ -0,0 +1,158 @@ | ||
| 1 | +/* | ||
| 2 | + * "Software pw3270, desenvolvido com base nos códigos fontes do WC3270 e X3270 | ||
| 3 | + * (Paul Mattes Paul.Mattes@usa.net), de emulação de terminal 3270 para acesso a | ||
| 4 | + * aplicativos mainframe. Registro no INPI sob o nome G3270. | ||
| 5 | + * | ||
| 6 | + * Copyright (C) <2008> <Banco do Brasil S.A.> | ||
| 7 | + * | ||
| 8 | + * Este programa é software livre. Você pode redistribuí-lo e/ou modificá-lo sob | ||
| 9 | + * os termos da GPL v.2 - Licença Pública Geral GNU, conforme publicado pela | ||
| 10 | + * Free Software Foundation. | ||
| 11 | + * | ||
| 12 | + * Este programa é distribuído na expectativa de ser útil, mas SEM QUALQUER | ||
| 13 | + * GARANTIA; sem mesmo a garantia implícita de COMERCIALIZAÇÃO ou de ADEQUAÇÃO | ||
| 14 | + * A QUALQUER PROPÓSITO EM PARTICULAR. Consulte a Licença Pública Geral GNU para | ||
| 15 | + * obter mais detalhes. | ||
| 16 | + * | ||
| 17 | + * Você deve ter recebido uma cópia da Licença Pública Geral GNU junto com este | ||
| 18 | + * programa; se não, escreva para a Free Software Foundation, Inc., 51 Franklin | ||
| 19 | + * St, Fifth Floor, Boston, MA 02110-1301 USA | ||
| 20 | + * | ||
| 21 | + * Este programa está nomeado como - e possui - linhas de código. | ||
| 22 | + * | ||
| 23 | + * Contatos: | ||
| 24 | + * | ||
| 25 | + * perry.werneck@gmail.com (Alexandre Perry de Souza Werneck) | ||
| 26 | + * erico.mendonca@gmail.com (Erico Mascarenhas Mendonça) | ||
| 27 | + * | ||
| 28 | + */ | ||
| 29 | + | ||
| 30 | + #include "private.h" | ||
| 31 | + #include <pw3270/actions.h> | ||
| 32 | + | ||
| 33 | + static const struct Button { | ||
| 34 | + const gchar * name; | ||
| 35 | + const gchar * icon_name; | ||
| 36 | + const gchar * label; | ||
| 37 | + const gchar * tooltip; | ||
| 38 | + } buttons[] = { | ||
| 39 | + { | ||
| 40 | + .name = "connect", | ||
| 41 | + .icon_name = "gtk-connect", | ||
| 42 | + .label = N_("Connect"), | ||
| 43 | + .tooltip = N_("Connect to host") | ||
| 44 | + }, | ||
| 45 | + | ||
| 46 | + { | ||
| 47 | + .name = "close", | ||
| 48 | + .icon_name = "window-close", | ||
| 49 | + .label = N_("Close"), | ||
| 50 | + .tooltip = N_("Close window") | ||
| 51 | + }, | ||
| 52 | + | ||
| 53 | + { | ||
| 54 | + .name = "preferences", | ||
| 55 | + .icon_name = "preferences-other", | ||
| 56 | + .label = N_("Preferences"), | ||
| 57 | + } | ||
| 58 | + | ||
| 59 | + }; | ||
| 60 | + | ||
| 61 | + static const struct Button * get_button_info(const gchar *name) { | ||
| 62 | + | ||
| 63 | + size_t ix; | ||
| 64 | + const gchar * ptr = strchr(name,'.'); | ||
| 65 | + | ||
| 66 | + if(ptr) | ||
| 67 | + ptr++; | ||
| 68 | + else | ||
| 69 | + ptr = name; | ||
| 70 | + | ||
| 71 | + for(ix = 0; ix < G_N_ELEMENTS(buttons); ix++) { | ||
| 72 | + | ||
| 73 | + if(!g_ascii_strcasecmp(ptr,buttons[ix].name)) { | ||
| 74 | + return &buttons[ix]; | ||
| 75 | + } | ||
| 76 | + | ||
| 77 | + } | ||
| 78 | + | ||
| 79 | + return NULL; | ||
| 80 | + } | ||
| 81 | + | ||
| 82 | + static GtkWidget * setup_button(GtkWidget *button, const gchar *action_name) { | ||
| 83 | + | ||
| 84 | + if(button) { | ||
| 85 | + gtk_tool_button_set_use_underline(GTK_TOOL_BUTTON(button),TRUE); | ||
| 86 | + gtk_widget_show_all(GTK_WIDGET(button)); | ||
| 87 | + } | ||
| 88 | + | ||
| 89 | + debug("%s(%s)=%p",__FUNCTION__,action_name,button); | ||
| 90 | + | ||
| 91 | + return button; | ||
| 92 | + | ||
| 93 | + } | ||
| 94 | + | ||
| 95 | + GtkWidget * pw3270_tool_button_new_from_action_name(const gchar * action_name) { | ||
| 96 | + | ||
| 97 | + // Do I have button info? | ||
| 98 | + GtkToolItem * button = NULL; | ||
| 99 | + | ||
| 100 | + const struct Button * info = get_button_info(action_name); | ||
| 101 | + | ||
| 102 | + if(info) { | ||
| 103 | + | ||
| 104 | + button = gtk_tool_button_new( | ||
| 105 | + NULL, | ||
| 106 | + info->label | ||
| 107 | + ); | ||
| 108 | + | ||
| 109 | + gtk_tool_button_set_icon_name(GTK_TOOL_BUTTON(button),info->icon_name); | ||
| 110 | + | ||
| 111 | + if(info->tooltip) | ||
| 112 | + gtk_widget_set_tooltip_markup(GTK_WIDGET(button),info->tooltip); | ||
| 113 | + | ||
| 114 | + | ||
| 115 | + } else { | ||
| 116 | + | ||
| 117 | + g_warning("No toolbar info for action \"%s\"",action_name); | ||
| 118 | + | ||
| 119 | + } | ||
| 120 | + | ||
| 121 | + return setup_button(GTK_WIDGET(button),action_name); | ||
| 122 | + | ||
| 123 | + } | ||
| 124 | + | ||
| 125 | + GtkWidget * pw3270_tool_button_new(GAction *action) { | ||
| 126 | + | ||
| 127 | + const gchar * action_name = g_action_get_name(action); | ||
| 128 | + GtkToolItem * button = NULL; | ||
| 129 | + | ||
| 130 | + if(PW3270_IS_ACTION(action)) { | ||
| 131 | + | ||
| 132 | + // It's a pw3270 action, get attributes from it. | ||
| 133 | + | ||
| 134 | + const gchar * icon_name = pw3270_action_get_icon_name(action); | ||
| 135 | + if(!icon_name) { | ||
| 136 | + g_message("Action doesn't have an icon"); | ||
| 137 | + return NULL; | ||
| 138 | + } | ||
| 139 | + | ||
| 140 | + button = gtk_tool_button_new( | ||
| 141 | + NULL, | ||
| 142 | + pw3270_action_get_label(action) | ||
| 143 | + ); | ||
| 144 | + | ||
| 145 | + gtk_tool_button_set_icon_name(GTK_TOOL_BUTTON(button),icon_name); | ||
| 146 | + | ||
| 147 | + const gchar * tooltip = pw3270_action_get_tooltip(action); | ||
| 148 | + if(tooltip) | ||
| 149 | + gtk_widget_set_tooltip_markup(GTK_WIDGET(button),tooltip); | ||
| 150 | + | ||
| 151 | + return setup_button(GTK_WIDGET(button),action_name); | ||
| 152 | + | ||
| 153 | + } | ||
| 154 | + | ||
| 155 | + return pw3270_tool_button_new_from_action_name(action_name); | ||
| 156 | + | ||
| 157 | + } | ||
| 158 | + |