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*)
84 qRegisterMetaType<bool*>();
85 qRegisterMetaType<SynchronizationState>();
86 qRegisterMetaType<SyncType>();
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");
99 #if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0)) 100 qRegisterMetaTypeStreamOperators<BitcoinUnit>(
"BitcoinUnit");
102 qRegisterMetaType<BitcoinUnit>(
"BitcoinUnit");
111 QString lang_territory = QLocale::system().name();
113 QString lang_territory_qsettings = settings.value(
"language",
"").toString();
114 if(!lang_territory_qsettings.isEmpty())
115 lang_territory = lang_territory_qsettings;
117 lang_territory = QString::fromStdString(
gArgs.
GetArg(
"-lang", lang_territory.toStdString()));
118 return lang_territory;
122 static void initTranslations(QTranslator &qtTranslatorBase, QTranslator &qtTranslator, QTranslator &translatorBase, QTranslator &translator)
125 QApplication::removeTranslator(&qtTranslatorBase);
126 QApplication::removeTranslator(&qtTranslator);
127 QApplication::removeTranslator(&translatorBase);
128 QApplication::removeTranslator(&translator);
135 QString lang = lang_territory;
136 lang.truncate(lang_territory.lastIndexOf(
'_'));
142 #if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0)) 143 const QString translation_path{QLibraryInfo::location(QLibraryInfo::TranslationsPath)};
145 const QString translation_path{QLibraryInfo::path(QLibraryInfo::TranslationsPath)};
148 if (qtTranslatorBase.load(
"qt_" + lang, translation_path)) {
149 QApplication::installTranslator(&qtTranslatorBase);
153 if (qtTranslator.load(
"qt_" + lang_territory, translation_path)) {
154 QApplication::installTranslator(&qtTranslator);
158 if (translatorBase.load(lang,
":/translations/")) {
159 QApplication::installTranslator(&translatorBase);
163 if (translator.load(lang_territory,
":/translations/")) {
164 QApplication::installTranslator(&translator);
174 std::vector<std::string> errors;
176 std::string
error = QT_TRANSLATE_NOOP(
"bitcoin-core",
"Settings file could not be read");
177 std::string error_translated = QCoreApplication::translate(
"bitcoin-core",
error.c_str()).toStdString();
180 QMessageBox messagebox(QMessageBox::Critical,
PACKAGE_NAME, QString::fromStdString(
strprintf(
"%s.", error_translated)), QMessageBox::Reset | QMessageBox::Abort);
183 messagebox.setInformativeText(QObject::tr(
"Do you want to reset settings to default values, or to abort without making changes?"));
185 messagebox.setTextFormat(Qt::PlainText);
186 messagebox.setDefaultButton(QMessageBox::Reset);
187 switch (messagebox.exec()) {
188 case QMessageBox::Reset:
190 case QMessageBox::Abort:
199 std::string
error = QT_TRANSLATE_NOOP(
"bitcoin-core",
"Settings file could not be written");
200 std::string error_translated = QCoreApplication::translate(
"bitcoin-core",
error.c_str()).toStdString();
203 QMessageBox messagebox(QMessageBox::Critical,
PACKAGE_NAME, QString::fromStdString(
strprintf(
"%s.", error_translated)), QMessageBox::Ok);
207 messagebox.setInformativeText(QObject::tr(
"A fatal error occurred. Check that settings file is writable, or try running with -nosettings."));
209 messagebox.setTextFormat(Qt::PlainText);
210 messagebox.setDefaultButton(QMessageBox::Ok);
221 if (type == QtDebugMsg) {
224 LogPrintf(
"GUI: %s\n", msg.toStdString());
233 optionsModel(nullptr),
234 clientModel(nullptr),
236 pollShutdownTimer(nullptr),
238 platformStyle(nullptr)
242 setQuitOnLastWindowClosed(
false);
250 std::string platformName;
269 void BitcoinApplication::createPaymentServer()
287 error.original +=
strprintf(
"Settings file %s might be corrupt or invalid.", quoted_path);
288 error.translated += tr(
"Settings file %1 might be corrupt or invalid.").arg(QString::fromStdString(quoted_path)).toStdString();
291 QMessageBox::critical(
nullptr,
PACKAGE_NAME, QString::fromStdString(
error.translated));
304 if (!QApplication::activeModalWidget()) {
341 QCoreApplication::exit(0);
365 qDebug() << __func__ <<
": Requesting initialize";
372 for (
const auto w : QGuiApplication::topLevelWindows()) {
381 qDebug() << __func__ <<
": Requesting shutdown";
401 delete m_wallet_controller;
402 m_wallet_controller =
nullptr;
403 #endif // ENABLE_WALLET 414 qDebug() << __func__ <<
": Initialization result: " << success;
426 window->setWalletController(m_wallet_controller);
431 #endif // ENABLE_WALLET 450 connect(paymentServer, &
PaymentServer::message, [
this](
const QString& title,
const QString& message,
unsigned int style) {
465 QMessageBox::critical(
466 nullptr, tr(
"Runaway exception"),
467 tr(
"A fatal error occurred. %1 can no longer continue safely and will quit.").arg(
PACKAGE_NAME) +
469 ::exit(EXIT_FAILURE);
474 assert(QThread::currentThread() == thread());
475 QMessageBox::warning(
476 nullptr, tr(
"Internal error"),
477 tr(
"An internal error occurred. %1 will attempt to continue safely. This is " 478 "an unexpected bug which can be reported as described below.").arg(
PACKAGE_NAME) +
492 if (e->type() == QEvent::Quit) {
497 return QApplication::event(e);
513 util::WinCmdLineArgs winArgs;
514 std::tie(argc, argv) = winArgs.get();
530 Q_INIT_RESOURCE(bitcoin);
531 Q_INIT_RESOURCE(bitcoin_locale);
533 #if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0)) 535 QApplication::setAttribute(Qt::AA_UseHighDpiPixmaps);
536 QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
539 #if defined(QT_QPA_PLATFORM_ANDROID) 540 QApplication::setAttribute(Qt::AA_DontUseNativeMenuBar);
541 QApplication::setAttribute(Qt::AA_DontCreateNativeWidgetSiblings);
542 QApplication::setAttribute(Qt::AA_DontUseNativeDialogs);
558 QString::fromStdString(
"Error parsing command line arguments: %1.").arg(QString::fromStdString(
error)));
574 QTranslator qtTranslatorBase, qtTranslator, translatorBase, translator;
575 initTranslations(qtTranslatorBase, qtTranslator, translatorBase, translator);
590 bool did_show_intro =
false;
591 int64_t prune_MiB = 0;
600 QObject::tr(
"Error: Specified data directory \"%1\" does not exist.").arg(QString::fromStdString(
gArgs.
GetArg(
"-datadir",
""))));
606 QObject::tr(
"Error: Cannot parse configuration file: %1.").arg(QString::fromStdString(
error)));
619 }
catch(std::exception &e) {
621 QMessageBox::critical(
nullptr,
PACKAGE_NAME, QObject::tr(
"Error: %1").arg(e.what()));
634 assert(!networkStyle.isNull());
636 QApplication::setApplicationName(networkStyle->getAppName());
638 initTranslations(qtTranslatorBase, qtTranslator, translatorBase, translator);
653 app.createPaymentServer();
655 #endif // ENABLE_WALLET 660 #if defined(Q_OS_WIN) 662 qApp->installNativeEventFilter(
new WinShutdownMonitor());
680 if (did_show_intro) {
694 #if defined(Q_OS_WIN) 695 WinShutdownMonitor::registerShutdownBlockReason(QObject::tr(
"%1 didn't yet exit safely…").arg(
PACKAGE_NAME), (HWND)app.
getMainWinId());
703 }
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)
CClientUIInterface uiInterface
#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.
void setNode(interfaces::Node &node)
virtual bool baseInitialize()=0
Initialize app dependencies.
void parameterSetup()
parameter interaction/setup based on rules
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.
bool HelpRequested(const ArgsManager &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)
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)
std::unique_ptr< interfaces::Node > m_node
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[])
static constexpr auto SHUTDOWN_POLLING_DELAY
void InitPruneSetting(int64_t prune_MiB)
Initialize prune setting.
void handleURIOrFile(const QString &s)
bool Init(bilingual_str &error)
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)
static QWidget * showShutdownWindow(QMainWindow *window)
void finish()
Hide the splash screen window and schedule the splash screen object for deletion. ...
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...
bool ReadSettingsFile(std::vector< std::string > *errors=nullptr)
Read settings file.
static std::string PathToString(const path &path)
Convert path object to a byte string.
void createNode(interfaces::Init &init)
Create or spawn node.
static void RegisterMetaTypes()
void createSplashScreen(const NetworkStyle *networkStyle)
Create splash screen.
Main Bitcoin application object.
bool InitError(const bilingual_str &str)
Show error message.
void SelectParams(const std::string &network)
Sets the params returned by Params() to those for the given chain name.
bool CheckDataDirOption()
virtual bilingual_str getWarnings()=0
Get warnings.
int GuiMain(int argc, char *argv[])
void AddArg(const std::string &name, const std::string &help, unsigned int flags, const OptionsCategory &cat)
Add argument.
std::string MakeUnorderedList(const std::vector< std::string > &items)
Create an unordered multi-line list of items.
static void initTranslations(QTranslator &qtTranslatorBase, QTranslator &qtTranslator, QTranslator &translatorBase, QTranslator &translator)
Set up translations.
void PrintExceptionContinue(const std::exception *pex, std::string_view thread_name)
void detectShutdown()
called by a timer to check if ShutdownRequested() has been set
Block and header tip information.
static bool InitSettings()
static int PruneMiBtoGB(int64_t mib)
Convert configured prune target MiB to displayed GB.
std::unique_ptr< QWidget > shutdownWindow
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
bool createOptionsModel(bool resetSettings)
Create options model.
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
bool WriteSettingsFile(std::vector< std::string > *errors=nullptr, bool backup=false) const
Write settings file or backup settings file.
void createWindow(const NetworkStyle *networkStyle)
Create main window.
static const int TOOLTIP_WRAP_THRESHOLD
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.
void initializeResult(bool success, interfaces::BlockAndHeaderTipInfo tip_info)
void LoadFont(const QString &file_name)
Loads the font from the file specified by file_name, aborts if it fails.
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.
static auto quoted(const std::string &s)
Initial interface created when a process is first started, and used to give and get access to other i...
static QString GetLangTerritory()
std::unique_ptr< Init > MakeGuiInit(int argc, char *argv[])
Return implementation of Init interface for the gui process.
static const std::string DEFAULT_UIPLATFORM
Path class wrapper to block calls to the fs::path(std::string) implicit constructor and the fs::path:...
void runawayException(const QString &message)
WId getMainWinId() const
Get window identifier of QMainWindow (BitcoinGUI)
bool error(const char *fmt, const Args &... args)
bool baseInitialize()
Basic initialization, before starting initialization/shutdown thread. Return true on success...
bool event(QEvent *e) override
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)
std::optional< InitExecutor > m_executor
int getReturnValue() const
Get process return value.
QTimer * pollShutdownTimer
const PlatformStyle * platformStyle