 |
Bitcoin Core
22.99.0
P2P Digital Currency
|
Go to the documentation of this file.
5 #if defined(HAVE_CONFIG_H)
35 #include <validation.h>
41 #endif // ENABLE_WALLET
43 #include <boost/signals2/connection.hpp>
47 #include <QApplication>
49 #include <QLatin1String>
50 #include <QLibraryInfo>
52 #include <QMessageBox>
56 #include <QTranslator>
59 #if defined(QT_STATICPLUGIN)
61 #if defined(QT_QPA_PLATFORM_XCB)
62 Q_IMPORT_PLUGIN(QXcbIntegrationPlugin);
63 #elif defined(QT_QPA_PLATFORM_WINDOWS)
64 Q_IMPORT_PLUGIN(QWindowsIntegrationPlugin);
65 Q_IMPORT_PLUGIN(QWindowsVistaStylePlugin);
66 #elif defined(QT_QPA_PLATFORM_COCOA)
67 Q_IMPORT_PLUGIN(QCocoaIntegrationPlugin);
68 Q_IMPORT_PLUGIN(QMacStylePlugin);
69 #elif defined(QT_QPA_PLATFORM_ANDROID)
70 Q_IMPORT_PLUGIN(QAndroidPlatformIntegrationPlugin)
75 Q_DECLARE_METATYPE(
bool*)
85 qRegisterMetaType<bool*>();
86 qRegisterMetaType<SynchronizationState>();
88 qRegisterMetaType<WalletModel*>();
92 qRegisterMetaType<CAmount>(
"CAmount");
93 qRegisterMetaType<size_t>(
"size_t");
95 qRegisterMetaType<std::function<void()>>(
"std::function<void()>");
96 qRegisterMetaType<QMessageBox::Icon>(
"QMessageBox::Icon");
97 qRegisterMetaType<interfaces::BlockAndHeaderTipInfo>(
"interfaces::BlockAndHeaderTipInfo");
105 QString lang_territory = QLocale::system().name();
107 QString lang_territory_qsettings = settings.value(
"language",
"").toString();
108 if(!lang_territory_qsettings.isEmpty())
109 lang_territory = lang_territory_qsettings;
111 lang_territory = QString::fromStdString(
gArgs.
GetArg(
"-lang", lang_territory.toStdString()));
112 return lang_territory;
116 static void initTranslations(QTranslator &qtTranslatorBase, QTranslator &qtTranslator, QTranslator &translatorBase, QTranslator &translator)
119 QApplication::removeTranslator(&qtTranslatorBase);
120 QApplication::removeTranslator(&qtTranslator);
121 QApplication::removeTranslator(&translatorBase);
122 QApplication::removeTranslator(&translator);
129 QString lang = lang_territory;
130 lang.truncate(lang_territory.lastIndexOf(
'_'));
137 if (qtTranslatorBase.load(
"qt_" + lang, QLibraryInfo::location(QLibraryInfo::TranslationsPath)))
138 QApplication::installTranslator(&qtTranslatorBase);
141 if (qtTranslator.load(
"qt_" + lang_territory, QLibraryInfo::location(QLibraryInfo::TranslationsPath)))
142 QApplication::installTranslator(&qtTranslator);
145 if (translatorBase.load(lang,
":/translations/"))
146 QApplication::installTranslator(&translatorBase);
149 if (translator.load(lang_territory,
":/translations/"))
150 QApplication::installTranslator(&translator);
159 std::vector<std::string> errors;
161 std::string
error = QT_TRANSLATE_NOOP(
"bitcoin-core",
"Settings file could not be read");
162 std::string error_translated = QCoreApplication::translate(
"bitcoin-core",
error.c_str()).toStdString();
165 QMessageBox messagebox(QMessageBox::Critical,
PACKAGE_NAME, QString::fromStdString(
strprintf(
"%s.", error_translated)), QMessageBox::Reset | QMessageBox::Abort);
168 messagebox.setInformativeText(QObject::tr(
"Do you want to reset settings to default values, or to abort without making changes?"));
170 messagebox.setTextFormat(Qt::PlainText);
171 messagebox.setDefaultButton(QMessageBox::Reset);
172 switch (messagebox.exec()) {
173 case QMessageBox::Reset:
175 case QMessageBox::Abort:
184 std::string
error = QT_TRANSLATE_NOOP(
"bitcoin-core",
"Settings file could not be written");
185 std::string error_translated = QCoreApplication::translate(
"bitcoin-core",
error.c_str()).toStdString();
188 QMessageBox messagebox(QMessageBox::Critical,
PACKAGE_NAME, QString::fromStdString(
strprintf(
"%s.", error_translated)), QMessageBox::Ok);
192 messagebox.setInformativeText(QObject::tr(
"A fatal error occurred. Check that settings file is writable, or try running with -nosettings."));
194 messagebox.setTextFormat(Qt::PlainText);
195 messagebox.setDefaultButton(QMessageBox::Ok);
206 if (type == QtDebugMsg) {
209 LogPrintf(
"GUI: %s\n", msg.toStdString());
218 optionsModel(nullptr),
219 clientModel(nullptr),
221 pollShutdownTimer(nullptr),
223 platformStyle(nullptr)
227 setQuitOnLastWindowClosed(
false);
235 std::string platformName;
254 void BitcoinApplication::createPaymentServer()
272 if (!QApplication::activeModalWidget()) {
332 qDebug() << __func__ <<
": Requesting initialize";
339 for (
const auto w : QGuiApplication::topLevelWindows()) {
348 qDebug() << __func__ <<
": Requesting shutdown";
368 delete m_wallet_controller;
369 m_wallet_controller =
nullptr;
370 #endif // ENABLE_WALLET
381 qDebug() << __func__ <<
": Initialization result: " << success;
383 returnValue = success ? EXIT_SUCCESS : EXIT_FAILURE;
393 window->setWalletController(m_wallet_controller);
398 #endif // ENABLE_WALLET
417 connect(paymentServer, &
PaymentServer::message, [
this](
const QString& title,
const QString& message,
unsigned int style) {
432 QMessageBox::critical(
433 nullptr, tr(
"Runaway exception"),
434 tr(
"A fatal error occurred. %1 can no longer continue safely and will quit.").arg(
PACKAGE_NAME) +
436 ::exit(EXIT_FAILURE);
441 assert(QThread::currentThread() == thread());
442 QMessageBox::warning(
443 nullptr, tr(
"Internal error"),
444 tr(
"An internal error occurred. %1 will attempt to continue safely. This is "
445 "an unexpected bug which can be reported as described below.").arg(
PACKAGE_NAME) +
470 util::WinCmdLineArgs winArgs;
471 std::tie(argc, argv) = winArgs.get();
487 Q_INIT_RESOURCE(bitcoin);
488 Q_INIT_RESOURCE(bitcoin_locale);
491 QApplication::setAttribute(Qt::AA_UseHighDpiPixmaps);
492 QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
494 #if defined(QT_QPA_PLATFORM_ANDROID)
495 QApplication::setAttribute(Qt::AA_DontUseNativeMenuBar);
496 QApplication::setAttribute(Qt::AA_DontCreateNativeWidgetSiblings);
497 QApplication::setAttribute(Qt::AA_DontUseNativeDialogs);
513 QString::fromStdString(
"Error parsing command line arguments: %1.").arg(QString::fromStdString(
error)));
529 QTranslator qtTranslatorBase, qtTranslator, translatorBase, translator;
530 initTranslations(qtTranslatorBase, qtTranslator, translatorBase, translator);
545 bool did_show_intro =
false;
546 int64_t prune_MiB = 0;
555 QObject::tr(
"Error: Specified data directory \"%1\" does not exist.").arg(QString::fromStdString(
gArgs.
GetArg(
"-datadir",
""))));
561 QObject::tr(
"Error: Cannot parse configuration file: %1.").arg(QString::fromStdString(
error)));
574 }
catch(std::exception &e) {
576 QMessageBox::critical(
nullptr,
PACKAGE_NAME, QObject::tr(
"Error: %1").arg(e.what()));
589 assert(!networkStyle.isNull());
591 QApplication::setApplicationName(networkStyle->getAppName());
593 initTranslations(qtTranslatorBase, qtTranslator, translatorBase, translator);
608 app.createPaymentServer();
610 #endif // ENABLE_WALLET
615 #if defined(Q_OS_WIN)
617 qApp->installNativeEventFilter(
new WinShutdownMonitor());
627 if (did_show_intro) {
637 int rv = EXIT_SUCCESS;
646 #if defined(Q_OS_WIN)
647 WinShutdownMonitor::registerShutdownBlockReason(QObject::tr(
"%1 didn't yet exit safely…").arg(
PACKAGE_NAME), (HWND)app.
getMainWinId());
655 }
catch (
const std::exception& e) {
static int PruneMiBtoGB(int64_t mib)
Convert configured prune target MiB to displayed GB.
void setClientModel(ClientModel *clientModel=nullptr, interfaces::BlockAndHeaderTipInfo *tip_info=nullptr)
Set the client model.
static void SetupUIArgs(ArgsManager &argsman)
Qt event filter that intercepts ToolTipChange events, and replaces the tooltip with a rich text repre...
void setupPlatformStyle()
Setup platform style.
bool GetBoolArg(const std::string &strArg, bool fDefault) const
Return boolean argument or default value.
void createSplashScreen(const NetworkStyle *networkStyle)
Create splash screen.
static const bool DEFAULT_SPLASHSCREEN
void setNode(interfaces::Node &node)
const PlatformStyle * platformStyle
interfaces::Node & node() const
"Help message" dialog box
void receivedURI(const QString &uri)
Signal raised when a URI was entered or dragged to the GUI.
#define PACKAGE_BUGREPORT
void InitParameterInteraction(ArgsManager &args)
Parameter interaction: change current parameters depending on various rules.
void handleRunawayException(const QString &message)
Handle runaway exceptions. Shows a message box with the problem and quits the program.
QTimer * pollShutdownTimer
bool SoftSetBoolArg(const std::string &strArg, bool fValue)
Set a boolean argument if it doesn't already have a value.
CClientUIInterface uiInterface
void InitLogging(const ArgsManager &args)
Initialize global loggers.
std::optional< InitExecutor > m_executor
static void initTranslations(QTranslator &qtTranslatorBase, QTranslator &qtTranslator, QTranslator &translatorBase, QTranslator &translator)
Set up translations.
void message(const QString &title, const QString &message, unsigned int style)
void finish()
Hide the splash screen window and schedule the splash screen object for deletion.
static bool isWalletEnabled()
@ ALLOW_ANY
disable validation
std::string GetChainName() const
Returns the appropriate chain name from the program arguments.
bool IsArgSet(const std::string &strArg) const
Return true if the given argument has been manually set.
NodeContext struct containing references to chain state and connection state.
Initial interface created when a process is first started, and used to give and get access to other i...
static bool showIfNeeded(bool &did_show_intro, int64_t &prune_MiB)
Determine data directory.
OptionsModel * optionsModel
void runawayException(const QString &message)
void requestedInitialize()
Block and header tip information.
static void ipcParseCommandLine(int argc, char *argv[])
int getReturnValue() const
Get process return value.
bool HelpRequested(const ArgsManager &args)
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.
std::unique_ptr< Init > MakeGuiInit(int argc, char *argv[])
Return implementation of Init interface for the gui process.
static const char * qt_argv
bool hasTrayIcon() const
Get the tray icon status.
std::string MakeUnorderedList(const std::vector< std::string > &items)
Create an unordered multi-line list of items.
static const int TOOLTIP_WRAP_THRESHOLD
Qt event filter that intercepts QEvent::FocusOut events for QLabel objects, and resets their ‘textInt...
static bool ipcSendCommandLine()
Interface from Qt to configuration data structure for Bitcoin client.
OptionsModel * getOptionsModel()
void DebugMessageHandler(QtMsgType type, const QMessageLogContext &context, const QString &msg)
static QString GetLangTerritory()
bool GetSettingsPath(fs::path *filepath=nullptr, bool temp=false) const
Get settings file path, or return false if read-write settings were disabled with -nosettings.
void createWindow(const NetworkStyle *networkStyle)
Create main window.
bilingual_str Untranslated(std::string original)
Mark a bilingual_str as untranslated.
void unsubscribeFromCoreSignals()
Disconnect core signals from GUI client.
#define QAPP_APP_NAME_DEFAULT
int GuiMain(int argc, char *argv[])
void SetPruneTargetGB(int prune_target_gb, bool force=false)
static bool InitSettings()
void receivedPaymentRequest(SendCoinsRecipient)
bool InitError(const bilingual_str &str)
Show error message.
void noui_InitMessage(const std::string &message)
Non-GUI handler, which only logs a message.
void AddArg(const std::string &name, const std::string &help, unsigned int flags, const OptionsCategory &cat)
Add argument.
bool WriteSettingsFile(std::vector< std::string > *errors=nullptr) const
Write settings file.
virtual void startShutdown()=0
Start shutdown.
void requestInitialize()
Request core initialization.
Controller between interfaces::Node, WalletModel instances and the GUI.
std::string GetArg(const std::string &strArg, const std::string &strDefault) const
Return string argument or default value.
int64_t CAmount
Amount in satoshis (Can be negative)
void createNode(interfaces::Init &init)
Create or spawn node.
void SelectParams(const std::string &network)
Sets the params returned by Params() to those for the given chain name.
void createOptionsModel(bool resetSettings)
Create options model.
bool ParseParameters(int argc, const char *const argv[], std::string &error)
#define LogPrint(category,...)
bool ReadConfigFiles(std::string &error, bool ignore_invalid_keys=false)
static constexpr auto SHUTDOWN_POLLING_DELAY
void detectShutdown()
called by a timer to check if ShutdownRequested() has been set
std::unique_ptr< QWidget > shutdownWindow
QString MakeHtmlLink(const QString &source, const QString &link)
Replaces a plain text link with an HTML tagged one.
void setNode(interfaces::Node &node)
bool ReadSettingsFile(std::vector< std::string > *errors=nullptr)
Read settings file.
bool CheckDataDirOption()
Model for Bitcoin network client.
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.
void requestShutdown()
Request core shutdown.
static QWidget * showShutdownWindow(QMainWindow *window)
void LogQtInfo()
Writes to debug.log short info about the used Qt and the host system.
const CChainParams & Params()
Return the currently selected parameters.
virtual bilingual_str getWarnings()=0
Get warnings.
bool baseInitialize()
Basic initialization, before starting initialization/shutdown thread. Return true on success.
void initializeResult(bool success, interfaces::BlockAndHeaderTipInfo tip_info)
WId getMainWinId() const
Get window identifier of QMainWindow (BitcoinGUI)
SynchronizationState
Current sync state passed to tip changed callbacks.
void handleNonFatalException(const QString &message)
A helper function that shows a message box with details about a non-fatal exception.
static const bool DEFAULT_CHOOSE_DATADIR
void PrintExceptionContinue(const std::exception *pex, const char *pszThread)
void handleURIOrFile(const QString &s)
void initializeResult(bool success, interfaces::BlockAndHeaderTipInfo tip_info)
bool error(const char *fmt, const Args &... args)
static void RegisterMetaTypes()
void windowShown(BitcoinGUI *window)
void InitPruneSetting(int64_t prune_MiB)
Initialize prune setting.
void LoadFont(const QString &file_name)
Loads the font from the file specified by file_name, aborts if it fails.
bool getMinimizeToTray() const
std::unique_ptr< interfaces::Node > m_node
void parameterSetup()
parameter interaction/setup based on rules
Main Bitcoin application object.
void SetupServerArgs(ArgsManager &argsman)
Register all arguments with the ArgsManager.
void ThreadSetInternalName(std::string &&)
Set the internal (in-memory) name of the current thread only.
static const std::string DEFAULT_UIPLATFORM
virtual bool baseInitialize()=0
Initialize app dependencies.
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.
ClientModel * clientModel
bool noui_ThreadSafeMessageBox(const bilingual_str &message, const std::string &caption, unsigned int style)
Non-GUI handler, which logs and prints messages.