Commit 8a99c3c74019612996ebb856e30866c52eaa2497
1 parent
d8c13e00
Exists in
master
and in
1 other branch
Refactoring host selection widget.
Showing
2 changed files
with
141 additions
and
95 deletions
Show diff stats
src/dialogs/hostselect.c
... | ... | @@ -35,6 +35,7 @@ |
35 | 35 | |
36 | 36 | /*--[ Widget definition ]----------------------------------------------------------------------------*/ |
37 | 37 | |
38 | +/* | |
38 | 39 | static const struct _colortable |
39 | 40 | { |
40 | 41 | unsigned short colors; |
... | ... | @@ -45,6 +46,7 @@ |
45 | 46 | { 8, N_( "8 colors" ) }, |
46 | 47 | { 2, N_( "Monochrome" ) }, |
47 | 48 | }; |
49 | + */ | |
48 | 50 | |
49 | 51 | enum _entry |
50 | 52 | { |
... | ... | @@ -54,7 +56,101 @@ |
54 | 56 | ENTRY_COUNT |
55 | 57 | }; |
56 | 58 | |
57 | - static const gchar *comboLabel[] = { N_("System _type"), N_("_Color table") }; | |
59 | + static const struct Combos | |
60 | + { | |
61 | + gint top; | |
62 | + gint left; | |
63 | + const gchar * label; | |
64 | + const gchar * tooltip; | |
65 | + const unsigned int * values; | |
66 | + const gchar **labels; | |
67 | + | |
68 | + unsigned int (*get)(const H3270 *); | |
69 | + int (*set)(H3270 *, unsigned int); | |
70 | + | |
71 | + } combos[] = | |
72 | + { | |
73 | + { | |
74 | + .top = 2, | |
75 | + .left = 0, | |
76 | + | |
77 | + .label = N_("System _type"), | |
78 | + .get = (unsigned int (*)(const H3270 *)) lib3270_get_host_type, | |
79 | + .set = (int (*)(H3270 *, unsigned int)) lib3270_set_host_type, | |
80 | + | |
81 | + .values = (const unsigned int []) | |
82 | + { | |
83 | + LIB3270_HOST_S390, | |
84 | + LIB3270_HOST_AS400, | |
85 | + LIB3270_HOST_TSO, | |
86 | + 0, | |
87 | + }, | |
88 | + | |
89 | + .labels = (const gchar *[]) | |
90 | + { | |
91 | + N_( "IBM S/390" ), | |
92 | + N_( "IBM AS/400" ), | |
93 | + N_( "Other (TSO)" ), | |
94 | + N_( "Other (VM/CMS)" ), | |
95 | + NULL | |
96 | + } | |
97 | + | |
98 | + }, | |
99 | + { | |
100 | + .top = 2, | |
101 | + .left = 3, | |
102 | + | |
103 | + .label = N_("_Color table"), | |
104 | + .get = lib3270_get_color_type, | |
105 | + .set = lib3270_set_color_type, | |
106 | + | |
107 | + .values = (const unsigned int []) | |
108 | + { | |
109 | + 0, | |
110 | + 2, | |
111 | + 8, | |
112 | + 16, | |
113 | + }, | |
114 | + | |
115 | + .labels = (const gchar *[]) | |
116 | + { | |
117 | + N_( "System default"), | |
118 | + N_( "Monochrome" ), | |
119 | + N_( "8 colors" ), | |
120 | + N_( "16 colors" ), | |
121 | + NULL | |
122 | + } | |
123 | + | |
124 | + }, | |
125 | + { | |
126 | + .top = 3, | |
127 | + .left = 0, | |
128 | + | |
129 | + .label = N_("_Model"), | |
130 | + .tooltip = N_("The model of 3270 display to be emulated"), | |
131 | + | |
132 | + .get = lib3270_get_model_number, | |
133 | + .set = lib3270_set_model_number, | |
134 | + | |
135 | + .values = (const unsigned int []) | |
136 | + { | |
137 | + 2, | |
138 | + 3, | |
139 | + 4, | |
140 | + 5 | |
141 | + }, | |
142 | + | |
143 | + .labels = (const gchar *[]) | |
144 | + { | |
145 | + N_( "Model 2 - 80x24" ), | |
146 | + N_( "Model 3 - 80x32" ), | |
147 | + N_( "Model 4 - 80x43" ), | |
148 | + N_( "Model 5 - 132x27" ), | |
149 | + NULL | |
150 | + } | |
151 | + | |
152 | + } | |
153 | + }; | |
58 | 154 | |
59 | 155 | struct _V3270HostSelectWidget |
60 | 156 | { |
... | ... | @@ -64,7 +160,7 @@ |
64 | 160 | { |
65 | 161 | GtkEntry * entry[ENTRY_COUNT]; /**< @brief Entry fields for host & service name */ |
66 | 162 | GtkToggleButton * ssl; /**< @brief SSL Connection? */ |
67 | - GtkComboBox * combo[G_N_ELEMENTS(comboLabel)]; /**< @brief Model & Color combobox */ | |
163 | + GtkComboBox * combos[G_N_ELEMENTS(combos)]; /**< @brief Combo-boxes */ | |
68 | 164 | |
69 | 165 | } input; |
70 | 166 | |
... | ... | @@ -103,39 +199,22 @@ static void apply(GtkWidget *w, GtkWidget *terminal) |
103 | 199 | |
104 | 200 | } |
105 | 201 | |
106 | - // Apply Host type | |
202 | + // Apply combos. | |
203 | + size_t combo; | |
204 | + for(combo = 0; combo < G_N_ELEMENTS(combos); combo++) | |
107 | 205 | { |
108 | 206 | GtkTreeIter iter; |
109 | 207 | |
110 | - if(gtk_combo_box_get_active_iter(GTK_COMBO_BOX(widget->input.combo[0]), &iter)) | |
208 | + if(gtk_combo_box_get_active_iter(GTK_COMBO_BOX(widget->input.combos[combo]), &iter)) | |
111 | 209 | { |
112 | 210 | GValue value = { 0, }; |
113 | - gtk_tree_model_get_value(gtk_combo_box_get_model(GTK_COMBO_BOX(widget->input.combo[0])),&iter,1,&value); | |
211 | + gtk_tree_model_get_value(gtk_combo_box_get_model(GTK_COMBO_BOX(widget->input.combos[combo])),&iter,1,&value); | |
114 | 212 | |
115 | - lib3270_set_host_type(hSession,g_value_get_int(&value)); | |
213 | + combos[combo].set(hSession,g_value_get_uint(&value)); | |
116 | 214 | |
117 | 215 | g_value_unset(&value); |
118 | 216 | |
119 | 217 | } |
120 | - | |
121 | - } | |
122 | - | |
123 | - // Apply color type | |
124 | - { | |
125 | - GtkTreeIter iter; | |
126 | - | |
127 | - if(gtk_combo_box_get_active_iter(GTK_COMBO_BOX(widget->input.combo[1]), &iter)) | |
128 | - { | |
129 | - GValue value = { 0, }; | |
130 | - | |
131 | - gtk_tree_model_get_value(gtk_combo_box_get_model(GTK_COMBO_BOX(widget->input.combo[1])),&iter,1,&value); | |
132 | - | |
133 | - lib3270_set_color_type(hSession,g_value_get_int(&value)); | |
134 | - | |
135 | - g_value_unset(&value); | |
136 | - | |
137 | - } | |
138 | - | |
139 | 218 | } |
140 | 219 | |
141 | 220 | } |
... | ... | @@ -184,53 +263,34 @@ static void load(GtkWidget *w, GtkWidget *terminal) |
184 | 263 | |
185 | 264 | } |
186 | 265 | |
187 | - LIB3270_HOST_TYPE type = lib3270_get_host_type(hSession); | |
188 | - | |
189 | - // Set host type | |
266 | + size_t combo; | |
267 | + for(combo = 0; combo < G_N_ELEMENTS(combos); combo++) | |
190 | 268 | { |
191 | - GtkTreeModel * model = gtk_combo_box_get_model(widget->input.combo[0]); | |
269 | + | |
270 | + GtkTreeModel * model = gtk_combo_box_get_model(widget->input.combos[combo]); | |
192 | 271 | GtkTreeIter iter; |
272 | + unsigned int value = combos[combo].get(hSession); | |
193 | 273 | |
194 | 274 | if(gtk_tree_model_get_iter_first(model,&iter)) |
195 | 275 | { |
276 | + GValue gVal = { 0, }; | |
277 | + | |
196 | 278 | do |
197 | 279 | { |
198 | - GValue value = { 0, }; | |
280 | + gtk_tree_model_get_value(model,&iter,1,&gVal); | |
199 | 281 | |
200 | - gtk_tree_model_get_value(model,&iter,1,&value); | |
201 | - | |
202 | - if(g_value_get_int(&value) == (int) type) | |
282 | + if(g_value_get_uint(&gVal) == value) | |
203 | 283 | { |
204 | - gtk_combo_box_set_active_iter(widget->input.combo[0],&iter); | |
284 | + gtk_combo_box_set_active_iter(widget->input.combos[combo],&iter); | |
205 | 285 | break; |
206 | 286 | } |
207 | 287 | |
208 | 288 | } while(gtk_tree_model_iter_next(model,&iter)); |
209 | - } | |
210 | - } | |
211 | - | |
212 | - // Set color type | |
213 | - { | |
214 | - GtkTreeModel * model = gtk_combo_box_get_model(widget->input.combo[1]); | |
215 | - GtkTreeIter iter; | |
216 | - int colors = (int) lib3270_get_color_type(hSession); | |
217 | 289 | |
218 | - if(gtk_tree_model_get_iter_first(model,&iter)) | |
219 | - { | |
220 | - do | |
221 | - { | |
222 | - GValue value = { 0, }; | |
290 | + g_value_unset(&gVal); | |
223 | 291 | |
224 | - gtk_tree_model_get_value(model,&iter,1,&value); | |
225 | - | |
226 | - if(g_value_get_int(&value) == colors) | |
227 | - { | |
228 | - gtk_combo_box_set_active_iter(widget->input.combo[1],&iter); | |
229 | - break; | |
230 | - } | |
231 | - | |
232 | - } while(gtk_tree_model_iter_next(model,&iter)); | |
233 | 292 | } |
293 | + | |
234 | 294 | } |
235 | 295 | |
236 | 296 | } |
... | ... | @@ -291,56 +351,42 @@ static void V3270HostSelectWidget_init(V3270HostSelectWidget *widget) |
291 | 351 | { |
292 | 352 | widget->input.ssl = GTK_TOGGLE_BUTTON(gtk_check_button_new_with_mnemonic(_( "_Secure connection." ))); |
293 | 353 | gtk_widget_set_tooltip_text(GTK_WIDGET(widget->input.ssl),_( "Check for SSL secure connection." )); |
294 | - | |
354 | + gtk_widget_set_halign(GTK_WIDGET(widget->input.ssl),GTK_ALIGN_START); | |
295 | 355 | gtk_grid_attach(GTK_GRID(widget),GTK_WIDGET(widget->input.ssl),3,1,1,1); |
296 | 356 | } |
297 | 357 | |
298 | - // Host type | |
358 | + // Create combo boxes | |
299 | 359 | { |
300 | - GtkTreeModel * model = (GtkTreeModel *) gtk_list_store_new(2,G_TYPE_STRING,G_TYPE_INT); | |
301 | 360 | GtkCellRenderer * renderer = gtk_cell_renderer_text_new(); |
302 | 361 | |
303 | - widget->input.combo[0] = GTK_COMBO_BOX(gtk_combo_box_new_with_model(model)); | |
362 | + size_t combo, item; | |
304 | 363 | |
305 | - gtk_cell_layout_pack_start(GTK_CELL_LAYOUT(widget->input.combo[0]), renderer, TRUE); | |
306 | - gtk_cell_layout_set_attributes(GTK_CELL_LAYOUT(widget->input.combo[0]), renderer, "text", 0, NULL); | |
364 | + for(combo = 0; combo < G_N_ELEMENTS(combos); combo++) { | |
307 | 365 | |
308 | - const LIB3270_HOST_TYPE_ENTRY *entry = lib3270_get_option_list(); | |
309 | - for(f=0;entry[f].name != NULL;f++) | |
310 | - { | |
311 | - GtkTreeIter iter; | |
312 | - gtk_list_store_append((GtkListStore *) model,&iter); | |
313 | - gtk_list_store_set((GtkListStore *) model, &iter, 0, gettext(entry[f].description), 1, entry[f].type, -1); | |
314 | - } | |
366 | + GtkTreeModel * model = (GtkTreeModel *) gtk_list_store_new(2,G_TYPE_STRING,G_TYPE_UINT); | |
315 | 367 | |
316 | - } | |
368 | + widget->input.combos[combo] = GTK_COMBO_BOX(gtk_combo_box_new_with_model(model)); | |
317 | 369 | |
318 | - // Color table | |
319 | - { | |
320 | - GtkTreeModel * model = (GtkTreeModel *) gtk_list_store_new(2,G_TYPE_STRING,G_TYPE_INT); | |
321 | - GtkCellRenderer * renderer = gtk_cell_renderer_text_new(); | |
370 | + if(combos[combo].tooltip) | |
371 | + gtk_widget_set_tooltip_markup(GTK_WIDGET(widget->input.combos[combo]),combos[combo].tooltip); | |
322 | 372 | |
323 | - widget->input.combo[1] = GTK_COMBO_BOX(gtk_combo_box_new_with_model(model)); | |
373 | + gtk_cell_layout_pack_start(GTK_CELL_LAYOUT(widget->input.combos[combo]), renderer, TRUE); | |
374 | + gtk_cell_layout_set_attributes(GTK_CELL_LAYOUT(widget->input.combos[combo]), renderer, "text", 0, NULL); | |
324 | 375 | |
325 | - gtk_cell_layout_pack_start(GTK_CELL_LAYOUT(widget->input.combo[1]), renderer, TRUE); | |
326 | - gtk_cell_layout_set_attributes(GTK_CELL_LAYOUT(widget->input.combo[1]), renderer, "text", 0, NULL); | |
376 | + for(item = 0; combos[combo].labels[item]; item++) | |
377 | + { | |
378 | + GtkTreeIter iter; | |
379 | + gtk_list_store_append((GtkListStore *) model, &iter); | |
380 | + gtk_list_store_set((GtkListStore *) model, &iter, 0, gettext(combos[combo].labels[item]), 1, combos[combo].values[item], -1); | |
381 | + } | |
327 | 382 | |
328 | - for(f=0;f< (int) G_N_ELEMENTS(colortable);f++) | |
329 | - { | |
330 | - GtkTreeIter iter; | |
331 | - gtk_list_store_append((GtkListStore *) model,&iter); | |
332 | - gtk_list_store_set((GtkListStore *) model, &iter, 0, gettext(colortable[f].description), 1, colortable[f].colors, -1); | |
333 | - } | |
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); | |
334 | 387 | |
335 | - } | |
388 | + } | |
336 | 389 | |
337 | - // Host options | |
338 | - for(f=0;f< (int) G_N_ELEMENTS(comboLabel);f++) | |
339 | - { | |
340 | - GtkWidget *label = gtk_label_new_with_mnemonic(gettext(comboLabel[f])); | |
341 | - gtk_widget_set_halign(label,GTK_ALIGN_END); | |
342 | - gtk_grid_attach(GTK_GRID(widget),label,0,f+2,1,1); | |
343 | - gtk_grid_attach(GTK_GRID(widget),GTK_WIDGET(widget->input.combo[f]),1,f+2,2,1); | |
344 | 390 | } |
345 | 391 | |
346 | 392 | gtk_widget_show_all(GTK_WIDGET(widget)); | ... | ... |
src/dialogs/settings/dialog.c
... | ... | @@ -137,7 +137,7 @@ static void dispose(GObject *object) |
137 | 137 | { |
138 | 138 | debug("%s",__FUNCTION__); |
139 | 139 | |
140 | - V3270SettingsDialog * widget = GTK_V3270_SETTINGS_DIALOG(object); | |
140 | +// V3270SettingsDialog * widget = GTK_V3270_SETTINGS_DIALOG(object); | |
141 | 141 | |
142 | 142 | |
143 | 143 | G_OBJECT_CLASS(V3270SettingsDialog_parent_class)->dispose(object); |
... | ... | @@ -229,19 +229,19 @@ void v3270_settings_dialog_set_terminal_widget(GtkWidget *widget, GtkWidget *ter |
229 | 229 | ); |
230 | 230 | } |
231 | 231 | |
232 | -void v3270_setttings_dialog_response(GtkDialog *dialog, gint response_id, GtkWidget *terminal) | |
232 | +void v3270_setttings_dialog_response(GtkDialog *dialog, gint response_id, GtkWidget G_GNUC_UNUSED(*terminal)) | |
233 | 233 | { |
234 | 234 | switch(response_id) |
235 | 235 | { |
236 | 236 | case GTK_RESPONSE_APPLY: |
237 | 237 | debug("%s:apply",__FUNCTION__); |
238 | - v3270_settings_dialog_apply(dialog); | |
238 | + v3270_settings_dialog_apply(GTK_WIDGET(dialog)); | |
239 | 239 | break; |
240 | 240 | |
241 | 241 | case GTK_RESPONSE_CANCEL: |
242 | 242 | case GTK_RESPONSE_DELETE_EVENT: |
243 | 243 | debug("%s:cancel",__FUNCTION__); |
244 | - v3270_settings_dialog_revert(dialog); | |
244 | + v3270_settings_dialog_revert(GTK_WIDGET(dialog)); | |
245 | 245 | break; |
246 | 246 | |
247 | 247 | default: | ... | ... |