2 * W.J. van der Laan 2011
4 #include "bitcoingui.h"
5 #include "clientmodel.h"
6 #include "walletmodel.h"
12 #include <QApplication>
13 #include <QMessageBox>
16 #include <QTranslator>
18 // Need a global reference for the notifications to find the GUI
21 int MyMessageBox(const std::string& message, const std::string& caption, int style, wxWindow* parent, int x, int y)
23 // Message from main thread
26 guiref->error(QString::fromStdString(caption),
27 QString::fromStdString(message));
31 QMessageBox::critical(0, QString::fromStdString(caption),
32 QString::fromStdString(message),
33 QMessageBox::Ok, QMessageBox::Ok);
38 int ThreadSafeMessageBox(const std::string& message, const std::string& caption, int style, wxWindow* parent, int x, int y)
40 // Message from network thread
43 QMetaObject::invokeMethod(guiref, "error", Qt::QueuedConnection,
44 Q_ARG(QString, QString::fromStdString(caption)),
45 Q_ARG(QString, QString::fromStdString(message)));
49 printf("%s: %s\n", caption.c_str(), message.c_str());
50 fprintf(stderr, "%s: %s\n", caption.c_str(), message.c_str());
55 bool ThreadSafeAskFee(int64 nFeeRequired, const std::string& strCaption, wxWindow* parent)
59 if(nFeeRequired < MIN_TX_FEE || nFeeRequired <= nTransactionFee || fDaemon)
63 // Call slot on GUI thread.
64 // If called from another thread, use a blocking QueuedConnection.
65 Qt::ConnectionType connectionType = Qt::DirectConnection;
66 if(QThread::currentThread() != QCoreApplication::instance()->thread())
68 connectionType = Qt::BlockingQueuedConnection;
71 QMetaObject::invokeMethod(guiref, "askFee", connectionType,
72 Q_ARG(qint64, nFeeRequired),
73 Q_ARG(bool*, &payFee));
78 void CalledSetStatusBar(const std::string& strText, int nField)
80 // Only used for built-in mining, which is disabled, simple ignore
83 void UIThreadCall(boost::function0<void> fn)
85 // Only used for built-in mining, which is disabled, simple ignore
88 void MainFrameRepaint()
93 Translate string to current locale using Qt.
95 std::string _(const char* psz)
97 return QCoreApplication::translate("bitcoin-core", psz).toStdString();
100 int main(int argc, char *argv[])
102 Q_INIT_RESOURCE(bitcoin);
103 QApplication app(argc, argv);
105 // Load language file for system locale
106 QString locale = QLocale::system().name();
107 QTranslator translator;
108 translator.load("bitcoin_"+locale);
109 app.installTranslator(&translator);
111 app.setQuitOnLastWindowClosed(false);
115 if(AppInit2(argc, argv))
118 // Put this in a block, so that BitcoinGUI is cleaned up properly before
121 ClientModel clientModel(pwalletMain);
122 WalletModel walletModel(pwalletMain);
125 window.setClientModel(&clientModel);
126 window.setWalletModel(&walletModel);
128 if (QtWin::isCompositionEnabled())
131 // Windows-specific customization
132 window.setAttribute(Qt::WA_TranslucentBackground);
133 window.setAttribute(Qt::WA_NoSystemBackground, false);
134 QPalette pal = window.palette();
135 QColor bg = pal.window().color();
137 pal.setColor(QPalette::Window, bg);
138 window.setPalette(pal);
139 window.ensurePolished();
140 window.setAttribute(Qt::WA_StyledBackground, false);
142 QtWin::extendFrameIntoClientArea(&window);
143 window.setContentsMargins(0, 0, 0, 0);
158 } catch (std::exception& e) {
159 PrintException(&e, "Runaway exception");
161 PrintException(NULL, "Runaway exception");