Audacity 3.2.0
CloudProjectPropertiesDialog.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 CloudProjectPropertiesDialog.cpp
7
8 Dmitry Vedenko
9
10**********************************************************************/
11
13
14#include <wx/button.h>
15#include <wx/choice.h>
16#include <wx/sizer.h>
17#include <wx/statline.h>
18#include <wx/stattext.h>
19#include <wx/textctrl.h>
20
21#include "../UserPanel.h"
22#include "LoginDialog.h"
23
24#include "AccessibilityUtils.h"
26#include "CodeConversions.h"
27#include "OAuthService.h"
28
30{
32 const ServiceConfig& serviceConfig, OAuthService& authService,
33 UserService& userService, const wxString& projectName, wxWindow* parent,
34 AudiocomTrace trace)
35 : wxDialogWrapper { parent, wxID_ANY, XO("Save to audio.com") }
36{
38
40 new UserPanel(serviceConfig, authService, userService,
41 UserPanel::LinkMode::SignIn, trace, this);
42
43 mProjectName = new wxTextCtrl { this, wxID_ANY,
44 projectName, wxDefaultPosition,
45 wxDefaultSize, wxTE_PROCESS_ENTER };
46 mProjectName->SetName(XO("Project Name").Translation());
47
48 if (!projectName.empty())
49 {
50 mProjectName->SetValue(projectName);
51 // mProjectName->SetInsertionPoint(-1);
52 }
53
54 const wxString choices[] = { XO("Private").Translation(),
55 XO("Unlisted").Translation(),
56 XO("Public").Translation() };
57
58 mSaveToCloud = new wxButton { this, wxID_ANY, XO("Save").Translation() };
59
61 new wxButton { this, wxID_ANY, XO("Save to computer...").Translation() };
62 mCancel = new wxButton { this, wxID_ANY, XO("Cancel").Translation() };
63
64 mProjectName->SetFocus();
65
68
70
72}
73
75{
77}
78
79std::pair<CloudProjectPropertiesDialog::Action, std::string>
81 const ServiceConfig& serviceConfig, OAuthService& authService,
82 UserService& userService, const wxString& projectName, wxWindow* parent,
83 bool allowLocalSave, AudiocomTrace trace)
84{
85 CloudProjectPropertiesDialog dialog { serviceConfig, authService,
86 userService, projectName,
87 parent, trace };
88
89 dialog.mSaveLocally->Show(allowLocalSave);
90
91 const auto resultCode = dialog.ShowModal();
92
93 const auto action =
94 resultCode == wxID_OK ?
96 (resultCode == wxID_CANCEL ? Action::Cancel : Action::SaveLocally);
97
98 return { action, dialog.GetProjectName() };
99}
100
102{
103 const bool canSubmit =
104 mUserPanel->IsAuthorized() && !GetProjectName().empty();
105
106 if (!canSubmit)
107 return false;
108
109 EndModal(wxID_OK);
110 return true;
111}
112
114{
115 auto* topSizer = new wxBoxSizer { wxVERTICAL };
116
117 constexpr auto spacerHeight = 8;
118
119 topSizer->AddSpacer(spacerHeight);
120
121 topSizer->Add(mUserPanel, 0, wxEXPAND | wxLEFT | wxRIGHT, 16);
122 topSizer->AddSpacer(spacerHeight);
123
124 topSizer->Add(new wxStaticLine { this }, 0, wxEXPAND | wxLEFT | wxRIGHT, 16);
125 topSizer->AddSpacer(spacerHeight);
126
127 topSizer->Add(
128 new wxStaticText { this, wxID_ANY, XO("Project Name").Translation() }, 0,
129 wxEXPAND | wxLEFT | wxRIGHT, 16);
130 topSizer->AddSpacer(spacerHeight);
131
132 topSizer->Add(mProjectName, 0, wxEXPAND | wxLEFT | wxRIGHT, 16);
133
134 topSizer->AddSpacer(spacerHeight);
135
136 topSizer->AddSpacer(2 * spacerHeight);
137
138 auto buttonSizer = new wxBoxSizer { wxHORIZONTAL };
139
140 buttonSizer->Add(mSaveLocally, 0, wxLEFT, 16);
141 buttonSizer->AddStretchSpacer();
142 buttonSizer->Add(mCancel, 0, wxRIGHT, 4);
143 buttonSizer->Add(mSaveToCloud, 0, wxRIGHT, 16);
144
145 topSizer->Add(buttonSizer, 0, wxEXPAND | wxALL, 0);
146 topSizer->AddSpacer(spacerHeight);
147
148 SetMinSize({ 450, -1 });
149 SetSizer(topSizer);
150 Fit();
151 Centre(wxBOTH);
152}
153
155{
156 mSaveToCloud->Bind(wxEVT_BUTTON, [this](auto&)
157 {
158 Disable();
159 if(!GetOAuthService().HasAccessToken())
160 {
162 }
163 Enable();
164 if(GetOAuthService().HasAccessToken())
165 {
166 EndModal(wxID_OK);
167 }
168 });
169 mSaveLocally->Bind(wxEVT_BUTTON, [this](auto&) { EndModal(wxID_SAVE); });
170 mCancel->Bind(wxEVT_BUTTON, [this](auto&) { EndModal(wxID_CANCEL); });
171
172 Bind(
173 wxEVT_CHAR_HOOK,
174 [this](auto& evt)
175 {
176 if (!IsEscapeKey(evt))
177 {
178 evt.Skip();
179 return;
180 }
181
182 EndModal(wxID_CANCEL);
183 });
184
185 Bind(
186 wxEVT_KEY_UP,
187 [this](auto& evt)
188 {
189 const auto keyCode = evt.GetKeyCode();
190 if (keyCode != WXK_RETURN && keyCode != WXK_NUMPAD_ENTER)
191 {
192 evt.Skip();
193 return;
194 }
195
196 if (!OnSubmit())
197 evt.Skip();
198 });
199
200 mProjectName->Bind(wxEVT_TEXT, [this](auto&) { OnUpdateCloudSaveState(); });
201 mProjectName->Bind(wxEVT_TEXT_ENTER, [this](auto&) { OnSubmit(); });
202}
203
205{
206 wxString result { mProjectName->GetValue() };
207 result.Trim(true).Trim(false);
208 return audacity::ToUTF8(result);
209}
210
212{
213 mSaveToCloud->Enable(!GetProjectName().empty());
214}
215
216} // namespace audacity::cloud::audiocom::sync
void SetupAccessibility(wxWindow *window)
Declare functions to perform UTF-8 to std::wstring conversions.
AudiocomTrace
Definition: ExportUtils.h:27
XO("Cut/Copy/Paste")
static bool SignIn(wxWindow *parent, Mode mode=Mode::SignIn)
Service responsible for OAuth authentication against the audio.com service.
Definition: OAuthService.h:43
Configuration for the audio.com.
Definition: ServiceConfig.h:25
Service for providing information about the user profile.
Definition: UserService.h:28
static std::pair< Action, std::string > Show(const ServiceConfig &serviceConfig, OAuthService &authService, UserService &userService, const wxString &projectName, wxWindow *parent, bool allowLocalSave, AudiocomTrace)
CloudProjectPropertiesDialog(const ServiceConfig &serviceConfig, OAuthService &authService, UserService &userService, const wxString &projectName, wxWindow *parent, AudiocomTrace)
AuthorizationHandler & GetAuthorizationHandler()
OAuthService & GetOAuthService()
Returns the instance of the OAuthService.
std::string ToUTF8(const std::wstring &wstr)