From 5a924996c7da4bae01f1ede76cadb7595c8f5ce5 Mon Sep 17 00:00:00 2001 From: TheLastRar Date: Fri, 21 Feb 2025 23:06:32 +0000 Subject: [PATCH] Host: Add async information prompts --- pcsx2-gsrunner/Main.cpp | 8 ++++++++ pcsx2-qt/MainWindow.cpp | 5 +++++ pcsx2-qt/MainWindow.h | 1 + pcsx2-qt/QtHost.cpp | 12 ++++++++++++ pcsx2/Host.cpp | 9 +++++++++ pcsx2/Host.h | 4 ++++ tests/ctest/core/StubHost.cpp | 4 ++++ 7 files changed, 43 insertions(+) diff --git a/pcsx2-gsrunner/Main.cpp b/pcsx2-gsrunner/Main.cpp index ad4fcd9c20..6eab3217cc 100644 --- a/pcsx2-gsrunner/Main.cpp +++ b/pcsx2-gsrunner/Main.cpp @@ -174,6 +174,14 @@ std::unique_ptr Host::CreateHostProgressCallback() return ProgressCallback::CreateNullProgressCallback(); } +void Host::ReportInfoAsync(const std::string_view title, const std::string_view message) +{ + if (!title.empty() && !message.empty()) + INFO_LOG("ReportInfoAsync: {}: {}", title, message); + else if (!message.empty()) + INFO_LOG("ReportInfoAsync: {}", message); +} + void Host::ReportErrorAsync(const std::string_view title, const std::string_view message) { if (!title.empty() && !message.empty()) diff --git a/pcsx2-qt/MainWindow.cpp b/pcsx2-qt/MainWindow.cpp index 659e3a3216..bdac5bcce8 100644 --- a/pcsx2-qt/MainWindow.cpp +++ b/pcsx2-qt/MainWindow.cpp @@ -1221,6 +1221,11 @@ void MainWindow::cancelGameListRefresh() m_game_list_widget->cancelRefresh(); } +void MainWindow::reportInfo(const QString& title, const QString& message) +{ + QMessageBox::information(this, title, message); +} + void MainWindow::reportError(const QString& title, const QString& message) { QMessageBox::critical(this, title, message); diff --git a/pcsx2-qt/MainWindow.h b/pcsx2-qt/MainWindow.h index 9dd42a8aa1..7a8f3b2747 100644 --- a/pcsx2-qt/MainWindow.h +++ b/pcsx2-qt/MainWindow.h @@ -109,6 +109,7 @@ public Q_SLOTS: void checkForUpdates(bool display_message, bool force_check); void refreshGameList(bool invalidate_cache); void cancelGameListRefresh(); + void reportInfo(const QString& title, const QString& message); void reportError(const QString& title, const QString& message); bool confirmMessage(const QString& title, const QString& message); void onStatusMessage(const QString& message); diff --git a/pcsx2-qt/QtHost.cpp b/pcsx2-qt/QtHost.cpp index 2375c70d9f..0893122bae 100644 --- a/pcsx2-qt/QtHost.cpp +++ b/pcsx2-qt/QtHost.cpp @@ -1612,6 +1612,18 @@ bool QtHost::DownloadFile(QWidget* parent, const QString& title, std::string url return true; } +void Host::ReportInfoAsync(const std::string_view title, const std::string_view message) +{ + if (!title.empty() && !message.empty()) + INFO_LOG("ReportInfoAsync: {}: {}", title, message); + else if (!message.empty()) + INFO_LOG("ReportInfoAsync: {}", message); + + QMetaObject::invokeMethod(g_main_window, "reportInfo", Qt::QueuedConnection, + Q_ARG(const QString&, title.empty() ? QString() : QString::fromUtf8(title.data(), title.size())), + Q_ARG(const QString&, message.empty() ? QString() : QString::fromUtf8(message.data(), message.size()))); +} + void Host::ReportErrorAsync(const std::string_view title, const std::string_view message) { if (!title.empty() && !message.empty()) diff --git a/pcsx2/Host.cpp b/pcsx2/Host.cpp index b25c813af5..0a78d7083d 100644 --- a/pcsx2/Host.cpp +++ b/pcsx2/Host.cpp @@ -138,6 +138,15 @@ void Host::ClearTranslationCache() s_translation_string_mutex.unlock(); } +void Host::ReportFormattedInfoAsync(const std::string_view title, const char* format, ...) +{ + std::va_list ap; + va_start(ap, format); + std::string message(StringUtil::StdStringFromFormatV(format, ap)); + va_end(ap); + ReportInfoAsync(title, message); +} + void Host::ReportFormattedErrorAsync(const std::string_view title, const char* format, ...) { std::va_list ap; diff --git a/pcsx2/Host.h b/pcsx2/Host.h index 613195c532..e960a21f9a 100644 --- a/pcsx2/Host.h +++ b/pcsx2/Host.h @@ -55,6 +55,10 @@ namespace Host void RemoveKeyedOSDMessage(std::string key); void ClearOSDMessages(); + /// Displays an asynchronous error on the UI thread, i.e. doesn't block the caller. + void ReportInfoAsync(const std::string_view title, const std::string_view message); + void ReportFormattedInfoAsync(const std::string_view title, const char* format, ...); + /// Displays an asynchronous error on the UI thread, i.e. doesn't block the caller. void ReportErrorAsync(const std::string_view title, const std::string_view message); void ReportFormattedErrorAsync(const std::string_view title, const char* format, ...); diff --git a/tests/ctest/core/StubHost.cpp b/tests/ctest/core/StubHost.cpp index 7eee7ef840..01d1574058 100644 --- a/tests/ctest/core/StubHost.cpp +++ b/tests/ctest/core/StubHost.cpp @@ -39,6 +39,10 @@ std::unique_ptr Host::CreateHostProgressCallback() return ProgressCallback::CreateNullProgressCallback(); } +void Host::ReportInfoAsync(const std::string_view title, const std::string_view message) +{ +} + void Host::ReportErrorAsync(const std::string_view title, const std::string_view message) { }