Commit 7f2f69c0172fd4e1a4f188f9a5a4ce2dd1a14b55
1 parent
6c60e001
Exists in
master
and in
1 other branch
Refactoring hostselect dialog.
Showing
5 changed files
with
330 additions
and
1 deletions
Show diff stats
src/dialogs/settings/host.c
@@ -307,7 +307,7 @@ static void update_message(GtkWidget *widget, GtkWidget *terminal) | @@ -307,7 +307,7 @@ static void update_message(GtkWidget *widget, GtkWidget *terminal) | ||
307 | gtk_widget_set_sensitive(widget, lib3270_is_disconnected(v3270_get_session(terminal))); | 307 | gtk_widget_set_sensitive(widget, lib3270_is_disconnected(v3270_get_session(terminal))); |
308 | } | 308 | } |
309 | 309 | ||
310 | -static void V3270HostSelectWidget_class_init(G_GNUC_UNUSED V3270HostSelectWidgetClass *klass) | 310 | +static void V3270HostSelectWidget_class_init(V3270HostSelectWidgetClass *klass) |
311 | { | 311 | { |
312 | V3270SettingsClass * widget = GTK_V3270_SETTINGS_CLASS(klass); | 312 | V3270SettingsClass * widget = GTK_V3270_SETTINGS_CLASS(klass); |
313 | 313 |
@@ -0,0 +1,258 @@ | @@ -0,0 +1,258 @@ | ||
1 | +/* SPDX-License-Identifier: LGPL-3.0-or-later */ | ||
2 | + | ||
3 | +/* | ||
4 | + * "Software pw3270, desenvolvido com base nos códigos fontes do WC3270 e X3270 | ||
5 | + * (Paul Mattes Paul.Mattes@usa.net), de emulação de terminal 3270 para acesso a | ||
6 | + * aplicativos mainframe. Registro no INPI sob o nome G3270. | ||
7 | + * | ||
8 | + * Copyright (C) <2008> <Banco do Brasil S.A.> | ||
9 | + * | ||
10 | + * Este programa é software livre. Você pode redistribuí-lo e/ou modificá-lo sob | ||
11 | + * os termos da GPL v.2 - Licença Pública Geral GNU, conforme publicado pela | ||
12 | + * Free Software Foundation. | ||
13 | + * | ||
14 | + * Este programa é distribuído na expectativa de ser útil, mas SEM QUALQUER | ||
15 | + * GARANTIA; sem mesmo a garantia implícita de COMERCIALIZAÇÃO ou de ADEQUAÇÃO | ||
16 | + * A QUALQUER PROPÓSITO EM PARTICULAR. Consulte a Licença Pública Geral GNU para | ||
17 | + * obter mais detalhes. | ||
18 | + * | ||
19 | + * Você deve ter recebido uma cópia da Licença Pública Geral GNU junto com este | ||
20 | + * programa; se não, escreva para a Free Software Foundation, Inc., 51 Franklin | ||
21 | + * St, Fifth Floor, Boston, MA 02110-1301 USA | ||
22 | + * | ||
23 | + * Este programa está nomeado como - e possui - linhas de código. | ||
24 | + * | ||
25 | + * Contatos: | ||
26 | + * | ||
27 | + * perry.werneck@gmail.com (Alexandre Perry de Souza Werneck) | ||
28 | + * erico.mendonca@gmail.com (Erico Mascarenhas Mendonça) | ||
29 | + * | ||
30 | + */ | ||
31 | + | ||
32 | + #include "private.h" | ||
33 | + #include <v3270/settings/url.h> | ||
34 | + | ||
35 | + struct _V3270URLEdit { | ||
36 | + | ||
37 | + GtkGrid parent; | ||
38 | + | ||
39 | + /// @brief Entry fields | ||
40 | + struct { | ||
41 | + GtkWidget *host; ///< @brief The hostname | ||
42 | + GtkWidget *service; ///< @brief The service/port name | ||
43 | + GtkWidget *ssl; ///< @brief The Security Drop-Down | ||
44 | + } entry; | ||
45 | + | ||
46 | + /// @brief Current URL | ||
47 | + gchar *url; | ||
48 | + | ||
49 | + }; | ||
50 | + | ||
51 | + struct _V3270URLEditClass { | ||
52 | + | ||
53 | + GtkGridClass parent; | ||
54 | + | ||
55 | + | ||
56 | + }; | ||
57 | + | ||
58 | + G_DEFINE_TYPE(V3270URLEdit, V3270URLEdit, GTK_TYPE_GRID); | ||
59 | + | ||
60 | + GtkWidget * v3270_url_edit_new() { | ||
61 | + return g_object_new(GTK_TYPE_V3270URLEdit, NULL); | ||
62 | + } | ||
63 | + | ||
64 | + static void finalize(GObject *object) { | ||
65 | + | ||
66 | + V3270URLEdit *edit = GTK_V3270URLEdit(object); | ||
67 | + | ||
68 | + if(edit->url) { | ||
69 | + g_free(edit->url); | ||
70 | + edit->url = NULL; | ||
71 | + } | ||
72 | + | ||
73 | + G_OBJECT_CLASS(V3270URLEdit_parent_class)->finalize(object); | ||
74 | + } | ||
75 | + | ||
76 | + static void V3270URLEdit_class_init(V3270URLEditClass *klass) { | ||
77 | + | ||
78 | + G_OBJECT_CLASS(klass)->finalize = finalize; | ||
79 | + | ||
80 | + } | ||
81 | + | ||
82 | + static void V3270URLEdit_init(V3270URLEdit *widget) { | ||
83 | + | ||
84 | + size_t ix; | ||
85 | + | ||
86 | + // Table of constants. | ||
87 | + static const struct _labels { | ||
88 | + int row; | ||
89 | + int col; | ||
90 | + const char *text; | ||
91 | + const char *tooltip; | ||
92 | + } labels[] = { | ||
93 | + { | ||
94 | + .row = 0, | ||
95 | + .col = 0, | ||
96 | + .text = N_("Hostname"), | ||
97 | + .tooltip = N_("Address or name of the host to connect."), | ||
98 | + }, | ||
99 | + { | ||
100 | + .row = 1, | ||
101 | + .col = 0, | ||
102 | + .text = N_("Service/Port"), | ||
103 | + .tooltip = N_("Port or service name."), | ||
104 | + }, | ||
105 | + { | ||
106 | + .row = 1, | ||
107 | + .col = 2, | ||
108 | + .text = N_("Security"), | ||
109 | + .tooltip = N_("Security engine"), | ||
110 | + } | ||
111 | + }; | ||
112 | + | ||
113 | + // setup grid | ||
114 | + gtk_widget_set_vexpand(GTK_WIDGET(widget),FALSE); | ||
115 | + gtk_grid_set_row_spacing(GTK_GRID(widget),6); | ||
116 | + gtk_grid_set_column_spacing(GTK_GRID(widget),12); | ||
117 | + | ||
118 | + // Create hostname field. | ||
119 | + { | ||
120 | + widget->entry.host = gtk_entry_new(); | ||
121 | + gtk_widget_set_hexpand(widget->entry.host,TRUE); | ||
122 | + gtk_entry_set_width_chars(GTK_ENTRY(widget->entry.host),50); | ||
123 | + gtk_entry_set_placeholder_text(GTK_ENTRY(widget->entry.host),_("The tn3270 host name")); | ||
124 | + gtk_widget_set_tooltip_text(widget->entry.host,g_dgettext(GETTEXT_PACKAGE,labels[0].tooltip)); | ||
125 | + gtk_grid_attach(GTK_GRID(widget),widget->entry.host,1,0,4,1); | ||
126 | + } | ||
127 | + | ||
128 | + // Create the service/port field. | ||
129 | + { | ||
130 | + widget->entry.service = gtk_entry_new(); | ||
131 | + gtk_widget_set_hexpand(widget->entry.service,FALSE); | ||
132 | + gtk_entry_set_max_length(GTK_ENTRY(widget->entry.service),6); | ||
133 | + gtk_entry_set_width_chars(GTK_ENTRY(widget->entry.service),7); | ||
134 | + gtk_widget_set_tooltip_text(widget->entry.service,g_dgettext(GETTEXT_PACKAGE,labels[1].tooltip)); | ||
135 | + gtk_grid_attach(GTK_GRID(widget),widget->entry.service,1,1,1,1); | ||
136 | + } | ||
137 | + | ||
138 | + // Create the security dropbox. | ||
139 | + { | ||
140 | + GtkTreeModel * model = (GtkTreeModel *) gtk_list_store_new(1,G_TYPE_STRING); | ||
141 | + widget->entry.ssl = gtk_combo_box_new_with_model(model); | ||
142 | + gtk_widget_set_hexpand(widget->entry.ssl,TRUE); | ||
143 | + | ||
144 | + GtkCellRenderer * text_renderer = gtk_cell_renderer_text_new(); | ||
145 | + gtk_cell_layout_pack_start(GTK_CELL_LAYOUT(widget->entry.ssl), text_renderer, TRUE); | ||
146 | + gtk_cell_layout_set_attributes(GTK_CELL_LAYOUT(widget->entry.ssl), text_renderer, "text", 0, NULL); | ||
147 | + | ||
148 | + static const gchar * levels[] = | ||
149 | + { | ||
150 | + N_("Unsecure"), | ||
151 | + N_("SSL/TLS") | ||
152 | + }; | ||
153 | + | ||
154 | + size_t level; | ||
155 | + for(level = 0; level < G_N_ELEMENTS(levels); level++) | ||
156 | + { | ||
157 | + GtkTreeIter iter; | ||
158 | + gtk_list_store_append((GtkListStore *) model, &iter); | ||
159 | + gtk_list_store_set((GtkListStore *) model, &iter, 0, g_dgettext(GETTEXT_PACKAGE,levels[level]), -1); | ||
160 | + }; | ||
161 | + | ||
162 | + gtk_widget_set_tooltip_text(widget->entry.ssl,g_dgettext(GETTEXT_PACKAGE,labels[2].tooltip)); | ||
163 | + gtk_grid_attach(GTK_GRID(widget),widget->entry.ssl,3,1,2,1); | ||
164 | + } | ||
165 | + | ||
166 | + // Create labels. | ||
167 | + { | ||
168 | + | ||
169 | + for(ix = 0; ix < G_N_ELEMENTS(labels);ix++) { | ||
170 | + GtkWidget * label = gtk_label_new(g_dgettext(GETTEXT_PACKAGE,labels[ix].text)); | ||
171 | + gtk_widget_set_halign(label,GTK_ALIGN_END); | ||
172 | + gtk_widget_set_hexpand(label,FALSE); | ||
173 | + gtk_grid_attach(GTK_GRID(widget),label,labels[ix].col,labels[ix].row,1,1); | ||
174 | + gtk_widget_set_tooltip_text(label,g_dgettext(GETTEXT_PACKAGE,labels[ix].tooltip)); | ||
175 | + } | ||
176 | + | ||
177 | + | ||
178 | + } | ||
179 | + | ||
180 | + v3270_url_edit_set_url(GTK_WIDGET(widget),NULL); | ||
181 | + | ||
182 | + } | ||
183 | + | ||
184 | + void v3270_url_edit_set_url(GtkWidget *widget, const gchar *url) { | ||
185 | + | ||
186 | + g_return_if_fail(GTK_IS_V3270URLEdit(widget)); | ||
187 | + V3270URLEdit *edit = GTK_V3270URLEdit(widget); | ||
188 | + | ||
189 | + if(edit->url) { | ||
190 | + g_free(edit->url); | ||
191 | + edit->url = NULL; | ||
192 | + } | ||
193 | + | ||
194 | + if(!(url && *url)) { | ||
195 | + gtk_combo_box_set_active(GTK_COMBO_BOX(edit->entry.ssl),0); | ||
196 | + gtk_entry_set_text(GTK_ENTRY(edit->entry.host),""); | ||
197 | + gtk_entry_set_text(GTK_ENTRY(edit->entry.service),""); | ||
198 | + return; | ||
199 | + } | ||
200 | + | ||
201 | + edit->url = g_strdup(url); | ||
202 | + | ||
203 | + gtk_combo_box_set_active(GTK_COMBO_BOX(edit->entry.ssl),(g_str_has_prefix(edit->url,"tn3270s") ? 1 : 0)); | ||
204 | + | ||
205 | + gchar *hostname = strstr(url,"://"); | ||
206 | + if(!hostname) | ||
207 | + { | ||
208 | + g_message("Invalid URL: \"%s\" (no scheme)",url); | ||
209 | + gtk_entry_set_text(GTK_ENTRY(edit->entry.host),""); | ||
210 | + gtk_entry_set_text(GTK_ENTRY(edit->entry.service),""); | ||
211 | + return; | ||
212 | + } | ||
213 | + | ||
214 | + hostname += 3; | ||
215 | + g_autofree gchar *str = g_strdup(hostname); | ||
216 | + | ||
217 | + gchar *srvcname = strchr(str,':'); | ||
218 | + | ||
219 | + if(srvcname) { | ||
220 | + *(srvcname++) = 0; | ||
221 | + } else { | ||
222 | + srvcname = "3270"; | ||
223 | + } | ||
224 | + | ||
225 | + gtk_entry_set_text(GTK_ENTRY(edit->entry.host),str); | ||
226 | + gtk_entry_set_text(GTK_ENTRY(edit->entry.service),srvcname); | ||
227 | + | ||
228 | + } | ||
229 | + | ||
230 | + const gchar * v3270_url_edit_get_url(GtkWidget *widget) { | ||
231 | + | ||
232 | + g_return_val_if_fail(GTK_IS_V3270URLEdit(widget),NULL); | ||
233 | + V3270URLEdit *edit = GTK_V3270URLEdit(widget); | ||
234 | + | ||
235 | + if(edit->url) { | ||
236 | + return edit->url; | ||
237 | + } | ||
238 | + | ||
239 | + const gchar *host = gtk_entry_get_text(GTK_ENTRY(edit->entry.host)); | ||
240 | + if(!*host) | ||
241 | + return ""; | ||
242 | + | ||
243 | + const gchar *service = gtk_entry_get_text(GTK_ENTRY(edit->entry.service)); | ||
244 | + if(!*service) | ||
245 | + service = "3270"; | ||
246 | + | ||
247 | + edit->url = | ||
248 | + g_strconcat( | ||
249 | + (gtk_combo_box_get_active(GTK_COMBO_BOX(edit->entry.ssl)) > 0 ? "tn3270s://" : "tn3270://"), | ||
250 | + host, | ||
251 | + ":", | ||
252 | + service, | ||
253 | + NULL | ||
254 | + ); | ||
255 | + | ||
256 | + return edit->url; | ||
257 | + } | ||
258 | + |
@@ -0,0 +1,58 @@ | @@ -0,0 +1,58 @@ | ||
1 | +/* SPDX-License-Identifier: LGPL-3.0-or-later */ | ||
2 | + | ||
3 | +/* | ||
4 | + * "Software pw3270, desenvolvido com base nos códigos fontes do WC3270 e X3270 | ||
5 | + * (Paul Mattes Paul.Mattes@usa.net), de emulação de terminal 3270 para acesso a | ||
6 | + * aplicativos mainframe. Registro no INPI sob o nome G3270. | ||
7 | + * | ||
8 | + * Copyright (C) <2008> <Banco do Brasil S.A.> | ||
9 | + * | ||
10 | + * Este programa é software livre. Você pode redistribuí-lo e/ou modificá-lo sob | ||
11 | + * os termos da GPL v.2 - Licença Pública Geral GNU, conforme publicado pela | ||
12 | + * Free Software Foundation. | ||
13 | + * | ||
14 | + * Este programa é distribuído na expectativa de ser útil, mas SEM QUALQUER | ||
15 | + * GARANTIA; sem mesmo a garantia implícita de COMERCIALIZAÇÃO ou de ADEQUAÇÃO | ||
16 | + * A QUALQUER PROPÓSITO EM PARTICULAR. Consulte a Licença Pública Geral GNU para | ||
17 | + * obter mais detalhes. | ||
18 | + * | ||
19 | + * Você deve ter recebido uma cópia da Licença Pública Geral GNU junto com este | ||
20 | + * programa; se não, escreva para a Free Software Foundation, Inc., 51 Franklin | ||
21 | + * St, Fifth Floor, Boston, MA 02110-1301 USA | ||
22 | + * | ||
23 | + * Este programa está nomeado como - e possui - linhas de código. | ||
24 | + * | ||
25 | + * Contatos: | ||
26 | + * | ||
27 | + * perry.werneck@gmail.com (Alexandre Perry de Souza Werneck) | ||
28 | + * erico.mendonca@gmail.com (Erico Mascarenhas Mendonça) | ||
29 | + * | ||
30 | + */ | ||
31 | + | ||
32 | +#ifndef V3270_SETTINGS_URL_H_INCLUDED | ||
33 | + | ||
34 | + #define V3270_SETTINGS_URL_H_INCLUDED | ||
35 | + | ||
36 | + #include <gtk/gtk.h> | ||
37 | + | ||
38 | + /*--[ URL Settings Widget ]--------------------------------------------------------------------------*/ | ||
39 | + | ||
40 | + G_BEGIN_DECLS | ||
41 | + | ||
42 | + #define GTK_TYPE_V3270URLEdit (V3270URLEdit_get_type ()) | ||
43 | + #define GTK_V3270URLEdit(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GTK_TYPE_V3270URLEdit, V3270URLEdit)) | ||
44 | + #define GTK_V3270URLEdit_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GTK_TYPE_V3270URLEdit, V3270URLEditClass)) | ||
45 | + #define GTK_IS_V3270URLEdit(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GTK_TYPE_V3270URLEdit)) | ||
46 | + #define GTK_IS_V3270URLEdit_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GTK_TYPE_V3270URLEdit)) | ||
47 | + #define GTK_V3270URLEdit_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GTK_TYPE_V3270URLEdit, V3270URLEditClass)) | ||
48 | + | ||
49 | + typedef struct _V3270URLEdit V3270URLEdit; | ||
50 | + typedef struct _V3270URLEditClass V3270URLEditClass; | ||
51 | + | ||
52 | + GtkWidget * v3270_url_edit_new(); | ||
53 | + void v3270_url_edit_set_url(GtkWidget *widget, const gchar *url); | ||
54 | + const gchar * v3270_url_edit_get_url(GtkWidget *widget); | ||
55 | + | ||
56 | + G_END_DECLS | ||
57 | + | ||
58 | +#endif // V3270_SETTINGS_URL_H_INCLUDED |
src/testprogram/toolbar.c
@@ -34,6 +34,7 @@ | @@ -34,6 +34,7 @@ | ||
34 | #include <v3270/colorscheme.h> | 34 | #include <v3270/colorscheme.h> |
35 | #include <v3270/dialogs.h> | 35 | #include <v3270/dialogs.h> |
36 | #include <v3270/settings.h> | 36 | #include <v3270/settings.h> |
37 | + #include <v3270/settings/url.h> | ||
37 | #include <v3270/selection.h> | 38 | #include <v3270/selection.h> |
38 | #include <v3270/trace.h> | 39 | #include <v3270/trace.h> |
39 | #include <lib3270/log.h> | 40 | #include <lib3270/log.h> |
@@ -70,6 +71,13 @@ | @@ -70,6 +71,13 @@ | ||
70 | 71 | ||
71 | static void preferences_clicked(GtkButton G_GNUC_UNUSED(*button), GtkWidget *terminal) | 72 | static void preferences_clicked(GtkButton G_GNUC_UNUSED(*button), GtkWidget *terminal) |
72 | { | 73 | { |
74 | + GtkWidget * dialog = gtk_window_new(GTK_WINDOW_TOPLEVEL); | ||
75 | + | ||
76 | + gtk_container_add(GTK_CONTAINER(dialog),v3270_url_edit_new()); | ||
77 | + gtk_widget_show_all(dialog); | ||
78 | + | ||
79 | + | ||
80 | + /* | ||
73 | size_t ix; | 81 | size_t ix; |
74 | GtkWidget * dialog = v3270_settings_dialog_new(); | 82 | GtkWidget * dialog = v3270_settings_dialog_new(); |
75 | 83 | ||
@@ -95,6 +103,7 @@ | @@ -95,6 +103,7 @@ | ||
95 | g_signal_connect(dialog,"response",G_CALLBACK(v3270_setttings_dialog_response),NULL); | 103 | g_signal_connect(dialog,"response",G_CALLBACK(v3270_setttings_dialog_response),NULL); |
96 | 104 | ||
97 | gtk_widget_show_all(dialog); | 105 | gtk_widget_show_all(dialog); |
106 | + */ | ||
98 | 107 | ||
99 | } | 108 | } |
100 | 109 |
v3270.cbp
@@ -121,6 +121,9 @@ | @@ -121,6 +121,9 @@ | ||
121 | <Unit filename="src/dialogs/settings/tools.c"> | 121 | <Unit filename="src/dialogs/settings/tools.c"> |
122 | <Option compilerVar="CC" /> | 122 | <Option compilerVar="CC" /> |
123 | </Unit> | 123 | </Unit> |
124 | + <Unit filename="src/dialogs/settings/url.c"> | ||
125 | + <Option compilerVar="CC" /> | ||
126 | + </Unit> | ||
124 | <Unit filename="src/dialogs/settings/widget.c"> | 127 | <Unit filename="src/dialogs/settings/widget.c"> |
125 | <Option compilerVar="CC" /> | 128 | <Option compilerVar="CC" /> |
126 | </Unit> | 129 | </Unit> |
@@ -197,6 +200,7 @@ | @@ -197,6 +200,7 @@ | ||
197 | <Unit filename="src/include/v3270/security.h" /> | 200 | <Unit filename="src/include/v3270/security.h" /> |
198 | <Unit filename="src/include/v3270/selection.h" /> | 201 | <Unit filename="src/include/v3270/selection.h" /> |
199 | <Unit filename="src/include/v3270/settings.h" /> | 202 | <Unit filename="src/include/v3270/settings.h" /> |
203 | + <Unit filename="src/include/v3270/settings/url.h" /> | ||
200 | <Unit filename="src/include/v3270/toggle.h" /> | 204 | <Unit filename="src/include/v3270/toggle.h" /> |
201 | <Unit filename="src/include/v3270/tools.h" /> | 205 | <Unit filename="src/include/v3270/tools.h" /> |
202 | <Unit filename="src/include/v3270/trace.h" /> | 206 | <Unit filename="src/include/v3270/trace.h" /> |