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>
20 #include <QLibraryInfo>
22 // Need a global reference for the notifications to find the GUI
24 QSplashScreen *splashref;
26 int MyMessageBox(const std::string& message, const std::string& caption, int style, wxWindow* parent, int x, int y)
28 // Message from main thread
31 guiref->error(QString::fromStdString(caption),
32 QString::fromStdString(message));
36 QMessageBox::critical(0, QString::fromStdString(caption),
37 QString::fromStdString(message),
38 QMessageBox::Ok, QMessageBox::Ok);
43 int ThreadSafeMessageBox(const std::string& message, const std::string& caption, int style, wxWindow* parent, int x, int y)
45 bool modal = style & wxMODAL;
51 // Message from network thread
54 QMetaObject::invokeMethod(guiref, "error", Qt::QueuedConnection,
55 Q_ARG(QString, QString::fromStdString(caption)),
56 Q_ARG(QString, QString::fromStdString(message)),
61 printf("%s: %s\n", caption.c_str(), message.c_str());
62 fprintf(stderr, "%s: %s\n", caption.c_str(), message.c_str());
67 bool ThreadSafeAskFee(int64 nFeeRequired, const std::string& strCaption, wxWindow* parent)
71 if(nFeeRequired < MIN_TX_FEE || nFeeRequired <= nTransactionFee || fDaemon)
75 // Call slot on GUI thread.
76 // If called from another thread, use a blocking QueuedConnection.
77 Qt::ConnectionType connectionType = Qt::DirectConnection;
78 if(QThread::currentThread() != QCoreApplication::instance()->thread())
80 connectionType = Qt::BlockingQueuedConnection;
83 QMetaObject::invokeMethod(guiref, "askFee", connectionType,
84 Q_ARG(qint64, nFeeRequired),
85 Q_ARG(bool*, &payFee));
90 void CalledSetStatusBar(const std::string& strText, int nField)
92 // Only used for built-in mining, which is disabled, simple ignore
95 void UIThreadCall(boost::function0<void> fn)
97 // Only used for built-in mining, which is disabled, simple ignore
100 void MainFrameRepaint()
103 QMetaObject::invokeMethod(guiref, "refreshStatusBar", Qt::QueuedConnection);
106 void InitMessage(const std::string &message)
110 splashref->showMessage(QString::fromStdString(message), Qt::AlignBottom|Qt::AlignHCenter, QColor(255,255,200));
111 QApplication::instance()->processEvents();
116 Translate string to current locale using Qt.
118 std::string _(const char* psz)
120 return QCoreApplication::translate("bitcoin-core", psz).toStdString();
123 int main(int argc, char *argv[])
125 QTextCodec::setCodecForTr(QTextCodec::codecForName("UTF-8"));
126 QTextCodec::setCodecForCStrings(QTextCodec::codecForTr());
128 Q_INIT_RESOURCE(bitcoin);
129 QApplication app(argc, argv);
131 // Load language files for system locale:
132 // - First load the translator for the base language, without territory
133 // - Then load the more specific locale translator
134 QString lang_territory = QLocale::system().name(); // "en_US"
135 QString lang = lang_territory;
136 lang.truncate(lang_territory.lastIndexOf('_')); // "en"
137 QTranslator qtTranslatorBase, qtTranslator, translatorBase, translator;
139 qtTranslatorBase.load(QLibraryInfo::location(QLibraryInfo::TranslationsPath) + "/qt_" + lang);
140 if (!qtTranslatorBase.isEmpty())
141 app.installTranslator(&qtTranslatorBase);
143 qtTranslator.load(QLibraryInfo::location(QLibraryInfo::TranslationsPath) + "/qt_" + lang_territory);
144 if (!qtTranslator.isEmpty())
145 app.installTranslator(&qtTranslator);
147 translatorBase.load(":/translations/"+lang);
148 if (!translatorBase.isEmpty())
149 app.installTranslator(&translatorBase);
151 translator.load(":/translations/"+lang_territory);
152 if (!translator.isEmpty())
153 app.installTranslator(&translator);
155 app.setApplicationName(QApplication::translate("main", "Bitcoin-Qt"));
157 QSplashScreen splash(QPixmap(":/images/splash"), 0);
158 if (!GetBoolArg("-min"))
161 splash.setAutoFillBackground(true);
167 app.setQuitOnLastWindowClosed(false);
171 if(AppInit2(argc, argv))
174 // Put this in a block, so that BitcoinGUI is cleaned up properly before
175 // calling Shutdown().
178 splash.finish(&window);
179 OptionsModel optionsModel(pwalletMain);
180 ClientModel clientModel(&optionsModel);
181 WalletModel walletModel(pwalletMain, &optionsModel);
184 window.setClientModel(&clientModel);
185 window.setWalletModel(&walletModel);
199 } catch (std::exception& e) {
200 PrintException(&e, "Runaway exception");
202 PrintException(NULL, "Runaway exception");