From fd0e7a4efa73a8c4afa10b974da75917337e0cb5 Mon Sep 17 00:00:00 2001 From: Megamouse Date: Tue, 1 Feb 2022 20:53:46 +0100 Subject: [PATCH] Qt: fix compat download abort --- rpcs3/rpcs3qt/downloader.cpp | 1 + rpcs3/rpcs3qt/downloader.h | 1 + rpcs3/rpcs3qt/game_compatibility.cpp | 12 +++++++--- rpcs3/rpcs3qt/game_compatibility.h | 2 ++ rpcs3/rpcs3qt/game_list_frame.cpp | 33 ++++++++++++++-------------- rpcs3/rpcs3qt/game_list_frame.h | 1 + 6 files changed, 30 insertions(+), 20 deletions(-) diff --git a/rpcs3/rpcs3qt/downloader.cpp b/rpcs3/rpcs3qt/downloader.cpp index c1d63ec83a..b349365c9c 100644 --- a/rpcs3/rpcs3qt/downloader.cpp +++ b/rpcs3/rpcs3qt/downloader.cpp @@ -123,6 +123,7 @@ void downloader::start(const std::string& url, bool follow_location, bool show_p { m_curl_abort = true; close_progress_dialog(); + Q_EMIT signal_download_canceled(); }); connect(m_progress_dialog, &QProgressDialog::finished, m_progress_dialog, &QProgressDialog::deleteLater); } diff --git a/rpcs3/rpcs3qt/downloader.h b/rpcs3/rpcs3qt/downloader.h index f87284dde3..f5b9452457 100644 --- a/rpcs3/rpcs3qt/downloader.h +++ b/rpcs3/rpcs3qt/downloader.h @@ -37,6 +37,7 @@ private Q_SLOTS: Q_SIGNALS: void signal_download_error(const QString& error); void signal_download_finished(const QByteArray& data); + void signal_download_canceled(); void signal_buffer_update(int size, int max); private: diff --git a/rpcs3/rpcs3qt/game_compatibility.cpp b/rpcs3/rpcs3qt/game_compatibility.cpp index b58d9ca850..01243a0009 100644 --- a/rpcs3/rpcs3qt/game_compatibility.cpp +++ b/rpcs3/rpcs3qt/game_compatibility.cpp @@ -26,6 +26,7 @@ game_compatibility::game_compatibility(std::shared_ptr gui_setting 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_canceled, this, &game_compatibility::handle_download_canceled); } 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 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 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)); } + + // 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) diff --git a/rpcs3/rpcs3qt/game_compatibility.h b/rpcs3/rpcs3qt/game_compatibility.h index 9c89e94634..4c9ea4e3ea 100644 --- a/rpcs3/rpcs3qt/game_compatibility.h +++ b/rpcs3/rpcs3qt/game_compatibility.h @@ -157,9 +157,11 @@ public: Q_SIGNALS: void DownloadStarted(); void DownloadFinished(); + void DownloadCanceled(); void DownloadError(const QString& error); private Q_SLOTS: void handle_download_error(const QString& error); void handle_download_finished(const QByteArray& content); + void handle_download_canceled(); }; diff --git a/rpcs3/rpcs3qt/game_list_frame.cpp b/rpcs3/rpcs3qt/game_list_frame.cpp index cd6f3c0663..6638fea3ff 100644 --- a/rpcs3/rpcs3qt/game_list_frame.cpp +++ b/rpcs3/rpcs3qt/game_list_frame.cpp @@ -162,7 +162,7 @@ game_list_frame::game_list_frame(std::shared_ptr gui_settings, std 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::customContextMenuRequested, [this](const QPoint& pos) + connect(m_game_list->horizontalHeader(), &QHeaderView::customContextMenuRequested, this, [this](const QPoint& pos) { QMenu* configure = new QMenu(this); configure->addActions(m_columnActs); @@ -173,7 +173,7 @@ game_list_frame::game_list_frame(std::shared_ptr gui_settings, std 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_compat, &game_compatibility::DownloadStarted, [this]() + connect(m_game_compat, &game_compatibility::DownloadStarted, this, [this]() { for (const auto& game : m_game_data) { @@ -181,21 +181,11 @@ game_list_frame::game_list_frame(std::shared_ptr gui_settings, std } 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) - { - 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(); + OnCompatFinished(); 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, std { 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 { @@ -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) { if (show) diff --git a/rpcs3/rpcs3qt/game_list_frame.h b/rpcs3/rpcs3qt/game_list_frame.h index 18490191d6..99cddd0200 100644 --- a/rpcs3/rpcs3qt/game_list_frame.h +++ b/rpcs3/rpcs3qt/game_list_frame.h @@ -77,6 +77,7 @@ public Q_SLOTS: private Q_SLOTS: void OnRefreshFinished(); void OnRepaintFinished(); + void OnCompatFinished(); void OnColClicked(int col); void ShowContextMenu(const QPoint &pos); void doubleClickedSlot(QTableWidgetItem *item);