int QAChecker::Check(CatalogItemPtr item) { int issues = 0; for (auto& c: m_checks) { if (item->GetString().empty() || (item->HasPlural() && item->GetPluralString().empty())) continue; if (c->CheckItem(item)) issues++; } return issues; }
bool QACheck::CheckItem(CatalogItemPtr item) { if (!item->GetTranslation().empty() && CheckString(item, item->GetString(), item->GetTranslation())) return true; if (item->HasPlural()) { unsigned count = item->GetNumberOfTranslations(); for (unsigned i = 1; i < count; i++) { auto t = item->GetTranslation(i); if (!t.empty() && CheckString(item, item->GetPluralString(), t)) return true; } } return false; }
void SuggestionsSidebarBlock::QueryProvider(SuggestionsBackend& backend, const CatalogItemPtr& item, uint64_t queryId) { m_pendingQueries++; // we need something to talk to GUI thread through that is guaranteed // to exist, and the app object is a good choice: auto backendPtr = &backend; std::weak_ptr<SuggestionsSidebarBlock> weakSelf = std::dynamic_pointer_cast<SuggestionsSidebarBlock>(shared_from_this()); m_provider->SuggestTranslation ( backend, m_parent->GetCurrentSourceLanguage(), m_parent->GetCurrentLanguage(), item->GetString().ToStdWstring(), // when receiving data [=](const SuggestionsList& hits){ call_on_main_thread([weakSelf,queryId,hits]{ auto self = weakSelf.lock(); // maybe this call is already out of date: if (!self || self->m_latestQueryId != queryId) return; self->UpdateSuggestions(hits); if (--self->m_pendingQueries == 0) self->OnQueriesFinished(); }); }, // on error: [=](std::exception_ptr e){ call_on_main_thread([weakSelf,queryId,backendPtr,e]{ auto self = weakSelf.lock(); // maybe this call is already out of date: if (!self || self->m_latestQueryId != queryId) return; self->ReportError(backendPtr, e); if (--self->m_pendingQueries == 0) self->OnQueriesFinished(); }); } ); }