summaryrefslogtreecommitdiff
path: root/Source
diff options
context:
space:
mode:
authorMichael M <mchtly@gmail.com>2017-07-25 21:11:47 -0700
committerMichael M <mchtly@gmail.com>2017-08-03 13:29:59 -0700
commit7bdfd862d729df3d9303973267535e096c90391d (patch)
tree54af455848044461012fe440ab04dfa536f66968 /Source
parent737651f298d4dfc6ce2b133fb5db02c8b315be1f (diff)
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.
Diffstat (limited to 'Source')
-rw-r--r--Source/Core/DolphinQt2/Main.cpp32
1 files changed, 32 insertions, 0 deletions
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 <QMessageBox>
#include <QObject>
+#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,