Host: Add async information prompts

This commit is contained in:
TheLastRar 2025-02-21 23:06:32 +00:00
parent 768e716624
commit 5a924996c7
7 changed files with 43 additions and 0 deletions

View File

@ -174,6 +174,14 @@ std::unique_ptr<ProgressCallback> Host::CreateHostProgressCallback()
return ProgressCallback::CreateNullProgressCallback(); 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) void Host::ReportErrorAsync(const std::string_view title, const std::string_view message)
{ {
if (!title.empty() && !message.empty()) if (!title.empty() && !message.empty())

View File

@ -1221,6 +1221,11 @@ void MainWindow::cancelGameListRefresh()
m_game_list_widget->cancelRefresh(); 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) void MainWindow::reportError(const QString& title, const QString& message)
{ {
QMessageBox::critical(this, title, message); QMessageBox::critical(this, title, message);

View File

@ -109,6 +109,7 @@ public Q_SLOTS:
void checkForUpdates(bool display_message, bool force_check); void checkForUpdates(bool display_message, bool force_check);
void refreshGameList(bool invalidate_cache); void refreshGameList(bool invalidate_cache);
void cancelGameListRefresh(); void cancelGameListRefresh();
void reportInfo(const QString& title, const QString& message);
void reportError(const QString& title, const QString& message); void reportError(const QString& title, const QString& message);
bool confirmMessage(const QString& title, const QString& message); bool confirmMessage(const QString& title, const QString& message);
void onStatusMessage(const QString& message); void onStatusMessage(const QString& message);

View File

@ -1612,6 +1612,18 @@ bool QtHost::DownloadFile(QWidget* parent, const QString& title, std::string url
return true; 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) void Host::ReportErrorAsync(const std::string_view title, const std::string_view message)
{ {
if (!title.empty() && !message.empty()) if (!title.empty() && !message.empty())

View File

@ -138,6 +138,15 @@ void Host::ClearTranslationCache()
s_translation_string_mutex.unlock(); 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, ...) void Host::ReportFormattedErrorAsync(const std::string_view title, const char* format, ...)
{ {
std::va_list ap; std::va_list ap;

View File

@ -55,6 +55,10 @@ namespace Host
void RemoveKeyedOSDMessage(std::string key); void RemoveKeyedOSDMessage(std::string key);
void ClearOSDMessages(); 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. /// 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 ReportErrorAsync(const std::string_view title, const std::string_view message);
void ReportFormattedErrorAsync(const std::string_view title, const char* format, ...); void ReportFormattedErrorAsync(const std::string_view title, const char* format, ...);

View File

@ -39,6 +39,10 @@ std::unique_ptr<ProgressCallback> Host::CreateHostProgressCallback()
return ProgressCallback::CreateNullProgressCallback(); 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) void Host::ReportErrorAsync(const std::string_view title, const std::string_view message)
{ {
} }