From 91d7e847e051c9aa8be87a72d2763872b6b4f385 Mon Sep 17 00:00:00 2001 From: Wladimir J. van der Laan Date: Sat, 31 Mar 2012 15:08:25 +0200 Subject: [PATCH] Use a messagebox to display the error when -server is provided without providing a rpc password (plus part of 7cfbe1fee465e82ddbdc8ed17dfcce791bd765f5) --- src/bitcoinrpc.cpp | 5 +++-- src/noui.h | 2 ++ src/qt/bitcoin.cpp | 9 ++++++++- src/qt/bitcoingui.cpp | 9 +++++++-- src/qt/bitcoingui.h | 2 +- src/qtui.h | 2 ++ 6 files changed, 23 insertions(+), 6 deletions(-) diff --git a/src/bitcoinrpc.cpp b/src/bitcoinrpc.cpp index 1f57bf9..a4a1fd4 100644 --- a/src/bitcoinrpc.cpp +++ b/src/bitcoinrpc.cpp @@ -2174,7 +2174,7 @@ void ThreadRPCServer2(void* parg) strWhatAmI = strprintf(_("To use the %s option"), "\"-server\""); else if (mapArgs.count("-daemon")) strWhatAmI = strprintf(_("To use the %s option"), "\"-daemon\""); - PrintConsole( + ThreadSafeMessageBox(strprintf( _("Error: %s, you must set a rpcpassword in the configuration file:\n %s\n" "It is recommended you use the following random password:\n" "rpcuser=bitcoinrpc\n" @@ -2183,7 +2183,8 @@ void ThreadRPCServer2(void* parg) "If the file does not exist, create it with owner-readable-only file permissions.\n"), strWhatAmI.c_str(), GetConfigFile().c_str(), - EncodeBase58(&rand_pwd[0],&rand_pwd[0]+32).c_str()); + EncodeBase58(&rand_pwd[0],&rand_pwd[0]+32).c_str()), + _("Error"), wxOK | wxMODAL); #ifndef QT_GUI CreateThread(Shutdown, NULL); #endif diff --git a/src/noui.h b/src/noui.h index 754c222..0bbf45a 100644 --- a/src/noui.h +++ b/src/noui.h @@ -36,6 +36,8 @@ typedef void wxWindow; #define wxHELP 0x00008000 #define wxMORE 0x00010000 #define wxSETUP 0x00020000 +// Force blocking, modal message box dialog (not just notification) +#define wxMODAL 0x00040000 inline int MyMessageBox(const std::string& message, const std::string& caption="Message", int style=wxOK, wxWindow* parent=NULL, int x=-1, int y=-1) { diff --git a/src/qt/bitcoin.cpp b/src/qt/bitcoin.cpp index 54e6bb3..311fab3 100644 --- a/src/qt/bitcoin.cpp +++ b/src/qt/bitcoin.cpp @@ -41,12 +41,19 @@ int MyMessageBox(const std::string& message, const std::string& caption, int sty int ThreadSafeMessageBox(const std::string& message, const std::string& caption, int style, wxWindow* parent, int x, int y) { + bool modal = style & wxMODAL; + + if (modal) + while (!guiref) + sleep(1); + // Message from network thread if(guiref) { QMetaObject::invokeMethod(guiref, "error", Qt::QueuedConnection, Q_ARG(QString, QString::fromStdString(caption)), - Q_ARG(QString, QString::fromStdString(message))); + Q_ARG(QString, QString::fromStdString(message)), + Q_ARG(bool, modal)); } else { diff --git a/src/qt/bitcoingui.cpp b/src/qt/bitcoingui.cpp index 78becaf..ed891f3 100644 --- a/src/qt/bitcoingui.cpp +++ b/src/qt/bitcoingui.cpp @@ -516,10 +516,15 @@ void BitcoinGUI::refreshStatusBar() setNumBlocks(clientModel->getNumBlocks()); } -void BitcoinGUI::error(const QString &title, const QString &message) +void BitcoinGUI::error(const QString &title, const QString &message, bool modal) { // Report errors from network/worker thread - notificator->notify(Notificator::Critical, title, message); + if (modal) + { + QMessageBox::critical(this, title, message, QMessageBox::Ok, QMessageBox::Ok); + } else { + notificator->notify(Notificator::Critical, title, message); + } } void BitcoinGUI::changeEvent(QEvent *e) diff --git a/src/qt/bitcoingui.h b/src/qt/bitcoingui.h index 9b672ee..efe3e9c 100644 --- a/src/qt/bitcoingui.h +++ b/src/qt/bitcoingui.h @@ -100,7 +100,7 @@ public slots: /** Set the status bar text if there are any warnings (removes sync progress bar if applicable) */ void refreshStatusBar(); - void error(const QString &title, const QString &message); + void error(const QString &title, const QString &message, bool modal = false); /* It is currently not possible to pass a return value to another thread through BlockingQueuedConnection, so use an indirected pointer. http://bugreports.qt.nokia.com/browse/QTBUG-10440 diff --git a/src/qtui.h b/src/qtui.h index 17fc44e..193f849 100644 --- a/src/qtui.h +++ b/src/qtui.h @@ -35,6 +35,8 @@ typedef void wxWindow; #define wxHELP 0x00008000 #define wxMORE 0x00010000 #define wxSETUP 0x00020000 +// Force blocking, modal message box dialog (not just notification) +#define wxMODAL 0x00040000 extern int MyMessageBox(const std::string& message, const std::string& caption="Message", int style=wxOK, wxWindow* parent=NULL, int x=-1, int y=-1); #define wxMessageBox MyMessageBox -- 1.7.1