Audacity 3.2.0
Public Member Functions | Static Public Member Functions | Private Attributes | List of all members
audacity::cloud::audiocom::sync::ProjectsListDialog::ProjectsTableData Class Referencefinal
Inheritance diagram for audacity::cloud::audiocom::sync::ProjectsListDialog::ProjectsTableData:
[legend]
Collaboration diagram for audacity::cloud::audiocom::sync::ProjectsListDialog::ProjectsTableData:
[legend]

Public Member Functions

 ProjectsTableData (ProjectsListDialog &owner, int pageSize)
 
int GetNumberRows () override
 
int GetNumberCols () override
 
wxString GetValue (int row, int col) override
 
void SetValue (int row, int col, const wxString &value) override
 
wxString GetRowLabelValue (int row) override
 
wxString GetColLabelValue (int col) override
 
wxString GetCornerLabelValue () const override
 
int GetColWidth (int col) const
 
void Refresh (int page, const wxString &searchTerm)
 
bool HasPrevPage () const
 
bool HasNextPage () const
 
void PrevPage ()
 
void NextPage ()
 
int GetCurrentPage () const
 
int GetPagesCount () const
 
const ProjectInfoGetSelectedProjectInfo () const
 
std::string GetSelectedProjectUrl () const
 

Static Public Member Functions

static wxString FormatTime (int64_t time)
 

Private Attributes

ProjectsListDialogmOwner
 
const int mPageSize
 
PaginatedProjectsResponse mResponse
 

Detailed Description

Definition at line 56 of file ProjectsListDialog.cpp.

Constructor & Destructor Documentation

◆ ProjectsTableData()

audacity::cloud::audiocom::sync::ProjectsListDialog::ProjectsTableData::ProjectsTableData ( ProjectsListDialog owner,
int  pageSize 
)
inline

Member Function Documentation

◆ FormatTime()

static wxString audacity::cloud::audiocom::sync::ProjectsListDialog::ProjectsTableData::FormatTime ( int64_t  time)
inlinestatic

Definition at line 75 of file ProjectsListDialog.cpp.

76 {
77 using namespace std::chrono;
78
79 const auto time_passed =
80 system_clock::now() - system_clock::from_time_t(time);
81
82 if (time_passed < minutes(1))
83 return XO("less than 1 minute").Translation();
84 if (time_passed < hours(1))
85 return XP("one minutes ago", "%d minutes ago",
86 0)(static_cast<int>(
87 duration_cast<minutes>(time_passed).count()))
88 .Translation();
89 if (time_passed < hours(48))
90 return XP("one hour ago", "%d hours ago", 0)(
91 static_cast<int>(duration_cast<hours>(time_passed).count()))
92 .Translation();
93
94 return wxDateTime(static_cast<time_t>(time)).Format();
95 }
XO("Cut/Copy/Paste")
#define XP(sing, plur, n)
Definition: Internat.h:94

References XO(), and XP.

Referenced by GetValue().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GetColLabelValue()

wxString audacity::cloud::audiocom::sync::ProjectsListDialog::ProjectsTableData::GetColLabelValue ( int  col)
inlineoverride

Definition at line 125 of file ProjectsListDialog.cpp.

126 {
127 static const wxString colLabels[] = {
128 XO("Project Name").Translation(),
129 XO("Modified").Translation(),
130 };
131
132 return col < 2 ? colLabels[col] : wxString {};
133 }

References XO().

Here is the call graph for this function:

◆ GetColWidth()

int audacity::cloud::audiocom::sync::ProjectsListDialog::ProjectsTableData::GetColWidth ( int  col) const
inline

Definition at line 140 of file ProjectsListDialog.cpp.

141 {
142 static const int colWidths[] = { 400, 150 };
143 return col < 2 ? colWidths[col] : 0;
144 }

Referenced by audacity::cloud::audiocom::sync::ProjectsListDialog::ProjectsListDialog().

Here is the caller graph for this function:

◆ GetCornerLabelValue()

wxString audacity::cloud::audiocom::sync::ProjectsListDialog::ProjectsTableData::GetCornerLabelValue ( ) const
inlineoverride

Definition at line 135 of file ProjectsListDialog.cpp.

136 {
137 return {};
138 }

◆ GetCurrentPage()

int audacity::cloud::audiocom::sync::ProjectsListDialog::ProjectsTableData::GetCurrentPage ( ) const
inline

◆ GetNumberCols()

int audacity::cloud::audiocom::sync::ProjectsListDialog::ProjectsTableData::GetNumberCols ( )
inlineoverride

Definition at line 70 of file ProjectsListDialog.cpp.

71 {
72 return 2;
73 }

Referenced by audacity::cloud::audiocom::sync::ProjectsListDialog::ProjectsListDialog().

Here is the caller graph for this function:

◆ GetNumberRows()

int audacity::cloud::audiocom::sync::ProjectsListDialog::ProjectsTableData::GetNumberRows ( )
inlineoverride

◆ GetPagesCount()

int audacity::cloud::audiocom::sync::ProjectsListDialog::ProjectsTableData::GetPagesCount ( ) const
inline

Definition at line 257 of file ProjectsListDialog.cpp.

References mResponse, audacity::cloud::audiocom::sync::PaginationInfo::PagesCount, and audacity::cloud::audiocom::sync::PaginatedProjectsResponse::Pagination.

Referenced by audacity::cloud::audiocom::sync::ProjectsListDialog::FormatPageLabel().

Here is the caller graph for this function:

◆ GetRowLabelValue()

wxString audacity::cloud::audiocom::sync::ProjectsListDialog::ProjectsTableData::GetRowLabelValue ( int  row)
inlineoverride

Definition at line 120 of file ProjectsListDialog.cpp.

121 {
122 return {};
123 }

◆ GetSelectedProjectInfo()

const ProjectInfo * audacity::cloud::audiocom::sync::ProjectsListDialog::ProjectsTableData::GetSelectedProjectInfo ( ) const
inline

Definition at line 262 of file ProjectsListDialog.cpp.

263 {
264 const auto selectedRow = mOwner.mProjectsTable->GetSelectedRows();
265
266 if (selectedRow.empty())
267 return {};
268
269 return &mResponse.Items[selectedRow[0]];
270 }

References audacity::cloud::audiocom::sync::PaginatedProjectsResponse::Items, mOwner, audacity::cloud::audiocom::sync::ProjectsListDialog::mProjectsTable, and mResponse.

Referenced by audacity::cloud::audiocom::sync::ProjectsListDialog::OnOpen().

Here is the caller graph for this function:

◆ GetSelectedProjectUrl()

std::string audacity::cloud::audiocom::sync::ProjectsListDialog::ProjectsTableData::GetSelectedProjectUrl ( ) const
inline

Definition at line 272 of file ProjectsListDialog.cpp.

273 {
274 const auto selectedRow = mOwner.mProjectsTable->GetSelectedRows();
275
276 if (selectedRow.empty())
277 return {};
278
279 auto& userService = GetUserService();
280 auto& oauthService = GetOAuthService();
281 auto& serviceConfig = GetServiceConfig();
282
283 auto userId = audacity::ToUTF8(userService.GetUserId());
284 auto& item = mResponse.Items[selectedRow[0]];
285
286 auto projectPage = serviceConfig.GetProjectPagePath(item.Username, item.Id, AudiocomTrace::OpenFromCloudMenu);
287 auto url = oauthService.MakeAudioComAuthorizeURL(userId, projectPage);
288
289 return url;
290 }
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 audacity::cloud::audiocom::GetOAuthService(), audacity::cloud::audiocom::GetServiceConfig(), audacity::cloud::audiocom::GetUserService(), audacity::cloud::audiocom::sync::PaginatedProjectsResponse::Items, mOwner, audacity::cloud::audiocom::sync::ProjectsListDialog::mProjectsTable, mResponse, OpenFromCloudMenu, audacity::ToUTF8(), and audacity::cloud::audiocom::anonymous_namespace{UserService.cpp}::userId.

Referenced by audacity::cloud::audiocom::sync::ProjectsListDialog::OnOpen().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GetValue()

wxString audacity::cloud::audiocom::sync::ProjectsListDialog::ProjectsTableData::GetValue ( int  row,
int  col 
)
inlineoverride

Definition at line 97 of file ProjectsListDialog.cpp.

98 {
99 if (row >= static_cast<int>(mResponse.Items.size()))
100 return {};
101
102 const auto item = mResponse.Items[row];
103
104 switch (col)
105 {
106 case 0:
107 return audacity::ToWXString(item.Name);
108 case 1:
109 return FormatTime(item.Updated);
110 }
111
112 return {};
113 }
wxString ToWXString(const std::string &str)

References FormatTime(), audacity::cloud::audiocom::sync::PaginatedProjectsResponse::Items, mResponse, and audacity::ToWXString().

Here is the call graph for this function:

◆ HasNextPage()

bool audacity::cloud::audiocom::sync::ProjectsListDialog::ProjectsTableData::HasNextPage ( ) const
inline

Definition at line 235 of file ProjectsListDialog.cpp.

References audacity::cloud::audiocom::sync::PaginationInfo::CurrentPage, mResponse, audacity::cloud::audiocom::sync::PaginationInfo::PagesCount, and audacity::cloud::audiocom::sync::PaginatedProjectsResponse::Pagination.

Referenced by NextPage(), and audacity::cloud::audiocom::sync::ProjectsListDialog::OnRefreshCompleted().

Here is the caller graph for this function:

◆ HasPrevPage()

bool audacity::cloud::audiocom::sync::ProjectsListDialog::ProjectsTableData::HasPrevPage ( ) const
inline

Definition at line 230 of file ProjectsListDialog.cpp.

231 {
233 }

References audacity::cloud::audiocom::sync::PaginationInfo::CurrentPage, mResponse, and audacity::cloud::audiocom::sync::PaginatedProjectsResponse::Pagination.

Referenced by audacity::cloud::audiocom::sync::ProjectsListDialog::OnRefreshCompleted(), and PrevPage().

Here is the caller graph for this function:

◆ NextPage()

void audacity::cloud::audiocom::sync::ProjectsListDialog::ProjectsTableData::NextPage ( )
inline

Definition at line 246 of file ProjectsListDialog.cpp.

References audacity::cloud::audiocom::sync::PaginationInfo::CurrentPage, HasNextPage(), audacity::cloud::audiocom::sync::ProjectsListDialog::mLastSearchValue, mOwner, mResponse, audacity::cloud::audiocom::sync::PaginatedProjectsResponse::Pagination, and Refresh().

Referenced by audacity::cloud::audiocom::sync::ProjectsListDialog::SetupHandlers().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ PrevPage()

void audacity::cloud::audiocom::sync::ProjectsListDialog::ProjectsTableData::PrevPage ( )
inline

Definition at line 240 of file ProjectsListDialog.cpp.

References audacity::cloud::audiocom::sync::PaginationInfo::CurrentPage, HasPrevPage(), audacity::cloud::audiocom::sync::ProjectsListDialog::mLastSearchValue, mOwner, mResponse, audacity::cloud::audiocom::sync::PaginatedProjectsResponse::Pagination, and Refresh().

Referenced by audacity::cloud::audiocom::sync::ProjectsListDialog::SetupHandlers().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ Refresh()

void audacity::cloud::audiocom::sync::ProjectsListDialog::ProjectsTableData::Refresh ( int  page,
const wxString &  searchTerm 
)
inline

Definition at line 146 of file ProjectsListDialog.cpp.

147 {
148 using namespace std::chrono_literals;
149
150 auto authResult = PerformBlockingAuth(
152
153 switch (authResult.Result)
154 {
156 break;
160 XO("Failed to authorize account"), {},
162 audacity::ToWString(authResult.ErrorMessage)));
163 [[fallthrough]];
164 default:
165 mOwner.EndModal(0);
166 return;
167 }
168
170
171 auto progressDialog = BasicUI::MakeGenericProgress(
173 XO("Loading projects list..."));
174
175 auto cancellationContext = concurrency::CancellationContext::Create();
176
177 auto future = CloudSyncService::Get().GetProjects(
178 cancellationContext, page, mPageSize, ToUTF8(searchTerm));
179
180 while (std::future_status::ready != future.wait_for(100ms))
181 {
183 if (progressDialog->Pulse() != BasicUI::ProgressResult::Success)
184 cancellationContext->Cancel();
185 }
186
187 auto result = future.get();
188
189 if (!mResponse.Items.empty())
190 {
191 wxGridTableMessage msg(
192 this, wxGRIDTABLE_NOTIFY_ROWS_DELETED, 0, mResponse.Items.size());
193
194 GetView()->ProcessTableMessage(msg);
195 }
196
197 if (std::holds_alternative<PaginatedProjectsResponse>(result))
198 {
199 auto response = std::get_if<PaginatedProjectsResponse>(&result);
200 mResponse = std::move(*response);
201
202 if (!mResponse.Items.empty())
203 {
204 wxGridTableMessage msg(
205 this, wxGRIDTABLE_NOTIFY_ROWS_APPENDED, mResponse.Items.size(),
206 0);
207
208 GetView()->ProcessTableMessage(msg);
209 }
210
212 }
213 else
214 {
215 auto responseResult = std::get_if<ResponseResult>(&result);
216
219 XO("Failed to get projects list"), {},
221 audacity::ToWString(responseResult->Content)));
222
223 if (mResponse.Items.empty())
224 mOwner.EndModal(0);
225
227 }
228 }
GetProjectsFuture GetProjects(concurrency::CancellationContextPtr context, int page, int pageSize, std::string_view searchString)
Retrieve the list of projects from the cloud.
std::unique_ptr< GenericProgressDialog > MakeGenericProgress(const WindowPlacement &placement, const TranslatableString &title, const TranslatableString &message, int style=(ProgressAppModal|ProgressShowElapsedTime|ProgressSmooth))
Create and display a progress dialog (return nullptr if Services not installed)
Definition: BasicUI.h:320
void ShowErrorDialog(const WindowPlacement &placement, const TranslatableString &dlogTitle, const TranslatableString &message, const ManualPageID &helpPage, const ErrorDialogOptions &options={})
Show an error dialog with a link to the manual for further help.
Definition: BasicUI.h:272
void Yield()
Dispatch waiting events, including actions enqueued by CallAfter.
Definition: BasicUI.cpp:225
AuthResult PerformBlockingAuth(AudacityProject *project, AudiocomTrace trace, const TranslatableString &alternativeActionLabel)
std::wstring ToWString(const std::string &str)
Options for variations of error dialogs; the default is for modal dialogs.
Definition: BasicUI.h:52
ErrorDialogOptions && Log(std::wstring log_) &&
Definition: BasicUI.h:64
Window placement information for wxWidgetsBasicUI can be constructed from a wxWindow pointer.

References audacity::cloud::audiocom::AuthResult::Authorised, audacity::concurrency::CancellationContext::Create(), audacity::cloud::audiocom::AuthResult::Failure, audacity::cloud::audiocom::CloudSyncService::Get(), audacity::cloud::audiocom::CloudSyncService::GetProjects(), audacity::cloud::audiocom::sync::PaginatedProjectsResponse::Items, BasicUI::ErrorDialogOptions::Log(), BasicUI::MakeGenericProgress(), mOwner, mPageSize, audacity::cloud::audiocom::sync::ProjectsListDialog::mProject, mResponse, audacity::cloud::audiocom::sync::ProjectsListDialog::OnBeforeRefresh(), audacity::cloud::audiocom::sync::ProjectsListDialog::OnRefreshCompleted(), OpenFromCloudMenu, audacity::cloud::audiocom::sync::anonymous_namespace{ProjectsListDialog.cpp}::OpenFromCloudTitle, audacity::cloud::audiocom::PerformBlockingAuth(), BasicUI::ShowErrorDialog(), BasicUI::Success, audacity::ToUTF8(), audacity::ToWString(), XO(), and BasicUI::Yield().

Referenced by NextPage(), PrevPage(), and audacity::cloud::audiocom::sync::ProjectsListDialog::ProjectsListDialog().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ SetValue()

void audacity::cloud::audiocom::sync::ProjectsListDialog::ProjectsTableData::SetValue ( int  row,
int  col,
const wxString &  value 
)
inlineoverride

Definition at line 115 of file ProjectsListDialog.cpp.

116 {
117 assert(false);
118 }

Member Data Documentation

◆ mOwner

ProjectsListDialog& audacity::cloud::audiocom::sync::ProjectsListDialog::ProjectsTableData::mOwner
private

◆ mPageSize

const int audacity::cloud::audiocom::sync::ProjectsListDialog::ProjectsTableData::mPageSize
private

Definition at line 294 of file ProjectsListDialog.cpp.

Referenced by Refresh().

◆ mResponse

PaginatedProjectsResponse audacity::cloud::audiocom::sync::ProjectsListDialog::ProjectsTableData::mResponse
private

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