2 * W.J. van der Laan 2011
4 #include "bitcoingui.h"
5 #include "clientmodel.h"
6 #include "walletmodel.h"
7 #include "optionsmodel.h"
12 #include <QApplication>
13 #include <QMessageBox>
17 #include <QTranslator>
18 #include <QSplashScreen>
20 // Need a global reference for the notifications to find the GUI
22 QSplashScreen *splashref;
24 int MyMessageBox(const std::string& message, const std::string& caption, int style, wxWindow* parent, int x, int y)
26 // Message from main thread
29 guiref->error(QString::fromStdString(caption),
30 QString::fromStdString(message));
34 QMessageBox::critical(0, QString::fromStdString(caption),
35 QString::fromStdString(message),
36 QMessageBox::Ok, QMessageBox::Ok);
41 int ThreadSafeMessageBox(const std::string& message, const std::string& caption, int style, wxWindow* parent, int x, int y)
43 // Message from network thread
46 QMetaObject::invokeMethod(guiref, "error", Qt::QueuedConnection,
47 Q_ARG(QString, QString::fromStdString(caption)),
48 Q_ARG(QString, QString::fromStdString(message)));
52 printf("%s: %s\n", caption.c_str(), message.c_str());
53 fprintf(stderr, "%s: %s\n", caption.c_str(), message.c_str());
58 bool ThreadSafeAskFee(int64 nFeeRequired, const std::string& strCaption, wxWindow* parent)
62 if(nFeeRequired < MIN_TX_FEE || nFeeRequired <= nTransactionFee || fDaemon)
66 // Call slot on GUI thread.
67 // If called from another thread, use a blocking QueuedConnection.
68 Qt::ConnectionType connectionType = Qt::DirectConnection;
69 if(QThread::currentThread() != QCoreApplication::instance()->thread())
71 connectionType = Qt::BlockingQueuedConnection;
74 QMetaObject::invokeMethod(guiref, "askFee", connectionType,
75 Q_ARG(qint64, nFeeRequired),
76 Q_ARG(bool*, &payFee));
81 void CalledSetStatusBar(const std::string& strText, int nField)
83 // Only used for built-in mining, which is disabled, simple ignore
86 void UIThreadCall(boost::function0<void> fn)
88 // Only used for built-in mining, which is disabled, simple ignore
91 void MainFrameRepaint()
95 void InitMessage(const std::string &message)
99 splashref->showMessage(QString::fromStdString(message), Qt::AlignBottom|Qt::AlignHCenter, QColor(255,255,200));
100 QApplication::instance()->processEvents();
105 Translate string to current locale using Qt.
107 std::string _(const char* psz)
109 return QCoreApplication::translate("bitcoin-core", psz).toStdString();
112 int main(int argc, char *argv[])
114 QTextCodec::setCodecForTr(QTextCodec::codecForName("UTF-8"));
115 QTextCodec::setCodecForCStrings(QTextCodec::codecForTr());
117 Q_INIT_RESOURCE(bitcoin);
118 QApplication app(argc, argv);
120 // Load language file for system locale
121 QString locale = QLocale::system().name();
122 QTranslator translator;
123 translator.load(":/translations/"+locale);
124 app.installTranslator(&translator);
126 QSplashScreen splash(QPixmap(":/images/splash"), 0);
128 splash.setAutoFillBackground(true);
133 app.setQuitOnLastWindowClosed(false);
137 if(AppInit2(argc, argv))
140 // Put this in a block, so that BitcoinGUI is cleaned up properly before
141 // calling Shutdown().
143 splash.finish(&window);
144 OptionsModel optionsModel(pwalletMain);
145 ClientModel clientModel(&optionsModel);
146 WalletModel walletModel(pwalletMain, &optionsModel);
149 window.setClientModel(&clientModel);
150 window.setWalletModel(&walletModel);
164 } catch (std::exception& e) {
165 PrintException(&e, "Runaway exception");
167 PrintException(NULL, "Runaway exception");