From 7bdfd862d729df3d9303973267535e096c90391d Mon Sep 17 00:00:00 2001 From: Michael M Date: Tue, 25 Jul 2017 21:11:47 -0700 Subject: [PATCH] Qt: register MsgAlertHandler This is the thing that pops up a message box when something goes wrong, or when you want to override a previously dumped file, etc. --- Source/Core/DolphinQt2/Main.cpp | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/Source/Core/DolphinQt2/Main.cpp b/Source/Core/DolphinQt2/Main.cpp index 5609e70d5b..8d9cd87179 100644 --- a/Source/Core/DolphinQt2/Main.cpp +++ b/Source/Core/DolphinQt2/Main.cpp @@ -8,17 +8,46 @@ #include #include +#include "Common/MsgHandler.h" #include "Core/Analytics.h" #include "Core/BootManager.h" #include "Core/Core.h" #include "DolphinQt2/Host.h" #include "DolphinQt2/InDevelopmentWarning.h" #include "DolphinQt2/MainWindow.h" +#include "DolphinQt2/QtUtils/RunOnObject.h" #include "DolphinQt2/Resources.h" #include "DolphinQt2/Settings.h" #include "UICommon/CommandLineParse.h" #include "UICommon/UICommon.h" +bool QtMsgAlertHandler(const char* caption, const char* text, bool yes_no, MsgType style) +{ + return RunOnObject(QApplication::instance(), [&] { + QMessageBox message_box(QApplication::activeWindow()); + message_box.setWindowTitle(QString::fromUtf8(caption)); + message_box.setText(QString::fromUtf8(text)); + message_box.setStandardButtons(yes_no ? QMessageBox::Yes | QMessageBox::No : QMessageBox::Ok); + message_box.setIcon([&] { + switch (style) + { + case MsgType::Information: + return QMessageBox::Information; + case MsgType::Question: + return QMessageBox::Question; + case MsgType::Warning: + return QMessageBox::Warning; + case MsgType::Critical: + return QMessageBox::Critical; + } + // appease MSVC + return QMessageBox::NoIcon; + }()); + + return message_box.exec() == QMessageBox::Yes; + }); +} + // N.B. On Windows, this should be called from WinMain. Link against qtmain and specify // /SubSystem:Windows int main(int argc, char* argv[]) @@ -40,6 +69,9 @@ int main(int argc, char* argv[]) UICommon::Init(); Resources::Init(); + // Hook up alerts from core + RegisterMsgAlertHandler(QtMsgAlertHandler); + // Whenever the event loop is about to go to sleep, dispatch the jobs // queued in the Core first. QObject::connect(QAbstractEventDispatcher::instance(), &QAbstractEventDispatcher::aboutToBlock,