Audacity 3.2.0
Public Types | Static Public Member Functions | Private Member Functions | Static Private Member Functions | Private Attributes | List of all members
LoginDialog Class Referencefinal

#include <LoginDialog.h>

Inheritance diagram for LoginDialog:
[legend]
Collaboration diagram for LoginDialog:
[legend]

Public Types

enum class  Mode { Create , SignIn }
 

Static Public Member Functions

static bool SignIn (wxWindow *parent, Mode mode=Mode::SignIn)
 

Private Member Functions

 LoginDialog (wxWindow *parent, wxWindowID id=wxID_ANY, Mode mode=Mode::SignIn)
 
void LayoutControls ()
 
void OnSignIn (wxHyperlinkEvent &)
 
void OnCreateAccount (wxHyperlinkEvent &)
 
void OnContinue (wxCommandEvent &)
 
void OnContinueWithGoogle (wxCommandEvent &)
 
void OnContinueWithFacebook (wxCommandEvent &)
 
void onUserCredentialsChange (wxCommandEvent &)
 
void ContinueCreateAccount ()
 
void ContinueSignIn ()
 
void OnOAuthStateChanged (audacity::cloud::audiocom::AuthStateChangedMessage)
 

Static Private Member Functions

static void ContinueAuthorize (std::string_view authClientId)
 

Private Attributes

const Mode mMode
 
wxTextCtrl * mEmail {}
 
wxTextCtrl * mPassword {}
 
wxButton * mContinue {}
 
Observer::Subscription mOAuthStateSubscription
 

Additional Inherited Members

- Public Member Functions inherited from wxDialogWrapper
 wxDialogWrapper ()
 
 wxDialogWrapper (wxWindow *parent, wxWindowID id, const TranslatableString &title, const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxDefaultSize, long style=wxDEFAULT_DIALOG_STYLE, const TranslatableString &name=XO("Dialog"))
 
bool Create (wxWindow *parent, wxWindowID id, const TranslatableString &title, const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxDefaultSize, long style=wxDEFAULT_DIALOG_STYLE, const TranslatableString &name=XO("Dialog"))
 
void SetTitle (const TranslatableString &title)
 
void SetLabel (const TranslatableString &title)
 
void SetName (const TranslatableString &title)
 
void SetName ()
 
- Public Member Functions inherited from wxTabTraversalWrapper< wxDialog >
 wxTabTraversalWrapper (Args &&... args)
 
 wxTabTraversalWrapper (const wxTabTraversalWrapper &)=delete
 
 wxTabTraversalWrapper (wxTabTraversalWrapper &&)=delete
 
wxTabTraversalWrapperoperator= (const wxTabTraversalWrapper &)=delete
 
wxTabTraversalWrapperoperator= (wxTabTraversalWrapper &&)=delete
 

Detailed Description

Definition at line 13 of file LoginDialog.h.

Member Enumeration Documentation

◆ Mode

enum class LoginDialog::Mode
strong
Enumerator
Create 
SignIn 

Definition at line 17 of file LoginDialog.h.

18 {
19 Create,
20 SignIn,
21 };
static bool SignIn(wxWindow *parent, Mode mode=Mode::SignIn)
bool Create(wxWindow *parent, wxWindowID id, const TranslatableString &title, const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxDefaultSize, long style=wxDEFAULT_DIALOG_STYLE, const TranslatableString &name=XO("Dialog"))

Constructor & Destructor Documentation

◆ LoginDialog()

LoginDialog::LoginDialog ( wxWindow *  parent,
wxWindowID  id = wxID_ANY,
Mode  mode = Mode::SignIn 
)
private

Definition at line 97 of file LoginDialog.cpp.

98 : wxDialogWrapper(parent, id, DialogNameForMode(mode))
99 , mMode(mode)
100{
103#if defined(__WXMSW__)
104 SetBackgroundColour(theTheme.Colour(clrMedium));
105#endif
106
108}
THEME_API Theme theTheme
Definition: Theme.cpp:82
Observer::Subscription mOAuthStateSubscription
Definition: LoginDialog.h:50
void LayoutControls()
const Mode mMode
Definition: LoginDialog.h:45
void OnOAuthStateChanged(audacity::cloud::audiocom::AuthStateChangedMessage)
Subscription Subscribe(Callback callback)
Connect a callback to the Publisher; later-connected are called earlier.
Definition: Observer.h:199
wxColour & Colour(int iIndex)
auto DialogNameForMode(LoginDialog::Mode mode)
Definition: LoginDialog.cpp:29
OAuthService & GetOAuthService()
Returns the instance of the OAuthService.

References ThemeBase::Colour(), audacity::cloud::audiocom::GetOAuthService(), OnOAuthStateChanged(), Observer::Publisher< Message, NotifyAll >::Subscribe(), and theTheme.

Here is the call graph for this function:

Member Function Documentation

◆ ContinueAuthorize()

void LoginDialog::ContinueAuthorize ( std::string_view  authClientId)
staticprivate

Definition at line 311 of file LoginDialog.cpp.

312{
315 );
316}
static std::string MakeOAuthRequestURL(std::string_view authClientId)
Creates a link to authorization request dialog.
bool OpenInDefaultBrowser(const wxString &url)
Open an URL in default browser.
Definition: BasicUI.cpp:246

References audacity::cloud::audiocom::OAuthService::MakeOAuthRequestURL(), and BasicUI::OpenInDefaultBrowser().

Referenced by OnContinueWithFacebook(), and OnContinueWithGoogle().

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

◆ ContinueCreateAccount()

void LoginDialog::ContinueCreateAccount ( )
private

Definition at line 247 of file LoginDialog.cpp.

248{
249 Disable();
250
251 const auto email = mEmail->GetValue().ToStdString();
252 const auto password = mPassword->GetValue().ToStdString();
253
254 auto& oauthService = audacity::cloud::audiocom::GetOAuthService();
255 oauthService.Register(
256 email,
257 password,
258 [weakThis = wxWeakRef(this)](auto token)
259 {
260 BasicUI::CallAfter([weakThis, token = std::string(token)]()
261 {
262 if(!weakThis)
263 return;
264
265 if(token.empty())
266 {
267 weakThis->Enable();
268 }
269 else
270 weakThis->EndModal(wxID_OK);
271 });
272 },
275}
wxTextCtrl * mPassword
Definition: LoginDialog.h:47
wxTextCtrl * mEmail
Definition: LoginDialog.h:46
void CallAfter(Action action)
Schedule an action to be done later, and in the main thread.
Definition: BasicUI.cpp:214
auto DefaultErrorHandler(LoginDialog *dialog, LoginDialog::Mode mode)
Definition: LoginDialog.cpp:62

References BasicUI::CallAfter(), anonymous_namespace{LoginDialog.cpp}::DefaultErrorHandler(), audacity::cloud::audiocom::GetOAuthService(), ignore, mEmail, mMode, and mPassword.

Referenced by OnContinue().

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

◆ ContinueSignIn()

void LoginDialog::ContinueSignIn ( )
private

Definition at line 277 of file LoginDialog.cpp.

278{
279 Disable();
280
281 const auto email = mEmail->GetValue().ToStdString();
282 const auto password = mPassword->GetValue().ToStdString();
283
284 auto& oauthService = audacity::cloud::audiocom::GetOAuthService();
285 oauthService.Authorize(email, password,
286 [weakThis = wxWeakRef(this)](auto token)
287 {
288 BasicUI::CallAfter([weakThis, token = std::string(token)]()
289 {
290 if(!weakThis)
291 return;
292
293 if(token.empty())
294 {
295 weakThis->Enable();
296 }
297 else
298 weakThis->EndModal(wxID_OK);
299 });
300 },
303}

References BasicUI::CallAfter(), anonymous_namespace{LoginDialog.cpp}::DefaultErrorHandler(), audacity::cloud::audiocom::GetOAuthService(), ignore, mEmail, mMode, and mPassword.

Referenced by OnContinue().

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

◆ LayoutControls()

void LoginDialog::LayoutControls ( )
private

Definition at line 126 of file LoginDialog.cpp.

127{
128 wxFont titleFont = GetFont();
129 titleFont.SetWeight(wxFONTWEIGHT_BOLD);
130 titleFont.SetPixelSize({ 0, 18 });
131
132 auto topSizer = std::make_unique<wxBoxSizer>(wxVERTICAL);
133 wxStaticText* title;
134 topSizer->Add(
135 title = MakeLabel(this,
137 ? _("Create an account to save to the cloud")
138 : _("Sign in to save to the cloud")),
139 0, wxALL, 16);
140 title->SetFont(titleFont);
141 {
142 auto hSizer = std::make_unique<wxBoxSizer>(wxHORIZONTAL);
143 hSizer->Add(MakeLoginButton(this, ID_WITH_GOOGLE, bmpGoogleLogo, XO("Continue with Google")), 1, wxEXPAND);
144 hSizer->AddSpacer(8);
145 hSizer->Add(MakeLoginButton(this, ID_WITH_FACEBOOK, bmpFacebookLogo, XO("Continue with Facebook")), 1, wxEXPAND);
146
147 topSizer->Add(hSizer.release(), 0, wxEXPAND | wxLEFT | wxRIGHT | wxBOTTOM, 16);
148 }
149
150 {
151 auto vSizer = std::make_unique<wxBoxSizer>(wxVERTICAL);
152 vSizer->Add(MakeLabel(this, _("Email")), 0, wxBOTTOM, 5);
153 vSizer->Add(mEmail = safenew wxTextCtrl(this, wxID_ANY), 0, wxEXPAND);
154 topSizer->Add(vSizer.release(), 0, wxEXPAND | wxLEFT | wxRIGHT | wxBOTTOM, 16);
155 }
156 {
157 auto vSizer = std::make_unique<wxBoxSizer>(wxVERTICAL);
158 vSizer->Add(MakeLabel(this, _("Password")), 0, wxBOTTOM, 5);
159 vSizer->Add(mPassword =
160 safenew wxTextCtrl(
161 this,
162 wxID_ANY,
163 wxEmptyString,
164 wxDefaultPosition,
165 wxDefaultSize,
166 wxTE_PASSWORD),
167 0, wxEXPAND);
168 if(mMode == Mode::SignIn)
169 vSizer->Add(safenew wxHyperlinkCtrl(this, wxID_ANY, _("Forgot your password?"), RestorePasswordURL), 0, wxTOP, 10);
170
171 topSizer->Add(vSizer.release(), 0, wxEXPAND | wxLEFT | wxRIGHT | wxBOTTOM, 16);
172
173 mEmail->Bind(wxEVT_TEXT, &LoginDialog::onUserCredentialsChange, this);
174 mPassword->Bind(wxEVT_TEXT, &LoginDialog::onUserCredentialsChange, this);
175 }
176 if(mMode == Mode::Create)
177 {
178 auto hSizer = std::make_unique<wxBoxSizer>(wxHORIZONTAL);
179 //i18b-hint: followed by hyperlink, keep whitespace at the end
180 hSizer->Add(MakeLabel(this, _("Already have an account? ")), 0, wxALIGN_CENTER_VERTICAL);
181 hSizer->Add(safenew wxHyperlinkCtrl(this, ID_SIGNIN, _("Sign in here"), ""));
182 topSizer->Add(hSizer.release(), 0, wxEXPAND | wxLEFT | wxRIGHT, 16);
183 }
184 else
185 {
186 auto hSizer = std::make_unique<wxBoxSizer>(wxHORIZONTAL);
187 //i18b-hint: followed by hyperlink, keep whitespace at the end
188 hSizer->Add(MakeLabel(this, _("Need an account? ")), 0, wxALIGN_CENTER_VERTICAL);
189 hSizer->Add(safenew wxHyperlinkCtrl(this, ID_CREATE_ACCOUNT, _("Create cloud account"), ""));
190 topSizer->Add(hSizer.release(), 0, wxEXPAND | wxALL, 16);
191 }
192
193 {
194 auto hSizer = std::make_unique<wxBoxSizer>(wxHORIZONTAL);
195 hSizer->Add(safenew wxButton(this, wxID_CANCEL, _("Cancel")));
196 hSizer->AddSpacer(8);
197 hSizer->Add(mContinue = safenew wxButton(this, wxID_OK, _("Continue")));
198 topSizer->Add(hSizer.release(), 0, wxALIGN_RIGHT | wxALL, 16);
199 mContinue->Disable();
200 }
201
202 mEmail->SetFocus();
203
204 SetSizerAndFit(topSizer.release());
205}
XO("Cut/Copy/Paste")
#define _(s)
Definition: Internat.h:73
#define safenew
Definition: MemoryX.h:10
static const auto title
void onUserCredentialsChange(wxCommandEvent &)
wxButton * mContinue
Definition: LoginDialog.h:48
AButton * MakeLoginButton(wxWindow *parent, wxWindowID id, int imageId, const TranslatableString &label)
Definition: LoginDialog.cpp:36
wxStaticText * MakeLabel(wxWindow *parent, const wxString &text)
Definition: LoginDialog.cpp:55

References _, Create, anonymous_namespace{LoginDialog.cpp}::ID_CREATE_ACCOUNT, anonymous_namespace{LoginDialog.cpp}::ID_SIGNIN, anonymous_namespace{LoginDialog.cpp}::ID_WITH_FACEBOOK, anonymous_namespace{LoginDialog.cpp}::ID_WITH_GOOGLE, anonymous_namespace{LoginDialog.cpp}::MakeLabel(), anonymous_namespace{LoginDialog.cpp}::MakeLoginButton(), mContinue, mEmail, mMode, mPassword, onUserCredentialsChange(), anonymous_namespace{LoginDialog.cpp}::RestorePasswordURL, safenew, SignIn, title, and XO().

Here is the call graph for this function:

◆ OnContinue()

void LoginDialog::OnContinue ( wxCommandEvent &  )
private

Definition at line 217 of file LoginDialog.cpp.

218{
219 if(mMode == Mode::Create)
221 else
223}
void ContinueCreateAccount()
void ContinueSignIn()

References ContinueCreateAccount(), ContinueSignIn(), Create, and mMode.

Here is the call graph for this function:

◆ OnContinueWithFacebook()

void LoginDialog::OnContinueWithFacebook ( wxCommandEvent &  )
private

Definition at line 230 of file LoginDialog.cpp.

231{
232 ContinueAuthorize("facebook");
233}
static void ContinueAuthorize(std::string_view authClientId)

References ContinueAuthorize().

Here is the call graph for this function:

◆ OnContinueWithGoogle()

void LoginDialog::OnContinueWithGoogle ( wxCommandEvent &  )
private

Definition at line 225 of file LoginDialog.cpp.

226{
227 ContinueAuthorize("google");
228}

References ContinueAuthorize().

Here is the call graph for this function:

◆ OnCreateAccount()

void LoginDialog::OnCreateAccount ( wxHyperlinkEvent &  )
private

Definition at line 212 of file LoginDialog.cpp.

213{
214 EndModal(ID_CREATE_ACCOUNT);
215}

References anonymous_namespace{LoginDialog.cpp}::ID_CREATE_ACCOUNT.

◆ OnOAuthStateChanged()

void LoginDialog::OnOAuthStateChanged ( audacity::cloud::audiocom::AuthStateChangedMessage  message)
private

Definition at line 305 of file LoginDialog.cpp.

306{
307 if(message.authorised)
308 EndModal(wxOK);
309}
bool authorised
Flag that indicates if user is authorised.
Definition: OAuthService.h:36

References audacity::cloud::audiocom::AuthStateChangedMessage::authorised.

Referenced by LoginDialog().

Here is the caller graph for this function:

◆ OnSignIn()

void LoginDialog::OnSignIn ( wxHyperlinkEvent &  )
private

Definition at line 207 of file LoginDialog.cpp.

208{
209 EndModal(ID_SIGNIN);
210}

References anonymous_namespace{LoginDialog.cpp}::ID_SIGNIN.

◆ onUserCredentialsChange()

void LoginDialog::onUserCredentialsChange ( wxCommandEvent &  )
private

Definition at line 235 of file LoginDialog.cpp.

236{
237 if (mEmail->IsEmpty() || mPassword->IsEmpty())
238 {
239 mContinue->Disable();
240 }
241 else
242 {
243 mContinue->Enable();
244 }
245}

References mContinue, mEmail, and mPassword.

Referenced by LayoutControls().

Here is the caller graph for this function:

◆ SignIn()

bool LoginDialog::SignIn ( wxWindow *  parent,
Mode  mode = Mode::SignIn 
)
static

Definition at line 110 of file LoginDialog.cpp.

111{
112 while(true)
113 {
114 LoginDialog dialog(parent, wxID_ANY, mode);
115 dialog.wxDialogWrapper::Center();
116 auto result = dialog.wxDialogWrapper::ShowModal();
117 if(result == ID_SIGNIN)
118 mode = Mode::SignIn;
119 else if(result == ID_CREATE_ACCOUNT)
120 mode = Mode::Create;
121 else
122 return result == wxID_OK;
123 }
124}

References Create, anonymous_namespace{LoginDialog.cpp}::ID_CREATE_ACCOUNT, anonymous_namespace{LoginDialog.cpp}::ID_SIGNIN, and SignIn.

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

Here is the caller graph for this function:

Member Data Documentation

◆ mContinue

wxButton* LoginDialog::mContinue {}
private

Definition at line 48 of file LoginDialog.h.

Referenced by LayoutControls(), and onUserCredentialsChange().

◆ mEmail

wxTextCtrl* LoginDialog::mEmail {}
private

◆ mMode

const Mode LoginDialog::mMode
private

Definition at line 45 of file LoginDialog.h.

Referenced by ContinueCreateAccount(), ContinueSignIn(), LayoutControls(), and OnContinue().

◆ mOAuthStateSubscription

Observer::Subscription LoginDialog::mOAuthStateSubscription
private

Definition at line 50 of file LoginDialog.h.

◆ mPassword

wxTextCtrl* LoginDialog::mPassword {}
private

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