5 #if defined(HAVE_CONFIG_H) 43 #include <boost/thread.hpp> 45 #include <QApplication> 47 #include <QLibraryInfo> 49 #include <QMessageBox> 53 #include <QTranslator> 55 #if defined(QT_STATICPLUGIN) 57 #if QT_VERSION < 0x050400 58 Q_IMPORT_PLUGIN(AccessibleFactory)
60 #if defined(QT_QPA_PLATFORM_XCB) 61 Q_IMPORT_PLUGIN(QXcbIntegrationPlugin);
62 #elif defined(QT_QPA_PLATFORM_WINDOWS) 63 Q_IMPORT_PLUGIN(QWindowsIntegrationPlugin);
64 #elif defined(QT_QPA_PLATFORM_COCOA) 65 Q_IMPORT_PLUGIN(QCocoaIntegrationPlugin);
70 Q_DECLARE_METATYPE(
bool*)
74 static void InitMessage(
const std::string& message)
81 return QCoreApplication::translate(
"bitcoin-core", psz).toStdString();
84 static QString GetLangTerritory()
89 QString lang_territory = QLocale::system().name();
91 QString lang_territory_qsettings = settings.value(
"language",
"").toString();
92 if(!lang_territory_qsettings.isEmpty())
93 lang_territory = lang_territory_qsettings;
95 lang_territory = QString::fromStdString(
gArgs.
GetArg(
"-lang", lang_territory.toStdString()));
96 return lang_territory;
100 static void initTranslations(QTranslator &qtTranslatorBase, QTranslator &qtTranslator, QTranslator &translatorBase, QTranslator &translator)
103 QApplication::removeTranslator(&qtTranslatorBase);
104 QApplication::removeTranslator(&qtTranslator);
105 QApplication::removeTranslator(&translatorBase);
106 QApplication::removeTranslator(&translator);
110 QString lang_territory = GetLangTerritory();
113 QString lang = lang_territory;
114 lang.truncate(lang_territory.lastIndexOf(
'_'));
121 if (qtTranslatorBase.load(
"qt_" + lang, QLibraryInfo::location(QLibraryInfo::TranslationsPath)))
122 QApplication::installTranslator(&qtTranslatorBase);
125 if (qtTranslator.load(
"qt_" + lang_territory, QLibraryInfo::location(QLibraryInfo::TranslationsPath)))
126 QApplication::installTranslator(&qtTranslator);
129 if (translatorBase.load(lang,
":/translations/"))
130 QApplication::installTranslator(&translatorBase);
133 if (translator.load(lang_territory,
":/translations/"))
134 QApplication::installTranslator(&translator);
141 if (type == QtDebugMsg) {
142 LogPrint(
BCLog::QT,
"GUI: %s\n", msg.toStdString());
144 LogPrintf(
"GUI: %s\n", msg.toStdString());
182 void createPaymentServer();
231 std::vector<WalletModel*> m_wallet_models;
232 std::unique_ptr<interfaces::Handler> m_handler_load_wallet;
241 #include <qt/bitcoin.moc> 244 QObject(), m_node(node)
258 qDebug() << __func__ <<
": Running initialization in thread";
261 }
catch (
const std::exception& e) {
272 qDebug() << __func__ <<
": Running Shutdown in thread";
274 qDebug() << __func__ <<
": Shutdown finished";
276 }
catch (
const std::exception& e) {
284 QApplication(argc, argv),
290 pollShutdownTimer(0),
298 setQuitOnLastWindowClosed(
false);
306 std::string platformName;
318 qDebug() << __func__ <<
": Stopping thread";
321 qDebug() << __func__ <<
": Stopped thread";
327 delete paymentServer;
337 void BitcoinApplication::createPaymentServer()
399 qDebug() << __func__ <<
": Requesting initialize";
411 qDebug() << __func__ <<
": Requesting shutdown";
418 window->removeAllWallets();
419 for (
const WalletModel* walletModel : m_wallet_models) {
422 m_wallet_models.clear();
436 window->addWallet(walletModel);
438 if (m_wallet_models.empty()) {
444 paymentServer, &PaymentServer::fetchPaymentACK);
448 m_wallet_models.push_back(walletModel);
456 m_wallet_models.erase(std::find(m_wallet_models.begin(), m_wallet_models.end(), walletModel));
457 window->removeWallet(walletModel);
458 walletModel->deleteLater();
464 qDebug() << __func__ <<
": Initialization result: " << success;
466 returnValue = success ? EXIT_SUCCESS : EXIT_FAILURE;
473 PaymentServer::LoadRootCAs();
485 wallet_model->moveToThread(thread());
486 QMetaObject::invokeMethod(
this,
"addWallet", Qt::QueuedConnection, Q_ARG(
WalletModel*, wallet_model));
510 connect(paymentServer, &
PaymentServer::message, [
this](
const QString& title,
const QString& message,
unsigned int style) {
529 QMessageBox::critical(0,
"Runaway exception", BitcoinGUI::tr(
"A fatal error occurred. BSHA3 can no longer continue safely and will quit.") + QString(
"\n\n") + message);
530 ::exit(EXIT_FAILURE);
541 static void SetupUIArgs()
543 #if defined(ENABLE_WALLET) && defined(ENABLE_BIP70) 555 #ifndef BITCOIN_QT_TEST 556 int main(
int argc,
char *argv[])
559 util::WinCmdLineArgs winArgs;
560 std::tie(argc, argv) = winArgs.get();
569 Q_INIT_RESOURCE(bitcoin);
570 Q_INIT_RESOURCE(bitcoin_locale);
573 #if QT_VERSION > 0x050100 575 QApplication::setAttribute(Qt::AA_UseHighDpiPixmaps);
577 #if QT_VERSION >= 0x050600 578 QGuiApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
581 QApplication::setAttribute(Qt::AA_DontShowIconsInMenus);
585 qRegisterMetaType< bool* >();
588 qRegisterMetaType< CAmount >(
"CAmount");
589 qRegisterMetaType< std::function<void()> >(
"std::function<void()>");
591 qRegisterMetaType<WalletModel*>(
"WalletModel*");
596 node->setupServerArgs();
599 if (!node->parseParameters(argc, argv,
error)) {
601 QObject::tr(
"Error parsing command line arguments: %1.").arg(QString::fromStdString(
error)));
617 QTranslator qtTranslatorBase, qtTranslator, translatorBase, translator;
618 initTranslations(qtTranslatorBase, qtTranslator, translatorBase, translator);
638 QObject::tr(
"Error: Specified data directory \"%1\" does not exist.").arg(QString::fromStdString(
gArgs.
GetArg(
"-datadir",
""))));
641 if (!node->readConfigFiles(
error)) {
643 QObject::tr(
"Error: Cannot parse configuration file: %1.").arg(QString::fromStdString(
error)));
656 }
catch(std::exception &e) {
657 QMessageBox::critical(0, QObject::tr(
PACKAGE_NAME), QObject::tr(
"Error: %1").arg(e.what()));
666 assert(!networkStyle.isNull());
668 QApplication::setApplicationName(networkStyle->getAppName());
670 initTranslations(qtTranslatorBase, qtTranslator, translatorBase, translator);
684 app.createPaymentServer();
690 #if defined(Q_OS_WIN) 692 qApp->installNativeEventFilter(
new WinShutdownMonitor());
702 std::unique_ptr<interfaces::Handler>
handler = node->handleInitMessage(InitMessage);
707 int rv = EXIT_SUCCESS;
714 if (node->baseInitialize()) {
716 #if defined(Q_OS_WIN) 717 WinShutdownMonitor::registerShutdownBlockReason(QObject::tr(
"%1 didn't yet exit safely...").arg(QObject::tr(
PACKAGE_NAME)), (HWND)app.
getMainWinId());
727 }
catch (
const std::exception& e) {
736 #endif // BITCOIN_QT_TEST OptionsModel * optionsModel
bool HelpRequested(const ArgsManager &args)
virtual bool appInitMain()=0
Start node.
bool(* handler)(HTTPRequest *req, const std::string &strReq)
bool IsArgSet(const std::string &strArg) const
Return true if the given argument has been manually set.
virtual std::string getWarnings(const std::string &type)=0
Get warnings.
void message(const QString &title, const QString &message, unsigned int style, bool *ret=nullptr)
Notify the user of an event from the core network or transaction handling code.
void setupPlatformStyle()
Setup platform style.
void coinsSent(WalletModel *wallet, SendCoinsRecipient recipient, QByteArray transaction)
void receivedURI(const QString &uri)
Signal raised when a URI was entered or dragged to the GUI.
void message(const QString &title, const QString &message, unsigned int style)
virtual void initLogging()=0
Init logging.
bool SoftSetBoolArg(const std::string &strArg, bool fValue)
Set a boolean argument if it doesn't already have a value.
Class for the splashscreen with information of the running client.
Class encapsulating Bitcoin Core startup and shutdown.
void parameterSetup()
parameter interaction/setup based on rules
static void ipcParseCommandLine(interfaces::Node &node, int argc, char *argv[])
void handleRunawayException(const std::exception *e)
Pass fatal exception message to UI thread.
virtual void startShutdown()=0
Start shutdown.
void handleRunawayException(const QString &message)
Handle runaway exceptions. Shows a message box with the problem and quits the program.
int main(int argc, char *argv[])
void requestInitialize()
Request core initialization.
void PrintExceptionContinue(const std::exception *pex, const char *pszThread)
void receivedPaymentRequest(SendCoinsRecipient)
Qt event filter that intercepts ToolTipChange events, and replaces the tooltip with a rich text repre...
bool GetBoolArg(const std::string &strArg, bool fDefault) const
Return boolean argument or default value.
interfaces::Node & m_node
virtual std::vector< std::unique_ptr< Wallet > > getWallets()=0
Return interfaces for accessing wallets (if any).
void createOptionsModel(bool resetSettings)
Create options model.
void noui_InitMessage(const std::string &message)
Non-GUI handler, which only logs a message.
void requestedInitialize()
void initializeResult(bool success)
void handleURIOrFile(const QString &s)
const std::function< std::string(const char *)> G_TRANSLATION_FUN
Translate string to current locale using Qt.
static bool ipcSendCommandLine()
int64_t CAmount
Amount in satoshis (Can be negative)
BitcoinApplication(interfaces::Node &node, int &argc, char **argv)
void setClientModel(ClientModel *clientModel)
Set the client model.
BitcoinCore(interfaces::Node &node)
static bool pickDataDirectory(interfaces::Node &node)
Determine data directory.
void createSplashScreen(const NetworkStyle *networkStyle)
Create splash screen.
Main Bitcoin application object.
interfaces::Node & m_node
void splashFinished(QWidget *window)
void detectShutdown()
called by a timer to check if ShutdownRequested() has been set
std::unique_ptr< QWidget > shutdownWindow
UniValue help(const JSONRPCRequest &jsonRequest)
QString getWalletName() const
Model for Bitcoin network client.
void requestShutdown()
Request core shutdown.
virtual void initParameterInteraction()=0
Init parameter interaction.
virtual std::unique_ptr< Handler > handleLoadWallet(LoadWalletFn fn)=0
void DebugMessageHandler(QtMsgType type, const QMessageLogContext &context, const QString &msg)
#define QAPP_APP_NAME_DEFAULT
virtual void appShutdown()=0
Stop node.
void createWindow(const NetworkStyle *networkStyle)
Create main window.
Interface from Qt to configuration data structure for Bitcoin client.
void initializeResult(bool success)
void slotFinish(QWidget *mainWin)
Slot to call finish() method as it's not defined as slot.
std::unique_ptr< Node > MakeNode()
Return implementation of Node interface.
const CChainParams & Params()
Return the currently selected parameters.
Interface to Bitcoin wallet from Qt view code.
void addWallet(WalletModel *walletModel)
void AddArg(const std::string &name, const std::string &help, const bool debug_only, const OptionsCategory &cat)
Add argument.
std::string GetArg(const std::string &strArg, const std::string &strDefault) const
Return string argument or default value.
static QWidget * showShutdownWindow(BitcoinGUI *window)
bool error(const char *fmt, const Args &... args)
"Help message" dialog box
std::string GetChainName() const
Looks for -regtest, -testnet and returns the appropriate BIP70 chain name.
const fs::path & GetDataDir(bool fNetSpecific)
static const std::string DEFAULT_UIPLATFORM
void runawayException(const QString &message)
WId getMainWinId() const
Get window identifier of QMainWindow (BitcoinGUI)
Top-level interface for a bitcoin node (bsha3d process).
ClientModel * clientModel
static const NetworkStyle * instantiate(const QString &networkId)
Get style associated with provided BIP70 network id, or 0 if not known.
int getReturnValue() const
Get process return value.
QTimer * pollShutdownTimer
const PlatformStyle * platformStyle