2 * W.J. van der Laan 2011
4 #include "bitcoingui.h"
5 #include "clientmodel.h"
6 #include "walletmodel.h"
11 #include <QApplication>
12 #include <QMessageBox>
15 #include <QTranslator>
17 // Need a global reference for the notifications to find the GUI
20 int MyMessageBox(const std::string& message, const std::string& caption, int style, wxWindow* parent, int x, int y)
22 // Message from main thread
25 guiref->error(QString::fromStdString(caption),
26 QString::fromStdString(message));
30 QMessageBox::critical(0, QString::fromStdString(caption),
31 QString::fromStdString(message),
32 QMessageBox::Ok, QMessageBox::Ok);
37 int ThreadSafeMessageBox(const std::string& message, const std::string& caption, int style, wxWindow* parent, int x, int y)
39 // Message from network thread
42 QMetaObject::invokeMethod(guiref, "error", Qt::QueuedConnection,
43 Q_ARG(QString, QString::fromStdString(caption)),
44 Q_ARG(QString, QString::fromStdString(message)));
48 printf("%s: %s\n", caption.c_str(), message.c_str());
49 fprintf(stderr, "%s: %s\n", caption.c_str(), message.c_str());
54 bool ThreadSafeAskFee(int64 nFeeRequired, const std::string& strCaption, wxWindow* parent)
58 if(nFeeRequired < MIN_TX_FEE || nFeeRequired <= nTransactionFee || fDaemon)
62 // Call slot on GUI thread.
63 // If called from another thread, use a blocking QueuedConnection.
64 Qt::ConnectionType connectionType = Qt::DirectConnection;
65 if(QThread::currentThread() != QCoreApplication::instance()->thread())
67 connectionType = Qt::BlockingQueuedConnection;
70 QMetaObject::invokeMethod(guiref, "askFee", connectionType,
71 Q_ARG(qint64, nFeeRequired),
72 Q_ARG(bool*, &payFee));
77 void CalledSetStatusBar(const std::string& strText, int nField)
79 // Only used for built-in mining, which is disabled, simple ignore
82 void UIThreadCall(boost::function0<void> fn)
84 // Only used for built-in mining, which is disabled, simple ignore
87 void MainFrameRepaint()
92 Translate string to current locale using Qt.
94 std::string _(const char* psz)
96 return QCoreApplication::translate("bitcoin-core", psz).toStdString();
99 int main(int argc, char *argv[])
101 Q_INIT_RESOURCE(bitcoin);
102 QApplication app(argc, argv);
104 // Load language file for system locale
105 QString locale = QLocale::system().name();
106 QTranslator translator;
107 translator.load("bitcoin_"+locale);
108 app.installTranslator(&translator);
110 app.setQuitOnLastWindowClosed(false);
114 if(AppInit2(argc, argv))
117 // Put this in a block, so that BitcoinGUI is cleaned up properly before
120 ClientModel clientModel(pwalletMain);
121 WalletModel walletModel(pwalletMain);
123 window.setClientModel(&clientModel);
124 window.setWalletModel(&walletModel);
138 } catch (std::exception& e) {
139 PrintException(&e, "Runaway exception");
141 PrintException(NULL, "Runaway exception");