MCPcopy Create free account
hub / github.com/Serial-Studio/Serial-Studio / onFileDownloadReply

Method onFileDownloadReply

app/src/Misc/Examples.cpp:373–419  ·  view source on GitHub ↗

* @brief Handles individual file download completion and triggers the next * download. Auto-opens the project file when all downloads complete. */

Source from the content-addressed store, hash-verified

371 * download. Auto-opens the project file when all downloads complete.
372 */
373void Misc::Examples::onFileDownloadReply()
374{
375 auto* reply = qobject_cast<QNetworkReply*>(sender());
376 if (!reply)
377 return;
378
379 reply->deleteLater();
380
381 if (reply->error() == QNetworkReply::NoError) {
382 const auto file_name = reply->property("fileName").toString();
383 const auto file_path = m_downloadPath + "/" + file_name;
384
385 QFileInfo info(file_path);
386 QDir().mkpath(info.absolutePath());
387
388 QFile file(file_path);
389 if (file.open(QIODevice::WriteOnly)) {
390 file.write(reply->readAll());
391 file.close();
392 }
393 }
394
395 --m_pendingDownloads;
396 m_downloadProgress = static_cast<float>(m_totalDownloads - m_pendingDownloads)
397 / static_cast<float>(m_totalDownloads);
398 Q_EMIT downloadProgressChanged();
399
400 if (!m_downloadQueue.isEmpty()) {
401 downloadNextFile();
402 return;
403 }
404
405 m_loading = false;
406 Q_EMIT loadingChanged();
407
408 Misc::Utilities::revealFile(m_downloadPath);
409
410 if (m_selectedIndex >= 0 && m_selectedIndex < m_filteredExamples.count()) {
411 const auto example = m_filteredExamples.at(m_selectedIndex).toMap();
412 const auto project_file = example.value("projectFileName").toString();
413 if (!project_file.isEmpty()) {
414 const auto path = m_downloadPath + "/" + project_file;
415 if (QFile::exists(path))
416 Q_EMIT projectFileReady(path);
417 }
418 }
419}
420
421//--------------------------------------------------------------------------------------------------
422// Internal helpers

Callers

nothing calls this directly

Calls 8

senderFunction · 0.85
errorMethod · 0.80
isEmptyMethod · 0.80
openMethod · 0.45
writeMethod · 0.45
closeMethod · 0.45
countMethod · 0.45
valueMethod · 0.45

Tested by

no test coverage detected