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#include "ExportUtils.h"
23
24#include "OAuthService.h"
25
27#include "LinkFailedDialog.h"
28#include "LinkSucceededDialog.h"
29
31{
34 parent, wxID_ANY, XO("Link account"), wxDefaultPosition, { 480, -1 },
35 wxDEFAULT_DIALOG_STYLE)
36 , mAudiocomTrace(trace)
37{
39
40 ShuttleGui s(this, eIsCreating);
41
42 s.StartVerticalLay();
43 {
44 s.StartInvisiblePanel(16);
45 {
46 s.SetBorder(0);
47 s.AddFixedText(XO("Enter token to link your account"));
48
49 s.AddSpace(0, 4, 0);
50
51 mToken = s.AddTextBox(TranslatableString {}, {}, 60);
52 mToken->SetName(XO("Token").Translation());
53 mToken->Bind(wxEVT_TEXT, [this](auto) { OnTextChanged(); });
54
55 s.AddSpace(0, 16, 0);
56
57 s.AddWindow(safenew wxStaticLine { s.GetParent() }, wxEXPAND);
58
59 s.AddSpace(0, 10, 0);
60
61 s.StartHorizontalLay(wxEXPAND, 0);
62 {
63 s.AddSpace(0, 0, 1);
64
65 s.AddButton(XXO("&Cancel"))
66 ->Bind(wxEVT_BUTTON, [this](auto) { Close(); });
67
68 mContinueButton = s.AddButton(XXO("C&ontinue"));
69 mContinueButton->Disable();
70 mContinueButton->Bind(wxEVT_BUTTON, [this](auto) { OnContinue(); });
71 }
72 s.EndHorizontalLay();
73 }
74 s.EndInvisiblePanel();
75 }
76 s.EndVerticalLay();
77
78 Layout();
79 Fit();
80 Centre();
81
82 mToken->SetFocus();
83}
84
86{
88}
89
91{
92 mContinueButton->Disable();
93
94 wxWeakRef<LinkWithTokenDialog> weakDialog(this);
95
98 [weakDialog, trace = mAudiocomTrace](auto accessToken) {
99 BasicUI::CallAfter(
100 [weakDialog, token = std::string(accessToken), trace]() {
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, trace);
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{
143 };
144 dialog.ShowModal();
145}
146
147using namespace MenuRegistry;
149 Command(
150 wxT("LinkAccount"), XXO("L&ink audio.com account..."),
152 Placement{ wxT("Help/Extra"), { OrderingHint::Begin } }
153};
154}
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
AudiocomTrace
Definition: ExportUtils.h:27
@ LinkAudiocomAccountHelpMenu
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, AudiocomTrace, AuthSuccessCallback 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)