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 53 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 72 of file ProjectsListDialog.cpp.

73 {
74 using namespace std::chrono;
75
76 const auto time_passed =
77 system_clock::now() - system_clock::from_time_t(time);
78
79 if (time_passed < minutes(1))
80 return XO("less than 1 minute").Translation();
81 if (time_passed < hours(1))
82 return XP("one minutes ago", "%d minutes ago",
83 0)(static_cast<int>(
84 duration_cast<minutes>(time_passed).count()))
85 .Translation();
86 if (time_passed < hours(48))
87 return XP("one hour ago", "%d hours ago", 0)(
88 static_cast<int>(duration_cast<hours>(time_passed).count()))
89 .Translation();
90
91 return wxDateTime(static_cast<time_t>(time)).Format();
92 }
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 122 of file ProjectsListDialog.cpp.

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

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 137 of file ProjectsListDialog.cpp.

138 {
139 static const int colWidths[] = { 400, 150 };
140 return col < 2 ? colWidths[col] : 0;
141 }

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 132 of file ProjectsListDialog.cpp.

133 {
134 return {};
135 }

◆ GetCurrentPage()

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

◆ GetNumberCols()

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

Definition at line 67 of file ProjectsListDialog.cpp.

68 {
69 return 2;
70 }

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 253 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 117 of file ProjectsListDialog.cpp.

118 {
119 return {};
120 }

◆ GetSelectedProjectInfo()

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

Definition at line 258 of file ProjectsListDialog.cpp.

259 {
260 const auto selectedRow = mOwner.mProjectsTable->GetSelectedRows();
261
262 if (selectedRow.empty())
263 return {};
264
265 return &mResponse.Items[selectedRow[0]];
266 }

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 268 of file ProjectsListDialog.cpp.

269 {
270 const auto selectedRow = mOwner.mProjectsTable->GetSelectedRows();
271
272 if (selectedRow.empty())
273 return {};
274
275 auto& item = mResponse.Items[selectedRow[0]];
276
277 return GetServiceConfig().GetProjectPageUrl(item.Username, item.Id);
278 }
std::string GetProjectPageUrl(std::string_view userId, std::string_view projectId) const
const ServiceConfig & GetServiceConfig()
Returns the instance of the ServiceConfig.

References audacity::cloud::audiocom::ServiceConfig::GetProjectPageUrl(), audacity::cloud::audiocom::GetServiceConfig(), 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 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 94 of file ProjectsListDialog.cpp.

95 {
96 if (row >= static_cast<int>(mResponse.Items.size()))
97 return {};
98
99 const auto item = mResponse.Items[row];
100
101 switch (col)
102 {
103 case 0:
104 return audacity::ToWXString(item.Name);
105 case 1:
106 return FormatTime(item.Updated);
107 }
108
109 return {};
110 }
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 231 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 226 of file ProjectsListDialog.cpp.

227 {
229 }

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 242 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 236 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 143 of file ProjectsListDialog.cpp.

144 {
145 using namespace std::chrono_literals;
146
147 auto authResult = PerformBlockingAuth(mOwner.mProject);
148
149 switch (authResult.Result)
150 {
152 break;
156 XO("Failed to authorize account"), {},
158 audacity::ToWString(authResult.ErrorMessage)));
159 [[fallthrough]];
160 default:
161 mOwner.EndModal(0);
162 return;
163 }
164
166
167 auto progressDialog = BasicUI::MakeGenericProgress(
169 XO("Loading projects list..."));
170
171 auto cancellationContext = concurrency::CancellationContext::Create();
172
173 auto future = CloudSyncService::Get().GetProjects(
174 cancellationContext, page, mPageSize, ToUTF8(searchTerm));
175
176 while (std::future_status::ready != future.wait_for(100ms))
177 {
179 if (progressDialog->Pulse() != BasicUI::ProgressResult::Success)
180 cancellationContext->Cancel();
181 }
182
183 auto result = future.get();
184
185 if (!mResponse.Items.empty())
186 {
187 wxGridTableMessage msg(
188 this, wxGRIDTABLE_NOTIFY_ROWS_DELETED, 0, mResponse.Items.size());
189
190 GetView()->ProcessTableMessage(msg);
191 }
192
193 if (std::holds_alternative<PaginatedProjectsResponse>(result))
194 {
195 auto response = std::get_if<PaginatedProjectsResponse>(&result);
196 mResponse = std::move(*response);
197
198 if (!mResponse.Items.empty())
199 {
200 wxGridTableMessage msg(
201 this, wxGRIDTABLE_NOTIFY_ROWS_APPENDED, mResponse.Items.size(),
202 0);
203
204 GetView()->ProcessTableMessage(msg);
205 }
206
208 }
209 else
210 {
211 auto responseResult = std::get_if<ResponseResult>(&result);
212
215 XO("Failed to get projects list"), {},
217 audacity::ToWString(responseResult->Content)));
218
219 if (mResponse.Items.empty())
220 mOwner.EndModal(0);
221
223 }
224 }
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)
Create and display a progress dialog (return nullptr if Services not installed)
Definition: BasicUI.h:312
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:264
void Yield()
Dispatch waiting events, including actions enqueued by CallAfter.
Definition: BasicUI.cpp:224
AuthResult PerformBlockingAuth(AudacityProject *project, const TranslatableString &alternativeActionLabel)
std::string ToUTF8(const std::wstring &wstr)
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(), 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 112 of file ProjectsListDialog.cpp.

113 {
114 assert(false);
115 }

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 282 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: