* @brief Handles the README.md fetch response and caches it. */
| 254 | * @brief Handles the README.md fetch response and caches it. |
| 255 | */ |
| 256 | void Misc::Examples::onReadmeReply() |
| 257 | { |
| 258 | auto* reply = qobject_cast<QNetworkReply*>(sender()); |
| 259 | if (!reply) |
| 260 | return; |
| 261 | |
| 262 | reply->deleteLater(); |
| 263 | |
| 264 | if (reply->error() == QNetworkReply::NoError) { |
| 265 | const auto raw = QString::fromUtf8(reply->readAll()); |
| 266 | |
| 267 | const auto id = reply->property("exampleId").toString(); |
| 268 | if (!id.isEmpty()) { |
| 269 | const auto path = exampleCachePath(id); |
| 270 | QDir().mkpath(path); |
| 271 | QFile file(path + "/README.md"); |
| 272 | if (file.open(QIODevice::WriteOnly)) { |
| 273 | file.write(raw.toUtf8()); |
| 274 | file.close(); |
| 275 | } |
| 276 | } |
| 277 | |
| 278 | m_selectedReadme = raw; |
| 279 | } |
| 280 | |
| 281 | else |
| 282 | m_selectedReadme = tr("Failed to load README: %1").arg(reply->errorString()); |
| 283 | |
| 284 | m_loading = false; |
| 285 | Q_EMIT loadingChanged(); |
| 286 | Q_EMIT selectedReadmeChanged(); |
| 287 | } |
| 288 | |
| 289 | /** |
| 290 | * @brief Handles the screenshot fetch response and caches it. |