5 #if defined(HAVE_CONFIG_H)
6 #include "config/bitcoin-config.h"
41 #include <boost/filesystem/operations.hpp>
42 #include <boost/thread.hpp>
44 #include <QApplication>
46 #include <QLibraryInfo>
48 #include <QMessageBox>
52 #include <QTranslator>
53 #include <QSslConfiguration>
55 #if defined(QT_STATICPLUGIN)
57 #if QT_VERSION < 0x050000
58 Q_IMPORT_PLUGIN(qcncodecs)
59 Q_IMPORT_PLUGIN(qjpcodecs)
60 Q_IMPORT_PLUGIN(qtwcodecs)
61 Q_IMPORT_PLUGIN(qkrcodecs)
62 Q_IMPORT_PLUGIN(qtaccessiblewidgets)
64 #if QT_VERSION < 0x050400
65 Q_IMPORT_PLUGIN(AccessibleFactory)
67 #if defined(QT_QPA_PLATFORM_XCB)
68 Q_IMPORT_PLUGIN(QXcbIntegrationPlugin);
69 #elif defined(QT_QPA_PLATFORM_WINDOWS)
70 Q_IMPORT_PLUGIN(QMinimalIntegrationPlugin);
71 Q_IMPORT_PLUGIN(QWindowsIntegrationPlugin);
72 Q_IMPORT_PLUGIN(QWindowsPrinterSupportPlugin);
73 #elif defined(QT_QPA_PLATFORM_COCOA)
74 Q_IMPORT_PLUGIN(QCocoaIntegrationPlugin);
79 #if QT_VERSION < 0x050000
84 Q_DECLARE_METATYPE(
bool*)
87 static void InitMessage(
const std::string &message)
95 static std::string Translate(
const char* psz)
97 return QCoreApplication::translate(
"bitcoin-core", psz).toStdString();
100 static QString GetLangTerritory()
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(
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);
126 QString lang_territory = GetLangTerritory();
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);
154 #if QT_VERSION < 0x050000
157 const char *category = (type == QtDebugMsg) ?
"qt" : NULL;
158 LogPrint(category,
"GUI: %s\n", msg);
161 void DebugMessageHandler(QtMsgType type,
const QMessageLogContext& context,
const QString &msg)
164 const char *category = (type == QtDebugMsg) ?
"qt" : NULL;
165 LogPrint(category,
"GUI: %s\n", msg.toStdString());
205 void createPaymentServer();
256 #include "bitcoin.moc"
273 qDebug() << __func__ <<
": Running AppInit2 in thread";
291 }
catch (
const std::exception& e) {
302 qDebug() << __func__ <<
": Running Shutdown in thread";
306 qDebug() << __func__ <<
": Shutdown finished";
308 }
catch (
const std::exception& e) {
316 QApplication(argc, argv),
321 pollShutdownTimer(0),
328 setQuitOnLastWindowClosed(
false);
333 std::string platformName;
345 qDebug() << __func__ <<
": Stopping thread";
348 qDebug() << __func__ <<
": Stopped thread";
354 delete paymentServer;
364 void BitcoinApplication::createPaymentServer()
390 connect(
this, SIGNAL(
splashFinished(QWidget*)), splash, SLOT(slotFinish(QWidget*)));
409 connect(
this, SIGNAL(
stopThread()), executor, SLOT(deleteLater()));
423 qDebug() << __func__ <<
": Requesting initialize";
435 qDebug() << __func__ <<
": Requesting shutdown";
442 window->removeAllWallets();
457 qDebug() << __func__ <<
": Initialization result: " << retval;
501 connect(
window, SIGNAL(receivedURI(QString)),
502 paymentServer, SLOT(handleURIOrFile(QString)));
503 connect(paymentServer, SIGNAL(message(QString,QString,
unsigned int)),
504 window, SLOT(message(QString,QString,
unsigned int)));
505 QTimer::singleShot(100, paymentServer, SLOT(uiReady()));
514 qDebug() << __func__ <<
": Shutdown result: " << retval;
520 QMessageBox::critical(0,
"Runaway exception", BitcoinGUI::tr(
"A fatal error occurred. Dogecoin can no longer continue safely and will quit.") + QString(
"\n\n") + message);
521 ::exit(EXIT_FAILURE);
532 #ifndef BITCOIN_QT_TEST
533 int main(
int argc,
char *argv[])
544 #if QT_VERSION < 0x050000
546 QTextCodec::setCodecForTr(QTextCodec::codecForName(
"UTF-8"));
547 QTextCodec::setCodecForCStrings(QTextCodec::codecForTr());
550 Q_INIT_RESOURCE(bitcoin);
551 Q_INIT_RESOURCE(bitcoin_locale);
554 #if QT_VERSION > 0x050100
556 QApplication::setAttribute(Qt::AA_UseHighDpiPixmaps);
558 #if QT_VERSION >= 0x050600
559 QGuiApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
562 QApplication::setAttribute(Qt::AA_DontShowIconsInMenus);
564 #if QT_VERSION >= 0x050500
567 QSslConfiguration sslconf = QSslConfiguration::defaultConfiguration();
568 sslconf.setProtocol(QSsl::TlsV1_0OrLater);
569 QSslConfiguration::setDefaultConfiguration(sslconf);
573 qRegisterMetaType< bool* >();
576 qRegisterMetaType< CAmount >(
"CAmount");
588 QTranslator qtTranslatorBase, qtTranslator, translatorBase, translator;
589 initTranslations(qtTranslatorBase, qtTranslator, translatorBase, translator);
608 if (!boost::filesystem::is_directory(
GetDataDir(
false)))
610 QMessageBox::critical(0, QObject::tr(PACKAGE_NAME),
611 QObject::tr(
"Error: Specified data directory \"%1\" does not exist.").arg(QString::fromStdString(
GetArg(
"-datadir",
""))));
616 }
catch (
const std::exception& e) {
617 QMessageBox::critical(0, QObject::tr(PACKAGE_NAME),
618 QObject::tr(
"Error: Cannot parse configuration file: %1. Only use key=value syntax.").arg(e.what()));
631 }
catch(std::exception &e) {
632 QMessageBox::critical(0, QObject::tr(PACKAGE_NAME), QObject::tr(
"Error: %1").arg(e.what()));
641 assert(!networkStyle.isNull());
643 QApplication::setApplicationName(networkStyle->getAppName());
645 initTranslations(qtTranslatorBase, qtTranslator, translatorBase, translator);
659 app.createPaymentServer();
665 #if QT_VERSION < 0x050000
669 #if defined(Q_OS_WIN)
671 qApp->installNativeEventFilter(
new WinShutdownMonitor());
691 #if defined(Q_OS_WIN) && QT_VERSION >= 0x050000
692 WinShutdownMonitor::registerShutdownBlockReason(QObject::tr(
"%1 didn't yet exit safely...").arg(QObject::tr(PACKAGE_NAME)), (HWND)app.
getMainWinId());
697 }
catch (
const std::exception& e) {
int64_t CAmount
Amount in satoshis (Can be negative)
int main(int argc, char *argv[])
void DebugMessageHandler(QtMsgType type, const char *msg)
void SelectParams(const std::string &network)
Sets the params returned by Params() to those for the given BIP70 chain name.
const CChainParams & Params()
Return the currently selected parameters.
std::string ChainNameFromCommandLine()
Looks for -regtest, -testnet and returns the appropriate BIP70 chain name.
Main Bitcoin application object.
void requestedInitialize()
ClientModel * clientModel
void splashFinished(QWidget *window)
void createSplashScreen(const NetworkStyle *networkStyle)
Create splash screen.
void requestShutdown()
Request core shutdown.
QTimer * pollShutdownTimer
const PlatformStyle * platformStyle
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
int getReturnValue()
Get process return value.
void createOptionsModel(bool resetSettings)
Create options model.
void shutdownResult(int retval)
void initializeResult(int retval)
std::unique_ptr< QWidget > shutdownWindow
void requestInitialize()
Request core initialization.
WId getMainWinId() const
Get window identifier of QMainWindow (BitcoinGUI)
BitcoinApplication(int &argc, char **argv)
Class encapsulating Bitcoin Core startup and shutdown.
void shutdownResult(int retval)
void initializeResult(int retval)
void runawayException(const QString &message)
boost::thread_group threadGroup
void handleRunawayException(const std::exception *e)
Pass fatal exception message to UI thread.
static const std::string DEFAULT_UIPLATFORM
void setClientModel(ClientModel *clientModel)
Set the client model.
static const QString DEFAULT_WALLET
Display name for default wallet name.
boost::signals2::signal< void(const std::string &message)> InitMessage
Progress message during initialization.
boost::signals2::signal< std::string(const char *psz)> Translate
Translate a message to the native language of the user.
A CWallet is an extension of a keystore, which also maintains a set of transactions and balances,...
Model for Bitcoin network client.
Qt event filter that intercepts ToolTipChange events, and replaces the tooltip with a rich text repre...
"Help message" dialog box
static bool pickDataDirectory()
Determine data directory.
static const NetworkStyle * instantiate(const QString &networkId)
Get style associated with provided BIP70 network id, or 0 if not known.
Interface from Qt to configuration data structure for Bitcoin client.
static bool ipcSendCommandLine()
static void ipcParseCommandLine(int argc, char *argv[])
static void LoadRootCAs(X509_STORE *store=NULL)
static QWidget * showShutdownWindow(BitcoinGUI *window)
Class for the splashscreen with information of the running client.
Interface to Bitcoin wallet from Qt view code.
#define QAPP_APP_NAME_DEFAULT
bool AppInitMain(boost::thread_group &threadGroup, CScheduler &scheduler)
Bitcoin core main initialization.
void InitParameterInteraction()
Parameter interaction: change current parameters depending on various rules.
bool AppInitParameterInteraction()
Initialization: parameter interaction.
bool AppInitBasicSetup()
Initialize bitcoin core: Basic context setup.
bool AppInitSanityChecks()
Initialization sanity checks: ecc init, sanity checks, dir lock.
void InitLogging()
Initialize the logging infrastructure.
void Interrupt(boost::thread_group &threadGroup)
Interrupt threads.
void SubstituteFonts(const QString &language)
UniValue help(const JSONRPCRequest &jsonRequest)
CClientUIInterface uiInterface
CTranslationInterface translationInterface
std::string GetArg(const std::string &strArg, const std::string &strDefault)
Return string argument or default value.
void ParseParameters(int argc, const char *const argv[])
void ReadConfigFile(const std::string &confPath)
bool GetBoolArg(const std::string &strArg, bool fDefault)
Return boolean argument or default value.
void PrintExceptionContinue(const std::exception *pex, const char *pszThread)
const boost::filesystem::path & GetDataDir(bool fNetSpecific)
const char *const BITCOIN_CONF_FILENAME
bool IsArgSet(const std::string &strArg)
Return true if the given argument has been manually set.
#define LogPrint(category,...)
std::string GetWarnings(const std::string &strFor)
Format a string that describes several potential problems detected by the core.