Audacity 3.2.0
UploadService.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 UploadService.h
7
8 Dmitry Vedenko
9
10**********************************************************************/
11#pragma once
12
13#include <functional>
14#include <memory>
15
16#include <wx/string.h>
17
18namespace cloud::audiocom
19{
20class ServiceConfig;
21class OAuthService;
22
25struct CLOUD_AUDIOCOM_API UploadOperationCompleted final
26{
28 enum class Result
29 {
31 Success,
33 Aborted,
35 FileNotFound,
37 Unauthorized,
39 InvalidData,
41 UnexpectedResponse,
43 UploadFailed
44 };
45
48
50 std::string errorMessage;
51
53 std::string finishUploadURL;
55 std::string audioSlug;
56};
57
59class CLOUD_AUDIOCOM_API UploadOperation
60{
61public:
63
65 virtual bool IsCompleted() = 0;
67 virtual void Abort() = 0;
70 virtual void DiscardResult() = 0;
71};
72
74class CLOUD_AUDIOCOM_API UploadOperationHandle final
75{
76public:
78 explicit UploadOperationHandle(std::shared_ptr<UploadOperation> operation);
79
84
86
87 explicit operator bool() const noexcept;
88
89 UploadOperation* operator->() const noexcept;
90
91private:
92 std::shared_ptr<UploadOperation> mOperation {};
93};
94
96class CLOUD_AUDIOCOM_API UploadService final
97{
98public:
99 UploadService(const ServiceConfig& config, OAuthService& service);
100
102 std::function<void(const UploadOperationCompleted&)>;
103
104 using ProgressCallback = std::function<void(uint64_t current, uint64_t total)>;
105
107 /*
108 Both callbacks are invoked from the network thread.
109
110 If projectName is empty, the name for the uploaded file is deduced from the fileName.
111 */
113 const wxString& fileName, const wxString& projectName, bool isPublic,
114 CompletedCallback completedCallback, ProgressCallback progressCallback);
115
116private:
119};
120
121CLOUD_AUDIOCOM_API wxString GetUploadTempPath();
122} // namespace cloud::audiocom
Service responsible for OAuth authentication against the audio.com service.
Definition: OAuthService.h:38
Configuration for the audio.com.
Definition: ServiceConfig.h:24
A unique_ptr like class that holds a pointer to UploadOperation.
Definition: UploadService.h:75
UploadOperationHandle(UploadOperationHandle &&)=default
UploadOperationHandle & operator=(const UploadOperationHandle &)=delete
UploadOperationHandle(const UploadOperationHandle &)=delete
UploadOperationHandle & operator=(UploadOperationHandle &&)=default
Class used to track the upload operation.
Definition: UploadService.h:60
virtual bool IsCompleted()=0
Returns true if the upload is finished.
virtual void Abort()=0
Abort the upload, if running.
Service, responsible for uploading audio files to audio.com.
Definition: UploadService.h:97
std::function< void(uint64_t current, uint64_t total)> ProgressCallback
const ServiceConfig & mServiceConfig
std::function< void(const UploadOperationCompleted &)> CompletedCallback
wxString GetUploadTempPath()
STL namespace.
std::string errorMessage
Error message if result is not Success.
Definition: UploadService.h:50
std::string finishUploadURL
URL to open in browser to finish up the anonymous upload.
Definition: UploadService.h:53
std::string audioSlug
"Slug" to be used for shareable URL construction
Definition: UploadService.h:55