[gnome-shell/gnome-3-34] polkitAgent: Update user name on user changes



commit 455eb67a49f9ebe704fe48ea5bf048b7465a986f
Author: Jonas Dreßler <verdre v0yd nl>
Date:   Sun Jun 23 11:52:54 2019 +0200

    polkitAgent: Update user name on user changes
    
    Right now we only update the user avatar on the user-changed signal, but
    since we also display the users real name we should also update that if
    the user changes.
    
    https://gitlab.gnome.org/GNOME/gnome-shell/merge_requests/788

 js/ui/components/polkitAgent.js | 73 ++++++++++++++++++++---------------------
 1 file changed, 36 insertions(+), 37 deletions(-)
---
diff --git a/js/ui/components/polkitAgent.js b/js/ui/components/polkitAgent.js
index ed40dbef7f..0896cab5ea 100644
--- a/js/ui/components/polkitAgent.js
+++ b/js/ui/components/polkitAgent.js
@@ -51,46 +51,37 @@ var AuthenticationDialog = GObject.registerClass({
             userName = userNames[0];
 
         this._user = AccountsService.UserManager.get_default().get_user(userName);
-        let userRealName = this._user.get_real_name();
+
+        let userBox = new St.BoxLayout({
+            style_class: 'polkit-dialog-user-layout',
+            vertical: false,
+        });
+        content.messageBox.add(userBox);
+
+        this._userAvatar = new UserWidget.Avatar(this._user, {
+            iconSize: DIALOG_ICON_SIZE,
+            styleClass: 'polkit-dialog-user-icon',
+        });
+        this._userAvatar.actor.hide();
+        userBox.add_child(this._userAvatar.actor);
+
+        this._userLabel = new St.Label({
+            style_class: userName === 'root'
+                ? 'polkit-dialog-user-root-label'
+                : 'polkit-dialog-user-label',
+            x_expand: true,
+            y_align: Clutter.ActorAlign.CENTER,
+        });
+
+        if (userName === 'root')
+            this._userLabel.text = _('Administrator');
+
+        userBox.add_child(this._userLabel);
+
         this._userLoadedId = this._user.connect('notify::is-loaded',
                                                 this._onUserChanged.bind(this));
         this._userChangedId = this._user.connect('changed',
                                                  this._onUserChanged.bind(this));
-
-        // Special case 'root'
-        let userIsRoot = false;
-        if (userName == 'root') {
-            userIsRoot = true;
-            userRealName = _("Administrator");
-        }
-
-        if (userIsRoot) {
-            let userLabel = new St.Label(({ style_class: 'polkit-dialog-user-root-label',
-                                            text: userRealName }));
-            content.messageBox.add(userLabel, { x_fill: false,
-                                                x_align: St.Align.START });
-        } else {
-            let userBox = new St.BoxLayout({ style_class: 'polkit-dialog-user-layout',
-                                             vertical: false });
-            content.messageBox.add(userBox);
-            this._userAvatar = new UserWidget.Avatar(this._user,
-                                                     { iconSize: DIALOG_ICON_SIZE,
-                                                       styleClass: 'polkit-dialog-user-icon' });
-            this._userAvatar.actor.hide();
-            userBox.add(this._userAvatar.actor,
-                        { x_fill: true,
-                          y_fill: false,
-                          x_align: St.Align.END,
-                          y_align: St.Align.START });
-            let userLabel = new St.Label(({ style_class: 'polkit-dialog-user-label',
-                                            text: userRealName }));
-            userBox.add(userLabel,
-                        { x_fill: true,
-                          y_fill: false,
-                          x_align: St.Align.END,
-                          y_align: St.Align.MIDDLE });
-        }
-
         this._onUserChanged();
 
         this._passwordBox = new St.BoxLayout({ vertical: false, style_class: 'prompt-dialog-password-box' });
@@ -305,7 +296,15 @@ var AuthenticationDialog = GObject.registerClass({
     }
 
     _onUserChanged() {
-        if (this._user.is_loaded && this._userAvatar) {
+        if (!this._user.is_loaded)
+            return;
+
+        let userName = this._user.get_user_name();
+        let realName = this._user.get_real_name();
+
+        if (userName !== 'root') {
+            this._userLabel.set_text(realName);
+
             this._userAvatar.update();
             this._userAvatar.actor.show();
         }


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]