Qt: fix compat download abort

This commit is contained in:
Megamouse 2022-02-01 20:53:46 +01:00
parent a4c4548c3a
commit fd0e7a4efa
6 changed files with 30 additions and 20 deletions

View file

@ -123,6 +123,7 @@ void downloader::start(const std::string& url, bool follow_location, bool show_p
{ {
m_curl_abort = true; m_curl_abort = true;
close_progress_dialog(); close_progress_dialog();
Q_EMIT signal_download_canceled();
}); });
connect(m_progress_dialog, &QProgressDialog::finished, m_progress_dialog, &QProgressDialog::deleteLater); connect(m_progress_dialog, &QProgressDialog::finished, m_progress_dialog, &QProgressDialog::deleteLater);
} }

View file

@ -37,6 +37,7 @@ private Q_SLOTS:
Q_SIGNALS: Q_SIGNALS:
void signal_download_error(const QString& error); void signal_download_error(const QString& error);
void signal_download_finished(const QByteArray& data); void signal_download_finished(const QByteArray& data);
void signal_download_canceled();
void signal_buffer_update(int size, int max); void signal_buffer_update(int size, int max);
private: private:

View file

@ -26,6 +26,7 @@ game_compatibility::game_compatibility(std::shared_ptr<gui_settings> gui_setting
connect(m_downloader, &downloader::signal_download_error, this, &game_compatibility::handle_download_error); connect(m_downloader, &downloader::signal_download_error, this, &game_compatibility::handle_download_error);
connect(m_downloader, &downloader::signal_download_finished, this, &game_compatibility::handle_download_finished); connect(m_downloader, &downloader::signal_download_finished, this, &game_compatibility::handle_download_finished);
connect(m_downloader, &downloader::signal_download_canceled, this, &game_compatibility::handle_download_canceled);
} }
void game_compatibility::handle_download_error(const QString& error) void game_compatibility::handle_download_error(const QString& error)
@ -40,9 +41,6 @@ void game_compatibility::handle_download_finished(const QByteArray& content)
// Create new map from database and write database to file if database was valid // Create new map from database and write database to file if database was valid
if (ReadJSON(QJsonDocument::fromJson(content).object(), true)) if (ReadJSON(QJsonDocument::fromJson(content).object(), true))
{ {
// We have a new database in map, therefore refresh gamelist to new state
Q_EMIT DownloadFinished();
// Write database to file // Write database to file
QFile file(m_filepath); QFile file(m_filepath);
@ -62,6 +60,14 @@ void game_compatibility::handle_download_finished(const QByteArray& content)
compat_log.success("Wrote database to file: %s", sstr(m_filepath)); compat_log.success("Wrote database to file: %s", sstr(m_filepath));
} }
// We have a new database in map, therefore refresh gamelist to new state
Q_EMIT DownloadFinished();
}
void game_compatibility::handle_download_canceled()
{
Q_EMIT DownloadCanceled();
} }
bool game_compatibility::ReadJSON(const QJsonObject& json_data, bool after_download) bool game_compatibility::ReadJSON(const QJsonObject& json_data, bool after_download)

View file

@ -157,9 +157,11 @@ public:
Q_SIGNALS: Q_SIGNALS:
void DownloadStarted(); void DownloadStarted();
void DownloadFinished(); void DownloadFinished();
void DownloadCanceled();
void DownloadError(const QString& error); void DownloadError(const QString& error);
private Q_SLOTS: private Q_SLOTS:
void handle_download_error(const QString& error); void handle_download_error(const QString& error);
void handle_download_finished(const QByteArray& content); void handle_download_finished(const QByteArray& content);
void handle_download_canceled();
}; };

View file

@ -162,7 +162,7 @@ game_list_frame::game_list_frame(std::shared_ptr<gui_settings> gui_settings, std
connect(m_game_list, &QTableWidget::itemDoubleClicked, this, &game_list_frame::doubleClickedSlot); connect(m_game_list, &QTableWidget::itemDoubleClicked, this, &game_list_frame::doubleClickedSlot);
connect(m_game_list->horizontalHeader(), &QHeaderView::sectionClicked, this, &game_list_frame::OnColClicked); connect(m_game_list->horizontalHeader(), &QHeaderView::sectionClicked, this, &game_list_frame::OnColClicked);
connect(m_game_list->horizontalHeader(), &QHeaderView::customContextMenuRequested, [this](const QPoint& pos) connect(m_game_list->horizontalHeader(), &QHeaderView::customContextMenuRequested, this, [this](const QPoint& pos)
{ {
QMenu* configure = new QMenu(this); QMenu* configure = new QMenu(this);
configure->addActions(m_columnActs); configure->addActions(m_columnActs);
@ -173,7 +173,7 @@ game_list_frame::game_list_frame(std::shared_ptr<gui_settings> gui_settings, std
connect(m_game_grid, &QTableWidget::itemSelectionChanged, this, &game_list_frame::ItemSelectionChangedSlot); connect(m_game_grid, &QTableWidget::itemSelectionChanged, this, &game_list_frame::ItemSelectionChangedSlot);
connect(m_game_grid, &QTableWidget::itemDoubleClicked, this, &game_list_frame::doubleClickedSlot); connect(m_game_grid, &QTableWidget::itemDoubleClicked, this, &game_list_frame::doubleClickedSlot);
connect(m_game_compat, &game_compatibility::DownloadStarted, [this]() connect(m_game_compat, &game_compatibility::DownloadStarted, this, [this]()
{ {
for (const auto& game : m_game_data) for (const auto& game : m_game_data)
{ {
@ -181,21 +181,11 @@ game_list_frame::game_list_frame(std::shared_ptr<gui_settings> gui_settings, std
} }
Refresh(); Refresh();
}); });
connect(m_game_compat, &game_compatibility::DownloadFinished, [this]() connect(m_game_compat, &game_compatibility::DownloadFinished, this, &game_list_frame::OnCompatFinished);
connect(m_game_compat, &game_compatibility::DownloadCanceled, this, &game_list_frame::OnCompatFinished);
connect(m_game_compat, &game_compatibility::DownloadError, this, [this](const QString& error)
{ {
for (const auto& game : m_game_data) OnCompatFinished();
{
game->compat = m_game_compat->GetCompatibility(game->info.serial);
}
Refresh();
});
connect(m_game_compat, &game_compatibility::DownloadError, [this](const QString& error)
{
for (const auto& game : m_game_data)
{
game->compat = m_game_compat->GetCompatibility(game->info.serial);
}
Refresh();
QMessageBox::warning(this, tr("Warning!"), tr("Failed to retrieve the online compatibility database!\nFalling back to local database.\n\n%0").arg(error)); QMessageBox::warning(this, tr("Warning!"), tr("Failed to retrieve the online compatibility database!\nFalling back to local database.\n\n%0").arg(error));
}); });
@ -203,7 +193,7 @@ game_list_frame::game_list_frame(std::shared_ptr<gui_settings> gui_settings, std
{ {
m_columnActs[col]->setCheckable(true); m_columnActs[col]->setCheckable(true);
connect(m_columnActs[col], &QAction::triggered, [this, col](bool checked) connect(m_columnActs[col], &QAction::triggered, this, [this, col](bool checked)
{ {
if (!checked) // be sure to have at least one column left so you can call the context menu at all time if (!checked) // be sure to have at least one column left so you can call the context menu at all time
{ {
@ -812,6 +802,15 @@ void game_list_frame::OnRepaintFinished()
} }
} }
void game_list_frame::OnCompatFinished()
{
for (const auto& game : m_game_data)
{
game->compat = m_game_compat->GetCompatibility(game->info.serial);
}
Refresh();
}
void game_list_frame::ToggleCategoryFilter(const QStringList& categories, bool show) void game_list_frame::ToggleCategoryFilter(const QStringList& categories, bool show)
{ {
if (show) if (show)

View file

@ -77,6 +77,7 @@ public Q_SLOTS:
private Q_SLOTS: private Q_SLOTS:
void OnRefreshFinished(); void OnRefreshFinished();
void OnRepaintFinished(); void OnRepaintFinished();
void OnCompatFinished();
void OnColClicked(int col); void OnColClicked(int col);
void ShowContextMenu(const QPoint &pos); void ShowContextMenu(const QPoint &pos);
void doubleClickedSlot(QTableWidgetItem *item); void doubleClickedSlot(QTableWidgetItem *item);