Blob Blame History Raw
From b07b91cdc973bcaa65e9df0fa0e304943dcaffa6 Mon Sep 17 00:00:00 2001
From: "Richard W.M. Jones" <rjones@redhat.com>
Date: Fri, 17 Jun 2016 21:32:33 +0100
Subject: [PATCH] p2v: Don't allow password & SSH identity URL fields to both
 be non-empty.

It makes no sense.  By setting one field to non-sensitive when the
other field is populated, we can avoid this happening, and also make
tabbing between the fields simpler.

As a consequence of making this change, I also got rid of the now
unnecessary explanatory text telling you to leave one field blank.

(cherry picked from commit b0d2d697e03a11642ab36f4a92b1f849085d2db9)
---
 p2v/gui.c | 44 ++++++++++++++++++++++++++++++++++----------
 1 file changed, 34 insertions(+), 10 deletions(-)

diff --git a/p2v/gui.c b/p2v/gui.c
index 832d72a..dad8f6e 100644
--- a/p2v/gui.c
+++ b/p2v/gui.c
@@ -92,6 +92,7 @@ gui_conversion (struct config *config)
 /*----------------------------------------------------------------------*/
 /* Connection dialog. */
 
+static void password_or_identity_changed_callback (GtkWidget *w, gpointer data);
 static void test_connection_clicked (GtkWidget *w, gpointer data);
 static void *test_connection_thread (void *data);
 static void configure_network_button_clicked (GtkWidget *w, gpointer data);
@@ -110,7 +111,6 @@ create_connection_dialog (struct config *config)
   GtkWidget *username_label;
   GtkWidget *password_label;
   GtkWidget *identity_label;
-  GtkWidget *identity_tip_label;
   GtkWidget *test_hbox, *test;
   GtkWidget *about;
   GtkWidget *configure_network;
@@ -126,7 +126,7 @@ create_connection_dialog (struct config *config)
   gtk_label_set_line_wrap (GTK_LABEL (intro), TRUE);
   gtk_misc_set_padding (GTK_MISC (intro), 10, 10);
 
-  table = gtk_table_new (6, 2, FALSE);
+  table = gtk_table_new (5, 2, FALSE);
   server_label = gtk_label_new (_("Conversion server:"));
   gtk_misc_set_alignment (GTK_MISC (server_label), 1., 0.5);
   gtk_table_attach (GTK_TABLE (table), server_label,
@@ -183,19 +183,12 @@ create_connection_dialog (struct config *config)
   gtk_table_attach (GTK_TABLE (table), identity_entry,
                     1, 2, 3, 4, GTK_EXPAND|GTK_FILL, GTK_FILL, 4, 4);
 
-  identity_tip_label = gtk_label_new (NULL);
-  gtk_label_set_markup (GTK_LABEL (identity_tip_label),
-                        _("<i>If using password authentication, leave the SSH Identity URL blank</i>"));
-  gtk_label_set_line_wrap (GTK_LABEL (identity_tip_label), TRUE);
-  gtk_table_attach (GTK_TABLE (table), identity_tip_label,
-                    1, 2, 4, 5, GTK_FILL, GTK_FILL, 4, 4);
-
   sudo_button =
     gtk_check_button_new_with_label (_("Use sudo when running virt-v2v"));
   gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (sudo_button),
                                 config->sudo);
   gtk_table_attach (GTK_TABLE (table), sudo_button,
-                    1, 2, 5, 6, GTK_FILL, GTK_FILL, 4, 4);
+                    1, 2, 4, 5, GTK_FILL, GTK_FILL, 4, 4);
 
   test_hbox = gtk_hbox_new (FALSE, 0);
   test = gtk_button_new_with_label (_("Test connection"));
@@ -247,6 +240,37 @@ create_connection_dialog (struct config *config)
                     G_CALLBACK (about_button_clicked), NULL);
   g_signal_connect (G_OBJECT (next_button), "clicked",
                     G_CALLBACK (connection_next_clicked), NULL);
+  g_signal_connect (G_OBJECT (password_entry), "changed",
+                    G_CALLBACK (password_or_identity_changed_callback), NULL);
+  g_signal_connect (G_OBJECT (identity_entry), "changed",
+                    G_CALLBACK (password_or_identity_changed_callback), NULL);
+}
+
+/**
+ * The password or SSH identity URL entries are mutually exclusive, so
+ * if one contains text then disable the other.  This function is
+ * called when the "changed" signal is received on either.
+ */
+static void
+password_or_identity_changed_callback (GtkWidget *w, gpointer data)
+{
+  const char *str;
+  int password_set;
+  int identity_set;
+
+  str = gtk_entry_get_text (GTK_ENTRY (password_entry));
+  password_set = str != NULL && STRNEQ (str, "");
+  str = gtk_entry_get_text (GTK_ENTRY (identity_entry));
+  identity_set = str != NULL && STRNEQ (str, "");
+
+  if (!password_set && !identity_set) {
+    gtk_widget_set_sensitive (password_entry, TRUE);
+    gtk_widget_set_sensitive (identity_entry, TRUE);
+  }
+  else if (identity_set)
+    gtk_widget_set_sensitive (password_entry, FALSE);
+  else if (password_set)
+    gtk_widget_set_sensitive (identity_entry, FALSE);
 }
 
 static void
-- 
1.8.3.1