| 106 | } |
| 107 | |
| 108 | void UserPanel::UpdateUserData() |
| 109 | { |
| 110 | Freeze(); |
| 111 | |
| 112 | auto layoutUpdater = finally( |
| 113 | [this]() |
| 114 | { |
| 115 | mLinkButton->Fit(); |
| 116 | |
| 117 | Layout(); |
| 118 | Thaw(); |
| 119 | |
| 120 | auto parent = GetParent(); |
| 121 | |
| 122 | if (parent != nullptr) |
| 123 | parent->Refresh(); |
| 124 | else |
| 125 | Refresh(); |
| 126 | }); |
| 127 | |
| 128 | auto& oauthService = GetOAuthService(); |
| 129 | |
| 130 | if (!oauthService.HasRefreshToken()) |
| 131 | { |
| 132 | SetAnonymousState(); |
| 133 | return; |
| 134 | } |
| 135 | |
| 136 | if (!oauthService.HasAccessToken()) |
| 137 | oauthService.ValidateAuth({}, mAudiocomTrace, true); |
| 138 | |
| 139 | auto& userService = GetUserService(); |
| 140 | |
| 141 | if (userService.GetUserSlug().empty()) |
| 142 | { |
| 143 | SetAnonymousState(); |
| 144 | return; |
| 145 | } |
| 146 | |
| 147 | wxString displayName = userService.GetDisplayName(); |
| 148 | |
| 149 | if (displayName.empty()) |
| 150 | { |
| 151 | displayName = userService.GetUserSlug(); |
| 152 | } |
| 153 | |
| 154 | mUserName->SetLabel(displayName); |
| 155 | mUserImage->wxPanel::SetLabel(displayName); // for screen readers |
| 156 | |
| 157 | const auto avatarPath = userService.GetAvatarPath(); |
| 158 | |
| 159 | if (!avatarPath.empty()) |
| 160 | mUserImage->SetBitmap(avatarPath); |
| 161 | else |
| 162 | mUserImage->SetBitmap(theTheme.Bitmap(bmpAnonymousUser)); |
| 163 | |
| 164 | mLinkButton->SetLabel(XXO("&Sign Out").Translation()); |
| 165 | mLinkButton->Show(); |
no test coverage detected