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 // 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()
95 QMetaObject::invokeMethod(guiref, "refreshStatusBar", Qt::QueuedConnection);
98 void InitMessage(const std::string &message)
102 splashref->showMessage(QString::fromStdString(message), Qt::AlignBottom|Qt::AlignHCenter, QColor(255,255,200));
103 QApplication::instance()->processEvents();
108 Translate string to current locale using Qt.
110 std::string _(const char* psz)
112 return QCoreApplication::translate("bitcoin-core", psz).toStdString();
115 int main(int argc, char *argv[])
117 QTextCodec::setCodecForTr(QTextCodec::codecForName("UTF-8"));
118 QTextCodec::setCodecForCStrings(QTextCodec::codecForTr());
120 Q_INIT_RESOURCE(bitcoin);
121 QApplication app(argc, argv);
123 // Load language files for system locale:
124 // - First load the translator for the base language, without territory
125 // - Then load the more specific locale translator
126 QString lang_territory = QLocale::system().name(); // "en_US"
127 QString lang = lang_territory;
128 lang.truncate(lang_territory.lastIndexOf('_')); // "en"
129 QTranslator qtTranslatorBase, qtTranslator, translatorBase, translator;
131 qtTranslatorBase.load(QLibraryInfo::location(QLibraryInfo::TranslationsPath) + "/qt_" + lang);
132 if (!qtTranslatorBase.isEmpty())
133 app.installTranslator(&qtTranslatorBase);
135 qtTranslator.load(QLibraryInfo::location(QLibraryInfo::TranslationsPath) + "/qt_" + lang_territory);
136 if (!qtTranslator.isEmpty())
137 app.installTranslator(&qtTranslator);
139 translatorBase.load(":/translations/"+lang);
140 if (!translatorBase.isEmpty())
141 app.installTranslator(&translatorBase);
143 translator.load(":/translations/"+lang_territory);
144 if (!translator.isEmpty())
145 app.installTranslator(&translator);
147 app.setApplicationName(QApplication::translate("main", "Bitcoin-Qt"));
149 QSplashScreen splash(QPixmap(":/images/splash"), 0);
151 splash.setAutoFillBackground(true);
156 app.setQuitOnLastWindowClosed(false);
160 if(AppInit2(argc, argv))
163 // Put this in a block, so that BitcoinGUI is cleaned up properly before
164 // calling Shutdown() in case of exceptions.
166 splash.finish(&window);
167 OptionsModel optionsModel(pwalletMain);
168 ClientModel clientModel(&optionsModel);
169 WalletModel walletModel(pwalletMain, &optionsModel);
172 window.setClientModel(&clientModel);
173 window.setWalletModel(&walletModel);
175 // If -min option passed, start window minimized.
176 if(GetBoolArg("-min"))
178 window.showMinimized();
195 } catch (std::exception& e) {
196 PrintException(&e, "Runaway exception");
198 PrintException(NULL, "Runaway exception");