Audacity 3.2.0
LinkWithTokenDialog.cpp
Go to the documentation of this file.
1/* SPDX-License-Identifier: GPL-2.0-or-later */
2/*!********************************************************************
3
4 Audacity: A Digital Audio Editor
5
6 LinkAccountDialog.cpp
7
8 Dmitry Vedenko
9
10**********************************************************************/
11#include "LinkWithTokenDialog.h"
12
13#include <wx/button.h>
14#include <wx/textctrl.h>
15#include <wx/statline.h>
16#include <wx/weakref.h>
17
18#include "ShuttleGui.h"
19
20#include "BasicUI.h"
21#include "CodeConversions.h"
22
23#include "OAuthService.h"
24
26#include "LinkFailedDialog.h"
27#include "LinkSucceededDialog.h"
28
30{
33 parent, wxID_ANY, XO("Link account"), wxDefaultPosition, { 480, -1 },
34 wxDEFAULT_DIALOG_STYLE)
35{
37
38 ShuttleGui s(this, eIsCreating);
39
40 s.StartVerticalLay();
41 {
42 s.StartInvisiblePanel(16);
43 {
44 s.SetBorder(0);
45 s.AddFixedText(XO("Enter token to link your account"));
46
47 s.AddSpace(0, 4, 0);
48
49 mToken = s.AddTextBox(TranslatableString {}, {}, 60);
50 mToken->SetName(XO("Token").Translation());
51 mToken->Bind(wxEVT_TEXT, [this](auto) { OnTextChanged(); });
52
53 s.AddSpace(0, 16, 0);
54
55 s.AddWindow(safenew wxStaticLine { s.GetParent() }, wxEXPAND);
56
57 s.AddSpace(0, 10, 0);
58
59 s.StartHorizontalLay(wxEXPAND, 0);
60 {
61 s.AddSpace(0, 0, 1);
62
63 s.AddButton(XXO("&Cancel"))
64 ->Bind(wxEVT_BUTTON, [this](auto) { Close(); });
65
66 mContinueButton = s.AddButton(XXO("C&ontinue"));
67 mContinueButton->Disable();
68 mContinueButton->Bind(wxEVT_BUTTON, [this](auto) { OnContinue(); });
69 }
70 s.EndHorizontalLay();
71 }
72 s.EndInvisiblePanel();
73 }
74 s.EndVerticalLay();
75
76 Layout();
77 Fit();
78 Centre();
79
80 mToken->SetFocus();
81}
82
84{
86}
87
89{
90 mContinueButton->Disable();
91
92 wxWeakRef<LinkWithTokenDialog> weakDialog(this);
93
95 audacity::ToUTF8(mToken->GetValue()),
96 [weakDialog](auto accessToken)
97 {
98 BasicUI::CallAfter(
99 [weakDialog, token = std::string(accessToken)]()
100 {
101 if (!token.empty())
102 {
103 if (weakDialog)
104 {
105 auto parent = weakDialog->GetParent();
106 weakDialog->Close();
107
108 LinkSucceededDialog successDialog { parent };
109 successDialog.ShowModal();
110 }
111
112 return;
113 }
114
115 LinkFailedDialog errorDialog(weakDialog);
116
117 if (wxID_RETRY != errorDialog.ShowModal())
118 {
119 if (weakDialog)
120 weakDialog->Close();
121 }
122 });
123 });
124}
125
126void LinkWithTokenDialog::OnTextChanged()
127{
128 mContinueButton->Enable(!mToken->GetValue().empty());
129}
130
131} // namespace audacity::cloud::audiocom
132
133// Remaining code hooks this add-on into the application
134#include "CommandContext.h"
135#include "MenuRegistry.h"
136
137namespace {
138// Define our extra menu item
140{
142 dialog.ShowModal();
143}
144
145using namespace MenuRegistry;
147 Command(
148 wxT("LinkAccount"), XXO("L&ink audio.com account..."),
150 Placement{ wxT("Help/Extra"), { OrderingHint::Begin } }
151};
152}
wxT("CloseDown"))
Toolkit-neutral facade for basic user interface services.
Declare functions to perform UTF-8 to std::wstring conversions.
constexpr CommandFlag AlwaysEnabledFlag
Definition: CommandFlag.h:34
XO("Cut/Copy/Paste")
XXO("&Cut/Copy/Paste Toolbar")
#define safenew
Definition: MemoryX.h:10
@ eIsCreating
Definition: ShuttleGui.h:37
CommandContext provides additional information to an 'Apply()' command. It provides the project,...
Generates classes whose instances register items at construction.
Definition: Registry.h:388
Derived from ShuttleGuiBase, an Audacity specific class for shuttling data to and from GUI.
Definition: ShuttleGui.h:640
Holds a msgid for the translation catalog; may also bind format arguments.
bool HandleLinkURI(std::string_view uri, std::function< void(std::string_view)> completedHandler)
Handle the OAuth callback.
bool Begin(const FilePath &dataDir)
Definition: Journal.cpp:226
constexpr auto Command
Definition: MenuRegistry.h:456
AuthorizationHandler & GetAuthorizationHandler()
OAuthService & GetOAuthService()
Returns the instance of the OAuthService.
std::string ToUTF8(const std::wstring &wstr)