Commit ba467025363a5c749beb307fc5d1beb564dc9dd3
1 parent
c6d5dc0d
Exists in
master
and in
4 other branches
Implementing action object.
Showing
7 changed files
with
253 additions
and
39 deletions
Show diff stats
src/actions/abstract.c
@@ -34,11 +34,15 @@ | @@ -34,11 +34,15 @@ | ||
34 | static void pw3270Action_init(pw3270Action *action); | 34 | static void pw3270Action_init(pw3270Action *action); |
35 | static void pw3270_action_get_property(GObject *object, guint prop_id, GValue *value, GParamSpec *pspec); | 35 | static void pw3270_action_get_property(GObject *object, guint prop_id, GValue *value, GParamSpec *pspec); |
36 | static void pw3270_action_set_property(GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec); | 36 | static void pw3270_action_set_property(GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec); |
37 | + static void pw3270_action_set_state(GAction *action, GVariant *value); | ||
38 | + | ||
39 | + static void finalize(GObject *object); | ||
37 | 40 | ||
38 | static const GVariantType * pw3270_action_get_state_type(GAction *action); | 41 | static const GVariantType * pw3270_action_get_state_type(GAction *action); |
39 | static GVariant * pw3270_action_get_state_property(GAction *action); | 42 | static GVariant * pw3270_action_get_state_property(GAction *action); |
40 | - static GVariantType * pw3270_action_get_parameter_type(GAction *action); | ||
41 | - | 43 | + static const GVariantType * pw3270_action_get_parameter_type(GAction *action); |
44 | + static GVariant * pw3270_action_get_state_hint(GAction *action); | ||
45 | + static void pw3270_action_change_state(GAction *action, GVariant *value); | ||
42 | 46 | ||
43 | enum { | 47 | enum { |
44 | PROP_NONE, | 48 | PROP_NONE, |
@@ -53,12 +57,12 @@ | @@ -53,12 +57,12 @@ | ||
53 | 57 | ||
54 | void pw3270_action_iface_init(GActionInterface *iface) { | 58 | void pw3270_action_iface_init(GActionInterface *iface) { |
55 | iface->get_name = pw3270_action_get_name; | 59 | iface->get_name = pw3270_action_get_name; |
56 | -// iface->get_parameter_type = pw3270_action_get_parameter_type; | 60 | + iface->get_parameter_type = pw3270_action_get_parameter_type; |
57 | iface->get_state_type = pw3270_action_get_state_type; | 61 | iface->get_state_type = pw3270_action_get_state_type; |
58 | -// iface->get_state_hint = pw3270_action_get_state_hint; | 62 | + iface->get_state_hint = pw3270_action_get_state_hint; |
59 | iface->get_enabled = pw3270_action_get_enabled; | 63 | iface->get_enabled = pw3270_action_get_enabled; |
60 | iface->get_state = pw3270_action_get_state_property; | 64 | iface->get_state = pw3270_action_get_state_property; |
61 | -// iface->change_state = pw3270_action_change_state; | 65 | + iface->change_state = pw3270_action_change_state; |
62 | iface->activate = pw3270_action_activate; | 66 | iface->activate = pw3270_action_activate; |
63 | } | 67 | } |
64 | 68 | ||
@@ -70,8 +74,9 @@ | @@ -70,8 +74,9 @@ | ||
70 | 74 | ||
71 | GObjectClass *object_class = G_OBJECT_CLASS(klass); | 75 | GObjectClass *object_class = G_OBJECT_CLASS(klass); |
72 | 76 | ||
73 | - object_class->set_property = pw3270_action_set_property; | ||
74 | - object_class->get_property = pw3270_action_get_property; | 77 | + object_class->finalize = finalize; |
78 | + object_class->set_property = pw3270_action_set_property; | ||
79 | + object_class->get_property = pw3270_action_get_property; | ||
75 | 80 | ||
76 | klass->get_enabled = return_false; | 81 | klass->get_enabled = return_false; |
77 | 82 | ||
@@ -124,15 +129,38 @@ | @@ -124,15 +129,38 @@ | ||
124 | 129 | ||
125 | void pw3270Action_init(pw3270Action *action) { | 130 | void pw3270Action_init(pw3270Action *action) { |
126 | 131 | ||
127 | - action->name = "unnamed"; | 132 | + action->name = NULL; |
128 | action->window = NULL; | 133 | action->window = NULL; |
134 | + action->state = NULL; | ||
135 | + | ||
136 | + } | ||
137 | + | ||
138 | + void finalize(GObject *object) { | ||
139 | + | ||
140 | + pw3270Action * action = PW3270_ACTION(object); | ||
141 | + | ||
142 | + if(action->name) { | ||
143 | + | ||
144 | + debug("Finalizing action \"%s\"",action->name); | ||
145 | + g_free(action->name); | ||
146 | + action->name = NULL; | ||
147 | + | ||
148 | + } | ||
149 | + | ||
150 | + if(action->parameter_type) | ||
151 | + g_variant_type_free(action->parameter_type); | ||
152 | + | ||
153 | + G_OBJECT_CLASS(pw3270Action_parent_class)->finalize(object); | ||
129 | 154 | ||
130 | } | 155 | } |
131 | 156 | ||
157 | + | ||
132 | void pw3270_action_get_property(GObject *object, guint prop_id, GValue *value, GParamSpec *pspec) { | 158 | void pw3270_action_get_property(GObject *object, guint prop_id, GValue *value, GParamSpec *pspec) { |
133 | 159 | ||
134 | GAction *action = G_ACTION(object); | 160 | GAction *action = G_ACTION(object); |
135 | 161 | ||
162 | + debug("%s(%d)",__FUNCTION__,prop_id); | ||
163 | + | ||
136 | switch (prop_id) { | 164 | switch (prop_id) { |
137 | case PROP_NAME: | 165 | case PROP_NAME: |
138 | g_value_set_string(value, pw3270_action_get_name(action)); | 166 | g_value_set_string(value, pw3270_action_get_name(action)); |
@@ -161,22 +189,57 @@ | @@ -161,22 +189,57 @@ | ||
161 | } | 189 | } |
162 | 190 | ||
163 | void pw3270_action_set_property(GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec) { | 191 | void pw3270_action_set_property(GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec) { |
192 | + | ||
193 | + debug("%s(%d)",__FUNCTION__,prop_id); | ||
194 | + | ||
195 | + GAction *action = G_ACTION(object); | ||
196 | + | ||
197 | + switch (prop_id) | ||
198 | + { | ||
199 | + case PROP_NAME: | ||
200 | + pw3270_action_set_name(action, g_value_get_string(value)); | ||
201 | + break; | ||
202 | + | ||
203 | + case PROP_PARAMETER_TYPE: | ||
204 | +// action->parameter_type = g_value_dup_boxed (value); | ||
205 | + break; | ||
206 | + | ||
207 | + case PROP_ENABLED: | ||
208 | +// action->enabled = g_value_get_boolean (value); | ||
209 | + break; | ||
210 | + | ||
211 | + case PROP_STATE: | ||
212 | + pw3270_action_set_state(action, g_value_get_variant(value)); | ||
213 | + break; | ||
214 | + | ||
215 | + default: | ||
216 | + g_assert_not_reached (); | ||
217 | + } | ||
218 | + | ||
164 | } | 219 | } |
165 | 220 | ||
166 | const gchar * pw3270_action_get_name(GAction *action) { | 221 | const gchar * pw3270_action_get_name(GAction *action) { |
167 | return PW3270_ACTION(action)->name; | 222 | return PW3270_ACTION(action)->name; |
168 | } | 223 | } |
169 | 224 | ||
170 | - const GVariantType * pw3270_action_get_state_type(GAction *action) { | ||
171 | - return NULL; | ||
172 | - } | 225 | + void pw3270_action_set_name(GAction *object, const gchar *name) { |
226 | + | ||
227 | + pw3270Action * action = PW3270_ACTION(object); | ||
228 | + | ||
229 | + debug("%s %s -> %s", __FUNCTION__, action->name, name); | ||
230 | + | ||
231 | + if(action->name) | ||
232 | + g_free(action->name); | ||
233 | + | ||
234 | + if(name) | ||
235 | + action->name = g_strdup(name); | ||
236 | + else | ||
237 | + action->name = NULL; | ||
173 | 238 | ||
174 | - GVariant * pw3270_action_get_state_property(GAction *action) { | ||
175 | - return g_variant_new_int16(0); | ||
176 | } | 239 | } |
177 | 240 | ||
178 | - GVariantType * pw3270_action_get_parameter_type(GAction *action) { | ||
179 | - return NULL; | 241 | + GVariant * pw3270_action_get_state_property(GAction *action) { |
242 | + return PW3270_ACTION(action)->state; | ||
180 | } | 243 | } |
181 | 244 | ||
182 | gboolean pw3270_action_get_enabled(GAction *action) { | 245 | gboolean pw3270_action_get_enabled(GAction *action) { |
@@ -195,3 +258,33 @@ | @@ -195,3 +258,33 @@ | ||
195 | PW3270_ACTION_GET_CLASS(action)->activate(action,window); | 258 | PW3270_ACTION_GET_CLASS(action)->activate(action,window); |
196 | 259 | ||
197 | } | 260 | } |
261 | + | ||
262 | + const GVariantType * pw3270_action_get_parameter_type(GAction *action) { | ||
263 | + debug("%s",__FUNCTION__); | ||
264 | + return NULL; | ||
265 | + } | ||
266 | + | ||
267 | + const GVariantType * pw3270_action_get_state_type(GAction *object) { | ||
268 | + | ||
269 | + pw3270Action * action = PW3270_ACTION(object); | ||
270 | + | ||
271 | + if(action->state != NULL) | ||
272 | + return g_variant_get_type(action->state); | ||
273 | + else | ||
274 | + return NULL; | ||
275 | + | ||
276 | + } | ||
277 | + | ||
278 | + GVariant * pw3270_action_get_state_hint(GAction *action) { | ||
279 | + debug("%s",__FUNCTION__); | ||
280 | + return NULL; | ||
281 | + } | ||
282 | + | ||
283 | + void pw3270_action_change_state(GAction *action, GVariant *value) { | ||
284 | + debug("%s",__FUNCTION__); | ||
285 | + pw3270_action_set_state (action, value); | ||
286 | + } | ||
287 | + | ||
288 | + void pw3270_action_set_state(GAction *action, GVariant *value) { | ||
289 | + debug("%s",__FUNCTION__); | ||
290 | + } |
src/actions/actions.cbp
@@ -50,6 +50,9 @@ | @@ -50,6 +50,9 @@ | ||
50 | <Unit filename="testprogram/testprogram.c"> | 50 | <Unit filename="testprogram/testprogram.c"> |
51 | <Option compilerVar="CC" /> | 51 | <Option compilerVar="CC" /> |
52 | </Unit> | 52 | </Unit> |
53 | + <Unit filename="window.c"> | ||
54 | + <Option compilerVar="CC" /> | ||
55 | + </Unit> | ||
53 | <Extensions> | 56 | <Extensions> |
54 | <code_completion /> | 57 | <code_completion /> |
55 | <envvars /> | 58 | <envvars /> |
src/actions/lib3270.c
@@ -47,15 +47,13 @@ | @@ -47,15 +47,13 @@ | ||
47 | typedef struct _Lib3270Action { | 47 | typedef struct _Lib3270Action { |
48 | pw3270Action parent; | 48 | pw3270Action parent; |
49 | 49 | ||
50 | - const LIB3270_ACTION * definition; | ||
51 | - | 50 | + const LIB3270_ACTION * definition; |
52 | 51 | ||
53 | } Lib3270Action; | 52 | } Lib3270Action; |
54 | 53 | ||
55 | static void Lib3270Action_class_init(Lib3270ActionClass *klass); | 54 | static void Lib3270Action_class_init(Lib3270ActionClass *klass); |
56 | static void Lib3270Action_init(Lib3270Action *action); | 55 | static void Lib3270Action_init(Lib3270Action *action); |
57 | 56 | ||
58 | - | ||
59 | G_DEFINE_TYPE(Lib3270Action, Lib3270Action, PW3270_TYPE_ACTION); | 57 | G_DEFINE_TYPE(Lib3270Action, Lib3270Action, PW3270_TYPE_ACTION); |
60 | 58 | ||
61 | static gboolean action_enabled(GAction *action, GtkWidget *window) { | 59 | static gboolean action_enabled(GAction *action, GtkWidget *window) { |
@@ -84,23 +82,23 @@ | @@ -84,23 +82,23 @@ | ||
84 | action->get_enabled = action_enabled; | 82 | action->get_enabled = action_enabled; |
85 | action->activate = action_activate; | 83 | action->activate = action_activate; |
86 | 84 | ||
87 | - | ||
88 | } | 85 | } |
89 | 86 | ||
90 | void Lib3270Action_init(Lib3270Action *action) { | 87 | void Lib3270Action_init(Lib3270Action *action) { |
91 | } | 88 | } |
92 | 89 | ||
93 | - GAction * pw3270_action_get_from_lib3270(const LIB3270_ACTION * definition) { | 90 | + GAction * pw3270_action_new_from_lib3270(const LIB3270_ACTION * definition, GtkWidget *window) { |
94 | 91 | ||
95 | - Lib3270Action * action = (Lib3270Action *) g_object_new(PW3270_TYPE_LIB3270_ACTION, NULL); | ||
96 | - action->definition = definition; | 92 | + Lib3270Action * action = (Lib3270Action *) g_object_new(PW3270_TYPE_LIB3270_ACTION, NULL); |
93 | + pw3270Action * abstract = PW3270_ACTION(action); | ||
97 | 94 | ||
98 | - { | ||
99 | - pw3270Action * abstract = PW3270_ACTION(action); | 95 | + action->definition = definition; |
96 | + abstract->window = window; | ||
100 | 97 | ||
101 | - abstract->name = definition->name; | 98 | + if(abstract->name) |
99 | + g_free(abstract->name); | ||
102 | 100 | ||
103 | - } | 101 | + abstract->name = g_strconcat("win.",definition->name,NULL); |
104 | 102 | ||
105 | return G_ACTION(action); | 103 | return G_ACTION(action); |
106 | } | 104 | } |
src/actions/private.h
@@ -47,8 +47,10 @@ | @@ -47,8 +47,10 @@ | ||
47 | struct _pw3270Action { | 47 | struct _pw3270Action { |
48 | GObject parent; | 48 | GObject parent; |
49 | 49 | ||
50 | - GtkWidget * window; | ||
51 | - const gchar * name; | 50 | + GVariantType * parameter_type; |
51 | + GVariant * state; | ||
52 | + GtkWidget * window; | ||
53 | + gchar * name; | ||
52 | 54 | ||
53 | }; | 55 | }; |
54 | 56 |
src/actions/testprogram/testprogram.c
@@ -29,10 +29,10 @@ | @@ -29,10 +29,10 @@ | ||
29 | */ | 29 | */ |
30 | 30 | ||
31 | #include <config.h> | 31 | #include <config.h> |
32 | - #include <pw3270/actions.h> | ||
33 | - #include <pw3270/window.h> | ||
34 | - #include <lib3270.h> | 32 | + #include <v3270.h> |
33 | + #include <v3270/trace.h> | ||
35 | #include <lib3270/log.h> | 34 | #include <lib3270/log.h> |
35 | + #include <pw3270/actions.h> | ||
36 | 36 | ||
37 | /*---[ Implement ]----------------------------------------------------------------------------------*/ | 37 | /*---[ Implement ]----------------------------------------------------------------------------------*/ |
38 | 38 | ||
@@ -44,17 +44,60 @@ | @@ -44,17 +44,60 @@ | ||
44 | return NULL; | 44 | return NULL; |
45 | } | 45 | } |
46 | 46 | ||
47 | - int main (int argc, char **argv) { | 47 | + static void activate(GtkApplication* app, G_GNUC_UNUSED gpointer user_data) { |
48 | 48 | ||
49 | - GAction * action = pw3270_action_get_from_lib3270(lib3270_action_get_by_name("testpattern")); | 49 | + GtkWidget * window = gtk_application_window_new(app); |
50 | + GtkWidget * terminal = v3270_new(); | ||
51 | + GtkWidget * vBox = gtk_box_new(GTK_ORIENTATION_VERTICAL,2); | ||
52 | + GtkWidget * notebook = gtk_notebook_new(); | ||
53 | + GtkWidget * toolbar = gtk_toolbar_new(); | ||
50 | 54 | ||
51 | - g_message("Action name is \"%s\"",g_action_get_name(action)); | ||
52 | - g_message("Action is %s",g_action_get_enabled(action) ? "enabled" : "disabled"); | 55 | + pw3270_window_add_actions(window); |
53 | 56 | ||
54 | - g_object_unref(action); | ||
55 | - return 0; | 57 | + gtk_box_pack_start(GTK_BOX(vBox),toolbar,FALSE,TRUE,0); |
58 | + gtk_box_pack_start(GTK_BOX(vBox),notebook,TRUE,TRUE,0); | ||
56 | 59 | ||
57 | - } | 60 | + // Create Terminal window |
61 | + { | ||
62 | + gtk_widget_set_can_default(terminal,TRUE); | ||
63 | + | ||
64 | + gtk_notebook_append_page(GTK_NOTEBOOK(notebook),terminal,gtk_label_new("Terminal")); | ||
65 | + | ||
66 | +#ifdef _WIN32 | ||
67 | + v3270_set_font_family(terminal,"Droid Sans Mono"); | ||
68 | +#endif // _WIN32 | ||
69 | + | ||
70 | + } | ||
71 | + | ||
72 | + // Create trace window | ||
73 | + gtk_notebook_append_page(GTK_NOTEBOOK(notebook),v3270_trace_new(terminal),gtk_label_new("Trace")); | ||
74 | + | ||
75 | + // Setup and show main window | ||
76 | + gtk_window_set_position(GTK_WINDOW(window),GTK_WIN_POS_CENTER); | ||
77 | + gtk_window_set_default_size (GTK_WINDOW (window), 800, 500); | ||
78 | + gtk_container_add(GTK_CONTAINER(window),vBox); | ||
79 | + gtk_widget_show_all(window); | ||
80 | + | ||
81 | + gtk_widget_grab_focus(terminal); | ||
82 | + | ||
83 | +} | ||
84 | + | ||
85 | +int main (int argc, char **argv) { | ||
86 | + | ||
87 | + GtkApplication *app; | ||
88 | + int status; | ||
89 | + | ||
90 | + app = gtk_application_new ("br.com.bb.pw3270",G_APPLICATION_FLAGS_NONE); | ||
91 | + | ||
92 | + g_signal_connect (app, "activate", G_CALLBACK(activate), NULL); | ||
93 | + | ||
94 | + status = g_application_run (G_APPLICATION (app), argc, argv); | ||
95 | + g_object_unref (app); | ||
96 | + | ||
97 | + g_message("rc=%d",status); | ||
98 | + | ||
99 | + return 0; | ||
58 | 100 | ||
101 | +} | ||
59 | 102 | ||
60 | 103 |
@@ -0,0 +1,69 @@ | @@ -0,0 +1,69 @@ | ||
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 Integrate pw3270 actions with the application window. | ||
32 | + * | ||
33 | + */ | ||
34 | + | ||
35 | + #include "private.h" | ||
36 | + #include <lib3270/actions.h> | ||
37 | + | ||
38 | + void pw3270_window_add_actions(GtkWidget * appwindow) { | ||
39 | + | ||
40 | + GActionMap *map = G_ACTION_MAP(appwindow); | ||
41 | + | ||
42 | + // g_action_map_add_action(map,pw3270_action_new_from_lib3270(lib3270_action_get_by_name("testpattern"), appwindow)); | ||
43 | + | ||
44 | + GAction *action = pw3270_action_new_from_lib3270(lib3270_action_get_by_name("testpattern"), appwindow); | ||
45 | + | ||
46 | + debug("--> \"%s\"",pw3270_action_get_name(action)); | ||
47 | + | ||
48 | + g_action_map_add_action(map,action); | ||
49 | + | ||
50 | + debug("--> \"%s\"",pw3270_action_get_name(action)); | ||
51 | + | ||
52 | + /* | ||
53 | + size_t ix; | ||
54 | + | ||
55 | + // Map lib3270 actions | ||
56 | + const LIB3270_ACTION * actions = lib3270_get_actions(); | ||
57 | + | ||
58 | + for(ix = 0; actions[ix].name; ix++) { | ||
59 | + | ||
60 | + // g_autofree gchar * name = g_strconcat("win.", actions[ix].name, NULL); | ||
61 | + debug("Creating action %s", actions[ix].name); | ||
62 | + g_action_map_add_action(map,pw3270_action_new_from_lib3270(&actions[ix],appwindow)); | ||
63 | + | ||
64 | + } | ||
65 | + */ | ||
66 | + | ||
67 | + | ||
68 | + debug("%s ends",__FUNCTION__); | ||
69 | + } |
src/include/pw3270/actions.h
@@ -54,11 +54,17 @@ | @@ -54,11 +54,17 @@ | ||
54 | 54 | ||
55 | GType pw3270Action_get_type(void) G_GNUC_CONST; | 55 | GType pw3270Action_get_type(void) G_GNUC_CONST; |
56 | 56 | ||
57 | - GAction * pw3270_action_get_from_lib3270(const LIB3270_ACTION * definition); | 57 | + GAction * pw3270_action_new_from_lib3270(const LIB3270_ACTION * definition, GtkWidget *window); |
58 | + | ||
58 | const gchar * pw3270_action_get_name(GAction *action); | 59 | const gchar * pw3270_action_get_name(GAction *action); |
60 | + void pw3270_action_set_name(GAction *action, const gchar *name); | ||
61 | + | ||
59 | gboolean pw3270_action_get_enabled(GAction *action); | 62 | gboolean pw3270_action_get_enabled(GAction *action); |
60 | void pw3270_action_activate(GAction *action, GVariant *parameter); | 63 | void pw3270_action_activate(GAction *action, GVariant *parameter); |
61 | 64 | ||
65 | + /// @brief Add lib3270 actions to an application window. | ||
66 | + void pw3270_window_add_actions(GtkWidget * appwindow); | ||
67 | + | ||
62 | G_END_DECLS | 68 | G_END_DECLS |
63 | 69 | ||
64 | #endif // PW3270_ACTIONS_H_INCLUDED | 70 | #endif // PW3270_ACTIONS_H_INCLUDED |