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 : wxDialogWrapper { parent, wxID_ANY, XO("Save to audio.com") }
33{
35
37 new UserPanel(serviceConfig, authService, userService, true, this);
38
40 mUserPanel->Subscribe([this](auto) { OnUpdateCloudSaveState(); });
41
42 mProjectName = new wxTextCtrl { this, wxID_ANY,
43 projectName, wxDefaultPosition,
44 wxDefaultSize, wxTE_PROCESS_ENTER };
45 mProjectName->SetName(XO("Project Name").Translation());
46
47 mAnonStateText = safenew wxStaticText {
48 this, wxID_ANY,
49 XO("Cloud saving requires a free audio.com account linked to Audacity. Press \"Link account\" above to proceed.")
50 .Translation()
51 };
52
53 mAnonStateText->Wrap(450 - 32);
54
55 if (!projectName.empty())
56 {
57 mProjectName->SetValue(projectName);
58 // mProjectName->SetInsertionPoint(-1);
59 }
60
61 const wxString choices[] = { XO("Private").Translation(),
62 XO("Unlisted").Translation(),
63 XO("Public").Translation() };
64
65 mSaveToCloud = new wxButton { this, wxID_ANY, XO("Save").Translation() };
66
68 new wxButton { this, wxID_ANY, XO("Save to computer...").Translation() };
69 mCancel = new wxButton { this, wxID_ANY, XO("Cancel").Translation() };
70
71 mProjectName->SetFocus();
72
75
77
79}
80
82{
84}
85
86std::pair<CloudProjectPropertiesDialog::Action, std::string>
88 const ServiceConfig& serviceConfig, OAuthService& authService,
89 UserService& userService, const wxString& projectName, wxWindow* parent,
90 bool allowLocalSave)
91{
92 CloudProjectPropertiesDialog dialog { serviceConfig, authService,
93 userService, projectName, parent };
94
95 dialog.mSaveLocally->Show(allowLocalSave);
96
97 const auto resultCode = dialog.ShowModal();
98
99 const auto action =
100 resultCode == wxID_OK ?
102 (resultCode == wxID_CANCEL ? Action::Cancel : Action::SaveLocally);
103
104 return { action, dialog.GetProjectName() };
105}
106
108{
109 const bool canSubmit =
110 mUserPanel->IsAuthorized() && !GetProjectName().empty();
111
112 if (!canSubmit)
113 return false;
114
115 EndModal(wxID_OK);
116 return true;
117}
118
120{
121 auto* topSizer = new wxBoxSizer { wxVERTICAL };
122
123 constexpr auto spacerHeight = 8;
124
125 topSizer->AddSpacer(spacerHeight);
126
127 topSizer->Add(mUserPanel, 0, wxEXPAND | wxLEFT | wxRIGHT, 16);
128 topSizer->AddSpacer(spacerHeight);
129
130 topSizer->Add(new wxStaticLine { this }, 0, wxEXPAND | wxLEFT | wxRIGHT, 16);
131 topSizer->AddSpacer(spacerHeight);
132
133 topSizer->Add(
134 new wxStaticText { this, wxID_ANY, XO("Project Name").Translation() }, 0,
135 wxEXPAND | wxLEFT | wxRIGHT, 16);
136 topSizer->AddSpacer(spacerHeight);
137
138 topSizer->Add(mProjectName, 0, wxEXPAND | wxLEFT | wxRIGHT, 16);
139
140 topSizer->AddSpacer(spacerHeight);
141
142 topSizer->Add(mAnonStateText, 0, wxEXPAND | wxLEFT | wxRIGHT, 16);
143
144 topSizer->AddSpacer(2 * spacerHeight);
145
146 auto buttonSizer = new wxBoxSizer { wxHORIZONTAL };
147
148 buttonSizer->Add(mSaveLocally, 0, wxLEFT, 16);
149 buttonSizer->AddStretchSpacer();
150 buttonSizer->Add(mCancel, 0, wxRIGHT, 4);
151 buttonSizer->Add(mSaveToCloud, 0, wxRIGHT, 16);
152
153 topSizer->Add(buttonSizer, 0, wxEXPAND | wxALL, 0);
154 topSizer->AddSpacer(spacerHeight);
155
156 SetMinSize({ 450, -1 });
157 SetSizer(topSizer);
158 Fit();
159 Centre(wxBOTH);
160
162}
163
165{
166 mSaveToCloud->Bind(wxEVT_BUTTON, [this](auto&) { EndModal(wxID_OK); });
167 mSaveLocally->Bind(wxEVT_BUTTON, [this](auto&) { EndModal(wxID_SAVE); });
168 mCancel->Bind(wxEVT_BUTTON, [this](auto&) { EndModal(wxID_CANCEL); });
169
170 Bind(
171 wxEVT_CHAR_HOOK,
172 [this](auto& evt)
173 {
174 if (!IsEscapeKey(evt))
175 {
176 evt.Skip();
177 return;
178 }
179
180 EndModal(wxID_CANCEL);
181 });
182
183 Bind(
184 wxEVT_KEY_UP,
185 [this](auto& evt)
186 {
187 const auto keyCode = evt.GetKeyCode();
188 if (keyCode != WXK_RETURN && keyCode != WXK_NUMPAD_ENTER)
189 {
190 evt.Skip();
191 return;
192 }
193
194 if (!OnSubmit())
195 evt.Skip();
196 });
197
198 mProjectName->Bind(wxEVT_TEXT, [this](auto&) { OnUpdateCloudSaveState(); });
199 mProjectName->Bind(wxEVT_TEXT_ENTER, [this](auto&) { OnSubmit(); });
200}
201
203{
204 wxString result { mProjectName->GetValue() };
205 result.Trim(true).Trim(false);
206 return audacity::ToUTF8(result);
207}
208
210{
211 mSaveToCloud->Enable(
212 mUserPanel->IsAuthorized() && !GetProjectName().empty());
213
215 Fit();
216 Layout();
217}
218
219} // namespace audacity::cloud::audiocom::sync
void SetupAccessibility(wxWindow *window)
Declare functions to perform UTF-8 to std::wstring conversions.
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:40
Configuration for the audio.com.
Definition: ServiceConfig.h:23
Service for providing information about the user profile.
Definition: UserService.h:28
CloudProjectPropertiesDialog(const ServiceConfig &serviceConfig, OAuthService &authService, UserService &userService, const wxString &projectName, wxWindow *parent)
static std::pair< Action, std::string > Show(const ServiceConfig &serviceConfig, OAuthService &authService, UserService &userService, const wxString &projectName, wxWindow *parent, bool allowLocalSave)
AuthorizationHandler & GetAuthorizationHandler()
std::string ToUTF8(const std::wstring &wstr)