* @brief Fetches the content for the page at the given index. Uses preloaded * content or network fetch. */
| 371 | * content or network fetch. |
| 372 | */ |
| 373 | void Misc::HelpCenter::fetchPage(int index) |
| 374 | { |
| 375 | if (index < 0 || index >= m_filteredPages.count()) |
| 376 | return; |
| 377 | |
| 378 | const auto page = m_filteredPages.at(index).toMap(); |
| 379 | const auto id = page.value("id").toString(); |
| 380 | const auto file = page.value("file").toString(); |
| 381 | |
| 382 | const auto it = m_pageContents.constFind(id); |
| 383 | if (it != m_pageContents.constEnd()) { |
| 384 | m_pageContent = *it; |
| 385 | Q_EMIT pageContentChanged(); |
| 386 | return; |
| 387 | } |
| 388 | |
| 389 | m_loading = true; |
| 390 | Q_EMIT loadingChanged(); |
| 391 | |
| 392 | auto encoded = QString::fromUtf8(QUrl::toPercentEncoding(file)); |
| 393 | auto url = QUrl::fromEncoded((kBase + encoded).toUtf8()); |
| 394 | auto* reply = m_nam.get(QNetworkRequest(url)); |
| 395 | reply->setProperty("pageId", id); |
| 396 | connect(reply, &QNetworkReply::finished, this, &HelpCenter::onPageReply); |
| 397 | } |
| 398 | |
| 399 | /** |
| 400 | * @brief Kicks off background preloading of all page contents for full-text |