5 #if defined(HAVE_CONFIG_H) 11 #include <chainparams.h> 40 #include <validation.h> 47 #endif // ENABLE_WALLET 49 #include <boost/signals2/connection.hpp> 53 #include <QApplication> 55 #include <QLatin1String> 56 #include <QLibraryInfo> 58 #include <QMessageBox> 62 #include <QTranslator> 65 #if defined(QT_STATICPLUGIN) 67 #if defined(QT_QPA_PLATFORM_XCB) 68 Q_IMPORT_PLUGIN(QXcbIntegrationPlugin);
69 #elif defined(QT_QPA_PLATFORM_WINDOWS) 70 Q_IMPORT_PLUGIN(QWindowsIntegrationPlugin);
71 Q_IMPORT_PLUGIN(QWindowsVistaStylePlugin);
72 #elif defined(QT_QPA_PLATFORM_COCOA) 73 Q_IMPORT_PLUGIN(QCocoaIntegrationPlugin);
74 Q_IMPORT_PLUGIN(QMacStylePlugin);
75 #elif defined(QT_QPA_PLATFORM_ANDROID) 76 Q_IMPORT_PLUGIN(QAndroidPlatformIntegrationPlugin)
81 Q_DECLARE_METATYPE(
bool*)
88 #endif // ENABLE_WALLET 93 qRegisterMetaType<bool*>();
94 qRegisterMetaType<SynchronizationState>();
95 qRegisterMetaType<SyncType>();
97 qRegisterMetaType<WalletModel*>();
98 qRegisterMetaType<wallet::AddressPurpose>();
99 #endif // ENABLE_WALLET 102 qRegisterMetaType<CAmount>(
"CAmount");
103 qRegisterMetaType<size_t>(
"size_t");
105 qRegisterMetaType<std::function<void()>>(
"std::function<void()>");
106 qRegisterMetaType<QMessageBox::Icon>(
"QMessageBox::Icon");
107 qRegisterMetaType<interfaces::BlockAndHeaderTipInfo>(
"interfaces::BlockAndHeaderTipInfo");
109 #if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0)) 110 qRegisterMetaTypeStreamOperators<BitcoinUnit>(
"BitcoinUnit");
112 qRegisterMetaType<BitcoinUnit>(
"BitcoinUnit");
121 QString lang_territory = QLocale::system().name();
123 QString lang_territory_qsettings = settings.value(
"language",
"").toString();
124 if(!lang_territory_qsettings.isEmpty())
125 lang_territory = lang_territory_qsettings;
127 lang_territory = QString::fromStdString(
gArgs.
GetArg(
"-lang", lang_territory.toStdString()));
128 return lang_territory;
132 static void initTranslations(QTranslator &qtTranslatorBase, QTranslator &qtTranslator, QTranslator &translatorBase, QTranslator &translator)
135 QApplication::removeTranslator(&qtTranslatorBase);
136 QApplication::removeTranslator(&qtTranslator);
137 QApplication::removeTranslator(&translatorBase);
138 QApplication::removeTranslator(&translator);
145 QString lang = lang_territory;
146 lang.truncate(lang_territory.lastIndexOf(
'_'));
152 #if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0)) 153 const QString translation_path{QLibraryInfo::location(QLibraryInfo::TranslationsPath)};
155 const QString translation_path{QLibraryInfo::path(QLibraryInfo::TranslationsPath)};
158 if (qtTranslatorBase.load(
"qt_" + lang, translation_path)) {
159 QApplication::installTranslator(&qtTranslatorBase);
163 if (qtTranslator.load(
"qt_" + lang_territory, translation_path)) {
164 QApplication::installTranslator(&qtTranslator);
168 if (translatorBase.load(lang,
":/translations/")) {
169 QApplication::installTranslator(&translatorBase);
173 if (translator.load(lang_territory,
":/translations/")) {
174 QApplication::installTranslator(&translator);
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 QMessageBox messagebox(QMessageBox::Critical,
PACKAGE_NAME, QString::fromStdString(
strprintf(
"%s.",
error.translated)), QMessageBox::Ok);
203 messagebox.setInformativeText(QObject::tr(
"A fatal error occurred. Check that settings file is writable, or try running with -nosettings."));
205 messagebox.setTextFormat(Qt::PlainText);
206 messagebox.setDefaultButton(QMessageBox::Ok);
214 if (type == QtDebugMsg) {
229 setQuitOnLastWindowClosed(
false);
237 std::string platformName;
256 void BitcoinApplication::createPaymentServer()
274 error.original +=
strprintf(
"Settings file %s might be corrupt or invalid.", quoted_path);
275 error.translated += tr(
"Settings file %1 might be corrupt or invalid.").arg(QString::fromStdString(quoted_path)).toStdString();
278 QMessageBox::critical(
nullptr,
PACKAGE_NAME, QString::fromStdString(
error.translated));
291 if (!QApplication::activeModalWidget()) {
324 QCoreApplication::exit(0);
348 qDebug() << __func__ <<
": Requesting initialize";
355 for (
const auto w : QGuiApplication::topLevelWindows()) {
367 qDebug() << __func__ <<
": Requesting shutdown";
387 delete m_wallet_controller;
388 m_wallet_controller =
nullptr;
389 #endif // ENABLE_WALLET 400 qDebug() << __func__ <<
": Initialization result: " << success;
416 window->setWalletController(m_wallet_controller, start_minimized);
421 #endif // ENABLE_WALLET 424 if (!start_minimized) {
439 connect(paymentServer, &
PaymentServer::message, [
this](
const QString& title,
const QString& message,
unsigned int style) {
453 QMessageBox::critical(
454 nullptr, tr(
"Runaway exception"),
455 tr(
"A fatal error occurred. %1 can no longer continue safely and will quit.").arg(
PACKAGE_NAME) +
457 ::exit(EXIT_FAILURE);
462 assert(QThread::currentThread() == thread());
463 QMessageBox::warning(
464 nullptr, tr(
"Internal error"),
465 tr(
"An internal error occurred. %1 will attempt to continue safely. This is " 466 "an unexpected bug which can be reported as described below.").arg(
PACKAGE_NAME) +
480 if (e->type() == QEvent::Quit) {
485 return QApplication::event(e);
501 common::WinCmdLineArgs winArgs;
502 std::tie(argc, argv) = winArgs.get();
518 Q_INIT_RESOURCE(bitcoin);
519 Q_INIT_RESOURCE(bitcoin_locale);
521 #if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0)) 523 QApplication::setAttribute(Qt::AA_UseHighDpiPixmaps);
524 QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
527 #if defined(QT_QPA_PLATFORM_ANDROID) 528 QApplication::setAttribute(Qt::AA_DontUseNativeMenuBar);
529 QApplication::setAttribute(Qt::AA_DontCreateNativeWidgetSiblings);
530 QApplication::setAttribute(Qt::AA_DontUseNativeDialogs);
546 QString::fromStdString(
"Error parsing command line arguments: %1.").arg(QString::fromStdString(
error)));
562 QTranslator qtTranslatorBase, qtTranslator, translatorBase, translator;
563 initTranslations(qtTranslatorBase, qtTranslator, translatorBase, translator);
578 bool did_show_intro =
false;
579 int64_t prune_MiB = 0;
598 QMessageBox::critical(
nullptr,
PACKAGE_NAME, QObject::tr(
"Error: %1").arg(QString::fromStdString(
error->message.translated)));
608 assert(!networkStyle.isNull());
610 QApplication::setApplicationName(networkStyle->getAppName());
612 initTranslations(qtTranslatorBase, qtTranslator, translatorBase, translator);
627 app.createPaymentServer();
629 #endif // ENABLE_WALLET 634 #if defined(Q_OS_WIN) 636 qApp->installNativeEventFilter(
new WinShutdownMonitor());
654 if (did_show_intro) {
667 #if defined(Q_OS_WIN) 668 WinShutdownMonitor::registerShutdownBlockReason(QObject::tr(
"%1 didn't yet exit safely…").arg(
PACKAGE_NAME), (HWND)app.
getMainWinId());
675 }
catch (
const std::exception& e) {
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.
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.
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.
Failed to write settings.json.
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
void PrintExceptionContinue(const std::exception *pex, std::string_view thread_name)
Qt event filter that intercepts QEvent::FocusOut events for QLabel objects, and resets their ‘textI...
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)
static const NetworkStyle * instantiate(const ChainType networkId)
Get style associated with provided network id, or 0 if not known.
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)
AddressPurpose
Address purpose field that has been been stored with wallet sending and receiving addresses since BIP...
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...
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.
virtual int getExitStatus()=0
Get exit status.
Main Bitcoin application object.
bool InitError(const bilingual_str &str)
Show error message.
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 detectShutdown()
called by a timer to check if ShutdownRequested() has been set
Block and header tip information.
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
void createWindow(const NetworkStyle *networkStyle)
Create main window.
static const int TOOLTIP_WRAP_THRESHOLD
Interface from Qt to configuration data structure for Bitcoin client.
bool error(const char *fmt, const Args &... args)
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.
bool HelpRequested(const ArgsManager &args)
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
static bool ErrorSettingsRead(const bilingual_str &error, const std::vector< std::string > &details)
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)
std::optional< ConfigError > InitConfig(ArgsManager &args, SettingsAbortFn settings_abort_fn)
bool baseInitialize()
Basic initialization, before starting initialization/shutdown thread. Return true on success...
bool event(QEvent *e) override
static void ErrorSettingsWrite(const bilingual_str &error, const std::vector< std::string > &details)
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
QTimer * pollShutdownTimer
const PlatformStyle * platformStyle