Connect button is now non-sensitive when host and port (or tls) entry is empty. Pressing enter will now also NOT connect, when the entries are empty. --- Changes since v4 - Code cleanup. Removed useless variables. Changes since v3 - Changed required entries from HOST and PORT to HOST and (PORT or TLS-PORT) Changes since v2 - New patch - Split from the v2 patch as requested - Changed response type from GtkResponseType to gboolean --- src/spicy-connect.c | 32 +++++++++++++++++++++++++++----- 1 file changed, 27 insertions(+), 5 deletions(-) diff --git a/src/spicy-connect.c b/src/spicy-connect.c index c168c4d..12c3a01 100644 --- a/src/spicy-connect.c +++ b/src/spicy-connect.c @@ -44,6 +44,16 @@ static struct { { .text = N_("TLS Port"), .prop = "tls-port" }, }; +static gboolean can_connect(void) +{ + if ((gtk_entry_get_text_length(GTK_ENTRY(connect_entries[0].entry)) > 0) && + ((gtk_entry_get_text_length(GTK_ENTRY(connect_entries[1].entry)) > 0) || + (gtk_entry_get_text_length(GTK_ENTRY(connect_entries[2].entry)) > 0))) + return TRUE; + + return FALSE; +} + static void set_connection_info(SpiceSession *session) { const gchar *txt; @@ -65,6 +75,12 @@ static gboolean close_cb(gpointer data) return TRUE; } +static void entry_changed_cb(GtkEditable* entry, gpointer data) +{ + GtkButton *connect_button = data; + gtk_widget_set_sensitive(GTK_WIDGET(connect_button), can_connect()); +} + static gboolean entry_focus_in_cb(GtkWidget *widget, GdkEvent *event, gpointer data) { GtkRecentChooser *recent = GTK_RECENT_CHOOSER(data); @@ -124,11 +140,13 @@ static void recent_selection_changed_dialog_cb(GtkRecentChooser *chooser, gpoint static void connect_cb(gpointer data) { ConnectionInfo *info = data; - info->connecting = TRUE; - set_connection_info(info->session); - - if (g_main_loop_is_running(info->loop)) - g_main_loop_quit(info->loop); + if (can_connect()) + { + info->connecting = TRUE; + set_connection_info(info->session); + if (g_main_loop_is_running(info->loop)) + g_main_loop_quit(info->loop); + } } gboolean spicy_connect_dialog(SpiceSession *session) @@ -195,6 +213,8 @@ gboolean spicy_connect_dialog(SpiceSession *session) gtk_box_pack_start(main_box, GTK_WIDGET(button_box), FALSE, TRUE, 0); + gtk_widget_set_sensitive(GTK_WIDGET(connect_button), can_connect()); + g_signal_connect(window, "key-press-event", G_CALLBACK(key_pressed_cb), window); g_signal_connect_swapped(window, "delete-event", @@ -225,6 +245,8 @@ gboolean spicy_connect_dialog(SpiceSession *session) for (i = 0; i < SPICE_N_ELEMENTS(connect_entries); i++) { g_signal_connect_swapped(connect_entries[i].entry, "activate", G_CALLBACK(connect_cb), &info); + g_signal_connect(connect_entries[i].entry, "changed", + G_CALLBACK(entry_changed_cb), connect_button); #ifndef G_OS_WIN32 g_signal_connect(connect_entries[i].entry, "focus-in-event", G_CALLBACK(entry_focus_in_cb), recent); -- 2.4.3 _______________________________________________ Spice-devel mailing list Spice-devel@xxxxxxxxxxxxxxxxxxxxx http://lists.freedesktop.org/mailman/listinfo/spice-devel