[master 1/9] Fix potential issues with the username guesser.

dashea installerbot-noreply at redhat.com
Thu Oct 8 19:05:29 UTC 2015


From: David Shea <dshea at redhat.com>

Add a new signal handler that can be blocked during username guessing
instead of cleaning up variables after the fact and hoping nothing was
asynchronous.

Also quit using a dict as a boolean, remove the references to the
hostname guessing that never existed that was probably the reason for
the dict, and remove gender-specific language.
---
 pyanaconda/ui/gui/spokes/user.glade |  1 +
 pyanaconda/ui/gui/spokes/user.py    | 51 ++++++++++++++++++++-----------------
 2 files changed, 29 insertions(+), 23 deletions(-)

diff --git a/pyanaconda/ui/gui/spokes/user.glade b/pyanaconda/ui/gui/spokes/user.glade
index e15c966..8025849 100644
--- a/pyanaconda/ui/gui/spokes/user.glade
+++ b/pyanaconda/ui/gui/spokes/user.glade
@@ -111,6 +111,7 @@
                         <property name="visible">True</property>
                         <property name="can_focus">True</property>
                         <signal name="changed" handler="username_changed" swapped="no"/>
+                        <signal name="changed" handler="on_username_set_by_user" swapped="no"/>
                         <child internal-child="accessible">
                           <object class="AtkObject" id="t_username-atkobject">
                             <property name="AtkObject::accessible-name" translatable="yes">User Name</property>
diff --git a/pyanaconda/ui/gui/spokes/user.py b/pyanaconda/ui/gui/spokes/user.py
index f627e0f..317aeba 100644
--- a/pyanaconda/ui/gui/spokes/user.py
+++ b/pyanaconda/ui/gui/spokes/user.py
@@ -32,6 +32,7 @@
 from pyanaconda.ui.common import FirstbootSpokeMixIn
 from pyanaconda.ui.helpers import InputCheck
 from pyanaconda.ui.gui.helpers import GUISpokeInputCheckHandler, GUIDialogInputCheckHandler
+from pyanaconda.ui.gui.utils import blockedHandler
 
 from pyanaconda.constants import ANACONDA_ENVIRON, FIRSTBOOT_ENVIRON,\
         PASSWORD_EMPTY_ERROR, PASSWORD_CONFIRM_ERROR_GUI, PASSWORD_STRENGTH_DESC,\
@@ -248,9 +249,7 @@ def initialize(self):
         self._waiveStrengthClicks = 0
         self._waiveASCIIClicks = 0
 
-        self.guesser = {
-            self.username: True
-            }
+        self.guesser = True
 
         # Updated during the password changed event and used by the password
         # field validity checker
@@ -442,35 +441,41 @@ def password_changed(self, editable=None, data=None):
         # Update the password/confirm match check on changes to the main password field
         self._confirm_check.update_check_status()
 
-    def username_changed(self, editable=None, data=None):
-        """Called by Gtk callback when the username or hostname
-        entry changes. It disables the guess algorithm if the
-        user added his own text there and reenable it when the
-        user deletes the whole text."""
+    def on_username_set_by_user(self, editable, data=None):
+        """Called by Gtk on user-driven changes to the username field.
 
-        if editable.get_text() == "":
-            self.guesser[editable] = True
-            self.b_advanced.set_sensitive(False)
+           This handler is blocked during changes from the username guesser.
+        """
+
+        # If the user set a user name, turn off the username guesser.
+        # If the user cleared the username, turn it back on.
+        if editable.get_text():
+            self.guesser = False
         else:
-            self.guesser[editable] = False
+            self.guesser = True
+
+    def username_changed(self, editable, data=None):
+        """Called by Gtk on all username changes."""
+
+        # Disable the advanced user dialog button when no username is set
+        if editable.get_text():
             self.b_advanced.set_sensitive(True)
+        else:
+            self.b_advanced.set_sensitive(False)
 
-            # Re-run the password checks against the new username
-            self.pw.emit("changed")
-            self.confirm.emit("changed")
+        # Re-run the password checks against the new username
+        self.pw.emit("changed")
+        self.confirm.emit("changed")
 
     def full_name_changed(self, editable=None, data=None):
-        """Called by Gtk callback when the full name field changes.
-        It guesses the username and hostname, strips diacritics
-        and make those lowercase.
-        """
+        """Called by Gtk callback when the full name field changes."""
 
-        # after the text is updated in guesser, the guess has to be reenabled
-        if self.guesser[self.username]:
+        if self.guesser:
             fullname = self.fullname.get_text()
             username = guess_username(fullname)
-            self.username.set_text(username)
-            self.guesser[self.username] = True
+
+            with blockedHandler(self.username, self.on_username_set_by_user):
+                self.username.set_text(username)
 
     def on_admin_toggled(self, togglebutton, data=None):
         # Add or remove "wheel" from the grouplist on changes to the admin checkbox


-- 
To view this commit on github, visit https://github.com/rhinstaller/anaconda/commit/7adc8a968991acb8d8f655176274472dab6c53fb


More information about the anaconda-patches mailing list