[virt-tools-list] [remote-viewer PATCH 7/7 v2] remote-viewer-connect: Address entry is now required

Lukas Venhoda lvenhoda at redhat.com
Thu Jun 11 14:28:42 UTC 2015


Connect button is now non-sensitive when address entry is empty.
Pressing enter will now also NOT connect, when address entry is empty.
---
Changes since v1
 - New patch
 - Split from the v1 patch as requested
---
 src/remote-viewer-connect.c | 27 +++++++++++++++++++++------
 1 file changed, 21 insertions(+), 6 deletions(-)

diff --git a/src/remote-viewer-connect.c b/src/remote-viewer-connect.c
index 194104e..3109524 100644
--- a/src/remote-viewer-connect.c
+++ b/src/remote-viewer-connect.c
@@ -27,6 +27,7 @@ typedef struct
 {
     GtkResponseType response;
     GMainLoop *loop;
+    GtkWidget *entry;
 } ConnectionInfo;

 static void
@@ -66,8 +67,11 @@ static void
 connect_button_clicked_cb(GtkButton *button G_GNUC_UNUSED, gpointer data)
 {
     ConnectionInfo *ci = data;
-    ci->response = GTK_RESPONSE_OK;
-    shutdown_loop(ci->loop);
+    if (gtk_entry_get_text_length(GTK_ENTRY(ci->entry)) > 0)
+    {
+        ci->response = GTK_RESPONSE_OK;
+        shutdown_loop(ci->loop);
+    }
 }

 static void
@@ -85,11 +89,14 @@ entry_icon_release_cb(GtkEntry* entry, gpointer data G_GNUC_UNUSED)
 }

 static void
-entry_changed_cb(GtkEditable* entry, gpointer data G_GNUC_UNUSED)
+entry_changed_cb(GtkEditable* entry, gpointer data)
 {
+    GtkButton *connect_button = data;
     gboolean rtl = (gtk_widget_get_direction(GTK_WIDGET(entry)) == GTK_TEXT_DIR_RTL);
     gboolean active = (gtk_entry_get_text_length(GTK_ENTRY(entry)) > 0);

+    gtk_widget_set_sensitive(GTK_WIDGET(connect_button), active);
+
     g_object_set(entry,
                  "secondary-icon-name", active ? (rtl ? "edit-clear-rtl-symbolic" : "edit-clear-symbolic") : NULL,
                  "secondary-icon-activatable", active,
@@ -109,8 +116,11 @@ static void
 entry_activated_cb(GtkEntry *entry G_GNUC_UNUSED, gpointer data)
 {
     ConnectionInfo *ci = data;
-    ci->response = GTK_RESPONSE_OK;
-    shutdown_loop(ci->loop);
+    if (gtk_entry_get_text_length(GTK_ENTRY(ci->entry)) > 0)
+    {
+        ci->response = GTK_RESPONSE_OK;
+        shutdown_loop(ci->loop);
+    }
 }

 static void
@@ -168,9 +178,11 @@ remote_viewer_connect_dialog(gchar **uri)
     GtkWidget *window, *label, *entry, *recent, *connect_button, *cancel_button;
     GtkRecentFilter *rfilter;
     GtkBuilder *builder;
+    gboolean active;

     ConnectionInfo ci = {
         GTK_RESPONSE_NONE,
+        NULL,
         NULL
     };

@@ -182,10 +194,13 @@ remote_viewer_connect_dialog(gchar **uri)
     connect_button = GTK_WIDGET(gtk_builder_get_object(builder, "connect-button"));
     cancel_button = GTK_WIDGET(gtk_builder_get_object(builder, "cancel-button"));
     label = GTK_WIDGET(gtk_builder_get_object(builder, "example-label"));
-    entry = GTK_WIDGET(gtk_builder_get_object(builder, "connection-address-entry"));
+    entry = ci.entry = GTK_WIDGET(gtk_builder_get_object(builder, "connection-address-entry"));

     make_label_small(GTK_LABEL(label));

+    active = (gtk_entry_get_text_length(GTK_ENTRY(ci.entry)) > 0);
+    gtk_widget_set_sensitive(GTK_WIDGET(connect_button), active);
+
     recent = GTK_WIDGET(gtk_builder_get_object(builder, "recent-chooser"));

     rfilter = gtk_recent_filter_new();
--
2.4.2




More information about the virt-tools-list mailing list