Audacity 3.2.0
Public Member Functions | Private Member Functions | Private Attributes | List of all members
audacity::cloud::audiocom::UserPanel Class Referencefinal

#include <UserPanel.h>

Inheritance diagram for audacity::cloud::audiocom::UserPanel:
[legend]
Collaboration diagram for audacity::cloud::audiocom::UserPanel:
[legend]

Public Member Functions

 UserPanel (const ServiceConfig &serviceConfig, OAuthService &authService, UserService &userService, bool hasLinkButton, wxWindow *parent=nullptr, const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxDefaultSize)
 
 ~UserPanel () override
 
bool IsAuthorized () const
 
- Public Member Functions inherited from wxPanelWrapper
 wxPanelWrapper ()
 
 wxPanelWrapper (wxWindow *parent, wxWindowID winid=wxID_ANY, const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxDefaultSize, long style=wxTAB_TRAVERSAL|wxNO_BORDER, const TranslatableString &name=XO("Panel"))
 
bool Create (wxWindow *parent, wxWindowID winid=wxID_ANY, const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxDefaultSize, long style=wxTAB_TRAVERSAL|wxNO_BORDER, const TranslatableString &name=XO("Panel"))
 
void SetLabel (const TranslatableString &label)
 
void SetName (const TranslatableString &name)
 
void SetToolTip (const TranslatableString &toolTip)
 
void SetName ()
 
- Public Member Functions inherited from wxTabTraversalWrapper< wxPanel >
 wxTabTraversalWrapper (Args &&... args)
 
 wxTabTraversalWrapper (const wxTabTraversalWrapper &)=delete
 
 wxTabTraversalWrapper (wxTabTraversalWrapper &&)=delete
 
wxTabTraversalWrapperoperator= (const wxTabTraversalWrapper &)=delete
 
wxTabTraversalWrapperoperator= (wxTabTraversalWrapper &&)=delete
 
- Public Member Functions inherited from Observer::Publisher< UserPanelStateChangedMessage >
 Publisher (ExceptionPolicy *pPolicy=nullptr, Alloc a={})
 Constructor supporting type-erased custom allocation/deletion. More...
 
 Publisher (Publisher &&)=default
 
Publisheroperator= (Publisher &&)=default
 
Subscription Subscribe (Callback callback)
 Connect a callback to the Publisher; later-connected are called earlier. More...
 
Subscription Subscribe (Object &obj, Return(Object::*callback)(Args...))
 Overload of Subscribe takes an object and pointer-to-member-function. More...
 

Private Member Functions

void OnStateChaged (bool isAuthorized)
 
void UpdateUserData ()
 
void OnLinkButtonPressed ()
 
void SetAnonymousState ()
 

Private Attributes

const ServiceConfigmServiceConfig
 
OAuthServicemAuthService
 
UserServicemUserService
 
UserImagemUserImage {}
 
wxStaticText * mUserName {}
 
wxButton * mLinkButton {}
 
Observer::Subscription mUserDataChangedSubscription
 
bool mIsAuthorized { false }
 

Additional Inherited Members

- Public Types inherited from Observer::Publisher< UserPanelStateChangedMessage >
using message_type = UserPanelStateChangedMessage
 
using CallbackReturn = std::conditional_t< true, void, bool >
 
using Callback = std::function< CallbackReturn(const UserPanelStateChangedMessage &) >
 Type of functions that can be connected to the Publisher. More...
 
- Static Public Attributes inherited from Observer::Publisher< UserPanelStateChangedMessage >
static constexpr bool notifies_all
 
- Protected Member Functions inherited from Observer::Publisher< UserPanelStateChangedMessage >
CallbackReturn Publish (const UserPanelStateChangedMessage &message)
 Send a message to connected callbacks. More...
 

Detailed Description

Definition at line 31 of file UserPanel.h.

Constructor & Destructor Documentation

◆ UserPanel()

audacity::cloud::audiocom::UserPanel::UserPanel ( const ServiceConfig serviceConfig,
OAuthService authService,
UserService userService,
bool  hasLinkButton,
wxWindow *  parent = nullptr,
const wxPoint &  pos = wxDefaultPosition,
const wxSize &  size = wxDefaultSize 
)

Definition at line 50 of file UserPanel.cpp.

54 : wxPanelWrapper { parent, wxID_ANY, pos, size }
55 , mServiceConfig { serviceConfig }
56 , mAuthService { authService }
57 , mUserService { userService }
58 , mUserDataChangedSubscription { userService.Subscribe(
59 [this](const auto&) { UpdateUserData(); }) }
60{
61 mUserImage = safenew UserImage(this, avatarSize);
62 mUserImage->SetLabel(anonymousText); // for screen readers
63 mUserName =
64 safenew wxStaticText(this, wxID_ANY, anonymousText.Translation());
66 safenew wxButton(this, wxID_ANY, XXO("&Link Account").Translation());
67 mLinkButton->Bind(wxEVT_BUTTON, [this](auto) { OnLinkButtonPressed(); });
68 mLinkButton->Show(hasLinkButton);
69
70 auto sizer = safenew wxBoxSizer { wxHORIZONTAL };
71
72 sizer->Add(mUserImage, 0, wxALIGN_CENTER_VERTICAL);
73 sizer->AddSpacer(8);
74 sizer->Add(mUserName, 0, wxALIGN_CENTER_VERTICAL);
75 sizer->AddStretchSpacer();
76 sizer->Add(mLinkButton, 0, wxALIGN_CENTER_VERTICAL);
77
78 SetSizerAndFit(sizer);
80}
XXO("&Cut/Copy/Paste Toolbar")
#define safenew
Definition: MemoryX.h:10
const ServiceConfig & mServiceConfig
Definition: UserPanel.h:53
Observer::Subscription mUserDataChangedSubscription
Definition: UserPanel.h:61
void SetLabel(const TranslatableString &label)

References UpdateUserData().

Here is the call graph for this function:

◆ ~UserPanel()

audacity::cloud::audiocom::UserPanel::~UserPanel ( )
overridedefault

Member Function Documentation

◆ IsAuthorized()

bool audacity::cloud::audiocom::UserPanel::IsAuthorized ( ) const

Definition at line 84 of file UserPanel.cpp.

85{
86 return mIsAuthorized;
87}

Referenced by audacity::cloud::audiocom::sync::CloudProjectPropertiesDialog::LayoutControls(), audacity::cloud::audiocom::sync::CloudProjectPropertiesDialog::OnSubmit(), and audacity::cloud::audiocom::sync::CloudProjectPropertiesDialog::OnUpdateCloudSaveState().

Here is the caller graph for this function:

◆ OnLinkButtonPressed()

void audacity::cloud::audiocom::UserPanel::OnLinkButtonPressed ( )
private

Definition at line 156 of file UserPanel.cpp.

157{
158 auto& oauthService = GetOAuthService();
159
160 if (oauthService.HasAccessToken())
161 oauthService.UnlinkAccount();
162 else
163 {
166
167#ifdef HAS_CUSTOM_URL_HANDLING
169#endif
170 {
171 LinkWithTokenDialog dlg(this);
172 dlg.ShowModal();
173 }
174 }
175}
bool IsURLHandlingSupported() const noexcept
Returns true, if Audacity can handle custom URLs.
static URLSchemesRegistry & Get()
Retrieves the registry instance.
std::string GetOAuthLoginPage() const
Page to open in browser to initiate OAuth.
bool OpenInDefaultBrowser(const wxString &url)
Open an URL in default browser.
Definition: BasicUI.cpp:245
OAuthService & GetOAuthService()
Returns the instance of the OAuthService.
wxString ToWXString(const std::string &str)

References URLSchemesRegistry::Get(), audacity::cloud::audiocom::GetOAuthService(), URLSchemesRegistry::IsURLHandlingSupported(), BasicUI::OpenInDefaultBrowser(), and audacity::ToWXString().

Here is the call graph for this function:

◆ OnStateChaged()

void audacity::cloud::audiocom::UserPanel::OnStateChaged ( bool  isAuthorized)
private

Definition at line 89 of file UserPanel.cpp.

90{
91 if (mIsAuthorized == isAuthorized)
92 return;
93
94 mIsAuthorized = isAuthorized;
95 Publish(UserPanelStateChangedMessage { isAuthorized });
96}
CallbackReturn Publish(const UserPanelStateChangedMessage &message)
Send a message to connected callbacks.
Definition: Observer.h:207

◆ SetAnonymousState()

void audacity::cloud::audiocom::UserPanel::SetAnonymousState ( )
private

Definition at line 177 of file UserPanel.cpp.

178{
179 mUserName->SetLabel(anonymousText.Translation());
180 mUserImage->SetBitmap(theTheme.Bitmap(bmpAnonymousUser));
181 mUserImage->SetLabel(anonymousText); // for screen readers
182 mLinkButton->SetLabel(XXO("&Link Account").Translation());
183
184 OnStateChaged(false);
185}
THEME_API Theme theTheme
Definition: Theme.cpp:82
wxBitmap & Bitmap(int iIndex)
void SetBitmap(const wxBitmap &bitmap)
Definition: UserImage.cpp:32
void OnStateChaged(bool isAuthorized)
Definition: UserPanel.cpp:89

References audacity::cloud::audiocom::anonymous_namespace{UserPanel.cpp}::anonymousText, ThemeBase::Bitmap(), wxDialogWrapper::SetLabel(), theTheme, and XXO().

Here is the call graph for this function:

◆ UpdateUserData()

void audacity::cloud::audiocom::UserPanel::UpdateUserData ( )
private

Definition at line 98 of file UserPanel.cpp.

99{
100 Freeze();
101
102 auto layoutUpdater = finally(
103 [this]()
104 {
105 mLinkButton->Fit();
106
107 Layout();
108 Thaw();
109
110 auto parent = GetParent();
111
112 if (parent != nullptr)
113 parent->Refresh();
114 else
115 Refresh();
116 });
117
118 auto& oauthService = GetOAuthService();
119
120 if (!oauthService.HasRefreshToken())
121 {
123 return;
124 }
125
126 if (!oauthService.HasAccessToken())
127 oauthService.ValidateAuth({}, true);
128
129 auto& userService = GetUserService();
130
131 if (userService.GetUserSlug().empty())
132 {
134 return;
135 }
136
137 const auto displayName = userService.GetDisplayName();
138
139 if (!displayName.empty()) {
140 mUserName->SetLabel(displayName);
141 mUserImage->wxPanel::SetLabel(displayName); // for screen readers
142 }
143
144 const auto avatarPath = userService.GetAvatarPath();
145
146 if (!avatarPath.empty())
147 mUserImage->SetBitmap(avatarPath);
148 else
149 mUserImage->SetBitmap(theTheme.Bitmap(bmpAnonymousUser));
150
151 mLinkButton->SetLabel(XXO("&Unlink Account").Translation());
152
153 OnStateChaged(true);
154}
UserService & GetUserService()

References ThemeBase::Bitmap(), audacity::cloud::audiocom::anonymous_namespace{UserService.cpp}::displayName, audacity::cloud::audiocom::GetOAuthService(), audacity::cloud::audiocom::GetUserService(), theTheme, and XXO().

Referenced by UserPanel().

Here is the call graph for this function:
Here is the caller graph for this function:

Member Data Documentation

◆ mAuthService

OAuthService& audacity::cloud::audiocom::UserPanel::mAuthService
private

Definition at line 54 of file UserPanel.h.

◆ mIsAuthorized

bool audacity::cloud::audiocom::UserPanel::mIsAuthorized { false }
private

Definition at line 63 of file UserPanel.h.

◆ mLinkButton

wxButton* audacity::cloud::audiocom::UserPanel::mLinkButton {}
private

Definition at line 59 of file UserPanel.h.

◆ mServiceConfig

const ServiceConfig& audacity::cloud::audiocom::UserPanel::mServiceConfig
private

Definition at line 53 of file UserPanel.h.

◆ mUserDataChangedSubscription

Observer::Subscription audacity::cloud::audiocom::UserPanel::mUserDataChangedSubscription
private

Definition at line 61 of file UserPanel.h.

◆ mUserImage

UserImage* audacity::cloud::audiocom::UserPanel::mUserImage {}
private

Definition at line 57 of file UserPanel.h.

◆ mUserName

wxStaticText* audacity::cloud::audiocom::UserPanel::mUserName {}
private

Definition at line 58 of file UserPanel.h.

◆ mUserService

UserService& audacity::cloud::audiocom::UserPanel::mUserService
private

Definition at line 55 of file UserPanel.h.


The documentation for this class was generated from the following files: