5 #if defined(HAVE_CONFIG_H)
28 #endif // ENABLE_WALLET
40 #include <validation.h>
42 #include <boost/signals2/connection.hpp>
45 #include <QApplication>
47 #include <QLibraryInfo>
49 #include <QMessageBox>
53 #include <QTranslator>
56 #if defined(QT_STATICPLUGIN)
58 #if defined(QT_QPA_PLATFORM_XCB)
59 Q_IMPORT_PLUGIN(QXcbIntegrationPlugin);
60 #elif defined(QT_QPA_PLATFORM_WINDOWS)
61 Q_IMPORT_PLUGIN(QWindowsIntegrationPlugin);
62 #elif defined(QT_QPA_PLATFORM_COCOA)
63 Q_IMPORT_PLUGIN(QCocoaIntegrationPlugin);
68 Q_DECLARE_METATYPE(
bool*)
76 qRegisterMetaType<bool*>();
77 qRegisterMetaType<SynchronizationState>();
79 qRegisterMetaType<WalletModel*>();
83 qRegisterMetaType<CAmount>(
"CAmount");
84 qRegisterMetaType<size_t>(
"size_t");
86 qRegisterMetaType<std::function<void()>>(
"std::function<void()>");
87 qRegisterMetaType<QMessageBox::Icon>(
"QMessageBox::Icon");
88 qRegisterMetaType<interfaces::BlockAndHeaderTipInfo>(
"interfaces::BlockAndHeaderTipInfo");
96 QString lang_territory = QLocale::system().name();
98 QString lang_territory_qsettings = settings.value(
"language",
"").toString();
99 if(!lang_territory_qsettings.isEmpty())
100 lang_territory = lang_territory_qsettings;
102 lang_territory = QString::fromStdString(
gArgs.
GetArg(
"-lang", lang_territory.toStdString()));
103 return lang_territory;
107 static void initTranslations(QTranslator &qtTranslatorBase, QTranslator &qtTranslator, QTranslator &translatorBase, QTranslator &translator)
110 QApplication::removeTranslator(&qtTranslatorBase);
111 QApplication::removeTranslator(&qtTranslator);
112 QApplication::removeTranslator(&translatorBase);
113 QApplication::removeTranslator(&translator);
120 QString lang = lang_territory;
121 lang.truncate(lang_territory.lastIndexOf(
'_'));
128 if (qtTranslatorBase.load(
"qt_" + lang, QLibraryInfo::location(QLibraryInfo::TranslationsPath)))
129 QApplication::installTranslator(&qtTranslatorBase);
132 if (qtTranslator.load(
"qt_" + lang_territory, QLibraryInfo::location(QLibraryInfo::TranslationsPath)))
133 QApplication::installTranslator(&qtTranslator);
136 if (translatorBase.load(lang,
":/translations/"))
137 QApplication::installTranslator(&translatorBase);
140 if (translator.load(lang_territory,
":/translations/"))
141 QApplication::installTranslator(&translator);
148 if (type == QtDebugMsg) {
151 LogPrintf(
"GUI: %s\n", msg.toStdString());
171 qDebug() << __func__ <<
": Running initialization in thread";
175 }
catch (
const std::exception& e) {
186 qDebug() << __func__ <<
": Running Shutdown in thread";
188 qDebug() << __func__ <<
": Shutdown finished";
190 }
catch (
const std::exception& e) {
203 optionsModel(nullptr),
204 clientModel(nullptr),
206 pollShutdownTimer(nullptr),
208 platformStyle(nullptr)
212 setQuitOnLastWindowClosed(
false);
220 std::string platformName;
232 qDebug() << __func__ <<
": Stopping thread";
235 qDebug() << __func__ <<
": Stopped thread";
245 void BitcoinApplication::createPaymentServer()
304 connect(
coreThread, &QThread::finished, executor, &QObject::deleteLater);
328 qDebug() << __func__ <<
": Requesting initialize";
340 qDebug() << __func__ <<
": Requesting shutdown";
363 qDebug() << __func__ <<
": Initialization result: " << success;
365 returnValue = success ? EXIT_SUCCESS : EXIT_FAILURE;
375 window->setWalletController(m_wallet_controller);
380 #endif // ENABLE_WALLET
399 connect(paymentServer, &
PaymentServer::message, [
this](
const QString& title,
const QString& message,
unsigned int style) {
419 QMessageBox::critical(
nullptr,
"Runaway exception", BitcoinGUI::tr(
"A fatal error occurred. %1 can no longer continue safely and will quit.").arg(
PACKAGE_NAME) + QString(
"<br><br>") + message);
420 ::exit(EXIT_FAILURE);
444 util::WinCmdLineArgs winArgs;
445 std::tie(argc, argv) = winArgs.get();
461 Q_INIT_RESOURCE(bitcoin);
462 Q_INIT_RESOURCE(bitcoin_locale);
465 QApplication::setAttribute(Qt::AA_UseHighDpiPixmaps);
466 #if QT_VERSION >= 0x050600
467 QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
470 #if (QT_VERSION <= QT_VERSION_CHECK(5, 9, 8)) && defined(Q_OS_MACOS)
471 const auto os_name = QSysInfo::prettyProductName();
472 if (os_name.startsWith(
"macOS 11") || os_name.startsWith(
"macOS 10.16")) {
473 QApplication::setStyle(
"fusion");
489 QString::fromStdString(
"Error parsing command line arguments: %1.").arg(QString::fromStdString(error)));
505 QTranslator qtTranslatorBase, qtTranslator, translatorBase, translator;
506 initTranslations(qtTranslatorBase, qtTranslator, translatorBase, translator);
521 bool did_show_intro =
false;
531 QObject::tr(
"Error: Specified data directory \"%1\" does not exist.").arg(QString::fromStdString(
gArgs.
GetArg(
"-datadir",
""))));
537 QObject::tr(
"Error: Cannot parse configuration file: %1.").arg(QString::fromStdString(error)));
550 }
catch(std::exception &e) {
552 QMessageBox::critical(
nullptr,
PACKAGE_NAME, QObject::tr(
"Error: %1").arg(e.what()));
561 QMessageBox::critical(
nullptr,
PACKAGE_NAME, QObject::tr(
"Error initializing settings: %1").arg(QString::fromStdString(error)));
566 assert(!networkStyle.isNull());
568 QApplication::setApplicationName(networkStyle->getAppName());
570 initTranslations(qtTranslatorBase, qtTranslator, translatorBase, translator);
585 app.createPaymentServer();
587 #endif // ENABLE_WALLET
592 #if defined(Q_OS_WIN)
594 qApp->installNativeEventFilter(
new WinShutdownMonitor());
604 if (did_show_intro) {
614 int rv = EXIT_SUCCESS;
623 #if defined(Q_OS_WIN)
624 WinShutdownMonitor::registerShutdownBlockReason(QObject::tr(
"%1 didn't yet exit safely...").arg(
PACKAGE_NAME), (HWND)app.
getMainWinId());
634 }
catch (
const std::exception& e) {
NODISCARD bool ReadConfigFiles(std::string &error, bool ignore_invalid_keys=false)
OptionsModel * optionsModel
void unsubscribeFromCoreSignals()
Disconnect core signals from GUI client.
static const bool DEFAULT_CHOOSE_DATADIR
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.
static constexpr int DEFAULT_PRUNE_TARGET_GB
void setupPlatformStyle()
Setup platform style.
void receivedURI(const QString &uri)
Signal raised when a URI was entered or dragged to the GUI.
void InitLogging(const ArgsManager &args)
Initialize global loggers.
void LogQtInfo()
Writes to debug.log short info about the used Qt and the host system.
SynchronizationState
Current sync state passed to tip changed callbacks.
void message(const QString &title, const QString &message, unsigned int style)
#define LogPrint(category,...)
static bool isWalletEnabled()
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.
static const NetworkStyle * instantiate(const std::string &networkId)
Get style associated with provided network id, or 0 if not known.
Class encapsulating Bitcoin Core startup and shutdown.
bool GetBoolArg(const std::string &strArg, bool fDefault) const
Return boolean argument or default value.
void setNode(interfaces::Node &node)
virtual bool baseInitialize()=0
Initialize app dependencies.
void parameterSetup()
parameter interaction/setup based on rules
void handleRunawayException(const std::exception *e)
Pass fatal exception message to UI thread.
virtual void startShutdown()=0
Start shutdown.
bool noui_ThreadSafeMessageBox(const bilingual_str &message, const std::string &caption, unsigned int style)
Non-GUI handler, which logs and prints messages.
static void LogPrintf(const char *fmt, const Args &...args)
bilingual_str Untranslated(std::string original)
Mark a bilingual_str as untranslated.
void handleRunawayException(const QString &message)
Handle runaway exceptions. Shows a message box with the problem and quits the program.
void SetPruneTargetGB(int prune_target_gb, bool force=false)
void ThreadRename(std::string &&)
Rename a thread both in terms of an internal (in-memory) name as well as its system thread name...
void requestInitialize()
Request core initialization.
int getReturnValue() const
Get process return value.
void setClientModel(ClientModel *clientModel=nullptr, interfaces::BlockAndHeaderTipInfo *tip_info=nullptr)
Set the client model.
Controller between interfaces::Node, WalletModel instances and the GUI.
OptionsModel * getOptionsModel()
void receivedPaymentRequest(SendCoinsRecipient)
NODISCARD bool ParseParameters(int argc, const char *const argv[], std::string &error)
Qt event filter that intercepts ToolTipChange events, and replaces the tooltip with a rich text repre...
static void SetupUIArgs(ArgsManager &argsman)
interfaces::Node & m_node
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 SetupServerArgs(NodeContext &node)
Register all arguments with the ArgsManager.
Qt event filter that intercepts QEvent::FocusOut events for QLabel objects, and resets their `textInt...
static const bool DEFAULT_SPLASHSCREEN
static void ipcParseCommandLine(int argc, char *argv[])
void setNode(interfaces::Node &node)
void handleURIOrFile(const QString &s)
static bool ipcSendCommandLine()
int64_t CAmount
Amount in satoshis (Can be negative)
bool CheckDataDirOption()
static QWidget * showShutdownWindow(QMainWindow *window)
BitcoinCore(interfaces::Node &node)
bool IsArgSet(const std::string &strArg) const
Return true if the given argument has been manually set.
void finish()
Hide the splash screen window and schedule the splash screen object for deletion. ...
bool error(const char *fmt, const Args &...args)
NodeContext struct containing references to chain state and connection state.
static void RegisterMetaTypes()
void createSplashScreen(const NetworkStyle *networkStyle)
Create splash screen.
Main Bitcoin application object.
void SelectParams(const std::string &network)
Sets the params returned by Params() to those for the given chain name.
virtual bilingual_str getWarnings()=0
Get warnings.
void initializeResult(bool success, interfaces::BlockAndHeaderTipInfo tip_info)
int GuiMain(int argc, char *argv[])
void AddArg(const std::string &name, const std::string &help, unsigned int flags, const OptionsCategory &cat)
Add argument.
bool HelpRequested(const ArgsManager &args)
static void initTranslations(QTranslator &qtTranslatorBase, QTranslator &qtTranslator, QTranslator &translatorBase, QTranslator &translator)
Set up translations.
WId getMainWinId() const
Get window identifier of QMainWindow (BitcoinGUI)
void detectShutdown()
called by a timer to check if ShutdownRequested() has been set
Block and header tip information.
bool InitError(const bilingual_str &str)
Show error message.
std::unique_ptr< QWidget > shutdownWindow
void PrintExceptionContinue(const std::exception *pex, const char *pszThread)
void setNode(interfaces::Node &node)
void windowShown(BitcoinGUI *window)
Model for Bitcoin network client.
void ThreadSetInternalName(std::string &&)
Set the internal (in-memory) name of the current thread only.
bool getMinimizeToTray() const
static const char * qt_argv
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.
void requestShutdown()
Request core shutdown.
void DebugMessageHandler(QtMsgType type, const QMessageLogContext &context, const QString &msg)
#define QAPP_APP_NAME_DEFAULT
virtual void appShutdown()=0
Stop node.
void handleLoadWallet()
Handle wallet load notifications.
bool hasTrayIcon() const
Get the tray icon status.
void createWindow(const NetworkStyle *networkStyle)
Create main window.
static const int TOOLTIP_WRAP_THRESHOLD
bool InitSettings(std::string &error)
Read and update settings file with saved settings.
Interface from Qt to configuration data structure for Bitcoin client.
const CChainParams & Params()
Return the currently selected parameters.
std::string GetArg(const std::string &strArg, const std::string &strDefault) const
Return string argument or default value.
static bool showIfNeeded(bool &did_show_intro, bool &prune)
Determine data directory.
interfaces::Node * m_node
"Help message" dialog box
std::string GetChainName() const
Returns the appropriate chain name from the program arguments.
CClientUIInterface uiInterface
static QString GetLangTerritory()
void InitializePruneSetting(bool prune)
Initialize prune setting.
static const std::string DEFAULT_UIPLATFORM
void runawayException(const QString &message)
std::unique_ptr< Node > MakeNode(NodeContext *context)
Return implementation of Node interface.
Top-level interface for a bitcoin node (bitcoind process).
bool baseInitialize()
Basic initialization, before starting initialization/shutdown thread. Return true on success...
ClientModel * clientModel
void InitParameterInteraction(ArgsManager &args)
Parameter interaction: change current parameters depending on various rules.
interfaces::Node & node() const
void initializeResult(bool success, interfaces::BlockAndHeaderTipInfo tip_info)
virtual bool appInitMain(interfaces::BlockAndHeaderTipInfo *tip_info=nullptr)=0
Start node.
QTimer * pollShutdownTimer
const PlatformStyle * platformStyle