Commit 79a7ba3568d51ce211bdb79b6414dfb38551302b

Authored by Perry Werneck
1 parent 91258993

Implementing the "connect" action.

pw3270.cbp
... ... @@ -73,7 +73,7 @@
73 73 <Option compilerVar="CC" />
74 74 </Unit>
75 75 <Unit filename="src/objects/actions/private.h" />
76   - <Unit filename="src/objects/actions/simple.c">
  76 + <Unit filename="src/objects/actions/window.c">
77 77 <Option compilerVar="CC" />
78 78 </Unit>
79 79 <Unit filename="src/objects/toolbar/actions.c">
... ...
src/include/pw3270.h
... ... @@ -46,9 +46,12 @@
46 46 #include <glib/gi18n.h>
47 47 #include <gtk/gtk.h>
48 48  
  49 + G_BEGIN_DECLS
  50 +
49 51 /* not really I18N-related, but also a string marker macro */
50 52 #define I_(string) g_intern_static_string (string)
51 53  
52   - G_GNUC_INTERNAL GSettings * pw3270_get_settings(void);
  54 +
  55 + G_END_DECLS
53 56  
54 57 #endif // PW3270_H_INCLUDED
... ...
src/include/pw3270/application.h
... ... @@ -64,6 +64,8 @@
64 64 GType pw3270Application_get_type();
65 65 GtkApplication * pw3270_application_new(const gchar *application_id, GApplicationFlags flags);
66 66  
  67 + GSettings * pw3270_application_get_settings(GApplication *app);
  68 +
67 69 void pw3270_application_set_ui_style(GApplication *app, PW3270_UI_STYLE type);
68 70 PW3270_UI_STYLE pw3270_application_get_ui_style(GApplication *app);
69 71  
... ...
src/main/tools.c
... ... @@ -34,40 +34,7 @@
34 34 */
35 35  
36 36 #include "private.h"
  37 + #include <pw3270/application.h>
37 38  
38 39 /*---[ Implement ]----------------------------------------------------------------------------------*/
39 40  
40   - GSettings * pw3270_get_settings() {
41   -
42   -#ifdef DEBUG
43   - GError * error = NULL;
44   - GSettingsSchemaSource * source =
45   - g_settings_schema_source_new_from_directory(
46   - ".",
47   - NULL,
48   - TRUE,
49   - &error
50   - );
51   -
52   - g_assert_no_error(error);
53   -
54   - GSettingsSchema * schema =
55   - g_settings_schema_source_lookup(
56   - source,
57   - "br.com.bb." PACKAGE_NAME,
58   - TRUE);
59   -
60   - g_settings_schema_source_unref(source);
61   -
62   - g_autofree gchar * path = g_strconcat("/apps/" PACKAGE_NAME "/", g_get_application_name(),"/",NULL);
63   -
64   - debug("path=%s",path);
65   - return g_settings_new_full(schema, NULL, path);
66   -
67   -#else
68   -
69   - #error TODO!
70   -
71   -#endif // DEBUG
72   -
73   - }
... ...
src/objects/actions/abstract.c
... ... @@ -94,7 +94,6 @@
94 94  
95 95 klass->change_widget = change_widget;
96 96 klass->get_enabled = get_enabled;
97   - klass->activate = activate;
98 97 klass->get_parameter_type = get_parameter_type;
99 98 klass->get_icon_name = get_null;
100 99 klass->get_label = get_null;
... ... @@ -175,6 +174,7 @@
175 174 action->name = NULL;
176 175 action->terminal = NULL;
177 176 action->state = NULL;
  177 + action->activate = activate;
178 178  
179 179 }
180 180  
... ... @@ -399,7 +399,7 @@
399 399 debug("%s: terminal=%p",__FUNCTION__,action->terminal);
400 400  
401 401 if(action && action->terminal) {
402   - PW3270_ACTION_GET_CLASS(object)->activate(object,parameter,action->terminal);
  402 + action->activate(object,parameter,action->terminal);
403 403 }
404 404  
405 405 }
... ...
src/objects/actions/connect.c
... ... @@ -34,15 +34,20 @@
34 34  
35 35 #include "private.h"
36 36  
  37 + static void activate(GAction G_GNUC_UNUSED(*action), GVariant G_GNUC_UNUSED(*parameter), GtkWidget *terminal) {
37 38  
38   - static void activate(GtkWidget *terminal) {
39   -
40   - debug("%s: Connect", __FUNCTION__);
  39 + debug("%s",__FUNCTION__);
  40 + gtk_widget_activate(terminal);
41 41  
42 42 }
43 43  
44 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);
  45 +
  46 + GAction * action = pw3270_action_new_from_lib3270(lib3270_action_get_by_name("reconnect"));
  47 +
  48 + PW3270_ACTION(action)->activate = activate;
  49 + pw3270_action_set_name(G_ACTION(action),"win.connect");
  50 +
  51 + return action;
  52 +
48 53 }
... ...
src/objects/actions/lib3270/action.c
... ... @@ -99,7 +99,6 @@
99 99  
100 100 pw3270ActionClass * action = PW3270_ACTION_CLASS(klass);
101 101  
102   - action->activate = activate;
103 102 action->get_enabled = get_enabled;
104 103 action->change_widget = change_widget;
105 104 action->get_icon_name = get_icon_name;
... ... @@ -110,7 +109,9 @@
110 109  
111 110 }
112 111  
113   - void Lib3270Action_init(Lib3270Action G_GNUC_UNUSED(*action)) {
  112 + void Lib3270Action_init(Lib3270Action *action) {
  113 + debug("%s",__FUNCTION__);
  114 + PW3270_ACTION(action)->activate = activate;
114 115 }
115 116  
116 117 GAction * pw3270_action_new_from_lib3270(const LIB3270_ACTION * definition) {
... ... @@ -132,8 +133,13 @@
132 133 return G_ACTION(action);
133 134 }
134 135  
  136 + static gboolean bg_notify_enabled(GAction *action) {
  137 + pw3270_action_notify_enabled(action);
  138 + return FALSE;
  139 + }
  140 +
135 141 static void event_listener(H3270 G_GNUC_UNUSED(*hSession), void *object) {
136   - pw3270_action_notify_enabled(G_ACTION(object));
  142 + g_idle_add((GSourceFunc) bg_notify_enabled, G_ACTION(object));
137 143 }
138 144  
139 145 void change_widget(GAction *object, GtkWidget *from, GtkWidget *to) {
... ...
src/objects/actions/lib3270/pakey.c
... ... @@ -103,14 +103,14 @@
103 103  
104 104 pw3270ActionClass * action = PW3270_ACTION_CLASS(klass);
105 105  
106   - action->activate = activate;
107 106 action->get_enabled = get_enabled;
108 107 action->change_widget = change_widget;
109 108 action->get_parameter_type = get_parameter_type;
110 109  
111 110 }
112 111  
113   - void Lib3270PaAction_init(Lib3270PaAction G_GNUC_UNUSED(*action)) {
  112 + void Lib3270PaAction_init(Lib3270PaAction *action) {
  113 + PW3270_ACTION(action)->activate = activate;
114 114 }
115 115  
116 116 GAction * pw3270_action_new_pakey(void) {
... ...
src/objects/actions/lib3270/pfkey.c
... ... @@ -102,14 +102,14 @@
102 102  
103 103 pw3270ActionClass * action = PW3270_ACTION_CLASS(klass);
104 104  
105   - action->activate = activate;
106 105 action->get_enabled = get_enabled;
107 106 action->change_widget = change_widget;
108 107 action->get_parameter_type = get_parameter_type;
109 108  
110 109 }
111 110  
112   - void Lib3270PfAction_init(Lib3270PfAction G_GNUC_UNUSED(*action)) {
  111 + void Lib3270PfAction_init(Lib3270PfAction *action) {
  112 + PW3270_ACTION(action)->activate = activate;
113 113 }
114 114  
115 115 GAction * pw3270_action_new_pfkey(void) {
... ...
src/objects/actions/lib3270/toggle.c
... ... @@ -101,7 +101,6 @@
101 101 void Lib3270ToggleAction_class_init(Lib3270ToggleActionClass *klass) {
102 102  
103 103 pw3270ActionClass * action = PW3270_ACTION_CLASS(klass);
104   - action->activate = activate;
105 104 action->change_widget = change_widget;
106 105  
107 106 }
... ... @@ -111,6 +110,8 @@
111 110 action->definition = NULL;
112 111 action->listener = NULL;
113 112  
  113 + PW3270_ACTION(action)->activate = activate;
  114 +
114 115 }
115 116  
116 117 GAction * pw3270_toggle_action_new_from_lib3270(const LIB3270_TOGGLE * definition) {
... ...
src/objects/actions/private.h
... ... @@ -59,6 +59,8 @@
59 59 GtkWidget * terminal;
60 60 gchar * name;
61 61  
  62 + void (*activate)(GAction *action, GVariant *parameter, GtkWidget *terminal);
  63 +
62 64 };
63 65  
64 66 struct _pw3270ActionClass {
... ... @@ -71,7 +73,6 @@
71 73  
72 74 void (*change_widget)(GAction *action, GtkWidget *from, GtkWidget *to);
73 75 gboolean (*get_enabled)(GAction *action, GtkWidget *terminal);
74   - void (*activate)(GAction *action, GVariant *parameter, GtkWidget *terminal);
75 76 const GVariantType * (*get_parameter_type)(GAction *action);
76 77 const gchar * (*get_icon_name)(GAction *action);
77 78 const gchar * (*get_label)(GAction *action);
... ... @@ -79,25 +80,6 @@
79 80  
80 81 };
81 82  
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   -
101 83 G_GNUC_INTERNAL GAction * pw3270_action_new_from_lib3270(const LIB3270_ACTION * definition);
102 84 G_GNUC_INTERNAL GAction * pw3270_toggle_action_new_from_lib3270(const LIB3270_TOGGLE * definition);
103 85 G_GNUC_INTERNAL GAction * pw3270_action_new_pfkey(void);
... ... @@ -107,9 +89,6 @@
107 89 G_GNUC_INTERNAL void pw3270_action_notify_enabled(GAction *action);
108 90  
109 91 // 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 92 G_GNUC_INTERNAL GAction * pw3270_connect_action_new(void);
114 93  
115 94 #endif // PRIVATE_H_INCLUDED
... ...
src/objects/actions/simple.c
... ... @@ -1,157 +0,0 @@
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   - }
src/objects/actions/window.c
... ... @@ -67,7 +67,8 @@
67 67 {
68 68 GAction * actions[] = {
69 69 pw3270_action_new_pfkey(),
70   - pw3270_action_new_pakey()
  70 + pw3270_action_new_pakey(),
  71 + pw3270_connect_action_new()
71 72 };
72 73  
73 74 for(ix = 0; ix < G_N_ELEMENTS(actions); ix++) {
... ...
src/objects/window/application.c
... ... @@ -50,13 +50,16 @@
50 50 struct _pw3270Application {
51 51 GtkApplication parent;
52 52  
  53 + GSettings * settings;
  54 +
53 55 PW3270_UI_STYLE ui_style;
54 56  
55 57 };
56 58  
57   - static void startup(GApplication * application);
58   - static void activate(GApplication * application);
59   - static void open(GApplication * application, GFile **files, gint n_files, const gchar *hint);
  59 + static void startup(GApplication * application);
  60 + static void activate(GApplication * application);
  61 + static void open(GApplication * application, GFile **files, gint n_files, const gchar *hint);
  62 + static void finalize(GObject *object);
60 63  
61 64 G_DEFINE_TYPE(pw3270Application, pw3270Application, GTK_TYPE_APPLICATION);
62 65  
... ... @@ -93,6 +96,7 @@
93 96  
94 97 object_class->get_property = get_property;
95 98 object_class->set_property = set_property;
  99 + object_class->finalize = finalize;
96 100  
97 101 application_class->startup = startup;
98 102 application_class->activate = activate;
... ... @@ -126,15 +130,63 @@
126 130 app->ui_style = PW3270_UI_STYLE_GNOME;
127 131 #endif // _WIN32
128 132  
129   - // Bind properties
130   - g_autoptr(GSettings) settings = pw3270_get_settings();
  133 + // Get settings
  134 + {
  135 +#ifdef DEBUG
  136 + GError * error = NULL;
  137 + GSettingsSchemaSource * source =
  138 + g_settings_schema_source_new_from_directory(
  139 + ".",
  140 + NULL,
  141 + TRUE,
  142 + &error
  143 + );
  144 +
  145 + g_assert_no_error(error);
  146 +
  147 + GSettingsSchema * schema =
  148 + g_settings_schema_source_lookup(
  149 + source,
  150 + "br.com.bb." PACKAGE_NAME,
  151 + TRUE);
  152 +
  153 + g_settings_schema_source_unref(source);
  154 +
  155 + g_autofree gchar * path = g_strconcat("/apps/" PACKAGE_NAME "/", g_get_application_name(),"/",NULL);
  156 +
  157 + debug("path=%s",path);
  158 + app->settings = g_settings_new_full(schema, NULL, path);
  159 +
  160 +#else
  161 +
  162 + #error TODO!
  163 +
  164 +#endif // DEBUG
  165 +
  166 + }
131 167  
132   - if(settings) {
133   - g_settings_bind(settings, "ui-style", app, "ui-style", G_SETTINGS_BIND_DEFAULT);
  168 + // Bind properties
  169 + if(app->settings) {
  170 + g_object_ref_sink(G_OBJECT(app->settings));
  171 + g_settings_bind(app->settings, "ui-style", app, "ui-style", G_SETTINGS_BIND_DEFAULT);
134 172 }
135 173  
136 174 }
137 175  
  176 + static void finalize(GObject *object) {
  177 +
  178 + pw3270Application * application = PW3270_APPLICATION(object);
  179 +
  180 + if(application->settings) {
  181 + g_object_unref(application->settings);
  182 + application->settings = NULL;
  183 + }
  184 +
  185 +
  186 + G_OBJECT_CLASS(pw3270Application_parent_class)->finalize(object);
  187 +
  188 + }
  189 +
138 190 GtkApplication * pw3270_application_new(const gchar *application_id, GApplicationFlags flags) {
139 191  
140 192 return g_object_new(
... ... @@ -272,3 +324,9 @@
272 324  
273 325 }
274 326  
  327 + GSettings * pw3270_application_get_settings(GApplication *app) {
  328 +
  329 + g_return_val_if_fail(PW3270_IS_APPLICATION(app),NULL);
  330 + return PW3270_APPLICATION(app)->settings;
  331 +
  332 + }
... ...
src/objects/window/window.c
... ... @@ -84,11 +84,6 @@
84 84 },
85 85  
86 86 {
87   - .name = "win.connect",
88   - .activate = pw3270_application_generic_activated,
89   - },
90   -
91   - {
92 87 .name = "win.preferences",
93 88 .activate = pw3270_application_generic_activated,
94 89 },
... ... @@ -133,7 +128,7 @@
133 128  
134 129 const gchar * title = _( "IBM 3270 Terminal emulator" );
135 130  
136   - g_autoptr(GSettings) settings = pw3270_get_settings();
  131 + g_autoptr(GSettings) settings = pw3270_application_get_settings(G_APPLICATION(application));
137 132  
138 133 g_return_val_if_fail(GTK_IS_APPLICATION(application), NULL);
139 134 pw3270ApplicationWindow * window =
... ...