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
23#include "AccessibilityUtils.h"
25#include "CodeConversions.h"
26
28{
30 const ServiceConfig& serviceConfig, OAuthService& authService,
31 UserService& userService, const wxString& projectName, wxWindow* parent,
32 AudiocomTrace trace)
33 : wxDialogWrapper { parent, wxID_ANY, XO("Save to audio.com") }
34{
36
38 new UserPanel(serviceConfig, authService, userService, true, trace, this);
39
41 mUserPanel->Subscribe([this](auto) { OnUpdateCloudSaveState(); });
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 mAnonStateText = safenew wxStaticText {
49 this, wxID_ANY,
50 XO("Cloud saving requires a free audio.com account linked to Audacity. Press \"Link account\" above to proceed.")
51 .Translation()
52 };
53
54 mAnonStateText->Wrap(450 - 32);
55
56 if (!projectName.empty())
57 {
58 mProjectName->SetValue(projectName);
59 // mProjectName->SetInsertionPoint(-1);
60 }
61
62 const wxString choices[] = { XO("Private").Translation(),
63 XO("Unlisted").Translation(),
64 XO("Public").Translation() };
65
66 mSaveToCloud = new wxButton { this, wxID_ANY, XO("Save").Translation() };
67
69 new wxButton { this, wxID_ANY, XO("Save to computer...").Translation() };
70 mCancel = new wxButton { this, wxID_ANY, XO("Cancel").Translation() };
71
72 mProjectName->SetFocus();
73
76
78
80}
81
83{
85}
86
87std::pair<CloudProjectPropertiesDialog::Action, std::string>
89 const ServiceConfig& serviceConfig, OAuthService& authService,
90 UserService& userService, const wxString& projectName, wxWindow* parent,
91 bool allowLocalSave, AudiocomTrace trace)
92{
93 CloudProjectPropertiesDialog dialog { serviceConfig, authService,
94 userService, projectName,
95 parent, trace };
96
97 dialog.mSaveLocally->Show(allowLocalSave);
98
99 const auto resultCode = dialog.ShowModal();
100
101 const auto action =
102 resultCode == wxID_OK ?
104 (resultCode == wxID_CANCEL ? Action::Cancel : Action::SaveLocally);
105
106 return { action, dialog.GetProjectName() };
107}
108
110{
111 const bool canSubmit =
112 mUserPanel->IsAuthorized() && !GetProjectName().empty();
113
114 if (!canSubmit)
115 return false;
116
117 EndModal(wxID_OK);
118 return true;
119}
120
122{
123 auto* topSizer = new wxBoxSizer { wxVERTICAL };
124
125 constexpr auto spacerHeight = 8;
126
127 topSizer->AddSpacer(spacerHeight);
128
129 topSizer->Add(mUserPanel, 0, wxEXPAND | wxLEFT | wxRIGHT, 16);
130 topSizer->AddSpacer(spacerHeight);
131
132 topSizer->Add(new wxStaticLine { this }, 0, wxEXPAND | wxLEFT | wxRIGHT, 16);
133 topSizer->AddSpacer(spacerHeight);
134
135 topSizer->Add(
136 new wxStaticText { this, wxID_ANY, XO("Project Name").Translation() }, 0,
137 wxEXPAND | wxLEFT | wxRIGHT, 16);
138 topSizer->AddSpacer(spacerHeight);
139
140 topSizer->Add(mProjectName, 0, wxEXPAND | wxLEFT | wxRIGHT, 16);
141
142 topSizer->AddSpacer(spacerHeight);
143
144 topSizer->Add(mAnonStateText, 0, wxEXPAND | wxLEFT | wxRIGHT, 16);
145
146 topSizer->AddSpacer(2 * spacerHeight);
147
148 auto buttonSizer = new wxBoxSizer { wxHORIZONTAL };
149
150 buttonSizer->Add(mSaveLocally, 0, wxLEFT, 16);
151 buttonSizer->AddStretchSpacer();
152 buttonSizer->Add(mCancel, 0, wxRIGHT, 4);
153 buttonSizer->Add(mSaveToCloud, 0, wxRIGHT, 16);
154
155 topSizer->Add(buttonSizer, 0, wxEXPAND | wxALL, 0);
156 topSizer->AddSpacer(spacerHeight);
157
158 SetMinSize({ 450, -1 });
159 SetSizer(topSizer);
160 Fit();
161 Centre(wxBOTH);
162
164}
165
167{
168 mSaveToCloud->Bind(wxEVT_BUTTON, [this](auto&) { EndModal(wxID_OK); });
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(
214 mUserPanel->IsAuthorized() && !GetProjectName().empty());
215
217 Fit();
218 Layout();
219}
220
221} // 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")
#define safenew
Definition: MemoryX.h:10
Subscription Subscribe(Callback callback)
Connect a callback to the Publisher; later-connected are called earlier.
Definition: Observer.h:199
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()
std::string ToUTF8(const std::wstring &wstr)