Audacity 3.2.0
Public Types | 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 Types

enum class  LinkMode { Link , SignIn }
 
- 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...
 

Public Member Functions

 UserPanel (const ServiceConfig &serviceConfig, OAuthService &authService, UserService &userService, LinkMode linkMode, AudiocomTrace, 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 OnStateChanged (bool isAuthorized)
 
void UpdateUserData ()
 
void OnLinkButtonPressed ()
 
void SetAnonymousState ()
 

Private Attributes

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

Additional Inherited Members

- 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 33 of file UserPanel.h.

Member Enumeration Documentation

◆ LinkMode

Enumerator
Link 
SignIn 

Definition at line 41 of file UserPanel.h.

41 {
42 Link,
43 SignIn,
44 };

Constructor & Destructor Documentation

◆ UserPanel()

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

Definition at line 52 of file UserPanel.cpp.

56 : wxPanelWrapper { parent, wxID_ANY, pos, size }
57 , mServiceConfig { serviceConfig }
58 , mAuthService { authService }
59 , mUserService { userService }
60 , mAudiocomTrace { trace }
61 , mUserDataChangedSubscription { userService.Subscribe(
62 [this](const auto&) { UpdateUserData(); }) }
63 , mLinkMode { linkMode }
64{
65 mUserImage = safenew UserImage(this, avatarSize);
67 notLinkedText : anonymousText ); // for screen readers
68 mUserName = safenew wxStaticText(
69 this,
70 wxID_ANY,
72 notLinkedText : anonymousText).Translation() );
73
75 safenew wxButton(this, wxID_ANY, XXO("&Link Account").Translation());
76 mLinkButton->Bind(wxEVT_BUTTON, [this](auto) { OnLinkButtonPressed(); });
77
79
80 auto sizer = safenew wxBoxSizer { wxHORIZONTAL };
81
82 sizer->Add(mUserImage, 0, wxALIGN_CENTER_VERTICAL);
83 sizer->AddSpacer(8);
84 sizer->Add(mUserName, 0, wxALIGN_CENTER_VERTICAL);
85 sizer->AddStretchSpacer();
86 sizer->Add(mLinkButton, 0, wxALIGN_CENTER_VERTICAL);
87
88 SetSizerAndFit(sizer);
90}
XXO("&Cut/Copy/Paste Toolbar")
#define safenew
Definition: MemoryX.h:10
const ServiceConfig & mServiceConfig
Definition: UserPanel.h:62
Observer::Subscription mUserDataChangedSubscription
Definition: UserPanel.h:71
const AudiocomTrace mAudiocomTrace
Definition: UserPanel.h:65
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 94 of file UserPanel.cpp.

95{
96 return mIsAuthorized;
97}

Referenced by audacity::cloud::audiocom::sync::CloudProjectPropertiesDialog::OnSubmit().

Here is the caller graph for this function:

◆ OnLinkButtonPressed()

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

Definition at line 169 of file UserPanel.cpp.

170{
171 auto& oauthService = GetOAuthService();
172
173 if (oauthService.HasAccessToken())
174 oauthService.UnlinkAccount(mAudiocomTrace);
175 else
176 {
179
180#ifdef HAS_CUSTOM_URL_HANDLING
182#endif
183 {
184 LinkWithTokenDialog dlg(mAudiocomTrace, this);
185 dlg.ShowModal();
186 }
187 }
188}
bool IsURLHandlingSupported() const noexcept
Returns true, if Audacity can handle custom URLs.
static URLSchemesRegistry & Get()
Retrieves the registry instance.
std::string GetOAuthLoginPage(AudiocomTrace) const
Page to open in browser to initiate OAuth.
bool OpenInDefaultBrowser(const wxString &url)
Open an URL in default browser.
Definition: BasicUI.cpp:246
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:

◆ OnStateChanged()

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

Definition at line 99 of file UserPanel.cpp.

100{
101 if (mIsAuthorized == isAuthorized)
102 return;
103
104 mIsAuthorized = isAuthorized;
105 Publish(UserPanelStateChangedMessage { isAuthorized });
106}
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 190 of file UserPanel.cpp.

191{
192 mUserName->SetLabel(anonymousText.Translation());
193 mUserImage->SetBitmap(theTheme.Bitmap(bmpAnonymousUser));
194 mUserImage->SetLabel(anonymousText); // for screen readers
195 mLinkButton->SetLabel(XXO("&Link Account").Translation());
197
198 OnStateChanged(false);
199}
THEME_API Theme theTheme
Definition: Theme.cpp:82
wxBitmap & Bitmap(int iIndex)
void SetBitmap(const wxBitmap &bitmap)
Definition: UserImage.cpp:32
void OnStateChanged(bool isAuthorized)
Definition: UserPanel.cpp:99

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 108 of file UserPanel.cpp.

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 {
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 {
144 return;
145 }
146
147 const auto displayName = userService.GetDisplayName();
148
149 if (!displayName.empty()) {
150 mUserName->SetLabel(displayName);
151 mUserImage->wxPanel::SetLabel(displayName); // for screen readers
152 }
153
154 const auto avatarPath = userService.GetAvatarPath();
155
156 if (!avatarPath.empty())
157 mUserImage->SetBitmap(avatarPath);
158 else
159 mUserImage->SetBitmap(theTheme.Bitmap(bmpAnonymousUser));
160
161 mLinkButton->SetLabel(( mLinkMode == LinkMode::Link ?
162 XXO("&Unlink Account") :
163 XXO("&Sign Out") ).Translation());
164 mLinkButton->Show();
165
166 OnStateChanged(true);
167}
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

◆ mAudiocomTrace

const AudiocomTrace audacity::cloud::audiocom::UserPanel::mAudiocomTrace
private

Definition at line 65 of file UserPanel.h.

◆ mAuthService

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

Definition at line 63 of file UserPanel.h.

◆ mIsAuthorized

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

Definition at line 73 of file UserPanel.h.

◆ mLinkButton

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

Definition at line 69 of file UserPanel.h.

◆ mLinkMode

const LinkMode audacity::cloud::audiocom::UserPanel::mLinkMode
private

Definition at line 74 of file UserPanel.h.

◆ mServiceConfig

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

Definition at line 62 of file UserPanel.h.

◆ mUserDataChangedSubscription

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

Definition at line 71 of file UserPanel.h.

◆ mUserImage

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

Definition at line 67 of file UserPanel.h.

◆ mUserName

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

Definition at line 68 of file UserPanel.h.

◆ mUserService

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

Definition at line 64 of file UserPanel.h.


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