2 * W.J. van der Laan 2011
4 #include "bitcoingui.h"
5 #include "clientmodel.h"
6 #include "walletmodel.h"
7 #include "optionsmodel.h"
12 #include <QApplication>
13 #include <QMessageBox>
17 #include <QTranslator>
18 #include <QSplashScreen>
19 #include <QLibraryInfo>
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 bool modal = style & wxMODAL;
50 // Message from network thread
53 QMetaObject::invokeMethod(guiref, "error", Qt::QueuedConnection,
54 Q_ARG(QString, QString::fromStdString(caption)),
55 Q_ARG(QString, QString::fromStdString(message)),
60 printf("%s: %s\n", caption.c_str(), message.c_str());
61 fprintf(stderr, "%s: %s\n", caption.c_str(), message.c_str());
66 bool ThreadSafeAskFee(int64 nFeeRequired, const std::string& strCaption, wxWindow* parent)
70 if(nFeeRequired < MIN_TX_FEE || nFeeRequired <= nTransactionFee || fDaemon)
74 // Call slot on GUI thread.
75 // If called from another thread, use a blocking QueuedConnection.
76 Qt::ConnectionType connectionType = Qt::DirectConnection;
77 if(QThread::currentThread() != QCoreApplication::instance()->thread())
79 connectionType = Qt::BlockingQueuedConnection;
82 QMetaObject::invokeMethod(guiref, "askFee", connectionType,
83 Q_ARG(qint64, nFeeRequired),
84 Q_ARG(bool*, &payFee));
89 void CalledSetStatusBar(const std::string& strText, int nField)
91 // Only used for built-in mining, which is disabled, simple ignore
94 void UIThreadCall(boost::function0<void> fn)
96 // Only used for built-in mining, which is disabled, simple ignore
99 void MainFrameRepaint()
102 QMetaObject::invokeMethod(guiref, "refreshStatusBar", Qt::QueuedConnection);
105 void InitMessage(const std::string &message)
109 splashref->showMessage(QString::fromStdString(message), Qt::AlignBottom|Qt::AlignHCenter, QColor(255,255,200));
110 QApplication::instance()->processEvents();
115 Translate string to current locale using Qt.
117 std::string _(const char* psz)
119 return QCoreApplication::translate("bitcoin-core", psz).toStdString();
122 int main(int argc, char *argv[])
124 QTextCodec::setCodecForTr(QTextCodec::codecForName("UTF-8"));
125 QTextCodec::setCodecForCStrings(QTextCodec::codecForTr());
127 Q_INIT_RESOURCE(bitcoin);
128 QApplication app(argc, argv);
130 // Load language files for system locale:
131 // - First load the translator for the base language, without territory
132 // - Then load the more specific locale translator
133 QString lang_territory = QLocale::system().name(); // "en_US"
134 QString lang = lang_territory;
135 lang.truncate(lang_territory.lastIndexOf('_')); // "en"
136 QTranslator qtTranslatorBase, qtTranslator, translatorBase, translator;
138 qtTranslatorBase.load(QLibraryInfo::location(QLibraryInfo::TranslationsPath) + "/qt_" + lang);
139 if (!qtTranslatorBase.isEmpty())
140 app.installTranslator(&qtTranslatorBase);
142 qtTranslator.load(QLibraryInfo::location(QLibraryInfo::TranslationsPath) + "/qt_" + lang_territory);
143 if (!qtTranslator.isEmpty())
144 app.installTranslator(&qtTranslator);
146 translatorBase.load(":/translations/"+lang);
147 if (!translatorBase.isEmpty())
148 app.installTranslator(&translatorBase);
150 translator.load(":/translations/"+lang_territory);
151 if (!translator.isEmpty())
152 app.installTranslator(&translator);
154 app.setApplicationName(QApplication::translate("main", "Bitcoin-Qt"));
156 QSplashScreen splash(QPixmap(":/images/splash"), 0);
157 if (!GetBoolArg("-min"))
160 splash.setAutoFillBackground(true);
166 app.setQuitOnLastWindowClosed(false);
170 if(AppInit2(argc, argv))
173 // Put this in a block, so that BitcoinGUI is cleaned up properly before
174 // calling Shutdown().
177 splash.finish(&window);
178 OptionsModel optionsModel(pwalletMain);
179 ClientModel clientModel(&optionsModel);
180 WalletModel walletModel(pwalletMain, &optionsModel);
183 window.setClientModel(&clientModel);
184 window.setWalletModel(&walletModel);
198 } catch (std::exception& e) {
199 PrintException(&e, "Runaway exception");
201 PrintException(NULL, "Runaway exception");