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 <QFontDatabase> 48 #include <QLatin1String> 49 #include <QLibraryInfo> 51 #include <QMessageBox> 55 #include <QTranslator> 57 #if defined(QT_STATICPLUGIN) 59 #if defined(QT_QPA_PLATFORM_XCB) 60 Q_IMPORT_PLUGIN(QXcbIntegrationPlugin);
61 #elif defined(QT_QPA_PLATFORM_WINDOWS) 62 Q_IMPORT_PLUGIN(QWindowsIntegrationPlugin);
63 Q_IMPORT_PLUGIN(QWindowsVistaStylePlugin);
64 #elif defined(QT_QPA_PLATFORM_COCOA) 65 Q_IMPORT_PLUGIN(QCocoaIntegrationPlugin);
66 Q_IMPORT_PLUGIN(QMacStylePlugin);
71 Q_DECLARE_METATYPE(
bool*)
79 qRegisterMetaType<bool*>();
80 qRegisterMetaType<SynchronizationState>();
82 qRegisterMetaType<WalletModel*>();
86 qRegisterMetaType<CAmount>(
"CAmount");
87 qRegisterMetaType<size_t>(
"size_t");
89 qRegisterMetaType<std::function<void()>>(
"std::function<void()>");
90 qRegisterMetaType<QMessageBox::Icon>(
"QMessageBox::Icon");
91 qRegisterMetaType<interfaces::BlockAndHeaderTipInfo>(
"interfaces::BlockAndHeaderTipInfo");
99 QString lang_territory = QLocale::system().name();
101 QString lang_territory_qsettings = settings.value(
"language",
"").toString();
102 if(!lang_territory_qsettings.isEmpty())
103 lang_territory = lang_territory_qsettings;
105 lang_territory = QString::fromStdString(
gArgs.
GetArg(
"-lang", lang_territory.toStdString()));
106 return lang_territory;
110 static void initTranslations(QTranslator &qtTranslatorBase, QTranslator &qtTranslator, QTranslator &translatorBase, QTranslator &translator)
113 QApplication::removeTranslator(&qtTranslatorBase);
114 QApplication::removeTranslator(&qtTranslator);
115 QApplication::removeTranslator(&translatorBase);
116 QApplication::removeTranslator(&translator);
123 QString lang = lang_territory;
124 lang.truncate(lang_territory.lastIndexOf(
'_'));
131 if (qtTranslatorBase.load(
"qt_" + lang, QLibraryInfo::location(QLibraryInfo::TranslationsPath)))
132 QApplication::installTranslator(&qtTranslatorBase);
135 if (qtTranslator.load(
"qt_" + lang_territory, QLibraryInfo::location(QLibraryInfo::TranslationsPath)))
136 QApplication::installTranslator(&qtTranslator);
139 if (translatorBase.load(lang,
":/translations/"))
140 QApplication::installTranslator(&translatorBase);
143 if (translator.load(lang_territory,
":/translations/"))
144 QApplication::installTranslator(&translator);
151 if (type == QtDebugMsg) {
154 LogPrintf(
"GUI: %s\n", msg.toStdString());
174 qDebug() << __func__ <<
": Running initialization in thread";
178 }
catch (
const std::exception& e) {
189 qDebug() << __func__ <<
": Running Shutdown in thread";
191 qDebug() << __func__ <<
": Shutdown finished";
193 }
catch (
const std::exception& e) {
206 optionsModel(nullptr),
207 clientModel(nullptr),
209 pollShutdownTimer(nullptr),
211 platformStyle(nullptr)
215 setQuitOnLastWindowClosed(
false);
223 std::string platformName;
235 qDebug() << __func__ <<
": Stopping thread";
238 qDebug() << __func__ <<
": Stopped thread";
248 void BitcoinApplication::createPaymentServer()
307 connect(
coreThread, &QThread::finished, executor, &QObject::deleteLater);
329 qDebug() << __func__ <<
": Requesting initialize";
341 qDebug() << __func__ <<
": Requesting shutdown";
364 qDebug() << __func__ <<
": Initialization result: " << success;
366 returnValue = success ? EXIT_SUCCESS : EXIT_FAILURE;
376 window->setWalletController(m_wallet_controller);
381 #endif // ENABLE_WALLET 400 connect(paymentServer, &
PaymentServer::message, [
this](
const QString& title,
const QString& message,
unsigned int style) {
420 QMessageBox::critical(
421 nullptr, tr(
"Runaway exception"),
422 tr(
"A fatal error occurred. %1 can no longer continue safely and will quit.").arg(
PACKAGE_NAME) +
424 ::exit(EXIT_FAILURE);
429 assert(QThread::currentThread() == thread());
430 QMessageBox::warning(
431 nullptr, tr(
"Internal error"),
432 tr(
"An internal error occurred. %1 will attempt to continue safely. This is " 433 "an unexpected bug which can be reported as described below.").arg(
PACKAGE_NAME) +
458 util::WinCmdLineArgs winArgs;
459 std::tie(argc, argv) = winArgs.get();
475 Q_INIT_RESOURCE(bitcoin);
476 Q_INIT_RESOURCE(bitcoin_locale);
479 QApplication::setAttribute(Qt::AA_UseHighDpiPixmaps);
480 QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
482 #if defined(QT_QPA_PLATFORM_ANDROID) 483 QApplication::setAttribute(Qt::AA_DontUseNativeMenuBar);
484 QApplication::setAttribute(Qt::AA_DontCreateNativeWidgetSiblings);
485 QApplication::setAttribute(Qt::AA_DontUseNativeDialogs);
489 QFontDatabase::addApplicationFont(
":/fonts/monospace");
502 QString::fromStdString(
"Error parsing command line arguments: %1.").arg(QString::fromStdString(
error)));
518 QTranslator qtTranslatorBase, qtTranslator, translatorBase, translator;
519 initTranslations(qtTranslatorBase, qtTranslator, translatorBase, translator);
534 bool did_show_intro =
false;
535 int64_t prune_MiB = 0;
544 QObject::tr(
"Error: Specified data directory \"%1\" does not exist.").arg(QString::fromStdString(
gArgs.
GetArg(
"-datadir",
""))));
550 QObject::tr(
"Error: Cannot parse configuration file: %1.").arg(QString::fromStdString(
error)));
563 }
catch(std::exception &e) {
565 QMessageBox::critical(
nullptr,
PACKAGE_NAME, QObject::tr(
"Error: %1").arg(e.what()));
574 QMessageBox::critical(
nullptr,
PACKAGE_NAME, QObject::tr(
"Error initializing settings: %1").arg(QString::fromStdString(
error)));
579 assert(!networkStyle.isNull());
581 QApplication::setApplicationName(networkStyle->getAppName());
583 initTranslations(qtTranslatorBase, qtTranslator, translatorBase, translator);
598 app.createPaymentServer();
600 #endif // ENABLE_WALLET 605 #if defined(Q_OS_WIN) 607 qApp->installNativeEventFilter(
new WinShutdownMonitor());
617 if (did_show_intro) {
627 int rv = EXIT_SUCCESS;
636 #if defined(Q_OS_WIN) 637 WinShutdownMonitor::registerShutdownBlockReason(QObject::tr(
"%1 didn't yet exit safely…").arg(
PACKAGE_NAME), (HWND)app.
getMainWinId());
647 }
catch (
const std::exception& e) {
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 IsArgSet(const std::string &strArg) const
Return true if the given argument has been manually set.
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 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()
void SetupServerArgs(ArgsManager &argsman)
Register all arguments with the ArgsManager.
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.
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.
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.
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)
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...
bool GetBoolArg(const std::string &strArg, bool fDefault) const
Return boolean argument or default value.
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 handleNonFatalException(const QString &message)
A helper function that shows a message box with details about a non-fatal exception.
void requestedInitialize()
interfaces::Node & node() const
Qt event filter that intercepts QEvent::FocusOut events for QLabel objects, and resets their ‘textIn...
static const bool DEFAULT_SPLASHSCREEN
static void ipcParseCommandLine(int argc, char *argv[])
void setNode(interfaces::Node &node)
void InitPruneSetting(int64_t prune_MiB)
Initialize prune setting.
void handleURIOrFile(const QString &s)
static bool showIfNeeded(bool &did_show_intro, int64_t &prune_MiB)
Determine data directory.
static bool ipcSendCommandLine()
int64_t CAmount
Amount in satoshis (Can be negative)
bool CheckDataDirOption()
static QWidget * showShutdownWindow(QMainWindow *window)
BitcoinCore(interfaces::Node &node)
void finish()
Hide the splash screen window and schedule the splash screen object for deletion. ...
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.
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.
static int PruneMiBtoGB(int64_t mib)
Convert configured prune target MiB to displayed GB.
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.
bool hasTrayIcon() const
Get the tray icon status.
void ThreadSetInternalName(std::string &&)
Set the internal (in-memory) name of the current thread only.
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.
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.
bool getMinimizeToTray() const
std::string GetArg(const std::string &strArg, const std::string &strDefault) const
Return string argument or default value.
interfaces::Node * m_node
QString MakeHtmlLink(const QString &source, const QString &link)
Replaces a plain text link with an HTML tagged one.
"Help message" dialog box
std::string GetChainName() const
Returns the appropriate chain name from the program arguments.
CClientUIInterface uiInterface
static QString GetLangTerritory()
static const std::string DEFAULT_UIPLATFORM
void runawayException(const QString &message)
std::unique_ptr< Node > MakeNode(NodeContext *context=nullptr)
Return implementation of Node interface.
WId getMainWinId() const
Get window identifier of QMainWindow (BitcoinGUI)
Top-level interface for a bitcoin node (bitcoind process).
bool error(const char *fmt, const Args &... args)
bool baseInitialize()
Basic initialization, before starting initialization/shutdown thread. Return true on success...
ClientModel * clientModel
#define PACKAGE_BUGREPORT
void InitParameterInteraction(ArgsManager &args)
Parameter interaction: change current parameters depending on various rules.
void initializeResult(bool success, interfaces::BlockAndHeaderTipInfo tip_info)
virtual bool appInitMain(interfaces::BlockAndHeaderTipInfo *tip_info=nullptr)=0
Start node.
int getReturnValue() const
Get process return value.
QTimer * pollShutdownTimer
const PlatformStyle * platformStyle