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>
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 Q_INIT_RESOURCE(bitcoin);
115 QApplication app(argc, argv);
117 // Load language file for system locale
118 QString locale = QLocale::system().name();
119 QTranslator translator;
120 translator.load("bitcoin_"+locale);
121 app.installTranslator(&translator);
123 QSplashScreen splash(QPixmap(":/images/splash"), 0);
125 splash.setAutoFillBackground(true);
130 app.setQuitOnLastWindowClosed(false);
134 if(AppInit2(argc, argv))
137 // Put this in a block, so that BitcoinGUI is cleaned up properly before
138 // calling Shutdown().
140 splash.finish(&window);
141 OptionsModel optionsModel(pwalletMain);
142 ClientModel clientModel(&optionsModel);
143 WalletModel walletModel(pwalletMain, &optionsModel);
146 window.setClientModel(&clientModel);
147 window.setWalletModel(&walletModel);
149 if (QtWin::isCompositionEnabled())
152 // Windows-specific customization
153 window.setAttribute(Qt::WA_TranslucentBackground);
154 window.setAttribute(Qt::WA_NoSystemBackground, false);
155 QPalette pal = window.palette();
156 QColor bg = pal.window().color();
158 pal.setColor(QPalette::Window, bg);
159 window.setPalette(pal);
160 window.ensurePolished();
161 window.setAttribute(Qt::WA_StyledBackground, false);
163 QtWin::extendFrameIntoClientArea(&window);
164 window.setContentsMargins(0, 0, 0, 0);
179 } catch (std::exception& e) {
180 PrintException(&e, "Runaway exception");
182 PrintException(NULL, "Runaway exception");