Commit 69fe5e35abae935db78864871931520ffacc0f35
1 parent
d52e2db3
Exists in
master
and in
1 other branch
Refactoring URL input component.
Showing
4 changed files
with
136 additions
and
7 deletions
Show diff stats
Makefile.in
@@ -109,7 +109,8 @@ DEPENDS= \ | @@ -109,7 +109,8 @@ DEPENDS= \ | ||
109 | src/filetransfer/marshal.h \ | 109 | src/filetransfer/marshal.h \ |
110 | src/filetransfer/private.h \ | 110 | src/filetransfer/private.h \ |
111 | src/terminal/marshal.h \ | 111 | src/terminal/marshal.h \ |
112 | - src/trace/marshal.h | 112 | + src/trace/marshal.h \ |
113 | + src/dialogs/settings/marshal.h | ||
113 | 114 | ||
114 | DATE_FMT = +%Y%m%d | 115 | DATE_FMT = +%Y%m%d |
115 | ifdef SOURCE_DATE_EPOCH | 116 | ifdef SOURCE_DATE_EPOCH |
@@ -239,6 +240,14 @@ src/terminal/marshal.h: \ | @@ -239,6 +240,14 @@ src/terminal/marshal.h: \ | ||
239 | 240 | ||
240 | @$(GENMARSHAL) --prefix=v3270 --header $< > $@ | 241 | @$(GENMARSHAL) --prefix=v3270 --header $< > $@ |
241 | 242 | ||
243 | +src/dialogs/settings/marshal.h: \ | ||
244 | + src/dialogs/settings/marshal | ||
245 | + | ||
246 | + @echo $@ ... | ||
247 | + @$(MKDIR) $(@D) | ||
248 | + | ||
249 | + @$(GENMARSHAL) --prefix=v3270 --header $< > $@ | ||
250 | + | ||
242 | $(OBJDIR)/marshal/v3270.c: \ | 251 | $(OBJDIR)/marshal/v3270.c: \ |
243 | src/terminal/marshal | 252 | src/terminal/marshal |
244 | 253 |
src/dialogs/settings/host.c
@@ -323,14 +323,16 @@ static void update_valid(V3270HostSelectWidget *settings, gboolean valid) { | @@ -323,14 +323,16 @@ static void update_valid(V3270HostSelectWidget *settings, gboolean valid) { | ||
323 | 323 | ||
324 | } | 324 | } |
325 | 325 | ||
326 | -/* | ||
327 | -static void required_changed(GtkEditable *editable, GtkWidget *settings) { | 326 | +static void url_valid(GtkWidget G_GNUC_UNUSED(*url), gboolean valid, V3270HostSelectWidget *settings) { |
328 | 327 | ||
329 | - const gchar * chars = gtk_editable_get_chars(editable,0,-1); | ||
330 | - update_valid(GTK_V3270HostSelectWidget(settings),(*chars ? TRUE : FALSE)); | 328 | + if(valid) { |
329 | + update_valid(settings,valid); | ||
330 | + return; | ||
331 | + } | ||
332 | + | ||
333 | + v3270_settings_set_valid(GTK_WIDGET(settings),valid); | ||
331 | 334 | ||
332 | } | 335 | } |
333 | -*/ | ||
334 | 336 | ||
335 | static void oversize_changed(GtkEditable *editable, GtkWidget *settings) { | 337 | static void oversize_changed(GtkEditable *editable, GtkWidget *settings) { |
336 | update_valid(GTK_V3270HostSelectWidget(settings), oversize_validate(editable)); | 338 | update_valid(GTK_V3270HostSelectWidget(settings), oversize_validate(editable)); |
@@ -418,6 +420,8 @@ static void V3270HostSelectWidget_init(V3270HostSelectWidget *widget) | @@ -418,6 +420,8 @@ static void V3270HostSelectWidget_init(V3270HostSelectWidget *widget) | ||
418 | GtkWidget *grids[GRID_COUNT]; | 420 | GtkWidget *grids[GRID_COUNT]; |
419 | 421 | ||
420 | grids[CONNECTION] = widget->input.url = v3270_url_edit_new(); | 422 | grids[CONNECTION] = widget->input.url = v3270_url_edit_new(); |
423 | + g_signal_connect(grids[CONNECTION],"valid",G_CALLBACK(url_valid),widget); | ||
424 | + | ||
421 | grids[EMULATION] = gtk_grid_new(); | 425 | grids[EMULATION] = gtk_grid_new(); |
422 | 426 | ||
423 | // Connection properties | 427 | // Connection properties |
src/dialogs/settings/url.c
@@ -30,7 +30,21 @@ | @@ -30,7 +30,21 @@ | ||
30 | */ | 30 | */ |
31 | 31 | ||
32 | #include "private.h" | 32 | #include "private.h" |
33 | + #include "marshal.h" | ||
33 | #include <v3270/settings/url.h> | 34 | #include <v3270/settings/url.h> |
35 | + #include <ctype.h> | ||
36 | + | ||
37 | + enum { | ||
38 | + PROP_0, | ||
39 | + PROP_URL | ||
40 | + }; | ||
41 | + | ||
42 | + enum { | ||
43 | + SIGNAL_VALID, | ||
44 | + LAST_SIGNAL | ||
45 | + }; | ||
46 | + | ||
47 | + static guint signals[LAST_SIGNAL] = { 0 }; | ||
34 | 48 | ||
35 | struct _V3270URLEdit { | 49 | struct _V3270URLEdit { |
36 | 50 | ||
@@ -46,12 +60,16 @@ | @@ -46,12 +60,16 @@ | ||
46 | /// @brief Current URL | 60 | /// @brief Current URL |
47 | gchar *url; | 61 | gchar *url; |
48 | 62 | ||
63 | + /// @brief Is the entry valid? | ||
64 | + gboolean isValid; | ||
65 | + | ||
49 | }; | 66 | }; |
50 | 67 | ||
51 | struct _V3270URLEditClass { | 68 | struct _V3270URLEditClass { |
52 | 69 | ||
53 | GtkGridClass parent; | 70 | GtkGridClass parent; |
54 | 71 | ||
72 | + GParamSpec *url; | ||
55 | 73 | ||
56 | }; | 74 | }; |
57 | 75 | ||
@@ -73,9 +91,101 @@ | @@ -73,9 +91,101 @@ | ||
73 | G_OBJECT_CLASS(V3270URLEdit_parent_class)->finalize(object); | 91 | G_OBJECT_CLASS(V3270URLEdit_parent_class)->finalize(object); |
74 | } | 92 | } |
75 | 93 | ||
94 | + static void set_property(GObject *object, guint prop_id, const GValue *value, GParamSpec G_GNUC_UNUSED(*pspec)) { | ||
95 | + | ||
96 | + switch(prop_id) { | ||
97 | + case PROP_URL: | ||
98 | + v3270_url_edit_set_url(GTK_WIDGET(object),g_value_get_string(value)); | ||
99 | + break; | ||
100 | + } | ||
101 | + } | ||
102 | + | ||
103 | + static void get_property(GObject *object, guint prop_id, GValue *value, GParamSpec G_GNUC_UNUSED(*pspec)) { | ||
104 | + switch(prop_id) { | ||
105 | + case PROP_URL: | ||
106 | + g_value_set_string(value,v3270_url_edit_get_url(GTK_WIDGET(object))); | ||
107 | + break; | ||
108 | + } | ||
109 | + } | ||
110 | + | ||
76 | static void V3270URLEdit_class_init(V3270URLEditClass *klass) { | 111 | static void V3270URLEdit_class_init(V3270URLEditClass *klass) { |
77 | 112 | ||
78 | - G_OBJECT_CLASS(klass)->finalize = finalize; | 113 | + GObjectClass *goc = G_OBJECT_CLASS(klass); |
114 | + | ||
115 | + goc->finalize = finalize; | ||
116 | + goc->set_property = set_property; | ||
117 | + goc->get_property = get_property; | ||
118 | + | ||
119 | + klass->url = | ||
120 | + g_param_spec_string( | ||
121 | + "url", "url", | ||
122 | + _( "TN3270 Host URL" ), | ||
123 | + lib3270_get_default_host(NULL), | ||
124 | + G_PARAM_READWRITE | ||
125 | + ); | ||
126 | + | ||
127 | + g_object_class_install_property( | ||
128 | + goc, | ||
129 | + PROP_URL, | ||
130 | + klass->url | ||
131 | + ); | ||
132 | + | ||
133 | + signals[SIGNAL_VALID] = | ||
134 | + g_signal_new( | ||
135 | + I_("valid"), | ||
136 | + G_OBJECT_CLASS_TYPE(goc), | ||
137 | + G_SIGNAL_RUN_FIRST, | ||
138 | + 0, | ||
139 | + NULL, NULL, | ||
140 | + v3270_VOID__BOOLEAN, | ||
141 | + G_TYPE_NONE, 1, G_TYPE_BOOLEAN, 0 | ||
142 | + ); | ||
143 | + | ||
144 | + } | ||
145 | + | ||
146 | + static void entry_changed(GtkEntry *entry, V3270URLEdit *widget) { | ||
147 | + | ||
148 | + g_object_notify_by_pspec(G_OBJECT(widget),GTK_V3270URLEdit_GET_CLASS(widget)->url); | ||
149 | + | ||
150 | + gboolean isValid = (gtk_entry_get_text(entry)[0] != 0); | ||
151 | + if(widget->isValid == isValid) { | ||
152 | + return; | ||
153 | + } | ||
154 | + | ||
155 | + if(isValid) { | ||
156 | + | ||
157 | + size_t ix; | ||
158 | + | ||
159 | + // Verify entry-fields | ||
160 | + GtkWidget *widgets[] = { | ||
161 | + widget->entry.host, | ||
162 | + widget->entry.service | ||
163 | + }; | ||
164 | + | ||
165 | + for(ix = 0; ix < G_N_ELEMENTS(widgets); ix++) { | ||
166 | + | ||
167 | + const gchar *str = gtk_entry_get_text(GTK_ENTRY(widgets[ix])); | ||
168 | + while(*str && isspace(*str)) { | ||
169 | + str++; | ||
170 | + } | ||
171 | + | ||
172 | + if(!*str) { | ||
173 | + isValid = FALSE; | ||
174 | + break; | ||
175 | + } | ||
176 | + | ||
177 | + } | ||
178 | + | ||
179 | + } | ||
180 | + | ||
181 | + if(isValid == widget->isValid) { | ||
182 | + return; | ||
183 | + } | ||
184 | + | ||
185 | + debug("The URL box is %s", isValid ? "valid" : "invalid"); | ||
186 | + | ||
187 | + widget->isValid = isValid; | ||
188 | + g_signal_emit(widget, signals[SIGNAL_VALID], 0, isValid); | ||
79 | 189 | ||
80 | } | 190 | } |
81 | 191 | ||
@@ -83,6 +193,8 @@ | @@ -83,6 +193,8 @@ | ||
83 | 193 | ||
84 | size_t ix; | 194 | size_t ix; |
85 | 195 | ||
196 | + widget->isValid = FALSE; | ||
197 | + | ||
86 | // Table of constants. | 198 | // Table of constants. |
87 | static const struct _labels { | 199 | static const struct _labels { |
88 | int row; | 200 | int row; |
@@ -122,6 +234,7 @@ | @@ -122,6 +234,7 @@ | ||
122 | gtk_entry_set_width_chars(GTK_ENTRY(widget->entry.host),50); | 234 | gtk_entry_set_width_chars(GTK_ENTRY(widget->entry.host),50); |
123 | gtk_widget_set_tooltip_text(widget->entry.host,g_dgettext(GETTEXT_PACKAGE,labels[0].tooltip)); | 235 | gtk_widget_set_tooltip_text(widget->entry.host,g_dgettext(GETTEXT_PACKAGE,labels[0].tooltip)); |
124 | gtk_grid_attach(GTK_GRID(widget),widget->entry.host,1,0,5,1); | 236 | gtk_grid_attach(GTK_GRID(widget),widget->entry.host,1,0,5,1); |
237 | + g_signal_connect(widget->entry.host,"changed",G_CALLBACK(entry_changed),widget); | ||
125 | } | 238 | } |
126 | 239 | ||
127 | // Create the service/port field. | 240 | // Create the service/port field. |
@@ -132,6 +245,7 @@ | @@ -132,6 +245,7 @@ | ||
132 | gtk_entry_set_width_chars(GTK_ENTRY(widget->entry.service),7); | 245 | gtk_entry_set_width_chars(GTK_ENTRY(widget->entry.service),7); |
133 | gtk_widget_set_tooltip_text(widget->entry.service,g_dgettext(GETTEXT_PACKAGE,labels[1].tooltip)); | 246 | gtk_widget_set_tooltip_text(widget->entry.service,g_dgettext(GETTEXT_PACKAGE,labels[1].tooltip)); |
134 | gtk_grid_attach(GTK_GRID(widget),widget->entry.service,1,1,1,1); | 247 | gtk_grid_attach(GTK_GRID(widget),widget->entry.service,1,1,1,1); |
248 | + g_signal_connect(widget->entry.service,"changed",G_CALLBACK(entry_changed),widget); | ||
135 | } | 249 | } |
136 | 250 | ||
137 | // Create the security dropbox. | 251 | // Create the security dropbox. |