5#include <bitcoin-build-config.h>
9#include <chainparams.h>
38#include <validation.h>
47#include <boost/signals2/connection.hpp>
51#include <QApplication>
53#include <QLatin1String>
54#include <QLibraryInfo>
159 messagebox.setInformativeText(QObject::tr(
"Do you want to reset settings to default values, or to abort without making changes?"));
160 messagebox.setDetailedText(QString::fromStdString(MakeUnorderedList(details)));
162 messagebox.setDefaultButton(QMessageBox::Reset);
164 case QMessageBox::Reset:
166 case QMessageBox::Abort:
179 messagebox.setInformativeText(QObject::tr(
"A fatal error occurred. Check that settings file is writable, or try running with -nosettings."));
180 messagebox.setDetailedText(QString::fromStdString(MakeUnorderedList(details)));
193 LogInfo(
"GUI: %s", msg.toStdString());
232void BitcoinApplication::createPaymentServer()
251 error.
translated +=
tr(
"Settings file %1 might be corrupt or invalid.").arg(QString::fromStdString(
quoted_path)).toStdString();
267 if (!QApplication::activeModalWidget()) {
300 QCoreApplication::exit(0);
331 for (
const auto w : QGuiApplication::topLevelWindows()) {
368 delete m_wallet_controller;
369 m_wallet_controller =
nullptr;
383 if (!success ||
m_node->shutdownRequested()) {
435 QMessageBox::critical(
436 nullptr,
tr(
"Runaway exception"),
437 tr(
"A fatal error occurred. %1 can no longer continue safely and will quit.").
arg(
CLIENT_NAME) +
444 assert(QThread::currentThread() == thread());
445 QMessageBox::warning(
446 nullptr,
tr(
"Internal error"),
447 tr(
"An internal error occurred. %1 will attempt to continue safely. This is "
448 "an unexpected bug which can be reported as described below.").
arg(
CLIENT_NAME) +
462 if (
e->type() == QEvent::Quit) {
467 return QApplication::event(
e);
498#if defined(QT_QPA_PLATFORM_ANDROID)
499 QApplication::setAttribute(Qt::AA_DontUseNativeMenuBar);
500 QApplication::setAttribute(Qt::AA_DontCreateNativeWidgetSiblings);
501 QApplication::setAttribute(Qt::AA_DontUseNativeDialogs);
517 QString::fromStdString(
"Error parsing command line arguments: %1.").
arg(QString::fromStdString(error)));
524 for (
int i = 1; i <
argc; i++) {
537 QString::fromStdString(
"Options ('%1') cannot follow a BIP-21 payment URI").
arg(QString::fromStdString(
argv[i])));
544 QString::fromStdString(
"Command line contains unexpected token '%1', see bitcoin-qt -h for a list of options.").
arg(QString::fromStdString(
argv[i])));
550 app.setupPlatformStyle();
589 InitError(error->message, error->details);
597 QMessageBox::critical(
nullptr,
CLIENT_NAME, QObject::tr(
"Error: %1").
arg(QString::fromStdString(error->message.translated)));
609 QApplication::setApplicationName(
networkStyle->getAppName());
626 app.createPaymentServer();
643 app.parameterSetup();
667 if (
app.baseInitialize()) {
668 app.requestInitialize();
670 WinShutdownMonitor::registerShutdownBlockReason(QObject::tr(
"%1 didn't yet exit safely…").
arg(
CLIENT_NAME), (
HWND)
app.getMainWinId());
677 }
catch (
const std::exception&
e) {
679 app.handleRunawayException(QString::fromStdString(
app.node().getWarnings().translated));
682 app.handleRunawayException(QString::fromStdString(
app.node().getWarnings().translated));
684 return app.node().getExitStatus();
int64_t CAmount
Amount in satoshis (Can be negative)
bool HelpRequested(const ArgsManager &args)
const CChainParams & Params()
Return the currently selected parameters.
@ ALLOW_ANY
disable validation
bool ParseParameters(int argc, const char *const argv[], std::string &error)
bool GetSettingsPath(fs::path *filepath=nullptr, bool temp=false, bool backup=false) const
Get settings file path, or return false if read-write settings were disabled with -nosettings.
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 GetBoolArg(const std::string &strArg, bool fDefault) const
Return boolean argument or default value.
Main Bitcoin application object.
bool createOptionsModel(bool resetSettings)
Create options model.
std::optional< InitExecutor > m_executor
void requestedInitialize()
ClientModel * clientModel
void InitPruneSetting(int64_t prune_MiB)
Initialize prune setting.
void createSplashScreen(const NetworkStyle *networkStyle)
Create splash screen.
void requestShutdown()
Request core shutdown.
void windowShown(BitcoinGUI *window)
void initializeResult(bool success, interfaces::BlockAndHeaderTipInfo tip_info)
interfaces::Node & node() const
void createNode(interfaces::Init &init)
Create or spawn node.
QTimer * pollShutdownTimer
const PlatformStyle * platformStyle
bool baseInitialize()
Basic initialization, before starting initialization/shutdown thread. Return true on success.
void createWindow(const NetworkStyle *networkStyle)
Create main window.
void parameterSetup()
parameter interaction/setup based on rules
void handleRunawayException(const QString &message)
Handle runaway exceptions. Shows a message box with the problem and quits the program.
OptionsModel * optionsModel
bool event(QEvent *e) override
void setupPlatformStyle()
Setup platform style.
std::unique_ptr< interfaces::Node > m_node
std::unique_ptr< QWidget > shutdownWindow
void requestInitialize()
Request core initialization.
WId getMainWinId() const
Get window identifier of QMainWindow (BitcoinGUI)
void handleNonFatalException(const QString &message)
A helper function that shows a message box with details about a non-fatal exception.
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 shutdown has been requested
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
void initializeResult(bool success, interfaces::BlockAndHeaderTipInfo tip_info)
void runawayException(const QString &message)
static bool showIfNeeded(bool &did_show_intro, int64_t &prune_MiB)
Determine data directory.
static const NetworkStyle * instantiate(ChainType networkId)
Get style associated with provided network id, or 0 if not known.
Interface from Qt to configuration data structure for Bitcoin client.
void SetPruneTargetGB(int prune_target_gb)
bool Init(bilingual_str &error)
bool getMinimizeToTray() const
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)
static QWidget * showShutdownWindow(QMainWindow *window)
Class for the splashscreen with information of the running client.
void setNode(interfaces::Node &node)
Controller between interfaces::Node, WalletModel instances and the GUI.
static bool isWalletEnabled()
Initial interface created when a process is first started, and used to give and get access to other i...
virtual bool baseInitialize()=0
Initialize app dependencies.
virtual void startShutdown()=0
Start shutdown.
void PrintExceptionContinue(const std::exception *pex, std::string_view thread_name)
static auto quoted(const std::string &s)
static std::string PathToString(const path &path)
Convert path object to a byte string.
static constexpr auto SHUTDOWN_POLLING_DELAY
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 InitParameterInteraction(ArgsManager &args)
Parameter interaction: change current parameters depending on various rules.
void SetupServerArgs(ArgsManager &argsman, bool can_listen_ipc)
Register all arguments with the ArgsManager.
CClientUIInterface uiInterface
bool InitError(const bilingual_str &str)
Show error message.
static const bool DEFAULT_CHOOSE_DATADIR
#define LogDebug(category,...)
QString MakeHtmlLink(const QString &source, const QString &link)
Replaces a plain text link with an HTML tagged one.
void LogQtInfo()
Writes to debug.log short info about the used Qt and the host system.
void LoadFont(const QString &file_name)
Loads the font from the file specified by file_name, aborts if it fails.
@ ABORTED
Aborted by user.
@ FAILED_WRITE
Failed to write settings.json.
std::optional< ConfigError > InitConfig(ArgsManager &args, SettingsAbortFn settings_abort_fn)
std::unique_ptr< Init > MakeGuiInit(int argc, char *argv[])
Return implementation of Init interface for the gui process.
std::string MakeUnorderedList(const std::vector< std::string > &items)
Create an unordered multi-line list of items.
void ThreadSetInternalName(const std::string &)
Set the internal (in-memory) name of the current thread only.
AddressPurpose
Address purpose field that has been been stored with wallet sending and receiving addresses since BIP...
bool noui_ThreadSafeQuestion(const bilingual_str &, const std::string &message, 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, unsigned int style)
Non-GUI handler, which logs and prints messages.
static int PruneMiBtoGB(int64_t mib)
Convert configured prune target MiB to displayed GB.
QT_END_NAMESPACE const QString BITCOIN_IPC_PREFIX
static bool ErrorSettingsRead(const bilingual_str &error, const std::vector< std::string > &details)
static void RegisterMetaTypes()
static QString GetLangTerritory()
int GuiMain(int argc, char *argv[])
static void ErrorSettingsWrite(const bilingual_str &error, const std::vector< std::string > &details)
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.
bilingual_str Untranslated(std::string original)
Mark a bilingual_str as untranslated.
constexpr auto Ticks(Dur2 d)
Helper to count the seconds of a duration/time_point.
SynchronizationState
Current sync state passed to tip changed callbacks.
is a home for public enum and struct type definitions that are used by internally by wallet code,...