18#include <wx/stattext.h>
20#ifdef HAS_CUSTOM_URL_HANDLING
55 wxWindow* parent,
const wxPoint& pos,
const wxSize&
size)
57 , mServiceConfig { serviceConfig }
58 , mAuthService { authService }
59 , mUserService { userService }
60 , mAudiocomTrace { trace }
61 , mUserDataChangedSubscription { userService.Subscribe(
63 , mLinkMode { linkMode }
66 mUserImage->SetLabel( mLinkMode == LinkMode::Link ?
68 mUserName =
safenew wxStaticText(
71 ( mLinkMode == LinkMode::Link ?
75 safenew wxButton(
this, wxID_ANY,
XXO(
"&Link Account").Translation());
76 mLinkButton->Bind(wxEVT_BUTTON, [
this](
auto) { OnLinkButtonPressed(); });
78 mLinkButton->Show(mLinkMode == LinkMode::Link);
80 auto sizer =
safenew wxBoxSizer { wxHORIZONTAL };
82 sizer->Add(mUserImage, 0, wxALIGN_CENTER_VERTICAL);
84 sizer->Add(mUserName, 0, wxALIGN_CENTER_VERTICAL);
85 sizer->AddStretchSpacer();
86 sizer->Add(mLinkButton, 0, wxALIGN_CENTER_VERTICAL);
88 SetSizerAndFit(sizer);
92UserPanel::~UserPanel() =
default;
94bool UserPanel::IsAuthorized()
const
99void UserPanel::OnStateChanged(
bool isAuthorized)
101 if (mIsAuthorized == isAuthorized)
104 mIsAuthorized = isAuthorized;
108void UserPanel::UpdateUserData()
112 auto layoutUpdater =
finally(
120 auto parent = GetParent();
122 if (parent !=
nullptr)
130 if (!oauthService.HasRefreshToken())
136 if (!oauthService.HasAccessToken())
137 oauthService.ValidateAuth({}, mAudiocomTrace,
true);
141 if (userService.GetUserSlug().empty())
147 const auto displayName = userService.GetDisplayName();
154 const auto avatarPath = userService.GetAvatarPath();
156 if (!avatarPath.empty())
157 mUserImage->SetBitmap(avatarPath);
161 mLinkButton->SetLabel(( mLinkMode == LinkMode::Link ?
162 XXO(
"&Unlink Account") :
163 XXO(
"&Sign Out") ).Translation());
166 OnStateChanged(
true);
169void UserPanel::OnLinkButtonPressed()
173 if (oauthService.HasAccessToken())
174 oauthService.UnlinkAccount(mAudiocomTrace);
178 mServiceConfig.GetOAuthLoginPage(mAudiocomTrace)) });
180#ifdef HAS_CUSTOM_URL_HANDLING
190void UserPanel::SetAnonymousState()
195 mLinkButton->SetLabel(
XXO(
"&Link Account").Translation());
196 mLinkButton->Show(mLinkMode == LinkMode::Link);
198 OnStateChanged(
false);
Declare functions to perform UTF-8 to std::wstring conversions.
XXO("&Cut/Copy/Paste Toolbar")
wxBitmap & Bitmap(int iIndex)
bool IsURLHandlingSupported() const noexcept
Returns true, if Audacity can handle custom URLs.
static URLSchemesRegistry & Get()
Retrieves the registry instance.
Service responsible for OAuth authentication against the audio.com service.
Configuration for the audio.com.
UserPanel(const ServiceConfig &serviceConfig, OAuthService &authService, UserService &userService, LinkMode linkMode, AudiocomTrace, wxWindow *parent=nullptr, const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxDefaultSize)
Service for providing information about the user profile.
void SetLabel(const TranslatableString &title)
bool OpenInDefaultBrowser(const wxString &url)
Open an URL in default browser.
StringSetting displayName
UserService & GetUserService()
OAuthService & GetOAuthService()
Returns the instance of the OAuthService.
wxString ToWXString(const std::string &str)