Commit 541f9cc15e895eb7f24550d006c25d24f3eca2c5
1 parent
8a99c3c7
Exists in
master
and in
1 other branch
Refactoring host select widget.
Showing
3 changed files
with
134 additions
and
64 deletions
Show diff stats
src/dialogs/hostselect.c
@@ -27,6 +27,11 @@ | @@ -27,6 +27,11 @@ | ||
27 | * | 27 | * |
28 | */ | 28 | */ |
29 | 29 | ||
30 | + /** | ||
31 | + * @brief Implements the host properties widget. | ||
32 | + * | ||
33 | + */ | ||
34 | + | ||
30 | #include "private.h" | 35 | #include "private.h" |
31 | #include <hostselect.h> | 36 | #include <hostselect.h> |
32 | #include <v3270/dialogs.h> | 37 | #include <v3270/dialogs.h> |
@@ -35,19 +40,6 @@ | @@ -35,19 +40,6 @@ | ||
35 | 40 | ||
36 | /*--[ Widget definition ]----------------------------------------------------------------------------*/ | 41 | /*--[ Widget definition ]----------------------------------------------------------------------------*/ |
37 | 42 | ||
38 | -/* | ||
39 | - static const struct _colortable | ||
40 | - { | ||
41 | - unsigned short colors; | ||
42 | - const gchar * description; | ||
43 | - } colortable[] = | ||
44 | - { | ||
45 | - { 16, N_( "16 colors" ) }, | ||
46 | - { 8, N_( "8 colors" ) }, | ||
47 | - { 2, N_( "Monochrome" ) }, | ||
48 | - }; | ||
49 | - */ | ||
50 | - | ||
51 | enum _entry | 43 | enum _entry |
52 | { | 44 | { |
53 | ENTRY_HOSTNAME, | 45 | ENTRY_HOSTNAME, |
@@ -56,12 +48,11 @@ | @@ -56,12 +48,11 @@ | ||
56 | ENTRY_COUNT | 48 | ENTRY_COUNT |
57 | }; | 49 | }; |
58 | 50 | ||
51 | + /// @brief Combo box descriptors. | ||
59 | static const struct Combos | 52 | static const struct Combos |
60 | { | 53 | { |
61 | - gint top; | ||
62 | - gint left; | ||
63 | - const gchar * label; | ||
64 | - const gchar * tooltip; | 54 | + ENTRY_FIELD_HEAD |
55 | + | ||
65 | const unsigned int * values; | 56 | const unsigned int * values; |
66 | const gchar **labels; | 57 | const gchar **labels; |
67 | 58 | ||
@@ -71,8 +62,10 @@ | @@ -71,8 +62,10 @@ | ||
71 | } combos[] = | 62 | } combos[] = |
72 | { | 63 | { |
73 | { | 64 | { |
74 | - .top = 2, | 65 | + .top = 0, |
75 | .left = 0, | 66 | .left = 0, |
67 | + .width = 2, | ||
68 | + .height = 1, | ||
76 | 69 | ||
77 | .label = N_("System _type"), | 70 | .label = N_("System _type"), |
78 | .get = (unsigned int (*)(const H3270 *)) lib3270_get_host_type, | 71 | .get = (unsigned int (*)(const H3270 *)) lib3270_get_host_type, |
@@ -97,8 +90,10 @@ | @@ -97,8 +90,10 @@ | ||
97 | 90 | ||
98 | }, | 91 | }, |
99 | { | 92 | { |
100 | - .top = 2, | 93 | + .top = 0, |
101 | .left = 3, | 94 | .left = 3, |
95 | + .width = 2, | ||
96 | + .height = 1, | ||
102 | 97 | ||
103 | .label = N_("_Color table"), | 98 | .label = N_("_Color table"), |
104 | .get = lib3270_get_color_type, | 99 | .get = lib3270_get_color_type, |
@@ -123,8 +118,10 @@ | @@ -123,8 +118,10 @@ | ||
123 | 118 | ||
124 | }, | 119 | }, |
125 | { | 120 | { |
126 | - .top = 3, | ||
127 | - .left = 0, | 121 | + .top = 0, |
122 | + .left = 6, | ||
123 | + .width = 2, | ||
124 | + .height = 1, | ||
128 | 125 | ||
129 | .label = N_("_Model"), | 126 | .label = N_("_Model"), |
130 | .tooltip = N_("The model of 3270 display to be emulated"), | 127 | .tooltip = N_("The model of 3270 display to be emulated"), |
@@ -142,9 +139,9 @@ | @@ -142,9 +139,9 @@ | ||
142 | 139 | ||
143 | .labels = (const gchar *[]) | 140 | .labels = (const gchar *[]) |
144 | { | 141 | { |
145 | - N_( "Model 2 - 80x24" ), | ||
146 | - N_( "Model 3 - 80x32" ), | ||
147 | - N_( "Model 4 - 80x43" ), | 142 | + N_( "Model 2 - 80x24" ), |
143 | + N_( "Model 3 - 80x32" ), | ||
144 | + N_( "Model 4 - 80x43" ), | ||
148 | N_( "Model 5 - 132x27" ), | 145 | N_( "Model 5 - 132x27" ), |
149 | NULL | 146 | NULL |
150 | } | 147 | } |
@@ -152,15 +149,48 @@ | @@ -152,15 +149,48 @@ | ||
152 | } | 149 | } |
153 | }; | 150 | }; |
154 | 151 | ||
152 | + static const struct Entry | ||
153 | + { | ||
154 | + ENTRY_FIELD_HEAD | ||
155 | + | ||
156 | + gint max_length; | ||
157 | + gint width_chars; | ||
158 | + | ||
159 | + } entryfields[] = { | ||
160 | + { | ||
161 | + .left = 0, | ||
162 | + .top = 0, | ||
163 | + .width = 5, | ||
164 | + .height = 1, | ||
165 | + | ||
166 | + .label = N_( "_Host" ), | ||
167 | + .tooltip = N_("Address or name of the host to connect."), | ||
168 | + .max_length = 0xFF, | ||
169 | + .width_chars = 50, | ||
170 | + | ||
171 | + }, | ||
172 | + { | ||
173 | + .left = 0, | ||
174 | + .top = 1, | ||
175 | + .width = 1, | ||
176 | + .height = 1, | ||
177 | + | ||
178 | + .label = N_( "_Service" ), | ||
179 | + .tooltip = N_("Port or service name (empty for \"telnet\")."), | ||
180 | + .max_length = 6, | ||
181 | + .width_chars = 7, | ||
182 | + } | ||
183 | + }; | ||
184 | + | ||
155 | struct _V3270HostSelectWidget | 185 | struct _V3270HostSelectWidget |
156 | { | 186 | { |
157 | V3270Settings parent; | 187 | V3270Settings parent; |
158 | 188 | ||
159 | struct | 189 | struct |
160 | { | 190 | { |
161 | - GtkEntry * entry[ENTRY_COUNT]; /**< @brief Entry fields for host & service name */ | ||
162 | - GtkToggleButton * ssl; /**< @brief SSL Connection? */ | ||
163 | - GtkComboBox * combos[G_N_ELEMENTS(combos)]; /**< @brief Combo-boxes */ | 191 | + GtkEntry * entry[G_N_ELEMENTS(entryfields)]; ///< @brief Entry fields for host & service name |
192 | + GtkToggleButton * ssl; ///< @brief SSL Connection? | ||
193 | + GtkComboBox * combos[G_N_ELEMENTS(combos)]; ///< @brief Combo-boxes | ||
164 | 194 | ||
165 | } input; | 195 | } input; |
166 | 196 | ||
@@ -273,13 +303,14 @@ static void load(GtkWidget *w, GtkWidget *terminal) | @@ -273,13 +303,14 @@ static void load(GtkWidget *w, GtkWidget *terminal) | ||
273 | 303 | ||
274 | if(gtk_tree_model_get_iter_first(model,&iter)) | 304 | if(gtk_tree_model_get_iter_first(model,&iter)) |
275 | { | 305 | { |
276 | - GValue gVal = { 0, }; | ||
277 | - | ||
278 | do | 306 | do |
279 | { | 307 | { |
308 | + GValue gVal = { 0, }; | ||
280 | gtk_tree_model_get_value(model,&iter,1,&gVal); | 309 | gtk_tree_model_get_value(model,&iter,1,&gVal); |
310 | + guint iVal = g_value_get_uint(&gVal); | ||
311 | + g_value_unset(&gVal); | ||
281 | 312 | ||
282 | - if(g_value_get_uint(&gVal) == value) | 313 | + if(iVal == value) |
283 | { | 314 | { |
284 | gtk_combo_box_set_active_iter(widget->input.combos[combo],&iter); | 315 | gtk_combo_box_set_active_iter(widget->input.combos[combo],&iter); |
285 | break; | 316 | break; |
@@ -287,7 +318,6 @@ static void load(GtkWidget *w, GtkWidget *terminal) | @@ -287,7 +318,6 @@ static void load(GtkWidget *w, GtkWidget *terminal) | ||
287 | 318 | ||
288 | } while(gtk_tree_model_iter_next(model,&iter)); | 319 | } while(gtk_tree_model_iter_next(model,&iter)); |
289 | 320 | ||
290 | - g_value_unset(&gVal); | ||
291 | 321 | ||
292 | } | 322 | } |
293 | 323 | ||
@@ -312,47 +342,58 @@ static void V3270HostSelectWidget_class_init(G_GNUC_UNUSED V3270HostSelectWidget | @@ -312,47 +342,58 @@ static void V3270HostSelectWidget_class_init(G_GNUC_UNUSED V3270HostSelectWidget | ||
312 | 342 | ||
313 | static void V3270HostSelectWidget_init(V3270HostSelectWidget *widget) | 343 | static void V3270HostSelectWidget_init(V3270HostSelectWidget *widget) |
314 | { | 344 | { |
315 | - int f; | ||
316 | - | ||
317 | - // Entry fields | ||
318 | - GtkWidget * label[ENTRY_COUNT] = | 345 | + // Connection properties |
346 | + GtkWidget * connection = gtk_grid_new(); | ||
347 | + gtk_grid_set_row_spacing(GTK_GRID(connection),6); | ||
348 | + gtk_grid_set_column_spacing(GTK_GRID(connection),12); | ||
349 | + | ||
350 | + gtk_grid_attach( | ||
351 | + GTK_GRID(widget), | ||
352 | + v3270_dialog_create_frame(connection,_("Connection")), | ||
353 | + 0,0,10,5 | ||
354 | + ); | ||
355 | + | ||
356 | + // Emulation properties | ||
357 | + GtkWidget * emulation = gtk_grid_new(); | ||
358 | + gtk_grid_set_row_spacing(GTK_GRID(emulation),6); | ||
359 | + gtk_grid_set_column_spacing(GTK_GRID(emulation),12); | ||
360 | + | ||
361 | + gtk_grid_attach( | ||
362 | + GTK_GRID(widget), | ||
363 | + v3270_dialog_create_frame(emulation,_("Emulation")), | ||
364 | + 0,6,10,5 | ||
365 | + ); | ||
366 | + | ||
367 | + // Entry fields | ||
319 | { | 368 | { |
320 | - gtk_label_new_with_mnemonic( _( "_Host" ) ), | ||
321 | - gtk_label_new_with_mnemonic( _( "_Service" ) ) | ||
322 | - }; | 369 | + size_t entry; |
323 | 370 | ||
324 | - for(f=0;f<ENTRY_COUNT;f++) | ||
325 | - { | ||
326 | - widget->input.entry[f] = GTK_ENTRY(gtk_entry_new()); | ||
327 | - gtk_widget_set_halign(label[f],GTK_ALIGN_END); | ||
328 | - gtk_label_set_mnemonic_widget(GTK_LABEL(label[f]),GTK_WIDGET(widget->input.entry[f])); | ||
329 | - } | ||
330 | - | ||
331 | - gtk_widget_set_tooltip_text(GTK_WIDGET(widget->input.entry[ENTRY_HOSTNAME]),_("Address or name of the host to connect.") ); | ||
332 | - gtk_widget_set_tooltip_text(GTK_WIDGET(widget->input.entry[ENTRY_SRVCNAME]),_("Port or service name (empty for \"telnet\").") ); | ||
333 | - | ||
334 | - gtk_entry_set_max_length(widget->input.entry[ENTRY_HOSTNAME],0xFF); | ||
335 | - gtk_entry_set_width_chars(widget->input.entry[ENTRY_HOSTNAME],50); | 371 | + for(entry = 0; entry < G_N_ELEMENTS(entryfields); entry++) |
372 | + { | ||
373 | + widget->input.entry[entry] = GTK_ENTRY(gtk_entry_new()); | ||
336 | 374 | ||
337 | - gtk_entry_set_max_length(widget->input.entry[ENTRY_SRVCNAME],6); | ||
338 | - gtk_entry_set_width_chars(widget->input.entry[ENTRY_SRVCNAME],7); | 375 | + gtk_entry_set_max_length(widget->input.entry[entry],entryfields[entry].max_length); |
376 | + gtk_entry_set_width_chars(widget->input.entry[entry],entryfields[entry].width_chars); | ||
339 | 377 | ||
340 | - gtk_entry_set_placeholder_text(widget->input.entry[ENTRY_SRVCNAME],"telnet"); | 378 | + v3270_grid_attach( |
379 | + GTK_GRID(connection), | ||
380 | + (struct v3270_entry_field *) & entryfields[entry], | ||
381 | + GTK_WIDGET(widget->input.entry[entry]) | ||
382 | + ); | ||
341 | 383 | ||
342 | - gtk_widget_set_hexpand(GTK_WIDGET(widget->input.entry[ENTRY_HOSTNAME]),TRUE); | 384 | + } |
343 | 385 | ||
344 | - gtk_grid_attach(GTK_GRID(widget),label[0],0,0,1,1); | ||
345 | - gtk_grid_attach(GTK_GRID(widget),GTK_WIDGET(widget->input.entry[ENTRY_HOSTNAME]),1,0,5,1); | 386 | + gtk_entry_set_placeholder_text(widget->input.entry[ENTRY_SRVCNAME],"telnet"); |
387 | + gtk_widget_set_hexpand(GTK_WIDGET(widget->input.entry[ENTRY_HOSTNAME]),TRUE); | ||
346 | 388 | ||
347 | - gtk_grid_attach(GTK_GRID(widget),label[1],0,1,1,1); | ||
348 | - gtk_grid_attach(GTK_GRID(widget),GTK_WIDGET(widget->input.entry[ENTRY_SRVCNAME]),1,1,1,1); | 389 | + } |
349 | 390 | ||
350 | // SSL checkbox | 391 | // SSL checkbox |
351 | { | 392 | { |
352 | widget->input.ssl = GTK_TOGGLE_BUTTON(gtk_check_button_new_with_mnemonic(_( "_Secure connection." ))); | 393 | widget->input.ssl = GTK_TOGGLE_BUTTON(gtk_check_button_new_with_mnemonic(_( "_Secure connection." ))); |
353 | gtk_widget_set_tooltip_text(GTK_WIDGET(widget->input.ssl),_( "Check for SSL secure connection." )); | 394 | gtk_widget_set_tooltip_text(GTK_WIDGET(widget->input.ssl),_( "Check for SSL secure connection." )); |
354 | gtk_widget_set_halign(GTK_WIDGET(widget->input.ssl),GTK_ALIGN_START); | 395 | gtk_widget_set_halign(GTK_WIDGET(widget->input.ssl),GTK_ALIGN_START); |
355 | - gtk_grid_attach(GTK_GRID(widget),GTK_WIDGET(widget->input.ssl),3,1,1,1); | 396 | + gtk_grid_attach(GTK_GRID(connection),GTK_WIDGET(widget->input.ssl),3,1,1,1); |
356 | } | 397 | } |
357 | 398 | ||
358 | // Create combo boxes | 399 | // Create combo boxes |
@@ -380,10 +421,7 @@ static void V3270HostSelectWidget_init(V3270HostSelectWidget *widget) | @@ -380,10 +421,7 @@ static void V3270HostSelectWidget_init(V3270HostSelectWidget *widget) | ||
380 | gtk_list_store_set((GtkListStore *) model, &iter, 0, gettext(combos[combo].labels[item]), 1, combos[combo].values[item], -1); | 421 | gtk_list_store_set((GtkListStore *) model, &iter, 0, gettext(combos[combo].labels[item]), 1, combos[combo].values[item], -1); |
381 | } | 422 | } |
382 | 423 | ||
383 | - GtkWidget *label = gtk_label_new_with_mnemonic(gettext(combos[combo].label)); | ||
384 | - gtk_widget_set_halign(label,GTK_ALIGN_END); | ||
385 | - gtk_grid_attach(GTK_GRID(widget),label,combos[combo].left,combos[combo].top,1,1); | ||
386 | - gtk_grid_attach(GTK_GRID(widget),GTK_WIDGET(widget->input.combos[combo]),combos[combo].left+1,combos[combo].top,2,1); | 424 | + v3270_grid_attach(GTK_GRID(emulation), (struct v3270_entry_field *) & combos[combo], GTK_WIDGET(widget->input.combos[combo])); |
387 | 425 | ||
388 | } | 426 | } |
389 | 427 | ||
@@ -397,7 +435,7 @@ LIB3270_EXPORT GtkWidget * v3270_host_select_new() | @@ -397,7 +435,7 @@ LIB3270_EXPORT GtkWidget * v3270_host_select_new() | ||
397 | { | 435 | { |
398 | V3270Settings * settings = GTK_V3270_SETTINGS(g_object_new(GTK_TYPE_V3270HostSelectWidget, NULL)); | 436 | V3270Settings * settings = GTK_V3270_SETTINGS(g_object_new(GTK_TYPE_V3270HostSelectWidget, NULL)); |
399 | 437 | ||
400 | - settings->title = _("Host definition"); | 438 | + settings->title = _("Host properties"); |
401 | settings->label = _("Host"); | 439 | settings->label = _("Host"); |
402 | 440 | ||
403 | return GTK_WIDGET(settings); | 441 | return GTK_WIDGET(settings); |
src/dialogs/tools.c
@@ -172,4 +172,18 @@ | @@ -172,4 +172,18 @@ | ||
172 | 172 | ||
173 | } | 173 | } |
174 | 174 | ||
175 | + void v3270_grid_attach(GtkGrid *grid, const struct v3270_entry_field * description, GtkWidget *widget) | ||
176 | + { | ||
177 | + GtkWidget *label = gtk_label_new_with_mnemonic(gettext(description->label)); | ||
178 | + gtk_label_set_mnemonic_widget(GTK_LABEL(label),widget); | ||
179 | + | ||
180 | + gtk_widget_set_halign(label,GTK_ALIGN_END); | ||
181 | + gtk_grid_attach(grid,label,description->left,description->top,1,1); | ||
182 | + gtk_grid_attach(grid,widget,description->left+1,description->top,description->width,description->height); | ||
183 | + | ||
184 | + if(description->tooltip) | ||
185 | + gtk_widget_set_tooltip_markup(widget,gettext(description->tooltip)); | ||
186 | + | ||
187 | + } | ||
188 | + | ||
175 | 189 |
src/include/internals.h
@@ -57,6 +57,21 @@ | @@ -57,6 +57,21 @@ | ||
57 | unsigned short attr; ///< @brief Character attribute. | 57 | unsigned short attr; ///< @brief Character attribute. |
58 | }; | 58 | }; |
59 | 59 | ||
60 | + | ||
61 | +/// @brief Head for settings widgets. | ||
62 | +#define ENTRY_FIELD_HEAD \ | ||
63 | + gint left; \ | ||
64 | + gint top; \ | ||
65 | + gint width; \ | ||
66 | + gint height; \ | ||
67 | + const gchar * label; \ | ||
68 | + const gchar * tooltip; | ||
69 | + | ||
70 | + struct v3270_entry_field | ||
71 | + { | ||
72 | + ENTRY_FIELD_HEAD | ||
73 | + }; | ||
74 | + | ||
60 | /*--[ Signals ]--------------------------------------------------------------------------------------*/ | 75 | /*--[ Signals ]--------------------------------------------------------------------------------------*/ |
61 | 76 | ||
62 | /// @brief V3270 Signal list | 77 | /// @brief V3270 Signal list |
@@ -134,6 +149,9 @@ | @@ -134,6 +149,9 @@ | ||
134 | G_GNUC_INTERNAL GtkWidget * v3270_dialog_button_new(GtkWidget *dialog, const gchar *mnemonic, GCallback callback); | 149 | G_GNUC_INTERNAL GtkWidget * v3270_dialog_button_new(GtkWidget *dialog, const gchar *mnemonic, GCallback callback); |
135 | #endif // ! GTK 3.12 | 150 | #endif // ! GTK 3.12 |
136 | 151 | ||
152 | + G_GNUC_INTERNAL void v3270_grid_attach(GtkGrid *grid, const struct v3270_entry_field * description, GtkWidget *widget); | ||
153 | + | ||
154 | + | ||
137 | // Toggle button widget | 155 | // Toggle button widget |
138 | #define GTK_TYPE_V3270_TOGGLE_BUTTON (V3270ToggleButton_get_type ()) | 156 | #define GTK_TYPE_V3270_TOGGLE_BUTTON (V3270ToggleButton_get_type ()) |
139 | #define GTK_V3270_TOGGLE_BUTTON(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GTK_TYPE_V3270_TOGGLE_BUTTON, V3270ToggleButton)) | 157 | #define GTK_V3270_TOGGLE_BUTTON(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GTK_TYPE_V3270_TOGGLE_BUTTON, V3270ToggleButton)) |