Commit 528ccfbfcf18a2f1fe2bdb5cfca7626fa2596a2f
1 parent
953d553a
Exists in
master
and in
1 other branch
Disabling "apply" button when host & service name are not set on host
properties widget.
Showing
2 changed files
with
54 additions
and
68 deletions
Show diff stats
src/dialogs/settings/host.c
@@ -317,28 +317,60 @@ static void V3270HostSelectWidget_class_init(G_GNUC_UNUSED V3270HostSelectWidget | @@ -317,28 +317,60 @@ static void V3270HostSelectWidget_class_init(G_GNUC_UNUSED V3270HostSelectWidget | ||
317 | 317 | ||
318 | } | 318 | } |
319 | 319 | ||
320 | -static void oversize_changed(GtkEditable *editable, GtkWidget *settings) | ||
321 | -{ | 320 | +static gboolean oversize_validate(GtkEditable *editable) { |
321 | + | ||
322 | const gchar * chars = gtk_editable_get_chars(editable,0,-1); | 322 | const gchar * chars = gtk_editable_get_chars(editable,0,-1); |
323 | - gboolean valid = TRUE; | ||
324 | - char junk; | ||
325 | - unsigned int ovc = 0, ovr = 0; | ||
326 | 323 | ||
327 | - if(*chars) | ||
328 | - { | 324 | + if(*chars) { |
325 | + char junk; | ||
326 | + unsigned int ovc = 0, ovr = 0; | ||
327 | + | ||
329 | if(sscanf(chars, "%ux%u%c", &ovc, &ovr, &junk) != 2) | 328 | if(sscanf(chars, "%ux%u%c", &ovc, &ovr, &junk) != 2) |
330 | - { | ||
331 | - valid = FALSE; | ||
332 | - debug("Can't parse \"%s\"",chars); | ||
333 | - } | ||
334 | - else if( (ovc * ovr) > 0x4000) | ||
335 | - { | ||
336 | - valid = FALSE; | ||
337 | - debug("Invalid values on \"%s\"",chars); | ||
338 | - } | 329 | + return FALSE; |
330 | + | ||
331 | + if( (ovc * ovr) > 0x4000) | ||
332 | + return FALSE; | ||
333 | + | ||
339 | } | 334 | } |
340 | 335 | ||
341 | - v3270_settings_set_valid(settings,valid); | 336 | + return TRUE; |
337 | +} | ||
338 | + | ||
339 | +static void update_valid(V3270HostSelectWidget *settings, gboolean valid) { | ||
340 | + | ||
341 | + if(valid) { | ||
342 | + | ||
343 | + // Check required inputs. | ||
344 | + | ||
345 | + static const int required[] = { ENTRY_HOSTNAME, ENTRY_SRVCNAME }; | ||
346 | + size_t ix; | ||
347 | + | ||
348 | + for(ix = 0; ix < G_N_ELEMENTS(required); ix++) { | ||
349 | + const gchar * chars = gtk_editable_get_chars(GTK_EDITABLE(settings->input.entry[required[ix]]),0,-1); | ||
350 | + if(!*chars) { | ||
351 | + valid = FALSE; | ||
352 | + break; | ||
353 | + } | ||
354 | + } | ||
355 | + } | ||
356 | + | ||
357 | + if(valid) { | ||
358 | + valid = oversize_validate(GTK_EDITABLE(settings->input.entry[ENTRY_OVERSIZE])); | ||
359 | + } | ||
360 | + | ||
361 | + v3270_settings_set_valid(GTK_WIDGET(settings),valid); | ||
362 | + | ||
363 | +} | ||
364 | + | ||
365 | +static void required_changed(GtkEditable *editable, GtkWidget *settings) { | ||
366 | + | ||
367 | + const gchar * chars = gtk_editable_get_chars(editable,0,-1); | ||
368 | + update_valid(GTK_V3270HostSelectWidget(settings),(*chars ? TRUE : FALSE)); | ||
369 | + | ||
370 | +} | ||
371 | + | ||
372 | +static void oversize_changed(GtkEditable *editable, GtkWidget *settings) { | ||
373 | + update_valid(GTK_V3270HostSelectWidget(settings), oversize_validate(editable)); | ||
342 | } | 374 | } |
343 | 375 | ||
344 | static void remap_file_changed(GtkEditable *editable, V3270HostSelectWidget *settings) | 376 | static void remap_file_changed(GtkEditable *editable, V3270HostSelectWidget *settings) |
@@ -454,24 +486,6 @@ static void V3270HostSelectWidget_init(V3270HostSelectWidget *widget) | @@ -454,24 +486,6 @@ static void V3270HostSelectWidget_init(V3270HostSelectWidget *widget) | ||
454 | { | 486 | { |
455 | v3270_settings_create_entry_fields(entryfields, G_N_ELEMENTS(entryfields), grids, widget->input.entry); | 487 | v3270_settings_create_entry_fields(entryfields, G_N_ELEMENTS(entryfields), grids, widget->input.entry); |
456 | 488 | ||
457 | - /* | ||
458 | - size_t entry; | ||
459 | - | ||
460 | - for(entry = 0; entry < G_N_ELEMENTS(entryfields); entry++) | ||
461 | - { | ||
462 | - widget->input.entry[entry] = GTK_ENTRY(gtk_entry_new()); | ||
463 | - gtk_entry_set_max_length(widget->input.entry[entry],entryfields[entry].max_length); | ||
464 | - gtk_entry_set_width_chars(widget->input.entry[entry],entryfields[entry].width_chars); | ||
465 | - | ||
466 | - v3270_grid_attach( | ||
467 | - GTK_GRID(grids[entryfields[entry].grid]), | ||
468 | - (struct v3270_entry_field *) & entryfields[entry], | ||
469 | - GTK_WIDGET(widget->input.entry[entry]) | ||
470 | - ); | ||
471 | - | ||
472 | - } | ||
473 | - */ | ||
474 | - | ||
475 | // Custom settings | 489 | // Custom settings |
476 | gtk_entry_set_placeholder_text(widget->input.entry[ENTRY_SRVCNAME],"telnet"); | 490 | gtk_entry_set_placeholder_text(widget->input.entry[ENTRY_SRVCNAME],"telnet"); |
477 | 491 | ||
@@ -486,6 +500,8 @@ static void V3270HostSelectWidget_init(V3270HostSelectWidget *widget) | @@ -486,6 +500,8 @@ static void V3270HostSelectWidget_init(V3270HostSelectWidget *widget) | ||
486 | g_signal_connect(G_OBJECT(widget->input.entry[ENTRY_REMAP_FILE]),"changed",G_CALLBACK(remap_file_changed),widget); | 500 | g_signal_connect(G_OBJECT(widget->input.entry[ENTRY_REMAP_FILE]),"changed",G_CALLBACK(remap_file_changed),widget); |
487 | 501 | ||
488 | g_signal_connect(G_OBJECT(widget->input.entry[ENTRY_OVERSIZE]),"changed",G_CALLBACK(oversize_changed),widget); | 502 | g_signal_connect(G_OBJECT(widget->input.entry[ENTRY_OVERSIZE]),"changed",G_CALLBACK(oversize_changed),widget); |
503 | + g_signal_connect(G_OBJECT(widget->input.entry[ENTRY_HOSTNAME]),"changed",G_CALLBACK(required_changed),widget); | ||
504 | + g_signal_connect(G_OBJECT(widget->input.entry[ENTRY_SRVCNAME]),"changed",G_CALLBACK(required_changed),widget); | ||
489 | 505 | ||
490 | } | 506 | } |
491 | 507 | ||
@@ -607,38 +623,6 @@ static void V3270HostSelectWidget_init(V3270HostSelectWidget *widget) | @@ -607,38 +623,6 @@ static void V3270HostSelectWidget_init(V3270HostSelectWidget *widget) | ||
607 | 623 | ||
608 | } | 624 | } |
609 | 625 | ||
610 | - | ||
611 | - /* | ||
612 | - // Create combo boxes | ||
613 | - { | ||
614 | - size_t combo, item; | ||
615 | - | ||
616 | - for(combo = 0; combo < G_N_ELEMENTS(combos); combo++) { | ||
617 | - | ||
618 | - | ||
619 | - widget->input.combos[combo] = GTK_COMBO_BOX(gtk_combo_box_new_with_model(model)); | ||
620 | - | ||
621 | - if(combos[combo].tooltip) | ||
622 | - gtk_widget_set_tooltip_markup(GTK_WIDGET(widget->input.combos[combo]),combos[combo].tooltip); | ||
623 | - | ||
624 | - gtk_cell_layout_pack_start(GTK_CELL_LAYOUT(widget->input.combos[combo]), text_renderer, TRUE); | ||
625 | - gtk_cell_layout_set_attributes(GTK_CELL_LAYOUT(widget->input.combos[combo]), text_renderer, "text", 0, NULL); | ||
626 | - | ||
627 | - for(item = 0; combos[combo].labels[item]; item++) | ||
628 | - { | ||
629 | - GtkTreeIter iter; | ||
630 | - gtk_list_store_append((GtkListStore *) model, &iter); | ||
631 | - gtk_list_store_set((GtkListStore *) model, &iter, 0, g_dgettext(GETTEXT_PACKAGE, combos[combo].labels[item]), 1, combos[combo].values[item], -1); | ||
632 | - } | ||
633 | - | ||
634 | - v3270_grid_attach(GTK_GRID(grids[EMULATION]), (struct v3270_entry_field *) & combos[combo], GTK_WIDGET(widget->input.combos[combo])); | ||
635 | - | ||
636 | - } | ||
637 | - | ||
638 | - } | ||
639 | - | ||
640 | - */ | ||
641 | - | ||
642 | gtk_widget_show_all(GTK_WIDGET(widget)); | 626 | gtk_widget_show_all(GTK_WIDGET(widget)); |
643 | 627 | ||
644 | } | 628 | } |
@@ -908,5 +892,7 @@ static void load(GtkWidget *w, GtkWidget *terminal) | @@ -908,5 +892,7 @@ static void load(GtkWidget *w, GtkWidget *terminal) | ||
908 | // Load unlock delay | 892 | // Load unlock delay |
909 | gtk_spin_button_set_value(widget->input.unlock_delay, lib3270_get_unlock_delay(hSession)); | 893 | gtk_spin_button_set_value(widget->input.unlock_delay, lib3270_get_unlock_delay(hSession)); |
910 | 894 | ||
895 | + update_valid(widget,TRUE); | ||
896 | + | ||
911 | } | 897 | } |
912 | 898 |
src/include/hostselect.h
@@ -45,7 +45,7 @@ | @@ -45,7 +45,7 @@ | ||
45 | 45 | ||
46 | G_BEGIN_DECLS | 46 | G_BEGIN_DECLS |
47 | 47 | ||
48 | -/*--[ Progress widget ]------------------------------------------------------------------------------*/ | 48 | +/*--[ Host selection dialog ]------------------------------------------------------------------------*/ |
49 | 49 | ||
50 | #define GTK_TYPE_V3270HostSelectWidget (V3270HostSelectWidget_get_type ()) | 50 | #define GTK_TYPE_V3270HostSelectWidget (V3270HostSelectWidget_get_type ()) |
51 | #define GTK_V3270HostSelectWidget(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GTK_TYPE_V3270HostSelectWidget, V3270HostSelectWidget)) | 51 | #define GTK_V3270HostSelectWidget(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GTK_TYPE_V3270HostSelectWidget, V3270HostSelectWidget)) |