[Spice-devel] [spicy PATCH 5/5 v3] spicy: Host and port entries are now required

Lukas Venhoda lvenhoda at redhat.com
Mon Jun 15 05:31:39 PDT 2015


Connect button is now non-sensitive when addres entry is empty.
Pressing enter will now also NOT connect, when address entry is empty.
---
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, 29 insertions(+), 3 deletions(-)

diff --git a/src/spicy-connect.c b/src/spicy-connect.c
index b803bf1..2a0cd0f 100644
--- a/src/spicy-connect.c
+++ b/src/spicy-connect.c
@@ -44,6 +44,15 @@ static void shutdown_loop(GMainLoop *loop)
         g_main_loop_quit(loop);
 }

+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))
+        return TRUE;
+
+    return FALSE;
+}
+
 static void set_connection_info(SpiceSession *session)
 {
     const gchar *txt;
@@ -65,6 +74,14 @@ static gboolean close_cb(gpointer data)
     return TRUE;
 }

+static void entry_changed_cb(GtkEditable* entry, gpointer data)
+{
+    GtkButton *connect_button = data;
+    gboolean active = (gtk_entry_get_text_length(GTK_ENTRY(entry)) > 0);
+
+    gtk_widget_set_sensitive(GTK_WIDGET(connect_button), active);
+}
+
 static gboolean entry_focus_in_cb(GtkWidget *widget, GdkEvent *event, gpointer data)
 {
     GtkRecentChooser *recent = data;
@@ -123,9 +140,12 @@ static void recent_selection_changed_dialog_cb(GtkRecentChooser *chooser, gpoint
 static void connect_cb(gpointer data)
 {
     ConnectionInfo *ci = data;
-    ci->response_id = TRUE;
-    set_connection_info(ci->session);
-    shutdown_loop(ci->loop);
+    if (can_connect())
+    {
+        ci->response_id = TRUE;
+        set_connection_info(ci->session);
+        shutdown_loop(ci->loop);
+    }
 }
 #endif

@@ -133,6 +153,7 @@ gboolean spicy_connect_dialog(SpiceSession *session)
 {
     GtkWidget *connect_button, *cancel_button, *label;
     GtkBox *main_box, *recent_box, *button_box;
+    gboolean entry_filled;
     GtkWindow *window;
     GtkTable *table;
     int i;
@@ -196,6 +217,9 @@ gboolean spicy_connect_dialog(SpiceSession *session)

     gtk_box_pack_start(main_box, GTK_WIDGET(button_box), FALSE, TRUE, 0);

+    entry_filled = can_connect();
+    gtk_widget_set_sensitive(GTK_WIDGET(connect_button), entry_filled);
+
     g_signal_connect(window, "key-press-event",
                      G_CALLBACK(key_pressed_cb), window);
     g_signal_connect_swapped(window, "delete-event",
@@ -226,6 +250,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), &ci);
+        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.2



More information about the Spice-devel mailing list