31 #include <validation.h>
40 #include <QLibraryInfo>
42 #include <QMessageBox>
46 #include <QTranslator>
48 #include <boost/signals2/connection.hpp>
52 #if defined(QT_STATICPLUGIN)
54 #if defined(QT_QPA_PLATFORM_XCB)
55 Q_IMPORT_PLUGIN(QXcbIntegrationPlugin);
56 #elif defined(QT_QPA_PLATFORM_WINDOWS)
57 Q_IMPORT_PLUGIN(QWindowsIntegrationPlugin);
58 #elif defined(QT_QPA_PLATFORM_COCOA)
59 Q_IMPORT_PLUGIN(QCocoaIntegrationPlugin);
60 Q_IMPORT_PLUGIN(QMacStylePlugin);
65 Q_DECLARE_METATYPE(
bool *)
72 Q_DECLARE_METATYPE(
Config *)
79 qRegisterMetaType<bool *>();
80 qRegisterMetaType<SynchronizationState>();
81 qRegisterMetaType<SyncType>();
83 qRegisterMetaType<WalletModel *>();
85 qRegisterMetaType<Amount>();
88 qRegisterMetaType<size_t>(
"size_t");
90 qRegisterMetaType<std::function<void()>>(
"std::function<void()>");
91 qRegisterMetaType<QMessageBox::Icon>(
"QMessageBox::Icon");
92 qRegisterMetaType<interfaces::BlockAndHeaderTipInfo>(
93 "interfaces::BlockAndHeaderTipInfo");
101 qRegisterMetaType<Config *>();
108 QString lang_territory = QLocale::system().name();
110 QString lang_territory_qsettings =
111 settings.value(
"language",
"").toString();
112 if (!lang_territory_qsettings.isEmpty()) {
113 lang_territory = lang_territory_qsettings;
116 lang_territory = QString::fromStdString(
117 gArgs.
GetArg(
"-lang", lang_territory.toStdString()));
118 return lang_territory;
123 QTranslator &qtTranslator,
124 QTranslator &translatorBase,
125 QTranslator &translator) {
127 QApplication::removeTranslator(&qtTranslatorBase);
128 QApplication::removeTranslator(&qtTranslator);
129 QApplication::removeTranslator(&translatorBase);
130 QApplication::removeTranslator(&translator);
137 QString lang = lang_territory;
138 lang.truncate(lang_territory.lastIndexOf(
'_'));
145 if (qtTranslatorBase.load(
147 QLibraryInfo::location(QLibraryInfo::TranslationsPath))) {
148 QApplication::installTranslator(&qtTranslatorBase);
152 if (qtTranslator.load(
153 "qt_" + lang_territory,
154 QLibraryInfo::location(QLibraryInfo::TranslationsPath))) {
155 QApplication::installTranslator(&qtTranslator);
160 if (translatorBase.load(lang,
":/translations/")) {
161 QApplication::installTranslator(&translatorBase);
166 if (translator.load(lang_territory,
":/translations/")) {
167 QApplication::installTranslator(&translator);
173 const QString &msg) {
175 if (type == QtDebugMsg) {
178 LogPrintf(
"GUI: %s\n", msg.toStdString());
194 qDebug() << __func__ <<
": Running initialization in thread";
197 *httpRPCRequestProcessor, &tip_info);
199 }
catch (
const std::exception &e) {
208 qDebug() << __func__ <<
": Running Shutdown in thread";
210 qDebug() << __func__ <<
": Shutdown finished";
212 }
catch (
const std::exception &e) {
223 : QApplication(
qt_argc, const_cast<char **>(&
qt_argv)), coreThread(nullptr),
224 optionsModel(nullptr), clientModel(nullptr), window(nullptr),
225 pollShutdownTimer(nullptr), returnValue(0), platformStyle(nullptr) {
228 setQuitOnLastWindowClosed(
false);
235 std::string platformName;
248 qDebug() << __func__ <<
": Stopping thread";
251 qDebug() << __func__ <<
": Stopped thread";
261 void BitcoinApplication::createPaymentServer() {
345 connect(
coreThread, &QThread::finished, executor, &QObject::deleteLater);
368 qDebug() << __func__ <<
": Requesting initialize";
382 qDebug() << __func__ <<
": Requesting shutdown";
405 qDebug() << __func__ <<
": Initialization result: " << success;
406 returnValue = success ? EXIT_SUCCESS : EXIT_FAILURE;
421 m_wallet_controller =
423 window->setWalletController(m_wallet_controller);
427 PaymentServer::LoadRootCAs();
429 paymentServer, &PaymentServer::fetchPaymentACK);
453 &BitcoinGUI::handlePaymentRequest);
457 [
this](
const QString &title,
const QString &message,
458 unsigned int style) {
474 QMessageBox::critical(
475 nullptr,
"Runaway exception",
476 BitcoinGUI::tr(
"A fatal error occurred. %1 can no longer continue "
477 "safely and will quit.")
479 QString(
"<br><br>") + message);
480 ::exit(EXIT_FAILURE);
492 #if defined(ENABLE_WALLET) && defined(ENABLE_BIP70)
494 "-allowselfsignedrootcertificates",
495 strprintf(
"Allow self signed root certificates (default: %d)",
499 argsman.
AddArg(
"-choosedatadir",
500 strprintf(
"Choose data directory on startup (default: %d)",
505 "Set language, for example \"de_DE\" (default: system locale)",
510 "-rootcertificates=<file>",
511 "Set SSL root certificates for payment request (default: -system-)",
514 strprintf(
"Show splash screen on startup (default: %d)",
517 argsman.
AddArg(
"-resetguisettings",
"Reset all settings changed in the GUI",
519 argsman.
AddArg(
"-uiplatform",
520 strprintf(
"Select platform to customize UI for (one of "
521 "windows, macosx, other; default: %s)",
529 util::WinCmdLineArgs winArgs;
530 std::tie(argc, argv) = winArgs.get();
536 std::unique_ptr<interfaces::Node>
node =
540 boost::signals2::scoped_connection handler_message_box =
542 boost::signals2::scoped_connection handler_question =
544 boost::signals2::scoped_connection handler_init_message =
552 Q_INIT_RESOURCE(bitcoin);
553 Q_INIT_RESOURCE(bitcoin_locale);
556 QApplication::setAttribute(Qt::AA_UseHighDpiPixmaps);
557 QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
572 QMessageBox::critical(
573 nullptr, PACKAGE_NAME,
576 QString::fromStdString(
"Error parsing command line arguments: %1.")
577 .arg(QString::fromStdString(
error)));
594 QTranslator qtTranslatorBase, qtTranslator, translatorBase, translator;
608 app.installEventFilter(
613 bool did_show_intro =
false;
626 Untranslated(
"Specified data directory \"%s\" does not exist.\n"),
628 QMessageBox::critical(
629 nullptr, PACKAGE_NAME,
631 "Error: Specified data directory \"%1\" does not exist.")
632 .arg(QString::fromStdString(
gArgs.
GetArg(
"-datadir",
""))));
638 QMessageBox::critical(
639 nullptr, PACKAGE_NAME,
640 QObject::tr(
"Error: Cannot parse configuration file: %1.")
641 .arg(QString::fromStdString(
error)));
657 }
catch (std::exception &e) {
659 QMessageBox::critical(
nullptr, PACKAGE_NAME,
660 QObject::tr(
"Error: %1").arg(e.what()));
669 QMessageBox::critical(
nullptr, PACKAGE_NAME,
670 QObject::tr(
"Error initializing settings: %1")
671 .arg(QString::fromStdString(
error)));
675 QScopedPointer<const NetworkStyle> networkStyle(
677 assert(!networkStyle.isNull());
679 QApplication::setApplicationName(networkStyle->getAppName());
702 app.createPaymentServer();
710 #if defined(Q_OS_WIN)
713 qApp->installNativeEventFilter(
new WinShutdownMonitor());
723 if (did_show_intro) {
739 std::any context{&node_context};
753 #if defined(Q_OS_WIN)
754 WinShutdownMonitor::registerShutdownBlockReason(
755 QObject::tr(
"%1 didn't yet exit safely...").arg(PACKAGE_NAME),
762 }
catch (
const std::exception &e) {
void SelectParams(const std::string &network)
Sets the params returned by Params() to those for the given BIP70 chain name.
const CChainParams & Params()
Return the currently selected parameters.
bool InitSettings(std::string &error)
Read and update settings file with saved settings.
bool ParseParameters(int argc, const char *const argv[], std::string &error)
bool IsArgSet(const std::string &strArg) const
Return true if the given argument has been manually set.
std::string GetArg(const std::string &strArg, const std::string &strDefault) const
Return string argument or default value.
bool SoftSetBoolArg(const std::string &strArg, bool fValue)
Set a boolean argument if it doesn't already have a value.
bool ReadConfigFiles(std::string &error, bool ignore_invalid_keys=false)
bool GetBoolArg(const std::string &strArg, bool fDefault) const
Return boolean argument or default value.
void AddArg(const std::string &name, const std::string &help, unsigned int flags, const OptionsCategory &cat)
Add argument.
std::string GetChainName() const
Looks for -regtest, -testnet and returns the appropriate BIP70 chain name.
Class encapsulating Bitcoin ABC startup and shutdown.
interfaces::Node & m_node
void initializeResult(bool success, interfaces::BlockAndHeaderTipInfo tip_info)
void handleRunawayException(const std::exception *e)
Pass fatal exception message to UI thread.
void runawayException(const QString &message)
BitcoinABC(interfaces::Node &node)
void initialize(Config *config, RPCServer *rpcServer, HTTPRPCRequestProcessor *httpRPCRequestProcessor)
Main Bitcoin application object.
ClientModel * clientModel
bool baseInitialize(Config &config)
Basic initialization, before starting initialization/shutdown thread.
void createSplashScreen(const NetworkStyle *networkStyle)
Create splash screen.
void windowShown(BitcoinGUI *window)
void initializeResult(bool success, interfaces::BlockAndHeaderTipInfo tip_info)
void setNode(interfaces::Node &node)
QTimer * pollShutdownTimer
void InitializePruneSetting(bool prune)
Initialize prune setting.
interfaces::Node * m_node
const PlatformStyle * platformStyle
int getReturnValue() const
Get process return value.
void parameterSetup()
parameter interaction/setup based on rules
void handleRunawayException(const QString &message)
Handle runaway exceptions.
void createWindow(const Config *, const NetworkStyle *networkStyle)
Create main window.
OptionsModel * optionsModel
void createOptionsModel(bool resetSettings)
Create options model.
void requestInitialize(Config &config, RPCServer &rpcServer, HTTPRPCRequestProcessor &httpRPCRequestProcessor)
Request core initialization.
void setupPlatformStyle()
Setup platform style.
void requestedInitialize(Config *config, RPCServer *rpcServer, HTTPRPCRequestProcessor *httpRPCRequestProcessor)
std::unique_ptr< QWidget > shutdownWindow
void requestShutdown(Config &config)
Request core shutdown.
WId getMainWinId() const
Get window identifier of QMainWindow (BitcoinGUI)
interfaces::Node & node() const
static const std::string DEFAULT_UIPLATFORM
void setClientModel(ClientModel *clientModel=nullptr, interfaces::BlockAndHeaderTipInfo *tip_info=nullptr)
Set the client model.
void receivedURI(const QString &uri)
Signal raised when a URI was entered or dragged to the GUI.
void unsubscribeFromCoreSignals()
Disconnect core signals from GUI client.
bool hasTrayIcon() const
Get the tray icon status.
void detectShutdown()
called by a timer to check if ShutdownRequested() has been set
void message(const QString &title, QString message, unsigned int style, bool *ret=nullptr, const QString &detailed_message=QString())
Notify the user of an event from the core network or transaction handling code.
Model for Bitcoin network client.
OptionsModel * getOptionsModel()
Qt event filter that intercepts QEvent::FocusOut events for QLabel objects, and resets their ‘textInt...
Qt event filter that intercepts ToolTipChange events, and replaces the tooltip with a rich text repre...
"Help message" dialog box
static bool showIfNeeded(bool &did_show_intro, bool &prune)
Determine data directory.
static const NetworkStyle * instantiate(const std::string &networkId)
Get style associated with provided BIP70 network id, or 0 if not known.
Interface from Qt to configuration data structure for Bitcoin client.
void SetPruneTargetGB(int prune_target_gb, bool force=false)
bool getMinimizeToTray() const
void setNode(interfaces::Node &node)
static bool ipcSendCommandLine()
void message(const QString &title, const QString &message, unsigned int style)
static void ipcParseCommandLine(int argc, char *argv[])
void receivedPaymentRequest(SendCoinsRecipient)
void handleURIOrFile(const QString &s)
Class for registering and managing all RPC calls.
static QWidget * showShutdownWindow(QMainWindow *window)
Class for the splashscreen with information of the running client.
void finish()
Hide the splash screen window and schedule the splash screen object for deletion.
void handleLoadWallet()
Handle wallet load notifications.
void setNode(interfaces::Node &node)
Controller between interfaces::Node, WalletModel instances and the GUI.
void coinsSent(interfaces::Wallet &wallet, SendCoinsRecipient recipient, QByteArray transaction)
static bool isWalletEnabled()
Top-level interface for a bitcoin node (bitcoind process).
virtual bilingual_str getWarnings()=0
Get warnings.
virtual void appShutdown()=0
Stop node.
virtual bool appInitMain(Config &config, RPCServer &rpcServer, HTTPRPCRequestProcessor &httpRPCRequestProcessor, interfaces::BlockAndHeaderTipInfo *tip_info=nullptr)=0
Start node.
virtual void startShutdown()=0
Start shutdown.
virtual bool baseInitialize(Config &config)=0
Initialize app dependencies.
const Config & GetConfig()
static constexpr int DEFAULT_PRUNE_TARGET_GB
static const int TOOLTIP_WRAP_THRESHOLD
static const bool DEFAULT_SPLASHSCREEN
#define QAPP_APP_NAME_DEFAULT
void InitLogging(const ArgsManager &args)
Initialize global loggers.
void SetupServerArgs(NodeContext &node)
Register all arguments with the ArgsManager.
void InitParameterInteraction(ArgsManager &args)
Parameter interaction: change current parameters depending on various rules.
static const bool DEFAULT_CHOOSE_DATADIR
#define LogPrint(category,...)
void LogQtInfo()
Writes to debug.log short info about the used Qt and the host system.
std::unique_ptr< Node > MakeNode(node::NodeContext *context)
Return implementation of Node interface.
void ThreadSetInternalName(std::string &&)
Set the internal (in-memory) name of the current thread only.
void ThreadRename(std::string &&)
Rename a thread both in terms of an internal (in-memory) name as well as its system thread name.
bool noui_ThreadSafeQuestion(const bilingual_str &, const std::string &message, const std::string &caption, unsigned int style)
Non-GUI handler, which logs and prints questions.
void noui_InitMessage(const std::string &message)
Non-GUI handler, which only logs a message.
bool noui_ThreadSafeMessageBox(const bilingual_str &message, const std::string &caption, unsigned int style)
Non-GUI handler, which logs and prints messages.
static const bool DEFAULT_SELFSIGNED_ROOTCERTS
static void RegisterMetaTypes()
static QString GetLangTerritory()
int GuiMain(int argc, char *argv[])
static void SetupUIArgs(ArgsManager &argsman)
static const char * qt_argv
static void initTranslations(QTranslator &qtTranslatorBase, QTranslator &qtTranslator, QTranslator &translatorBase, QTranslator &translator)
Set up translations.
void DebugMessageHandler(QtMsgType type, const QMessageLogContext &context, const QString &msg)
Block and header tip information.
NodeContext struct containing references to chain state and connection state.
bool HelpRequested(const ArgsManager &args)
bool CheckDataDirOption()
void PrintExceptionContinue(const std::exception *pex, const char *pszThread)
bool error(const char *fmt, const Args &...args)
bilingual_str Untranslated(std::string original)
Mark a bilingual_str as untranslated.
CClientUIInterface uiInterface
bool InitError(const bilingual_str &str)
Show error message.
SynchronizationState
Current sync state passed to tip changed callbacks.