18#include <wx/stattext.h>
20#ifdef HAS_CUSTOM_URL_HANDLING
54 wxWindow* parent,
const wxPoint& pos,
const wxSize&
size)
56 , mServiceConfig { serviceConfig }
57 , mAuthService { authService }
58 , mUserService { userService }
59 , mAudiocomTrace { trace }
60 , mUserDataChangedSubscription { userService.Subscribe(
68 safenew wxButton(
this, wxID_ANY,
XXO(
"&Link Account").Translation());
69 mLinkButton->Bind(wxEVT_BUTTON, [
this](
auto) { OnLinkButtonPressed(); });
70 mLinkButton->Show(hasLinkButton);
72 auto sizer =
safenew wxBoxSizer { wxHORIZONTAL };
74 sizer->Add(mUserImage, 0, wxALIGN_CENTER_VERTICAL);
76 sizer->Add(mUserName, 0, wxALIGN_CENTER_VERTICAL);
77 sizer->AddStretchSpacer();
78 sizer->Add(mLinkButton, 0, wxALIGN_CENTER_VERTICAL);
80 SetSizerAndFit(sizer);
84UserPanel::~UserPanel() =
default;
86bool UserPanel::IsAuthorized()
const
91void UserPanel::OnStateChaged(
bool isAuthorized)
93 if (mIsAuthorized == isAuthorized)
96 mIsAuthorized = isAuthorized;
100void UserPanel::UpdateUserData()
104 auto layoutUpdater =
finally(
112 auto parent = GetParent();
114 if (parent !=
nullptr)
122 if (!oauthService.HasRefreshToken())
128 if (!oauthService.HasAccessToken())
129 oauthService.ValidateAuth({}, mAudiocomTrace,
true);
133 if (userService.GetUserSlug().empty())
139 const auto displayName = userService.GetDisplayName();
146 const auto avatarPath = userService.GetAvatarPath();
148 if (!avatarPath.empty())
149 mUserImage->SetBitmap(avatarPath);
153 mLinkButton->SetLabel(
XXO(
"&Unlink Account").Translation());
158void UserPanel::OnLinkButtonPressed()
162 if (oauthService.HasAccessToken())
163 oauthService.UnlinkAccount(mAudiocomTrace);
167 mServiceConfig.GetOAuthLoginPage(mAudiocomTrace)) });
169#ifdef HAS_CUSTOM_URL_HANDLING
179void UserPanel::SetAnonymousState()
184 mLinkButton->SetLabel(
XXO(
"&Link Account").Translation());
186 OnStateChaged(
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, bool hasLinkButton, 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)