* @brief Handles the screenshot fetch response and caches it. */
| 290 | * @brief Handles the screenshot fetch response and caches it. |
| 291 | */ |
| 292 | void Misc::Examples::onScreenshotReply() |
| 293 | { |
| 294 | auto* reply = qobject_cast<QNetworkReply*>(sender()); |
| 295 | if (!reply) |
| 296 | return; |
| 297 | |
| 298 | reply->deleteLater(); |
| 299 | |
| 300 | if (reply->error() == QNetworkReply::NoError) { |
| 301 | const auto data = reply->readAll(); |
| 302 | const auto id = reply->property("exampleId").toString(); |
| 303 | if (!id.isEmpty()) { |
| 304 | const auto path = exampleCachePath(id) + "/doc"; |
| 305 | QDir().mkpath(path); |
| 306 | auto name = reply->property("fileName").toString(); |
| 307 | if (name.isEmpty()) |
| 308 | name = QStringLiteral("screenshot.png"); |
| 309 | |
| 310 | const auto file_path = path + "/" + name; |
| 311 | QFile file(file_path); |
| 312 | if (file.open(QIODevice::WriteOnly)) { |
| 313 | file.write(data); |
| 314 | file.close(); |
| 315 | m_selectedScreenshot = QUrl::fromLocalFile(file_path); |
| 316 | Q_EMIT selectedScreenshotChanged(); |
| 317 | } |
| 318 | } |
| 319 | } |
| 320 | } |
| 321 | |
| 322 | /** |
| 323 | * @brief Handles the GitHub Contents API response listing all files in an |