* @brief Handles the GitHub Contents API response listing all files in an * example directory. Populates the download queue and starts fetching. */
| 324 | * example directory. Populates the download queue and starts fetching. |
| 325 | */ |
| 326 | void 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 |