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>
19 // Need a global reference for the notifications to find the GUI
22 int MyMessageBox(const std::string& message, const std::string& caption, int style, wxWindow* parent, int x, int y)
24 // Message from main thread
27 guiref->error(QString::fromStdString(caption),
28 QString::fromStdString(message));
32 QMessageBox::critical(0, QString::fromStdString(caption),
33 QString::fromStdString(message),
34 QMessageBox::Ok, QMessageBox::Ok);
39 int ThreadSafeMessageBox(const std::string& message, const std::string& caption, int style, wxWindow* parent, int x, int y)
41 // Message from network thread
44 QMetaObject::invokeMethod(guiref, "error", Qt::QueuedConnection,
45 Q_ARG(QString, QString::fromStdString(caption)),
46 Q_ARG(QString, QString::fromStdString(message)));
50 printf("%s: %s\n", caption.c_str(), message.c_str());
51 fprintf(stderr, "%s: %s\n", caption.c_str(), message.c_str());
56 bool ThreadSafeAskFee(int64 nFeeRequired, const std::string& strCaption, wxWindow* parent)
60 if(nFeeRequired < MIN_TX_FEE || nFeeRequired <= nTransactionFee || fDaemon)
64 // Call slot on GUI thread.
65 // If called from another thread, use a blocking QueuedConnection.
66 Qt::ConnectionType connectionType = Qt::DirectConnection;
67 if(QThread::currentThread() != QCoreApplication::instance()->thread())
69 connectionType = Qt::BlockingQueuedConnection;
72 QMetaObject::invokeMethod(guiref, "askFee", connectionType,
73 Q_ARG(qint64, nFeeRequired),
74 Q_ARG(bool*, &payFee));
79 void CalledSetStatusBar(const std::string& strText, int nField)
81 // Only used for built-in mining, which is disabled, simple ignore
84 void UIThreadCall(boost::function0<void> fn)
86 // Only used for built-in mining, which is disabled, simple ignore
89 void MainFrameRepaint()
94 Translate string to current locale using Qt.
96 std::string _(const char* psz)
98 return QCoreApplication::translate("bitcoin-core", psz).toStdString();
101 int main(int argc, char *argv[])
103 Q_INIT_RESOURCE(bitcoin);
104 QApplication app(argc, argv);
106 // Load language file for system locale
107 QString locale = QLocale::system().name();
108 QTranslator translator;
109 translator.load("bitcoin_"+locale);
110 app.installTranslator(&translator);
112 app.setQuitOnLastWindowClosed(false);
116 if(AppInit2(argc, argv))
119 // Put this in a block, so that BitcoinGUI is cleaned up properly before
122 OptionsModel optionsModel(pwalletMain);
123 ClientModel clientModel(&optionsModel);
124 WalletModel walletModel(pwalletMain, &optionsModel);
127 window.setClientModel(&clientModel);
128 window.setWalletModel(&walletModel);
130 if (QtWin::isCompositionEnabled())
133 // Windows-specific customization
134 window.setAttribute(Qt::WA_TranslucentBackground);
135 window.setAttribute(Qt::WA_NoSystemBackground, false);
136 QPalette pal = window.palette();
137 QColor bg = pal.window().color();
139 pal.setColor(QPalette::Window, bg);
140 window.setPalette(pal);
141 window.ensurePolished();
142 window.setAttribute(Qt::WA_StyledBackground, false);
144 QtWin::extendFrameIntoClientArea(&window);
145 window.setContentsMargins(0, 0, 0, 0);
160 } catch (std::exception& e) {
161 PrintException(&e, "Runaway exception");
163 PrintException(NULL, "Runaway exception");