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

Method onContentsReply

app/src/Misc/Examples.cpp:326–367  ·  view source on GitHub ↗

* @brief Handles the GitHub Contents API response listing all files in an * example directory. Populates the download queue and starts fetching. */

Source from the content-addressed store, hash-verified

324 * example directory. Populates the download queue and starts fetching.
325 */
326void Misc::Examples::onContentsReply()
327{
328 auto* reply = qobject_cast<QNetworkReply*>(sender());
329 if (!reply)
330 return;
331
332 reply->deleteLater();
333
334 if (reply->error() != QNetworkReply::NoError) {
335 m_loading = false;
336 Q_EMIT loadingChanged();
337 return;
338 }
339
340 const auto doc = QJsonDocument::fromJson(reply->readAll());
341 const auto files = doc.array();
342
343 m_downloadQueue.clear();
344 for (const auto& entry : files) {
345 const auto obj = entry.toObject();
346 const auto type = obj.value("type").toString();
347
348 if (type != "file")
349 continue;
350
351 const auto name = obj.value("name").toString();
352 const auto download_url = QUrl(obj.value("download_url").toString());
353 if (!download_url.isEmpty())
354 m_downloadQueue.append({name, download_url});
355 }
356
357 m_totalDownloads = m_downloadQueue.count();
358 m_pendingDownloads = m_totalDownloads;
359
360 if (m_totalDownloads == 0) {
361 m_loading = false;
362 Q_EMIT loadingChanged();
363 return;
364 }
365
366 downloadNextFile();
367}
368
369/**
370 * @brief Handles individual file download completion and triggers the next

Callers

nothing calls this directly

Calls 9

senderFunction · 0.85
fromJsonFunction · 0.85
errorMethod · 0.80
isEmptyMethod · 0.80
QUrlClass · 0.50
clearMethod · 0.45
valueMethod · 0.45
appendMethod · 0.45
countMethod · 0.45

Tested by

no test coverage detected