[gnome-shell/uajain/adapt-user-avatar-part2: 9/10] userWidget: Adapt if user is not mentioned for username login



commit fa48d6e0bb1b0624ddd1c5becfbbd7775c50ac94
Author: Umang Jain <mailumangjain gmail com>
Date:   Fri Jan 17 12:17:34 2020 +0530

    userWidget: Adapt if user is not mentioned for username login
    
    If username-based login flow is followed, we need a default avatar
    for the userWidget. Hence, check if the user passed to userWidget
    is (null) which implies a username-based login flow.
    
    https://gitlab.gnome.org/GNOME/gnome-shell/merge_requests/922

 js/ui/userWidget.js | 27 ++++++++++++++++++---------
 1 file changed, 18 insertions(+), 9 deletions(-)
---
diff --git a/js/ui/userWidget.js b/js/ui/userWidget.js
index be52923897..8d79684120 100644
--- a/js/ui/userWidget.js
+++ b/js/ui/userWidget.js
@@ -82,9 +82,12 @@ class Avatar extends St.Bin {
     update() {
         let iconSize = this._getIconSize();
 
-        let iconFile = this._user.get_icon_file();
-        if (iconFile && !GLib.file_test(iconFile, GLib.FileTest.EXISTS))
-            iconFile = null;
+        let iconFile = null;
+        if (this._user) {
+            iconFile = this._user.get_icon_file();
+            if (iconFile && !GLib.file_test(iconFile, GLib.FileTest.EXISTS))
+                iconFile = null;
+        }
 
         if (iconFile) {
             this.child = null;
@@ -188,6 +191,7 @@ class UserWidgetLabel extends St.Widget {
 var UserWidget = GObject.registerClass(
 class UserWidget extends St.BoxLayout {
     _init(user, orientation = Clutter.Orientation.HORIZONTAL) {
+        // If user is null, that implies a username-based login authorization.
         this._user = user;
 
         let vertical = orientation == Clutter.Orientation.VERTICAL;
@@ -206,14 +210,19 @@ class UserWidget extends St.BoxLayout {
         this._avatar.x_align = Clutter.ActorAlign.CENTER;
         this.add_child(this._avatar);
 
-        this._label = new UserWidgetLabel(user);
-        this.add_child(this._label);
+        this._userLoadedId = 0;
+        this._userChangedId = 0;
+        if (user) {
+            this._label = new UserWidgetLabel(user);
+            this.add_child(this._label);
 
-        this._label.bind_property('label-actor', this, 'label-actor',
-                                  GObject.BindingFlags.SYNC_CREATE);
+            this._label.bind_property('label-actor', this, 'label-actor',
+                                      GObject.BindingFlags.SYNC_CREATE);
+
+            this._userLoadedId = this._user.connect('notify::is-loaded', this._updateUser.bind(this));
+            this._userChangedId = this._user.connect('changed', this._updateUser.bind(this));
+        }
 
-        this._userLoadedId = this._user.connect('notify::is-loaded', this._updateUser.bind(this));
-        this._userChangedId = this._user.connect('changed', this._updateUser.bind(this));
         this._updateUser();
     }
 


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