| 446 | } |
| 447 | |
| 448 | void MainWindow::CreateCountryStatusControls() |
| 449 | { |
| 450 | QHBoxLayout * mainLayout = new QHBoxLayout(); |
| 451 | m_downloadButton = CreateBlackControl<QPushButton>("Download"); |
| 452 | mainLayout->addWidget(m_downloadButton, 0, Qt::AlignHCenter); |
| 453 | m_downloadButton->setVisible(false); |
| 454 | connect(m_downloadButton, &QAbstractButton::released, this, &MainWindow::OnDownloadClicked); |
| 455 | |
| 456 | m_retryButton = CreateBlackControl<QPushButton>("Retry downloading"); |
| 457 | mainLayout->addWidget(m_retryButton, 0, Qt::AlignHCenter); |
| 458 | m_retryButton->setVisible(false); |
| 459 | connect(m_retryButton, &QAbstractButton::released, this, &MainWindow::OnRetryDownloadClicked); |
| 460 | |
| 461 | m_cancelDownloadButton = CreateBlackControl<QPushButton>("Downloading (click to cancel)"); |
| 462 | mainLayout->addWidget(m_cancelDownloadButton, 0, Qt::AlignHCenter); |
| 463 | m_cancelDownloadButton->setVisible(false); |
| 464 | connect(m_cancelDownloadButton, &QAbstractButton::released, this, &MainWindow::OnCancelDownloadClicked); |
| 465 | |
| 466 | m_pDrawWidget->setLayout(mainLayout); |
| 467 | |
| 468 | auto const OnCountryChanged = [this](storage::CountryId const & countryId) |
| 469 | { |
| 470 | m_downloadButton->setVisible(false); |
| 471 | m_retryButton->setVisible(false); |
| 472 | m_cancelDownloadButton->setVisible(false); |
| 473 | |
| 474 | m_lastCountry = countryId; |
| 475 | // Called by Framework in World zoom level. |
| 476 | if (countryId.empty()) |
| 477 | return; |
| 478 | |
| 479 | auto const & storage = GetFramework().GetStorage(); |
| 480 | auto status = storage.CountryStatusEx(countryId); |
| 481 | auto const & countryName = countryId; |
| 482 | |
| 483 | if (status == storage::Status::NotDownloaded) |
| 484 | { |
| 485 | m_downloadButton->setVisible(true); |
| 486 | |
| 487 | std::string units; |
| 488 | size_t sizeToDownload = 0; |
| 489 | FormatMapSize(storage.CountrySizeInBytes(countryId).second, units, sizeToDownload); |
| 490 | std::stringstream str; |
| 491 | str << "Download (" << countryName << ") " << sizeToDownload << units; |
| 492 | m_downloadButton->setText(str.str().c_str()); |
| 493 | } |
| 494 | else if (status == storage::Status::Downloading) |
| 495 | { |
| 496 | m_cancelDownloadButton->setVisible(true); |
| 497 | } |
| 498 | else if (status == storage::Status::InQueue) |
| 499 | { |
| 500 | m_cancelDownloadButton->setVisible(true); |
| 501 | |
| 502 | std::stringstream str; |
| 503 | str << countryName << " is waiting for downloading (click to cancel)"; |
| 504 | m_cancelDownloadButton->setText(str.str().c_str()); |
| 505 | } |
nothing calls this directly
no test coverage detected