Audacity 3.2.0
ProjectCloudExtension.h
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 CloudProjectExtension.h
7
8 Dmitry Vedenko
9
10**********************************************************************/
11#pragma once
12
13#include <atomic>
14#include <cstdint>
15#include <functional>
16#include <memory>
17#include <mutex>
18#include <optional>
19#include <string>
20#include <string_view>
21#include <vector>
22
23#include "ClientData.h"
24#include "Observer.h"
25
26#include "CloudSyncError.h"
27#include "CloudSyncDTO.h"
29
30class AudacityProject;
32
34{
35class ProjectUploadOperation;
36
38{
39 Local,
41 Synced,
42 Failed,
44};
45
46struct CLOUD_AUDIOCOM_API CloudStatusChangedMessage final
47{
49 double Progress {};
50 std::optional<CloudSyncError> Error {};
51
52 bool IsSyncing() const noexcept;
53};
54
55class CLOUD_AUDIOCOM_API ProjectCloudExtension final : public ClientData::Base
56{
57public:
60
62 static const ProjectCloudExtension& Get(const AudacityProject& project);
63
64 bool IsCloudProject() const;
65
66 void OnLoad();
67
69 void OnSyncStarted();
71 void OnSyncResumed(
72 std::shared_ptr<ProjectUploadOperation> uploadOperation,
73 int64_t missingBlocksCount, bool needsProjectUpload);
75 void OnUploadOperationCreated(
76 std::shared_ptr<ProjectUploadOperation> uploadOperation);
78 void OnBlocksHashed(ProjectUploadOperation& uploadOperation);
80 void OnSnapshotCreated(
81 const ProjectUploadOperation& uploadOperation,
82 const CreateSnapshotResponse& response);
84 void OnProjectDataUploaded(const ProjectUploadOperation& uploadOperation);
86 void OnBlockUploaded(
87 const ProjectUploadOperation& uploadOperation, std::string_view blockID,
88 bool successful);
90 void OnSyncCompleted(
91 const ProjectUploadOperation* uploadOperation,
92 std::optional<CloudSyncError> error);
93
95
96 void CancelSync();
97
98 bool IsSyncing() const;
99
100 std::string GetCloudProjectId() const;
101 std::string GetSnapshotId() const;
102
103 void OnUpdateSaved(const ProjectSerializer& serializer);
104
105 std::weak_ptr<AudacityProject> GetProject() const;
106
107 int64_t GetSavesCount() const;
108
109 Observer::Subscription SubscribeStatusChanged(
110 std::function<void(const CloudStatusChangedMessage&)> callback,
111 bool onUIThread);
112
113 std::string GetCloudProjectPage() const;
114
115 bool IsBlockLocked(int64_t blockID) const;
116
117 ProjectSyncStatus GetCurrentSyncStatus() const;
118
119 bool IsFirstSyncDialogShown() const;
120 void SetFirstSyncDialogShown(bool shown = true);
121
122private:
123 struct UploadQueueElement;
125
126 void UpdateIdFromDatabase();
127
128 void UnsafeUpdateProgress();
129 void Publish(CloudStatusChangedMessage cloudStatus, bool canMerge);
130
131 void MarkProjectSynced(bool success);
132
134 UnsafeFindUploadQueueElement(const ProjectUploadOperation& uploadOperation);
135 const UploadQueueElement* UnsafeFindUploadQueueElement(
136 const ProjectUploadOperation& uploadOperation) const;
137
138 void OnProjectPathChanged();
139
141
143
144 mutable std::mutex mIdentifiersMutex;
145 std::string mProjectId;
146 std::string mSnapshotId;
147
149 std::vector<std::shared_ptr<UploadQueueElement>> mUploadQueue;
150
151 mutable std::mutex mStatusMutex;
153
154 std::unique_ptr<CloudStatusChangedNotifier> mAsyncStateNotifier;
155 std::unique_ptr<CloudStatusChangedNotifier> mUIStateNotifier;
156 std::atomic<bool> mUINotificationPending { false };
157}; // class ProjectCloudExtension
158
159} // namespace audacity::cloud::audiocom::sync
Utility ClientData::Site to register hooks into a host class that attach client data.
const auto project
The top-level handle to an Audacity project. It serves as a source of events that other objects can b...
Definition: Project.h:90
A move-only handle representing a connection to a Publisher.
Definition: Observer.h:70
a class used to (de)serialize the project catalog
std::unique_ptr< CloudStatusChangedNotifier > mUIStateNotifier
std::unique_ptr< CloudStatusChangedNotifier > mAsyncStateNotifier
std::vector< std::shared_ptr< UploadQueueElement > > mUploadQueue
Utility ClientData::Site to register hooks into a host class that attach client data.
Definition: ClientData.h:25
const AudacityProject & GetProject(const Track &track)
Definition: TrackArt.cpp:479