Commit 9125899389900fac6d91407bd4aa4fe3caca6544
1 parent
d784dee6
Exists in
master
and in
4 other branches
Implementing internal actions.
Showing
6 changed files
with
236 additions
and
4 deletions
Show diff stats
pw3270.cbp
| @@ -57,6 +57,9 @@ | @@ -57,6 +57,9 @@ | ||
| 57 | <Unit filename="src/objects/actions/abstract.c"> | 57 | <Unit filename="src/objects/actions/abstract.c"> |
| 58 | <Option compilerVar="CC" /> | 58 | <Option compilerVar="CC" /> |
| 59 | </Unit> | 59 | </Unit> |
| 60 | + <Unit filename="src/objects/actions/connect.c"> | ||
| 61 | + <Option compilerVar="CC" /> | ||
| 62 | + </Unit> | ||
| 60 | <Unit filename="src/objects/actions/lib3270/action.c"> | 63 | <Unit filename="src/objects/actions/lib3270/action.c"> |
| 61 | <Option compilerVar="CC" /> | 64 | <Option compilerVar="CC" /> |
| 62 | </Unit> | 65 | </Unit> |
| @@ -70,7 +73,7 @@ | @@ -70,7 +73,7 @@ | ||
| 70 | <Option compilerVar="CC" /> | 73 | <Option compilerVar="CC" /> |
| 71 | </Unit> | 74 | </Unit> |
| 72 | <Unit filename="src/objects/actions/private.h" /> | 75 | <Unit filename="src/objects/actions/private.h" /> |
| 73 | - <Unit filename="src/objects/actions/window.c"> | 76 | + <Unit filename="src/objects/actions/simple.c"> |
| 74 | <Option compilerVar="CC" /> | 77 | <Option compilerVar="CC" /> |
| 75 | </Unit> | 78 | </Unit> |
| 76 | <Unit filename="src/objects/toolbar/actions.c"> | 79 | <Unit filename="src/objects/toolbar/actions.c"> |
| @@ -0,0 +1,48 @@ | @@ -0,0 +1,48 @@ | ||
| 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 | + /** | ||
| 31 | + * @brief Implement PW3270 "connect" action. | ||
| 32 | + * | ||
| 33 | + */ | ||
| 34 | + | ||
| 35 | + #include "private.h" | ||
| 36 | + | ||
| 37 | + | ||
| 38 | + static void activate(GtkWidget *terminal) { | ||
| 39 | + | ||
| 40 | + debug("%s: Connect", __FUNCTION__); | ||
| 41 | + | ||
| 42 | + } | ||
| 43 | + | ||
| 44 | + GAction * pw3270_connect_action_new(void) { | ||
| 45 | + SimpleAction * action = pw3270_simple_action_from_name("reconnect"); | ||
| 46 | + action->activate = activate; | ||
| 47 | + return G_ACTION(action); | ||
| 48 | + } |
src/objects/actions/lib3270/action.c
| @@ -75,11 +75,11 @@ | @@ -75,11 +75,11 @@ | ||
| 75 | return PW3270_LIB3270_ACTION(action)->definition->icon; | 75 | return PW3270_LIB3270_ACTION(action)->definition->icon; |
| 76 | } | 76 | } |
| 77 | 77 | ||
| 78 | - const gchar * get_label(GAction *action) { | 78 | + static const gchar * get_label(GAction *action) { |
| 79 | return PW3270_LIB3270_ACTION(action)->definition->label; | 79 | return PW3270_LIB3270_ACTION(action)->definition->label; |
| 80 | } | 80 | } |
| 81 | 81 | ||
| 82 | - const gchar * get_tooltip(GAction *action) { | 82 | + static const gchar * get_tooltip(GAction *action) { |
| 83 | return PW3270_LIB3270_ACTION(action)->definition->summary; | 83 | return PW3270_LIB3270_ACTION(action)->definition->summary; |
| 84 | } | 84 | } |
| 85 | 85 |
src/objects/actions/lib3270/toggle.c
| @@ -58,7 +58,7 @@ | @@ -58,7 +58,7 @@ | ||
| 58 | 58 | ||
| 59 | G_DEFINE_TYPE(Lib3270ToggleAction, Lib3270ToggleAction, PW3270_TYPE_ACTION); | 59 | G_DEFINE_TYPE(Lib3270ToggleAction, Lib3270ToggleAction, PW3270_TYPE_ACTION); |
| 60 | 60 | ||
| 61 | - static void change_state(H3270 *hSession, LIB3270_TOGGLE_ID id, char state, void * action) { | 61 | + static void change_state(H3270 G_GNUC_UNUSED(*hSession), LIB3270_TOGGLE_ID id, char state, void * action) { |
| 62 | debug("%s: %s",__FUNCTION__,state ? "ON" : "OFF"); | 62 | debug("%s: %s",__FUNCTION__,state ? "ON" : "OFF"); |
| 63 | pw3270_action_change_state_boolean((GAction *) action, state == 0 ? FALSE : TRUE); | 63 | pw3270_action_change_state_boolean((GAction *) action, state == 0 ? FALSE : TRUE); |
| 64 | } | 64 | } |
src/objects/actions/private.h
| @@ -79,6 +79,25 @@ | @@ -79,6 +79,25 @@ | ||
| 79 | 79 | ||
| 80 | }; | 80 | }; |
| 81 | 81 | ||
| 82 | + typedef struct _SimpleActionClass { | ||
| 83 | + pw3270ActionClass parent_class; | ||
| 84 | + | ||
| 85 | + } SimpleActionClass; | ||
| 86 | + | ||
| 87 | + typedef struct _SimpleAction { | ||
| 88 | + | ||
| 89 | + pw3270Action parent; | ||
| 90 | + | ||
| 91 | + LIB3270_ACTION_GROUP group; ///< @brief LIB3270 Group id. | ||
| 92 | + const void * listener; ///< @brief Event listener. | ||
| 93 | + const gchar * icon_name; ///< @brief The action icon name. | ||
| 94 | + const gchar * label; ///< @brief The action label. | ||
| 95 | + const gchar * tooltip; ///< @brief The action tooltip. | ||
| 96 | + | ||
| 97 | + void (*activate)(GtkWidget *terminal); | ||
| 98 | + | ||
| 99 | + } SimpleAction; | ||
| 100 | + | ||
| 82 | G_GNUC_INTERNAL GAction * pw3270_action_new_from_lib3270(const LIB3270_ACTION * definition); | 101 | G_GNUC_INTERNAL GAction * pw3270_action_new_from_lib3270(const LIB3270_ACTION * definition); |
| 83 | G_GNUC_INTERNAL GAction * pw3270_toggle_action_new_from_lib3270(const LIB3270_TOGGLE * definition); | 102 | G_GNUC_INTERNAL GAction * pw3270_toggle_action_new_from_lib3270(const LIB3270_TOGGLE * definition); |
| 84 | G_GNUC_INTERNAL GAction * pw3270_action_new_pfkey(void); | 103 | G_GNUC_INTERNAL GAction * pw3270_action_new_pfkey(void); |
| @@ -87,5 +106,10 @@ | @@ -87,5 +106,10 @@ | ||
| 87 | G_GNUC_INTERNAL void pw3270_action_change_state_boolean(GAction *action, gboolean state); | 106 | G_GNUC_INTERNAL void pw3270_action_change_state_boolean(GAction *action, gboolean state); |
| 88 | G_GNUC_INTERNAL void pw3270_action_notify_enabled(GAction *action); | 107 | G_GNUC_INTERNAL void pw3270_action_notify_enabled(GAction *action); |
| 89 | 108 | ||
| 109 | + // Internal actions | ||
| 110 | + G_GNUC_INTERNAL SimpleAction * pw3270_simple_action_new(); | ||
| 111 | + G_GNUC_INTERNAL SimpleAction * pw3270_simple_action_from_name(const gchar *name); | ||
| 112 | + | ||
| 113 | + G_GNUC_INTERNAL GAction * pw3270_connect_action_new(void); | ||
| 90 | 114 | ||
| 91 | #endif // PRIVATE_H_INCLUDED | 115 | #endif // PRIVATE_H_INCLUDED |
| @@ -0,0 +1,157 @@ | @@ -0,0 +1,157 @@ | ||
| 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 | + /** | ||
| 31 | + * @brief Implement PW3270 "simple" action. | ||
| 32 | + * | ||
| 33 | + */ | ||
| 34 | + | ||
| 35 | + #include "private.h" | ||
| 36 | + #include <v3270.h> | ||
| 37 | + | ||
| 38 | + #define PW3270_TYPE_SIMPLE_ACTION (SimpleAction_get_type()) | ||
| 39 | + #define PW3270_SIMPLE_ACTION(inst) (G_TYPE_CHECK_INSTANCE_CAST ((inst), PW3270_TYPE_SIMPLE_ACTION, SimpleAction)) | ||
| 40 | + #define PW3270_IS_SIMPLE_ACTION(inst) (G_TYPE_CHECK_INSTANCE_TYPE ((inst), PW3270_TYPE_SIMPLE_ACTION)) | ||
| 41 | + | ||
| 42 | + static void SimpleAction_class_init(SimpleActionClass *klass); | ||
| 43 | + static void SimpleAction_init(SimpleAction *action); | ||
| 44 | + static void change_widget(GAction *object, GtkWidget *from, GtkWidget *to); | ||
| 45 | + static void change_widget(GAction *object, GtkWidget *from, GtkWidget *to); | ||
| 46 | + | ||
| 47 | + G_DEFINE_TYPE(SimpleAction, SimpleAction, PW3270_TYPE_ACTION); | ||
| 48 | + | ||
| 49 | + static void activate(GAction *action, GVariant G_GNUC_UNUSED(*parameter), GtkWidget *terminal) { | ||
| 50 | + PW3270_SIMPLE_ACTION(action)->activate(terminal); | ||
| 51 | + } | ||
| 52 | + | ||
| 53 | + static const gchar * get_icon_name(GAction *action) { | ||
| 54 | + return PW3270_SIMPLE_ACTION(action)->icon_name; | ||
| 55 | + } | ||
| 56 | + | ||
| 57 | + static const gchar * get_label(GAction *action) { | ||
| 58 | + const gchar * text = PW3270_SIMPLE_ACTION(action)->label; | ||
| 59 | + if(text) | ||
| 60 | + return gettext(text); | ||
| 61 | + return NULL; | ||
| 62 | + } | ||
| 63 | + | ||
| 64 | + static const gchar * get_tooltip(GAction *action) { | ||
| 65 | + const gchar * text = PW3270_SIMPLE_ACTION(action)->tooltip; | ||
| 66 | + if(text) | ||
| 67 | + return gettext(text); | ||
| 68 | + return NULL; | ||
| 69 | + } | ||
| 70 | + | ||
| 71 | + static void dispose(GObject *object) { | ||
| 72 | + | ||
| 73 | + SimpleAction *action = PW3270_SIMPLE_ACTION(object); | ||
| 74 | + | ||
| 75 | + if(action->listener) { | ||
| 76 | + lib3270_unregister_action_group_listener(pw3270_action_get_session(G_ACTION(object)),action->group,action->listener); | ||
| 77 | + action->listener = NULL; | ||
| 78 | + } | ||
| 79 | + | ||
| 80 | + G_OBJECT_CLASS(SimpleAction_parent_class)->dispose(object); | ||
| 81 | + } | ||
| 82 | + | ||
| 83 | + void SimpleAction_class_init(SimpleActionClass *klass) { | ||
| 84 | + | ||
| 85 | + pw3270ActionClass * action = PW3270_ACTION_CLASS(klass); | ||
| 86 | + | ||
| 87 | + action->change_widget = change_widget; | ||
| 88 | + action->get_icon_name = get_icon_name; | ||
| 89 | + action->get_label = get_label; | ||
| 90 | + action->get_tooltip = get_tooltip; | ||
| 91 | + action->activate = activate; | ||
| 92 | + | ||
| 93 | + G_OBJECT_CLASS(klass)->dispose = dispose; | ||
| 94 | + | ||
| 95 | + } | ||
| 96 | + | ||
| 97 | + static void _activate(GtkWidget G_GNUC_UNUSED(*terminal)) { | ||
| 98 | + } | ||
| 99 | + | ||
| 100 | + void SimpleAction_init(SimpleAction *action) { | ||
| 101 | + action->group = LIB3270_ACTION_GROUP_NONE; | ||
| 102 | + action->activate = _activate; | ||
| 103 | + } | ||
| 104 | + | ||
| 105 | + static void event_listener(H3270 G_GNUC_UNUSED(*hSession), void *object) { | ||
| 106 | + pw3270_action_notify_enabled(G_ACTION(object)); | ||
| 107 | + } | ||
| 108 | + | ||
| 109 | + void change_widget(GAction *object, GtkWidget *from, GtkWidget *to) { | ||
| 110 | + | ||
| 111 | + // Remove old listener | ||
| 112 | + SimpleAction * action = PW3270_SIMPLE_ACTION(object); | ||
| 113 | + | ||
| 114 | + if(action->listener) { | ||
| 115 | + lib3270_unregister_action_group_listener(pw3270_action_get_session(object),action->group,action->listener); | ||
| 116 | + action->listener = NULL; | ||
| 117 | + } | ||
| 118 | + | ||
| 119 | + // Change widget | ||
| 120 | + PW3270_ACTION_CLASS(SimpleAction_parent_class)->change_widget(object,from,to); | ||
| 121 | + | ||
| 122 | + // Setup new listener | ||
| 123 | + if(action->group && to) { | ||
| 124 | + action->listener = lib3270_register_action_group_listener(pw3270_action_get_session(object),action->group,event_listener,object); | ||
| 125 | + } | ||
| 126 | + | ||
| 127 | + // Does the "enabled" state has changed? If yes notify customers. | ||
| 128 | + gboolean enabled = PW3270_ACTION_CLASS(SimpleAction_parent_class)->get_enabled(object,to); | ||
| 129 | + if(PW3270_ACTION_CLASS(SimpleAction_parent_class)->get_enabled(object,from) != enabled) | ||
| 130 | + pw3270_action_notify_enabled(object); | ||
| 131 | + | ||
| 132 | + } | ||
| 133 | + | ||
| 134 | + SimpleAction * pw3270_simple_action_new() { | ||
| 135 | + return PW3270_SIMPLE_ACTION(g_object_new(PW3270_TYPE_SIMPLE_ACTION, NULL)); | ||
| 136 | + } | ||
| 137 | + | ||
| 138 | + SimpleAction * pw3270_simple_action_from_name(const gchar *name) { | ||
| 139 | + | ||
| 140 | + SimpleAction * action = pw3270_simple_action_new(); | ||
| 141 | + | ||
| 142 | + const LIB3270_ACTION * description = lib3270_action_get_by_name(name); | ||
| 143 | + | ||
| 144 | + if(description) { | ||
| 145 | + action->group = description->group; | ||
| 146 | + action->icon_name = description->icon; | ||
| 147 | + action->label = description->label; | ||
| 148 | + action->tooltip = description->summary; | ||
| 149 | + } else { | ||
| 150 | + action->group = LIB3270_ACTION_GROUP_NONE; | ||
| 151 | + action->label = N_("Invalid action"); | ||
| 152 | + action->tooltip = N_("This action is not valid"); | ||
| 153 | + } | ||
| 154 | + | ||
| 155 | + | ||
| 156 | + return action; | ||
| 157 | + } |