Skip to content

Commit 7cfbe1f

Browse files
committed
qtui.h/noui.h interface cleanup
- rename wxMessageBox, remove redundant arguments to noui/qtui calls - also, add flag to force blocking, modal dialog box for disk space warning etc - clarify function naming - no more special MessageBox needed from AppInit2, as window object is created before calling AppInit2
1 parent 1a3f0da commit 7cfbe1f

File tree

12 files changed

+47
-51
lines changed

12 files changed

+47
-51
lines changed

src/init.cpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ bool AppInit2(int argc, char* argv[])
237237
strUsage.erase(std::remove(strUsage.begin(), strUsage.end(), '\t'), strUsage.end());
238238
#if defined(QT_GUI) && defined(WIN32)
239239
// On windows, show a message box, as there is no stderr
240-
wxMessageBox(strUsage, "Usage");
240+
ThreadSafeMessageBox(strUsage, _("Usage"), wxOK | wxMODAL);
241241
#else
242242
fprintf(stderr, "%s", strUsage.c_str());
243243
#endif
@@ -326,7 +326,7 @@ bool AppInit2(int argc, char* argv[])
326326
static boost::interprocess::file_lock lock(strLockFile.c_str());
327327
if (!lock.try_lock())
328328
{
329-
wxMessageBox(strprintf(_("Cannot obtain a lock on data directory %s. Bitcoin is probably already running."), GetDataDir().c_str()), "Bitcoin");
329+
ThreadSafeMessageBox(strprintf(_("Cannot obtain a lock on data directory %s. Bitcoin is probably already running."), GetDataDir().c_str()), _("Bitcoin"), wxOK|wxMODAL);
330330
return false;
331331
}
332332

@@ -368,7 +368,7 @@ bool AppInit2(int argc, char* argv[])
368368
{
369369
strErrors << _("Wallet needed to be rewritten: restart Bitcoin to complete") << "\n";
370370
printf("%s", strErrors.str().c_str());
371-
wxMessageBox(strErrors.str(), "Bitcoin", wxOK | wxICON_ERROR);
371+
ThreadSafeMessageBox(strErrors.str(), _("Bitcoin"), wxOK | wxICON_ERROR | wxMODAL);
372372
return false;
373373
}
374374
else
@@ -440,7 +440,7 @@ bool AppInit2(int argc, char* argv[])
440440

441441
if (!strErrors.str().empty())
442442
{
443-
wxMessageBox(strErrors.str(), "Bitcoin", wxOK | wxICON_ERROR);
443+
ThreadSafeMessageBox(strErrors.str(), _("Bitcoin"), wxOK | wxICON_ERROR | wxMODAL);
444444
return false;
445445
}
446446

@@ -496,7 +496,7 @@ bool AppInit2(int argc, char* argv[])
496496
addrProxy = CService(mapArgs["-proxy"], 9050);
497497
if (!addrProxy.IsValid())
498498
{
499-
wxMessageBox(_("Invalid -proxy address"), "Bitcoin");
499+
ThreadSafeMessageBox(_("Invalid -proxy address"), _("Bitcoin"), wxOK | wxMODAL);
500500
return false;
501501
}
502502
}
@@ -527,7 +527,7 @@ bool AppInit2(int argc, char* argv[])
527527
std::string strError;
528528
if (!BindListenPort(strError))
529529
{
530-
wxMessageBox(strError, "Bitcoin");
530+
ThreadSafeMessageBox(strError, _("Bitcoin"), wxOK | wxMODAL);
531531
return false;
532532
}
533533
}
@@ -547,11 +547,11 @@ bool AppInit2(int argc, char* argv[])
547547
{
548548
if (!ParseMoney(mapArgs["-paytxfee"], nTransactionFee))
549549
{
550-
wxMessageBox(_("Invalid amount for -paytxfee=<amount>"), "Bitcoin");
550+
ThreadSafeMessageBox(_("Invalid amount for -paytxfee=<amount>"), _("Bitcoin"), wxOK | wxMODAL);
551551
return false;
552552
}
553553
if (nTransactionFee > 0.25 * COIN)
554-
wxMessageBox(_("Warning: -paytxfee is set very high. This is the transaction fee you will pay if you send a transaction."), "Bitcoin", wxOK | wxICON_EXCLAMATION);
554+
ThreadSafeMessageBox(_("Warning: -paytxfee is set very high. This is the transaction fee you will pay if you send a transaction."), _("Bitcoin"), wxOK | wxICON_EXCLAMATION | wxMODAL);
555555
}
556556

557557
//
@@ -563,7 +563,7 @@ bool AppInit2(int argc, char* argv[])
563563
RandAddSeedPerfmon();
564564

565565
if (!CreateThread(StartNode, NULL))
566-
wxMessageBox(_("Error: CreateThread(StartNode) failed"), "Bitcoin");
566+
ThreadSafeMessageBox(_("Error: CreateThread(StartNode) failed"), _("Bitcoin"), wxOK | wxMODAL);
567567

568568
if (fServer)
569569
CreateThread(ThreadRPCServer, NULL);

src/main.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1811,7 +1811,7 @@ bool CheckDiskSpace(uint64 nAdditionalBytes)
18111811
string strMessage = _("Warning: Disk space is low ");
18121812
strMiscWarning = strMessage;
18131813
printf("*** %s\n", strMessage.c_str());
1814-
ThreadSafeMessageBox(strMessage, "Bitcoin", wxOK | wxICON_EXCLAMATION);
1814+
ThreadSafeMessageBox(strMessage, "Bitcoin", wxOK | wxICON_EXCLAMATION | wxMODAL);
18151815
QueueShutdown();
18161816
return false;
18171817
}

src/noui.h

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
#include "wallet.h"
1010
#include "init.h"
1111

12-
typedef void wxWindow;
1312
#define wxYES 0x00000002
1413
#define wxOK 0x00000004
1514
#define wxNO 0x00000008
@@ -36,21 +35,17 @@ typedef void wxWindow;
3635
#define wxHELP 0x00008000
3736
#define wxMORE 0x00010000
3837
#define wxSETUP 0x00020000
38+
// Force blocking, modal message box dialog (not just notification)
39+
#define wxMODAL 0x00040000
3940

40-
inline int MyMessageBox(const std::string& message, const std::string& caption="Message", int style=wxOK, wxWindow* parent=NULL, int x=-1, int y=-1)
41+
inline int ThreadSafeMessageBox(const std::string& message, const std::string& caption, int style=wxOK)
4142
{
4243
printf("%s: %s\n", caption.c_str(), message.c_str());
4344
fprintf(stderr, "%s: %s\n", caption.c_str(), message.c_str());
4445
return 4;
4546
}
46-
#define wxMessageBox MyMessageBox
4747

48-
inline int ThreadSafeMessageBox(const std::string& message, const std::string& caption, int style=wxOK, wxWindow* parent=NULL, int x=-1, int y=-1)
49-
{
50-
return MyMessageBox(message, caption, style, parent, x, y);
51-
}
52-
53-
inline bool ThreadSafeAskFee(int64 nFeeRequired, const std::string& strCaption, wxWindow* parent)
48+
inline bool ThreadSafeAskFee(int64 nFeeRequired, const std::string& strCaption)
5449
{
5550
return true;
5651
}

src/qt/bitcoin.cpp

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -38,23 +38,18 @@ static QSplashScreen *splashref;
3838
static WalletModel *walletmodel;
3939
static ClientModel *clientmodel;
4040

41-
int MyMessageBox(const std::string& message, const std::string& caption, int style, wxWindow* parent, int x, int y)
42-
{
43-
// Message from AppInit2(), always in main thread before main window is constructed
44-
QMessageBox::critical(0, QString::fromStdString(caption),
45-
QString::fromStdString(message),
46-
QMessageBox::Ok, QMessageBox::Ok);
47-
return 4;
48-
}
49-
50-
int ThreadSafeMessageBox(const std::string& message, const std::string& caption, int style, wxWindow* parent, int x, int y)
41+
int ThreadSafeMessageBox(const std::string& message, const std::string& caption, int style)
5142
{
5243
// Message from network thread
5344
if(guiref)
5445
{
55-
QMetaObject::invokeMethod(guiref, "error", Qt::QueuedConnection,
46+
bool modal = (style & wxMODAL);
47+
// in case of modal message, use blocking connection to wait for user to click OK
48+
QMetaObject::invokeMethod(guiref, "error",
49+
modal ? GUIUtil::blockingGUIThreadConnection() : Qt::QueuedConnection,
5650
Q_ARG(QString, QString::fromStdString(caption)),
57-
Q_ARG(QString, QString::fromStdString(message)));
51+
Q_ARG(QString, QString::fromStdString(message)),
52+
Q_ARG(bool, modal));
5853
}
5954
else
6055
{
@@ -64,7 +59,7 @@ int ThreadSafeMessageBox(const std::string& message, const std::string& caption,
6459
return 4;
6560
}
6661

67-
bool ThreadSafeAskFee(int64 nFeeRequired, const std::string& strCaption, wxWindow* parent)
62+
bool ThreadSafeAskFee(int64 nFeeRequired, const std::string& strCaption)
6863
{
6964
if(!guiref)
7065
return false;
@@ -222,15 +217,16 @@ int main(int argc, char *argv[])
222217

223218
try
224219
{
220+
BitcoinGUI window;
221+
guiref = &window;
225222
if(AppInit2(argc, argv))
226223
{
227224
{
228-
// Put this in a block, so that BitcoinGUI is cleaned up properly before
229-
// calling Shutdown() in case of exceptions.
225+
// Put this in a block, so that the Model objects are cleaned up before
226+
// calling Shutdown().
230227

231228
optionsModel.Upgrade(); // Must be done after AppInit2
232229

233-
BitcoinGUI window;
234230
if (splashref)
235231
splash.finish(&window);
236232

@@ -239,7 +235,6 @@ int main(int argc, char *argv[])
239235
WalletModel walletModel(pwalletMain, &optionsModel);
240236
walletmodel = &walletModel;
241237

242-
guiref = &window;
243238
window.setClientModel(&clientModel);
244239
window.setWalletModel(&walletModel);
245240

@@ -276,6 +271,8 @@ int main(int argc, char *argv[])
276271
#endif
277272
app.exec();
278273

274+
window.setClientModel(0);
275+
window.setWalletModel(0);
279276
guiref = 0;
280277
clientmodel = 0;
281278
walletmodel = 0;

src/qt/bitcoingui.cpp

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -336,7 +336,7 @@ void BitcoinGUI::setClientModel(ClientModel *clientModel)
336336
connect(clientModel, SIGNAL(numBlocksChanged(int)), this, SLOT(setNumBlocks(int)));
337337

338338
// Report errors from network/worker thread
339-
connect(clientModel, SIGNAL(error(QString,QString)), this, SLOT(error(QString,QString)));
339+
connect(clientModel, SIGNAL(error(QString,QString, bool)), this, SLOT(error(QString,QString,bool)));
340340
}
341341
}
342342

@@ -346,7 +346,7 @@ void BitcoinGUI::setWalletModel(WalletModel *walletModel)
346346
if(walletModel)
347347
{
348348
// Report errors from wallet thread
349-
connect(walletModel, SIGNAL(error(QString,QString)), this, SLOT(error(QString,QString)));
349+
connect(walletModel, SIGNAL(error(QString,QString,bool)), this, SLOT(error(QString,QString,bool)));
350350

351351
// Put transaction list in tabs
352352
transactionView->setModel(walletModel);
@@ -538,10 +538,15 @@ void BitcoinGUI::setNumBlocks(int count)
538538
progressBar->setToolTip(tooltip);
539539
}
540540

541-
void BitcoinGUI::error(const QString &title, const QString &message)
541+
void BitcoinGUI::error(const QString &title, const QString &message, bool modal)
542542
{
543543
// Report errors from network/worker thread
544-
notificator->notify(Notificator::Critical, title, message);
544+
if(modal)
545+
{
546+
QMessageBox::critical(this, title, message, QMessageBox::Ok, QMessageBox::Ok);
547+
} else {
548+
notificator->notify(Notificator::Critical, title, message);
549+
}
545550
}
546551

547552
void BitcoinGUI::changeEvent(QEvent *e)

src/qt/bitcoingui.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ public slots:
115115
void setEncryptionStatus(int status);
116116

117117
/** Notify the user of an error in the network or transaction handling code. */
118-
void error(const QString &title, const QString &message);
118+
void error(const QString &title, const QString &message, bool modal);
119119
/** Asks the user whether to pay the transaction fee or to cancel the transaction.
120120
It is currently not possible to pass a return value to another thread through
121121
BlockingQueuedConnection, so an indirected pointer is used.

src/qt/clientmodel.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ class ClientModel : public QObject
5252
void numBlocksChanged(int count);
5353

5454
//! Asynchronous error notification
55-
void error(const QString &title, const QString &message);
55+
void error(const QString &title, const QString &message, bool modal);
5656

5757
public slots:
5858

src/qt/walletmodel.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ WalletModel::SendCoinsReturn WalletModel::sendCoins(const QList<SendCoinsRecipie
140140
}
141141
return TransactionCreationFailed;
142142
}
143-
if(!ThreadSafeAskFee(nFeeRequired, tr("Sending...").toStdString(), NULL))
143+
if(!ThreadSafeAskFee(nFeeRequired, tr("Sending...").toStdString()))
144144
{
145145
return Aborted;
146146
}

src/qt/walletmodel.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ class WalletModel : public QObject
135135
void requireUnlock();
136136

137137
// Asynchronous error notification
138-
void error(const QString &title, const QString &message);
138+
void error(const QString &title, const QString &message, bool modal);
139139

140140
public slots:
141141
void update();

src/qtui.h

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
#include <string>
88
#include "wallet.h"
99

10-
typedef void wxWindow;
1110
#define wxYES 0x00000002
1211
#define wxOK 0x00000004
1312
#define wxNO 0x00000008
@@ -34,11 +33,11 @@ typedef void wxWindow;
3433
#define wxHELP 0x00008000
3534
#define wxMORE 0x00010000
3635
#define wxSETUP 0x00020000
36+
// Force blocking, modal message box dialog (not just notification)
37+
#define wxMODAL 0x00040000
3738

38-
extern int MyMessageBox(const std::string& message, const std::string& caption="Message", int style=wxOK, wxWindow* parent=NULL, int x=-1, int y=-1);
39-
#define wxMessageBox MyMessageBox
40-
extern int ThreadSafeMessageBox(const std::string& message, const std::string& caption, int style=wxOK, wxWindow* parent=NULL, int x=-1, int y=-1);
41-
extern bool ThreadSafeAskFee(int64 nFeeRequired, const std::string& strCaption, wxWindow* parent);
39+
extern int ThreadSafeMessageBox(const std::string& message, const std::string& caption, int style=wxOK);
40+
extern bool ThreadSafeAskFee(int64 nFeeRequired, const std::string& strCaption);
4241
extern void ThreadSafeHandleURL(const std::string& strURL);
4342
extern void MainFrameRepaint();
4443
extern void AddressBookRepaint();

0 commit comments

Comments
 (0)