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)
 
OnSaveAction SaveCloudProject (AudacityProject &project, const ProjectSaveCallback &projectSaveCallback)
 
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 }
 
bool mForceCloudSave {}
 

Detailed Description

Definition at line 46 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 261 of file CloudProjectFileIOExtensions.cpp.

262 {
264 }
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 198 of file CloudProjectFileIOExtensions.cpp.

199 {
200 auto& projectCloudExtension = ProjectCloudExtension::Get(project);
201
202 if (!projectCloudExtension.IsCloudProject())
204
207 }
@ 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 55 of file CloudProjectFileIOExtensions.cpp.

56 {
57 auto& projectCloudExtenstion = ProjectCloudExtension::Get(project);
58 projectCloudExtenstion.OnLoad();
59
60 if (projectCloudExtenstion.IsCloudProject())
62 projectCloudExtenstion,
64 }
void ResumeProjectUpload(ProjectCloudExtension &projectCloudExtension, std::function< void()> onBeforeUploadStarts)
AuthResult PerformBlockingAuth(AudacityProject *project, 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 49 of file CloudProjectFileIOExtensions.cpp.

50 {
53 }
@ Continue
ProjectManager should continue with the open.
@ Cancel
Open was cancelled by the extension.
bool SyncCloudProject(AudacityProject &project, std::string_view path, bool force)

References Cancel, Continue, 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 140 of file CloudProjectFileIOExtensions.cpp.

143 {
144 auto& projectCloudExtension = ProjectCloudExtension::Get(project);
145 auto& projectFileIO = ProjectFileIO::Get(project);
146
147 const bool isTemporary = projectFileIO.IsTemporary();
148 const bool isCloudProject = projectCloudExtension.IsCloudProject();
149
150 const bool pendingCloudSave = mForceCloudSave;
151 mForceCloudSave = false;
152
153 auto parent = &ProjectWindow::Get(project);
154
155 // Check location first
156 if (isTemporary && !pendingCloudSave)
157 {
158 CloudLocationDialog cloudLocationDialog { parent,
160 const auto saveAction = cloudLocationDialog.ShowDialog();
161
162 // Not doing a cloud save
163 if (saveAction == LocationDialogResult::Local)
165 else if (saveAction == LocationDialogResult::Cancel)
167 }
168
169 // For regular projects - do nothing
170 if (!isTemporary && !pendingCloudSave && !isCloudProject)
172
173 if (!isTemporary)
174 return SaveCloudProject(project, projectSaveCallback);
175
178 project.GetProjectName(), parent, false);
179
180 if (result.first == CloudProjectPropertiesDialog::Action::Cancel)
181 // Suppress the Save function completely
183 else if (
184 result.first == CloudProjectPropertiesDialog::Action::SaveLocally)
185 // Just let the things flow as usual
187
188 const auto dir = CloudProjectsSavePath.Read();
189 FileNames::MkDir(dir);
190
191 const auto filePath = sync::MakeSafeProjectPath(dir, result.second);
192
193 return PerformCloudSave(
194 project, result.second, audacity::ToUTF8(filePath),
195 projectSaveCallback, true);
196 }
@ 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)
OnSaveAction SaveCloudProject(AudacityProject &project, const ProjectSaveCallback &projectSaveCallback)
static std::pair< Action, std::string > Show(const ServiceConfig &serviceConfig, OAuthService &authService, UserService &userService, const wxString &projectName, wxWindow *parent, bool allowLocalSave)
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)

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(), 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 209 of file CloudProjectFileIOExtensions.cpp.

211 {
212 auto& projectCloudExtension = ProjectCloudExtension::Get(project);
213
214 if (!projectCloudExtension.IsCloudProject())
215 return;
216
217 projectCloudExtension.OnUpdateSaved(serializer);
218
219 const int savesCount = projectCloudExtension.GetSavesCount();
220
221 if (savesCount < 2)
222 {
223 SyncInBackroundDialog { &project }.ShowDialog();
224 }
225
226 if (projectCloudExtension.IsFirstSyncDialogShown())
227 return;
228
230 [weakProject = project.weak_from_this()]
231 {
232 auto project = weakProject.lock();
233
234 if (!project)
235 return true;
236
237 return ProjectCloudExtension::Get(*project)
238 .GetCurrentSyncStatus() == ProjectSyncStatus::Synced;
239 },
240 [weakProject = project.weak_from_this()]
241 {
242 auto project = weakProject.lock();
243
244 if (
245 !project ||
246 ProjectCloudExtension::Get(*project).IsFirstSyncDialogShown())
247 return;
248
249 ProjectCloudExtension::Get(*project).SetFirstSyncDialogShown(true);
250
251 const auto result =
252 SyncSucceededDialog { project.get() }.ShowDialog();
253
257 });
258 }
bool OpenInDefaultBrowser(const wxString &url)
Open an URL in default browser.
Definition: BasicUI.cpp:245
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 
)
inlineprivate

Definition at line 66 of file CloudProjectFileIOExtensions.cpp.

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

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 
)
inlineprivate

Definition at line 112 of file CloudProjectFileIOExtensions.cpp.

114 {
115 auto authResult = PerformBlockingAuth(&project);
116
117 if (authResult.Result == AuthResult::Status::Failure)
118 {
120 dialog.ShowModal();
121 // Pretend we have canceled the save
123 }
124 else if (authResult.Result == AuthResult::Status::Cancelled)
125 {
127 }
128 else if (authResult.Result == AuthResult::Status::UseAlternative)
129 {
132 }
133
134 return PerformCloudSave(
135 project, audacity::ToUTF8(project.GetProjectName()),
137 projectSaveCallback, false);
138 }
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 277 of file CloudProjectFileIOExtensions.cpp.

278 {
279 mSnapshotCallback = std::move(callback);
280 }

◆ SetUploadModeForNextSave()

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

Definition at line 272 of file CloudProjectFileIOExtensions.cpp.

273 {
274 mUploadMode = mode;
275 }

Member Data Documentation

◆ mForceCloudSave

bool anonymous_namespace{CloudProjectFileIOExtensions.cpp}::IOExtension::mForceCloudSave {}
private

Definition at line 288 of file CloudProjectFileIOExtensions.cpp.

◆ mSnapshotCallback

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

Definition at line 284 of file CloudProjectFileIOExtensions.cpp.

◆ mUploadMode

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

Definition at line 286 of file CloudProjectFileIOExtensions.cpp.


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