void BtSourcesThread::run() { emit percentComplete(0); emit showMessage(tr("Getting Library List")); if (BtInstallMgr().refreshRemoteSourceConfiguration()) qWarning("InstallMgr: getting remote list returned an error."); emit percentComplete(10); if (shouldStop()) { emit showMessage(tr("Updating stopped")); return; } QStringList const sourceNames = BtInstallBackend::sourceNameList(); int const sourceCount = sourceNames.count(); std::unique_ptr<int[]> failedSources{new int[sourceCount]}; int numFailedSources = 0; BtInstallMgr iMgr; for (int i = 0; i < sourceCount; ++i) { if (shouldStop()) { emit showMessage(tr("Updating stopped")); return; } QString const & sourceName = sourceNames[i]; emit showMessage(tr("Updating remote library \"%1\"").arg(sourceName)); { sword::InstallSource source = BtInstallBackend::source(sourceName); if (iMgr.refreshRemoteSource(&source)) { failedSources[numFailedSources] = i; ++numFailedSources; } } emit percentComplete(10 + 90 * ((i + 1.0) / sourceCount)); } emit percentComplete(100); if (numFailedSources <= 0) { emit showMessage(tr("Remote libraries have been updated.")); m_finishedSuccessfully.store(true, std::memory_order_release); } else { QString msg = tr("The following remote libraries failed to update: "); for (int i = 0;;) { msg += sourceNames[failedSources[i]]; if (++i >= numFailedSources) break; msg += ", "; }; emit showMessage(std::move(msg)); m_finishedSuccessfully.store(true, std::memory_order_release); } }
void InstallSources::refreshWorks(const QStringList& sourceNames) { int sourceCount = sourceNames.count(); for (int i=0; i<sourceCount; ++i) { if (m_canceled) break; QString sourceName = sourceNames.at(i); int percent = 10 + 90 *((double)i/sourceCount); QString title = "Refreshing " + sourceName; emit percentComplete(percent, title); sword::InstallSource source = BtInstallBackend::source(sourceName); bool result = (m_iMgr->refreshRemoteSource(&source) == 0); if (result) { ; } else { QString error = QString(tr("Failed to refresh source %1")).arg(sourceName); qDebug() << error; } } emit percentComplete(100, "Done"); }