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>
18 #include <QTranslator>
19 #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 QTextCodec::setCodecForTr(QTextCodec::codecForName("UTF-8"));
116 QTextCodec::setCodecForCStrings(QTextCodec::codecForTr());
118 Q_INIT_RESOURCE(bitcoin);
119 QApplication app(argc, argv);
121 // Load language file for system locale
122 QString locale = QLocale::system().name();
123 QTranslator translator;
124 translator.load("bitcoin_"+locale);
125 app.installTranslator(&translator);
127 QSplashScreen splash(QPixmap(":/images/splash"), 0);
129 splash.setAutoFillBackground(true);
134 app.setQuitOnLastWindowClosed(false);
138 if(AppInit2(argc, argv))
141 // Put this in a block, so that BitcoinGUI is cleaned up properly before
142 // calling Shutdown().
144 splash.finish(&window);
145 OptionsModel optionsModel(pwalletMain);
146 ClientModel clientModel(&optionsModel);
147 WalletModel walletModel(pwalletMain, &optionsModel);
150 window.setClientModel(&clientModel);
151 window.setWalletModel(&walletModel);
153 if (QtWin::isCompositionEnabled())
156 // Windows-specific customization
157 window.setAttribute(Qt::WA_TranslucentBackground);
158 window.setAttribute(Qt::WA_NoSystemBackground, false);
159 QPalette pal = window.palette();
160 QColor bg = pal.window().color();
162 pal.setColor(QPalette::Window, bg);
163 window.setPalette(pal);
164 window.ensurePolished();
165 window.setAttribute(Qt::WA_StyledBackground, false);
167 QtWin::extendFrameIntoClientArea(&window);
168 window.setContentsMargins(0, 0, 0, 0);
183 } catch (std::exception& e) {
184 PrintException(&e, "Runaway exception");
186 PrintException(NULL, "Runaway exception");