Blame SOURCES/0109-p2v-Disable-the-sudo-button-when-the-username-is-roo.patch

e76f14
From 8bc5cc1f3b8ec7c71f7dc961a575abadfb578ace Mon Sep 17 00:00:00 2001
e76f14
From: "Richard W.M. Jones" <rjones@redhat.com>
e76f14
Date: Fri, 17 Jun 2016 22:24:45 +0100
e76f14
Subject: [PATCH] p2v: Disable the sudo button when the username is root.
e76f14
e76f14
(cherry picked from commit 072cf26dc3fdd90e8301b15f430b3f34a9bbf85b)
e76f14
---
e76f14
 p2v/gui.c | 29 +++++++++++++++++++++++++++++
e76f14
 1 file changed, 29 insertions(+)
e76f14
e76f14
diff --git a/p2v/gui.c b/p2v/gui.c
e76f14
index dad8f6e..93b086a 100644
e76f14
--- a/p2v/gui.c
e76f14
+++ b/p2v/gui.c
e76f14
@@ -92,6 +92,7 @@ gui_conversion (struct config *config)
e76f14
 /*----------------------------------------------------------------------*/
e76f14
 /* Connection dialog. */
e76f14
 
e76f14
+static void username_changed_callback (GtkWidget *w, gpointer data);
e76f14
 static void password_or_identity_changed_callback (GtkWidget *w, gpointer data);
e76f14
 static void test_connection_clicked (GtkWidget *w, gpointer data);
e76f14
 static void *test_connection_thread (void *data);
e76f14
@@ -240,10 +241,38 @@ create_connection_dialog (struct config *config)
e76f14
                     G_CALLBACK (about_button_clicked), NULL);
e76f14
   g_signal_connect (G_OBJECT (next_button), "clicked",
e76f14
                     G_CALLBACK (connection_next_clicked), NULL);
e76f14
+  g_signal_connect (G_OBJECT (username_entry), "changed",
e76f14
+                    G_CALLBACK (username_changed_callback), NULL);
e76f14
   g_signal_connect (G_OBJECT (password_entry), "changed",
e76f14
                     G_CALLBACK (password_or_identity_changed_callback), NULL);
e76f14
   g_signal_connect (G_OBJECT (identity_entry), "changed",
e76f14
                     G_CALLBACK (password_or_identity_changed_callback), NULL);
e76f14
+
e76f14
+  /* Call this signal to initialize the sensitivity of the sudo
e76f14
+   * button correctly.
e76f14
+   */
e76f14
+  username_changed_callback (NULL, NULL);
e76f14
+}
e76f14
+
e76f14
+/**
e76f14
+ * If the username is "root", disable the sudo button.
e76f14
+ */
e76f14
+static void
e76f14
+username_changed_callback (GtkWidget *w, gpointer data)
e76f14
+{
e76f14
+  const char *str;
e76f14
+  int username_is_root;
e76f14
+  int sudo_is_set;
e76f14
+
e76f14
+  str = gtk_entry_get_text (GTK_ENTRY (username_entry));
e76f14
+  username_is_root = str != NULL && STREQ (str, "root");
e76f14
+  sudo_is_set = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (sudo_button));
e76f14
+
e76f14
+  /* The sudo button is sensitive if:
e76f14
+   * - The username is not "root", or
e76f14
+   * - The button is not already checked (to allow the user to uncheck it)
e76f14
+   */
e76f14
+  gtk_widget_set_sensitive (sudo_button, !username_is_root || sudo_is_set);
e76f14
 }
e76f14
 
e76f14
 /**
e76f14
-- 
aa0300
2.7.4
e76f14