2 * W.J. van der Laan 2011
4 #include "bitcoingui.h"
5 #include "clientmodel.h"
6 #include "walletmodel.h"
7 #include "optionsmodel.h"
13 #include <QApplication>
14 #include <QMessageBox>
17 #include <QTranslator>
18 #include <QSplashScreen>
21 // Need a global reference for the notifications to find the GUI
23 QSplashScreen *splashref;
25 int MyMessageBox(const std::string& message, const std::string& caption, int style, wxWindow* parent, int x, int y)
27 // Message from main thread
30 guiref->error(QString::fromStdString(caption),
31 QString::fromStdString(message));
35 QMessageBox::critical(0, QString::fromStdString(caption),
36 QString::fromStdString(message),
37 QMessageBox::Ok, QMessageBox::Ok);
42 int ThreadSafeMessageBox(const std::string& message, const std::string& caption, int style, wxWindow* parent, int x, int y)
44 // Message from network thread
47 QMetaObject::invokeMethod(guiref, "error", Qt::QueuedConnection,
48 Q_ARG(QString, QString::fromStdString(caption)),
49 Q_ARG(QString, QString::fromStdString(message)));
53 printf("%s: %s\n", caption.c_str(), message.c_str());
54 fprintf(stderr, "%s: %s\n", caption.c_str(), message.c_str());
59 bool ThreadSafeAskFee(int64 nFeeRequired, const std::string& strCaption, wxWindow* parent)
63 if(nFeeRequired < MIN_TX_FEE || nFeeRequired <= nTransactionFee || fDaemon)
67 // Call slot on GUI thread.
68 // If called from another thread, use a blocking QueuedConnection.
69 Qt::ConnectionType connectionType = Qt::DirectConnection;
70 if(QThread::currentThread() != QCoreApplication::instance()->thread())
72 connectionType = Qt::BlockingQueuedConnection;
75 QMetaObject::invokeMethod(guiref, "askFee", connectionType,
76 Q_ARG(qint64, nFeeRequired),
77 Q_ARG(bool*, &payFee));
82 void CalledSetStatusBar(const std::string& strText, int nField)
84 // Only used for built-in mining, which is disabled, simple ignore
87 void UIThreadCall(boost::function0<void> fn)
89 // Only used for built-in mining, which is disabled, simple ignore
92 void MainFrameRepaint()
96 void InitMessage(const std::string &message)
100 splashref->showMessage(QString::fromStdString(message), Qt::AlignBottom|Qt::AlignHCenter, QColor(255,255,200));
101 QApplication::instance()->processEvents();
106 Translate string to current locale using Qt.
108 std::string _(const char* psz)
110 return QCoreApplication::translate("bitcoin-core", psz).toStdString();
113 int main(int argc, char *argv[])
115 Q_INIT_RESOURCE(bitcoin);
116 QApplication app(argc, argv);
118 // Load language file for system locale
119 QString locale = QLocale::system().name();
120 QTranslator translator;
121 translator.load("bitcoin_"+locale);
122 app.installTranslator(&translator);
124 QSplashScreen splash(QPixmap(":/images/splash"), Qt::WindowStaysOnTopHint);
126 splash.setAutoFillBackground(true);
131 app.setQuitOnLastWindowClosed(false);
135 if(AppInit2(argc, argv))
138 // Put this in a block, so that BitcoinGUI is cleaned up properly before
141 splash.finish(&window);
142 OptionsModel optionsModel(pwalletMain);
143 ClientModel clientModel(&optionsModel);
144 WalletModel walletModel(pwalletMain, &optionsModel);
147 window.setClientModel(&clientModel);
148 window.setWalletModel(&walletModel);
150 if (QtWin::isCompositionEnabled())
153 // Windows-specific customization
154 window.setAttribute(Qt::WA_TranslucentBackground);
155 window.setAttribute(Qt::WA_NoSystemBackground, false);
156 QPalette pal = window.palette();
157 QColor bg = pal.window().color();
159 pal.setColor(QPalette::Window, bg);
160 window.setPalette(pal);
161 window.ensurePolished();
162 window.setAttribute(Qt::WA_StyledBackground, false);
164 QtWin::extendFrameIntoClientArea(&window);
165 window.setContentsMargins(0, 0, 0, 0);
180 } catch (std::exception& e) {
181 PrintException(&e, "Runaway exception");
183 PrintException(NULL, "Runaway exception");