Audacity 3.2.0
Public Member Functions | Private Member Functions | Private Attributes | List of all members
anonymous_namespace{CloudProjectFileIOExtensions.cpp}::IOExtension Class Referencefinal
Inheritance diagram for anonymous_namespace{CloudProjectFileIOExtensions.cpp}::IOExtension:
[legend]
Collaboration diagram for anonymous_namespace{CloudProjectFileIOExtensions.cpp}::IOExtension:
[legend]

Public Member Functions

void ForceCloudSave ()
 
void SetUploadModeForNextSave (UploadMode mode)
 
void SetSnapshotCallbackForNextSave (CreateSnapshotCallback callback)
 
- Public Member Functions inherited from ProjectFileIOExtension
virtual ~ProjectFileIOExtension ()
 
virtual OnOpenAction OnOpen (AudacityProject &project, const std::string &path)=0
 This hook is called before the project is opened. More...
 
virtual void OnLoad (AudacityProject &project)=0
 This hook is called after the project is loaded. More...
 
virtual OnSaveAction OnSave (AudacityProject &project, const ProjectSaveCallback &projectSaveCallback)=0
 This hook is called before the project is saved. More...
 
virtual OnCloseAction OnClose (AudacityProject &project)=0
 This hook is called before the project is closed. More...
 
virtual void OnUpdateSaved (AudacityProject &project, const ProjectSerializer &serializer)=0
 This hook is called after the project blob is saved. More...
 
virtual bool IsBlockLocked (const AudacityProject &project, int64_t blockId) const =0
 This hook is called to check if a block is locked. More...
 

Private Member Functions

OnOpenAction OnOpen (AudacityProject &project, const std::string &path) override
 This hook is called before the project is opened. More...
 
void OnLoad (AudacityProject &project) override
 This hook is called after the project is loaded. More...
 
OnSaveAction PerformCloudSave (AudacityProject &project, std::string name, std::string filePath, const ProjectSaveCallback &projectSaveCallback, bool fileRenamed, AudiocomTrace trace)
 
OnSaveAction SaveCloudProject (AudacityProject &project, const ProjectSaveCallback &projectSaveCallback, AudiocomTrace trace)
 
OnSaveAction OnSave (AudacityProject &project, const ProjectSaveCallback &projectSaveCallback) override
 This hook is called before the project is saved. More...
 
OnCloseAction OnClose (AudacityProject &project) override
 This hook is called before the project is closed. More...
 
void OnUpdateSaved (AudacityProject &project, const ProjectSerializer &serializer) override
 This hook is called after the project blob is saved. More...
 
bool IsBlockLocked (const AudacityProject &project, int64_t blockId) const override
 This hook is called to check if a block is locked. More...
 

Private Attributes

CreateSnapshotCallback mSnapshotCallback
 
UploadMode mUploadMode { UploadMode::Normal }
 
AudiocomTrace mAudiocomTrace { AudiocomTrace::SaveProjectSaveToCloudMenu }
 

Detailed Description

Definition at line 47 of file CloudProjectFileIOExtensions.cpp.

Member Function Documentation

◆ ForceCloudSave()

void anonymous_namespace{CloudProjectFileIOExtensions.cpp}::IOExtension::ForceCloudSave ( )
inline

◆ IsBlockLocked()

bool anonymous_namespace{CloudProjectFileIOExtensions.cpp}::IOExtension::IsBlockLocked ( const AudacityProject project,
int64_t  blockId 
) const
inlineoverrideprivatevirtual

This hook is called to check if a block is locked.

Implements ProjectFileIOExtension.

Definition at line 274 of file CloudProjectFileIOExtensions.cpp.

275 {
277 }
const auto project
static ProjectCloudExtension & Get(AudacityProject &project)

References BasicUI::Get(), and project.

Here is the call graph for this function:

◆ OnClose()

OnCloseAction anonymous_namespace{CloudProjectFileIOExtensions.cpp}::IOExtension::OnClose ( AudacityProject project)
inlineoverrideprivatevirtual

This hook is called before the project is closed.

Implements ProjectFileIOExtension.

Definition at line 212 of file CloudProjectFileIOExtensions.cpp.

213 {
214 auto& projectCloudExtension = ProjectCloudExtension::Get(project);
215
216 if (!projectCloudExtension.IsCloudProject())
218
221 }
@ Veto
Extension vetoed the close.
@ Continue
Extension did not veto the close.
static result_type Call(Arguments &&...arguments)
Null check of the installed function is done for you.

References Continue, BasicUI::Get(), project, and Veto.

Here is the call graph for this function:

◆ OnLoad()

void anonymous_namespace{CloudProjectFileIOExtensions.cpp}::IOExtension::OnLoad ( AudacityProject project)
inlineoverrideprivatevirtual

This hook is called after the project is loaded.

Implements ProjectFileIOExtension.

Definition at line 58 of file CloudProjectFileIOExtensions.cpp.

59 {
60 auto& projectCloudExtenstion = ProjectCloudExtension::Get(project);
61 projectCloudExtenstion.OnLoad();
62
63 if (projectCloudExtenstion.IsCloudProject())
65 projectCloudExtenstion, [&project](AudiocomTrace trace) {
67 });
68 }
AudiocomTrace
Definition: ExportUtils.h:27
void ResumeProjectUpload(ProjectCloudExtension &projectCloudExtension, std::function< void(AudiocomTrace)> onBeforeUploadStarts)
AuthResult PerformBlockingAuth(AudacityProject *project, AudiocomTrace trace, const TranslatableString &alternativeActionLabel)

References BasicUI::Get(), audacity::cloud::audiocom::PerformBlockingAuth(), project, and audacity::cloud::audiocom::sync::ResumeProjectUpload().

Here is the call graph for this function:

◆ OnOpen()

OnOpenAction anonymous_namespace{CloudProjectFileIOExtensions.cpp}::IOExtension::OnOpen ( AudacityProject project,
const std::string &  path 
)
inlineoverrideprivatevirtual

This hook is called before the project is opened.

Implements ProjectFileIOExtension.

Definition at line 50 of file CloudProjectFileIOExtensions.cpp.

51 {
52 return SyncCloudProject(
56 }
@ Continue
ProjectManager should continue with the open.
@ Cancel
Open was cancelled by the extension.
bool SyncCloudProject(AudacityProject &project, std::string_view path, AudiocomTrace trace, bool force)

References Cancel, Continue, OpenFromCloudMenu, project, and audacity::cloud::audiocom::sync::SyncCloudProject().

Here is the call graph for this function:

◆ OnSave()

OnSaveAction anonymous_namespace{CloudProjectFileIOExtensions.cpp}::IOExtension::OnSave ( AudacityProject project,
const ProjectSaveCallback projectSaveCallback 
)
inlineoverrideprivatevirtual

This hook is called before the project is saved.

Implements ProjectFileIOExtension.

Definition at line 146 of file CloudProjectFileIOExtensions.cpp.

149 {
150 auto& projectCloudExtension = ProjectCloudExtension::Get(project);
151 auto& projectFileIO = ProjectFileIO::Get(project);
152
153 const bool isTemporary = projectFileIO.IsTemporary();
154 const bool isCloudProject = projectCloudExtension.IsCloudProject();
155
156 const bool forceSaveToCloud =
158
159 Finally finally { [&] {
161 } };
162
163 auto parent = &ProjectWindow::Get(project);
164
165 // Check location first
166 if (isTemporary && !forceSaveToCloud)
167 {
168 CloudLocationDialog cloudLocationDialog { parent,
170 const auto saveAction = cloudLocationDialog.ShowDialog();
171
172 // Not doing a cloud save
173 if (saveAction == LocationDialogResult::Local)
175 else if (saveAction == LocationDialogResult::Cancel)
177 }
178
179 // For regular projects - do nothing
180 if (!isTemporary && !forceSaveToCloud && !isCloudProject)
182
183 const auto trace = forceSaveToCloud ?
186
187 if (!isTemporary)
188 return SaveCloudProject(project, projectSaveCallback, trace);
189
192 project.GetProjectName(), parent, false, trace);
193
194 if (result.first == CloudProjectPropertiesDialog::Action::Cancel)
195 // Suppress the Save function completely
197 else if (
198 result.first == CloudProjectPropertiesDialog::Action::SaveLocally)
199 // Just let the things flow as usual
201
202 const auto dir = CloudProjectsSavePath.Read();
203 FileNames::MkDir(dir);
204
205 const auto filePath = sync::MakeSafeProjectPath(dir, result.second);
206
207 return PerformCloudSave(
208 project, result.second, audacity::ToUTF8(filePath),
209 projectSaveCallback, true, mAudiocomTrace);
210 }
@ SaveProjectSaveToCloudMenu
@ Continue
Save was not handled by the extension.
@ Cancelled
Save was cancelled by the extension.
static ProjectFileIO & Get(AudacityProject &project)
static ProjectWindow & Get(AudacityProject &project)
bool Read(T *pVar) const
overload of Read returning a boolean that is true if the value was previously defined *‍/
Definition: Prefs.h:207
OnSaveAction PerformCloudSave(AudacityProject &project, std::string name, std::string filePath, const ProjectSaveCallback &projectSaveCallback, bool fileRenamed, AudiocomTrace trace)
OnSaveAction SaveCloudProject(AudacityProject &project, const ProjectSaveCallback &projectSaveCallback, AudiocomTrace trace)
static std::pair< Action, std::string > Show(const ServiceConfig &serviceConfig, OAuthService &authService, UserService &userService, const wxString &projectName, wxWindow *parent, bool allowLocalSave, AudiocomTrace)
FILES_API wxString MkDir(const wxString &Str)
wxString MakeSafeProjectPath(const wxString &rootDir, const wxString &projectName)
UserService & GetUserService()
OAuthService & GetOAuthService()
Returns the instance of the OAuthService.
const ServiceConfig & GetServiceConfig()
Returns the instance of the ServiceConfig.
std::string ToUTF8(const std::wstring &wstr)
"finally" as in The C++ Programming Language, 4th ed., p. 358 Useful for defining ad-hoc RAII actions...
Definition: MemoryX.h:175

References Cancelled, audacity::cloud::audiocom::CloudProjectsSavePath, Continue, BasicUI::Get(), ProjectFileIO::Get(), ProjectWindow::Get(), audacity::cloud::audiocom::GetOAuthService(), audacity::cloud::audiocom::GetServiceConfig(), audacity::cloud::audiocom::GetUserService(), audacity::cloud::audiocom::sync::MakeSafeProjectPath(), FileNames::MkDir(), project, Setting< T >::Read(), SaveProjectSaveToCloudMenu, SaveToCloudMenu, ExportProgressUI::Show(), audacity::cloud::audiocom::sync::CloudLocationDialog::ShowDialog(), and audacity::ToUTF8().

Here is the call graph for this function:

◆ OnUpdateSaved()

void anonymous_namespace{CloudProjectFileIOExtensions.cpp}::IOExtension::OnUpdateSaved ( AudacityProject project,
const ProjectSerializer serializer 
)
inlineoverrideprivatevirtual

This hook is called after the project blob is saved.

Implements ProjectFileIOExtension.

Definition at line 223 of file CloudProjectFileIOExtensions.cpp.

225 {
226 auto& projectCloudExtension = ProjectCloudExtension::Get(project);
227
228 if (!projectCloudExtension.IsCloudProject())
229 return;
230
231 projectCloudExtension.OnUpdateSaved(serializer);
232
233 const int savesCount = projectCloudExtension.GetSavesCount();
234
235 if (savesCount < 2)
236 {
237 SyncInBackroundDialog { &project }.ShowDialog();
238 }
239
240 if (projectCloudExtension.IsFirstSyncDialogShown())
241 return;
242
244 [weakProject = project.weak_from_this()] {
245 auto project = weakProject.lock();
246
247 if (!project)
248 return true;
249
250 return ProjectCloudExtension::Get(*project)
251 .GetCurrentSyncStatus() == ProjectSyncStatus::Synced;
252 },
253 [weakProject = project.weak_from_this(), trace = mAudiocomTrace] {
254 auto project = weakProject.lock();
255
256 if (
257 !project ||
258 ProjectCloudExtension::Get(*project).IsFirstSyncDialogShown())
259 return;
260
261 ProjectCloudExtension::Get(*project).SetFirstSyncDialogShown(true);
262
263 const auto result =
264 SyncSucceededDialog { project.get() }.ShowDialog();
265
269 trace)));
270 });
271 }
bool OpenInDefaultBrowser(const wxString &url)
Open an URL in default browser.
Definition: BasicUI.cpp:246
void ShowDialogOn(std::function< bool()> condition, std::function< void()> dialogFactory)
wxString ToWXString(const std::string &str)

References BasicUI::Get(), BasicUI::OpenInDefaultBrowser(), project, audacity::cloud::audiocom::sync::ShowDialogOn(), and audacity::ToWXString().

Here is the call graph for this function:

◆ PerformCloudSave()

OnSaveAction anonymous_namespace{CloudProjectFileIOExtensions.cpp}::IOExtension::PerformCloudSave ( AudacityProject project,
std::string  name,
std::string  filePath,
const ProjectSaveCallback projectSaveCallback,
bool  fileRenamed,
AudiocomTrace  trace 
)
inlineprivate

Definition at line 70 of file CloudProjectFileIOExtensions.cpp.

74 {
75 auto& projectCloudExtension = ProjectCloudExtension::Get(project);
76
77 projectCloudExtension.OnSyncStarted();
78
79 auto future = LocalProjectSnapshot::Create(
80 GetServiceConfig(), GetOAuthService(), projectCloudExtension, name,
81 mUploadMode, trace);
82
84
85 // Do we need UI here?
86 // while (future.wait_for(std::chrono::milliseconds(50)) !=
87 // std::future_status::ready)
88 // BasicUI::Yield();
89
90 auto result = future.get();
91
92 if (!result.Response)
93 // Prevent any updates to the file to preserve the correct state.
94 // Errors would be handled by the UI extension
96
97 if (!projectSaveCallback(audacity::ToUTF8(filePath), fileRenamed))
98 {
99 if (result.Operation)
100 result.Operation->Abort();
101 else
102 projectCloudExtension.OnSyncCompleted(
103 nullptr, CloudSyncError { CloudSyncError::Aborted }, trace);
104 // Something has failed horrible during the save
106 }
107
109 {
110 mSnapshotCallback(*result.Response);
112 }
113
115 }
@ Handled
Save was handled by the extension.
wxString name
Definition: TagsEditor.cpp:166
static Future Create(const ServiceConfig &config, const OAuthService &oauthService, ProjectCloudExtension &extension, std::string name, UploadMode mode, AudiocomTrace trace)

References Cancelled, BasicUI::Get(), audacity::cloud::audiocom::GetOAuthService(), audacity::cloud::audiocom::GetServiceConfig(), Handled, name, project, and audacity::ToUTF8().

Here is the call graph for this function:

◆ SaveCloudProject()

OnSaveAction anonymous_namespace{CloudProjectFileIOExtensions.cpp}::IOExtension::SaveCloudProject ( AudacityProject project,
const ProjectSaveCallback projectSaveCallback,
AudiocomTrace  trace 
)
inlineprivate

Definition at line 117 of file CloudProjectFileIOExtensions.cpp.

120 {
121 auto authResult = PerformBlockingAuth(&project, trace);
122
123 if (authResult.Result == AuthResult::Status::Failure)
124 {
125 LinkFailedDialog dialog { &ProjectWindow::Get(project), trace };
126 dialog.ShowModal();
127 // Pretend we have canceled the save
129 }
130 else if (authResult.Result == AuthResult::Status::Cancelled)
131 {
133 }
134 else if (authResult.Result == AuthResult::Status::UseAlternative)
135 {
138 }
139
140 return PerformCloudSave(
141 project, audacity::ToUTF8(project.GetProjectName()),
143 projectSaveCallback, false, trace);
144 }
const FilePath & GetFileName() const

References Cancelled, RefreshCode::Cancelled, Continue, ProjectFileIO::Get(), ProjectWindow::Get(), ProjectFileIO::GetFileName(), ProjectFileIO::MarkTemporary(), audacity::cloud::audiocom::PerformBlockingAuth(), project, and audacity::ToUTF8().

Here is the call graph for this function:

◆ SetSnapshotCallbackForNextSave()

void anonymous_namespace{CloudProjectFileIOExtensions.cpp}::IOExtension::SetSnapshotCallbackForNextSave ( CreateSnapshotCallback  callback)
inline

Definition at line 290 of file CloudProjectFileIOExtensions.cpp.

291 {
292 mSnapshotCallback = std::move(callback);
293 }

◆ SetUploadModeForNextSave()

void anonymous_namespace{CloudProjectFileIOExtensions.cpp}::IOExtension::SetUploadModeForNextSave ( UploadMode  mode)
inline

Definition at line 285 of file CloudProjectFileIOExtensions.cpp.

286 {
287 mUploadMode = mode;
288 }

Member Data Documentation

◆ mAudiocomTrace

AudiocomTrace anonymous_namespace{CloudProjectFileIOExtensions.cpp}::IOExtension::mAudiocomTrace { AudiocomTrace::SaveProjectSaveToCloudMenu }
private

Definition at line 301 of file CloudProjectFileIOExtensions.cpp.

◆ mSnapshotCallback

CreateSnapshotCallback anonymous_namespace{CloudProjectFileIOExtensions.cpp}::IOExtension::mSnapshotCallback
private

Definition at line 297 of file CloudProjectFileIOExtensions.cpp.

◆ mUploadMode

UploadMode anonymous_namespace{CloudProjectFileIOExtensions.cpp}::IOExtension::mUploadMode { UploadMode::Normal }
private

Definition at line 299 of file CloudProjectFileIOExtensions.cpp.


The documentation for this class was generated from the following file: