Audacity 3.2.0
LinkAccountDialog.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 "LinkAccountDialog.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
29namespace cloud::audiocom
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
82{
84}
85
87{
88 mContinueButton->Disable();
89
90 wxWeakRef<LinkAccountDialog> weakDialog(this);
91
93 audacity::ToUTF8(mToken->GetValue()),
94 [weakDialog](auto accessToken)
95 {
96 BasicUI::CallAfter(
97 [weakDialog, token = std::string(accessToken)]()
98 {
99 if (!token.empty())
100 {
101 if (weakDialog)
102 {
103 auto parent = weakDialog->GetParent();
104 weakDialog->Close();
105
106 LinkSucceededDialog successDialog { parent };
107 successDialog.ShowModal();
108 }
109
110 return;
111 }
112
113 LinkFailedDialog errorDialog(weakDialog);
114
115 if (wxID_RETRY != errorDialog.ShowModal())
116 {
117 if (weakDialog)
118 weakDialog->Close();
119 }
120 });
121 });
122}
123
124void LinkAccountDialog::OnTextChanged()
125{
126 mContinueButton->Enable(!mToken->GetValue().empty());
127}
128
129} // namespace cloud::audiocom
130
131// Remaining code hooks this add-on into the application
132#include "../../commands/CommandContext.h"
133#include "../../commands/CommandManager.h"
134
135namespace {
136// Define our extra menu item
138{
140 dialog.ShowModal();
141}
142
143using namespace MenuTable;
145 Placement{ wxT("Help/Extra"), { OrderingHint::Begin } },
146 Command(
147 wxT("LinkAccount"), XXO("L&ink audio.com account..."),
149};
150}
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,...
Derived from ShuttleGuiBase, an Audacity specific class for shuttling data to and from GUI.
Definition: ShuttleGui.h:630
Holds a msgid for the translation catalog; may also bind format arguments.
void 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
std::string ToUTF8(const std::wstring &wstr)
AuthorizationHandler & GetAuthorizationHandler()
OAuthService & GetOAuthService()
Returns the instance of the OAuthService.