* @brief Continues the PDF flow on the main thread once the worker has shipped data. */
| 948 | * @brief Continues the PDF flow on the main thread once the worker has shipped data. |
| 949 | */ |
| 950 | void Sessions::DatabaseManager::renderReportFromPayload(const ReportPayloadPtr& payload) |
| 951 | { |
| 952 | if (!m_pendingPdfActive) |
| 953 | return; |
| 954 | |
| 955 | if (!payload || payload->sessionId != m_pendingPdfSessionId) |
| 956 | return; |
| 957 | |
| 958 | if (!payload->ok) { |
| 959 | if (m_pdfExportBusy) { |
| 960 | m_pdfExportBusy = false; |
| 961 | m_pdfExportProgress = 0.0; |
| 962 | m_pdfExportStatus = tr("Failed"); |
| 963 | Q_EMIT pdfExportBusyChanged(); |
| 964 | Q_EMIT pdfExportProgressChanged(); |
| 965 | } |
| 966 | |
| 967 | Misc::Utilities::showMessageBox( |
| 968 | tr("Report Failed"), |
| 969 | payload->error.isEmpty() |
| 970 | ? tr("Could not generate the report. Check the output path and try again.") |
| 971 | : payload->error, |
| 972 | QMessageBox::Warning); |
| 973 | |
| 974 | Q_EMIT pdfExportFinished(QString(), false); |
| 975 | m_pendingPdfActive = false; |
| 976 | return; |
| 977 | } |
| 978 | |
| 979 | const bool reportBusy = (m_pendingPdfOpts.format != HtmlReportOptions::Format::Html); |
| 980 | |
| 981 | auto* renderer = new HtmlReport(this); |
| 982 | |
| 983 | if (reportBusy) { |
| 984 | connect(renderer, &HtmlReport::progress, this, [this](const QString& status, double percent) { |
| 985 | m_pdfExportStatus = status; |
| 986 | m_pdfExportProgress = percent; |
| 987 | Q_EMIT pdfExportProgressChanged(); |
| 988 | }); |
| 989 | } |
| 990 | |
| 991 | connect(renderer, |
| 992 | &HtmlReport::finished, |
| 993 | this, |
| 994 | [this, renderer, reportBusy](const QString& outputPath, bool ok) { |
| 995 | if (reportBusy) { |
| 996 | m_pdfExportBusy = false; |
| 997 | m_pdfExportProgress = 1.0; |
| 998 | m_pdfExportStatus = ok ? tr("Done") : tr("Failed"); |
| 999 | Q_EMIT pdfExportBusyChanged(); |
| 1000 | Q_EMIT pdfExportProgressChanged(); |
| 1001 | } |
| 1002 | Q_EMIT pdfExportFinished(outputPath, ok); |
| 1003 | |
| 1004 | if (ok) { |
| 1005 | Misc::Utilities::revealFile(outputPath); |
| 1006 | } else { |
| 1007 | Misc::Utilities::showMessageBox( |