From c90e2f19fc00b233908781b3659d7e28756c937b Mon Sep 17 00:00:00 2001 From: Connor McLaughlin Date: Sat, 27 Aug 2022 19:00:31 +1000 Subject: [PATCH] NoGUI: Add ConfirmMessage() to platform --- src/duckstation-nogui/nogui_host.cpp | 3 +-- src/duckstation-nogui/nogui_platform.h | 1 + src/duckstation-nogui/vty_nogui_platform.cpp | 10 +++++++--- src/duckstation-nogui/vty_nogui_platform.h | 1 + src/duckstation-nogui/wayland_nogui_platform.cpp | 10 +++++++--- src/duckstation-nogui/wayland_nogui_platform.h | 1 + src/duckstation-nogui/win32_nogui_platform.cpp | 8 ++++++++ src/duckstation-nogui/win32_nogui_platform.h | 1 + src/duckstation-nogui/x11_nogui_platform.cpp | 10 +++++++--- src/duckstation-nogui/x11_nogui_platform.h | 1 + 10 files changed, 35 insertions(+), 11 deletions(-) diff --git a/src/duckstation-nogui/nogui_host.cpp b/src/duckstation-nogui/nogui_host.cpp index 323697620..97ba3c9c5 100644 --- a/src/duckstation-nogui/nogui_host.cpp +++ b/src/duckstation-nogui/nogui_host.cpp @@ -293,7 +293,6 @@ void Host::ReportErrorAsync(const std::string_view& title, const std::string_vie bool Host::ConfirmMessage(const std::string_view& title, const std::string_view& message) { - // TODO: Post to window if (!title.empty() && !message.empty()) { Log_ErrorPrintf("ConfirmMessage: %.*s: %.*s", static_cast(title.size()), title.data(), @@ -304,7 +303,7 @@ bool Host::ConfirmMessage(const std::string_view& title, const std::string_view& Log_ErrorPrintf("ConfirmMessage: %.*s", static_cast(message.size()), message.data()); } - return true; + return g_nogui_window->ConfirmMessage(title, message); } void Host::ReportDebuggerMessage(const std::string_view& message) diff --git a/src/duckstation-nogui/nogui_platform.h b/src/duckstation-nogui/nogui_platform.h index 168d9a9c6..124438448 100644 --- a/src/duckstation-nogui/nogui_platform.h +++ b/src/duckstation-nogui/nogui_platform.h @@ -16,6 +16,7 @@ public: virtual ~NoGUIPlatform() = default; virtual void ReportError(const std::string_view& title, const std::string_view& message) = 0; + virtual bool ConfirmMessage(const std::string_view& title, const std::string_view& message) = 0; virtual void SetDefaultConfig(SettingsInterface& si) = 0; diff --git a/src/duckstation-nogui/vty_nogui_platform.cpp b/src/duckstation-nogui/vty_nogui_platform.cpp index 057c67c51..8cc6d0b73 100644 --- a/src/duckstation-nogui/vty_nogui_platform.cpp +++ b/src/duckstation-nogui/vty_nogui_platform.cpp @@ -43,9 +43,13 @@ bool VTYNoGUIPlatform::Initialize() void VTYNoGUIPlatform::ReportError(const std::string_view& title, const std::string_view& message) { - const std::string title_copy(title); - const std::string message_copy(message); - Log_ErrorPrintf("%s: %s", title_copy.c_str(), message_copy.c_str()); + // not implemented +} + +bool VTYNoGUIPlatform::ConfirmMessage(const std::string_view& title, const std::string_view& message) +{ + // not implemented + return true; } void VTYNoGUIPlatform::SetDefaultConfig(SettingsInterface& si) diff --git a/src/duckstation-nogui/vty_nogui_platform.h b/src/duckstation-nogui/vty_nogui_platform.h index ad120e7fd..f417a91c1 100644 --- a/src/duckstation-nogui/vty_nogui_platform.h +++ b/src/duckstation-nogui/vty_nogui_platform.h @@ -16,6 +16,7 @@ public: bool Initialize(); void ReportError(const std::string_view& title, const std::string_view& message) override; + bool ConfirmMessage(const std::string_view& title, const std::string_view& message) override; void SetDefaultConfig(SettingsInterface& si) override; diff --git a/src/duckstation-nogui/wayland_nogui_platform.cpp b/src/duckstation-nogui/wayland_nogui_platform.cpp index 201f7c295..58982113e 100644 --- a/src/duckstation-nogui/wayland_nogui_platform.cpp +++ b/src/duckstation-nogui/wayland_nogui_platform.cpp @@ -78,9 +78,13 @@ bool WaylandNoGUIPlatform::Initialize() void WaylandNoGUIPlatform::ReportError(const std::string_view& title, const std::string_view& message) { - const std::string title_copy(title); - const std::string message_copy(message); - Log_ErrorPrintf("%s: %s", title_copy.c_str(), message_copy.c_str()); + // not implemented +} + +bool WaylandNoGUIPlatform::ConfirmMessage(const std::string_view& title, const std::string_view& message) +{ + // not implemented + return true; } void WaylandNoGUIPlatform::SetDefaultConfig(SettingsInterface& si) {} diff --git a/src/duckstation-nogui/wayland_nogui_platform.h b/src/duckstation-nogui/wayland_nogui_platform.h index 934a3415d..49f06bd25 100644 --- a/src/duckstation-nogui/wayland_nogui_platform.h +++ b/src/duckstation-nogui/wayland_nogui_platform.h @@ -21,6 +21,7 @@ public: bool Initialize(); void ReportError(const std::string_view& title, const std::string_view& message) override; + bool ConfirmMessage(const std::string_view& title, const std::string_view& message) override; void SetDefaultConfig(SettingsInterface& si) override; diff --git a/src/duckstation-nogui/win32_nogui_platform.cpp b/src/duckstation-nogui/win32_nogui_platform.cpp index ae666a2a4..46102a8f9 100644 --- a/src/duckstation-nogui/win32_nogui_platform.cpp +++ b/src/duckstation-nogui/win32_nogui_platform.cpp @@ -79,6 +79,14 @@ void Win32NoGUIPlatform::ReportError(const std::string_view& title, const std::s MessageBoxW(m_hwnd, message_copy.c_str(), title_copy.c_str(), MB_ICONERROR | MB_OK); } +bool Win32NoGUIPlatform::ConfirmMessage(const std::string_view& title, const std::string_view& message) +{ + const std::wstring title_copy(StringUtil::UTF8StringToWideString(title)); + const std::wstring message_copy(StringUtil::UTF8StringToWideString(message)); + + return (MessageBoxW(m_hwnd, message_copy.c_str(), title_copy.c_str(), MB_ICONQUESTION | MB_YESNO) == IDYES); +} + void Win32NoGUIPlatform::SetDefaultConfig(SettingsInterface& si) { // noop diff --git a/src/duckstation-nogui/win32_nogui_platform.h b/src/duckstation-nogui/win32_nogui_platform.h index 880409289..c58a66d39 100644 --- a/src/duckstation-nogui/win32_nogui_platform.h +++ b/src/duckstation-nogui/win32_nogui_platform.h @@ -15,6 +15,7 @@ public: bool Initialize(); void ReportError(const std::string_view& title, const std::string_view& message) override; + bool ConfirmMessage(const std::string_view& title, const std::string_view& message) override; void SetDefaultConfig(SettingsInterface& si) override; diff --git a/src/duckstation-nogui/x11_nogui_platform.cpp b/src/duckstation-nogui/x11_nogui_platform.cpp index 4b06dee00..23d5851b1 100644 --- a/src/duckstation-nogui/x11_nogui_platform.cpp +++ b/src/duckstation-nogui/x11_nogui_platform.cpp @@ -36,9 +36,13 @@ bool X11NoGUIPlatform::Initialize() void X11NoGUIPlatform::ReportError(const std::string_view& title, const std::string_view& message) { - const std::string title_copy(title); - const std::string message_copy(message); - Log_ErrorPrintf("%s: %s", title_copy.c_str(), message_copy.c_str()); + // not implemented +} + +bool X11NoGUIPlatform::ConfirmMessage(const std::string_view& title, const std::string_view& message) +{ + // not implemented + return true; } void X11NoGUIPlatform::SetDefaultConfig(SettingsInterface& si) {} diff --git a/src/duckstation-nogui/x11_nogui_platform.h b/src/duckstation-nogui/x11_nogui_platform.h index 9be7a6206..fc8819364 100644 --- a/src/duckstation-nogui/x11_nogui_platform.h +++ b/src/duckstation-nogui/x11_nogui_platform.h @@ -40,6 +40,7 @@ public: bool Initialize(); void ReportError(const std::string_view& title, const std::string_view& message) override; + bool ConfirmMessage(const std::string_view& title, const std::string_view& message) override; void SetDefaultConfig(SettingsInterface& si) override;