18#include <wx/stattext.h>
20#ifdef HAS_CUSTOM_URL_HANDLING
52 UserService& userService,
bool hasLinkButton, wxWindow* parent,
53 const wxPoint& pos,
const wxSize&
size)
55 , mServiceConfig { serviceConfig }
56 , mAuthService { authService }
57 , mUserService { userService }
58 , mUserDataChangedSubscription { userService.Subscribe(
66 safenew wxButton(
this, wxID_ANY,
XXO(
"&Link Account").Translation());
67 mLinkButton->Bind(wxEVT_BUTTON, [
this](
auto) { OnLinkButtonPressed(); });
68 mLinkButton->Show(hasLinkButton);
70 auto sizer =
safenew wxBoxSizer { wxHORIZONTAL };
72 sizer->Add(mUserImage, 0, wxALIGN_CENTER_VERTICAL);
74 sizer->Add(mUserName, 0, wxALIGN_CENTER_VERTICAL);
75 sizer->AddStretchSpacer();
76 sizer->Add(mLinkButton, 0, wxALIGN_CENTER_VERTICAL);
78 SetSizerAndFit(sizer);
82UserPanel::~UserPanel() =
default;
84bool UserPanel::IsAuthorized()
const
89void UserPanel::OnStateChaged(
bool isAuthorized)
91 if (mIsAuthorized == isAuthorized)
94 mIsAuthorized = isAuthorized;
98void UserPanel::UpdateUserData()
102 auto layoutUpdater =
finally(
110 auto parent = GetParent();
112 if (parent !=
nullptr)
120 if (!oauthService.HasRefreshToken())
126 if (!oauthService.HasAccessToken())
127 oauthService.ValidateAuth({},
true);
131 if (userService.GetUserSlug().empty())
137 const auto displayName = userService.GetDisplayName();
144 const auto avatarPath = userService.GetAvatarPath();
146 if (!avatarPath.empty())
147 mUserImage->SetBitmap(avatarPath);
151 mLinkButton->SetLabel(
XXO(
"&Unlink Account").Translation());
156void UserPanel::OnLinkButtonPressed()
160 if (oauthService.HasAccessToken())
161 oauthService.UnlinkAccount();
167#ifdef HAS_CUSTOM_URL_HANDLING
177void UserPanel::SetAnonymousState()
182 mLinkButton->SetLabel(
XXO(
"&Link Account").Translation());
184 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, 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)