6 #if defined(HAVE_CONFIG_H) 44 #include <boost/thread.hpp> 47 #include <QApplication> 49 #include <QLibraryInfo> 51 #include <QMessageBox> 56 #include <QTranslator> 57 #include <QSslConfiguration> 59 #include <QFontDatabase> 61 #if defined(QT_STATICPLUGIN) 63 #if QT_VERSION < 0x050000 64 Q_IMPORT_PLUGIN(qcncodecs)
65 Q_IMPORT_PLUGIN(qjpcodecs)
66 Q_IMPORT_PLUGIN(qtwcodecs)
67 Q_IMPORT_PLUGIN(qkrcodecs)
68 Q_IMPORT_PLUGIN(qtaccessiblewidgets)
70 #if QT_VERSION < 0x050400 71 Q_IMPORT_PLUGIN(AccessibleFactory)
73 #if defined(QT_QPA_PLATFORM_XCB) 74 Q_IMPORT_PLUGIN(QXcbIntegrationPlugin);
75 #elif defined(QT_QPA_PLATFORM_WINDOWS) 76 Q_IMPORT_PLUGIN(QWindowsIntegrationPlugin);
77 #elif defined(QT_QPA_PLATFORM_COCOA) 78 Q_IMPORT_PLUGIN(QCocoaIntegrationPlugin);
83 #if QT_VERSION < 0x050000 88 Q_DECLARE_METATYPE(
bool*)
91 static void InitMessage(
const std::string &message)
99 static std::string Translate(
const char* psz)
101 return QCoreApplication::translate(
"raven-core", psz).toStdString();
104 static QString GetLangTerritory()
109 QString lang_territory = QLocale::system().name();
111 QString lang_territory_qsettings = settings.value(
"language",
"").toString();
112 if(!lang_territory_qsettings.isEmpty())
113 lang_territory = lang_territory_qsettings;
115 lang_territory = QString::fromStdString(
gArgs.
GetArg(
"-lang", lang_territory.toStdString()));
116 return lang_territory;
120 static void initTranslations(QTranslator &qtTranslatorBase, QTranslator &qtTranslator, QTranslator &translatorBase, QTranslator &translator)
123 QApplication::removeTranslator(&qtTranslatorBase);
124 QApplication::removeTranslator(&qtTranslator);
125 QApplication::removeTranslator(&translatorBase);
126 QApplication::removeTranslator(&translator);
130 QString lang_territory = GetLangTerritory();
133 QString lang = lang_territory;
134 lang.truncate(lang_territory.lastIndexOf(
'_'));
141 if (qtTranslatorBase.load(
"qt_" + lang, QLibraryInfo::location(QLibraryInfo::TranslationsPath)))
142 QApplication::installTranslator(&qtTranslatorBase);
145 if (qtTranslator.load(
"qt_" + lang_territory, QLibraryInfo::location(QLibraryInfo::TranslationsPath)))
146 QApplication::installTranslator(&qtTranslator);
149 if (translatorBase.load(lang,
":/translations/"))
150 QApplication::installTranslator(&translatorBase);
153 if (translator.load(lang_territory,
":/translations/"))
154 QApplication::installTranslator(&translator);
158 #if QT_VERSION < 0x050000 161 if (type == QtDebugMsg) {
168 void DebugMessageHandler(QtMsgType type,
const QMessageLogContext& context,
const QString &msg)
171 if (type == QtDebugMsg) {
174 LogPrintf(
"GUI: %s\n", msg.toStdString());
195 void restart(QStringList args);
219 void createPaymentServer();
222 void parameterSetup();
225 void createOptionsModel(
bool resetSettings);
229 void createSplashScreen(
const NetworkStyle *networkStyle);
232 void requestInitialize();
234 void requestShutdown();
240 WId getMainWinId()
const;
251 void requestedInitialize();
252 void requestedRestart(QStringList args);
253 void requestedShutdown();
255 void splashFinished(QWidget *window);
312 qDebug() << __func__ <<
": Running initialization in thread";
315 }
catch (
const std::exception& e) {
324 static bool executing_restart{
false};
326 if(!executing_restart) {
327 executing_restart =
true;
330 qDebug() << __func__ <<
": Running Restart in thread";
335 qDebug() << __func__ <<
": Shutdown finished";
338 QProcess::startDetached(QApplication::applicationFilePath(), args);
339 qDebug() << __func__ <<
": Restart initiated...";
340 QApplication::quit();
341 }
catch (std::exception& e) {
353 qDebug() << __func__ <<
": Running Shutdown in thread";
357 qDebug() << __func__ <<
": Shutdown finished";
359 }
catch (
const std::exception& e) {
367 QApplication(argc, argv),
372 pollShutdownTimer(0),
379 setQuitOnLastWindowClosed(
false);
384 std::string platformName;
396 qDebug() << __func__ <<
": Stopping thread";
399 qDebug() << __func__ <<
": Stopped thread";
405 delete paymentServer;
415 void RavenApplication::createPaymentServer()
429 window->setMinimumSize(200,200);
430 window->setBaseSize(640,640);
443 connect(
this, SIGNAL(
splashFinished(QWidget*)), splash, SLOT(slotFinish(QWidget*)));
463 connect(
this, SIGNAL(
stopThread()), executor, SLOT(deleteLater()));
477 qDebug() << __func__ <<
": Requesting initialize";
489 qDebug() << __func__ <<
": Requesting shutdown";
496 window->removeAllWallets();
511 qDebug() << __func__ <<
": Initialization result: " << success;
513 returnValue = success ? EXIT_SUCCESS : EXIT_FAILURE;
556 connect(
window, SIGNAL(receivedURI(QString)),
557 paymentServer, SLOT(handleURIOrFile(QString)));
558 connect(paymentServer, SIGNAL(message(QString,QString,
unsigned int)),
559 window, SLOT(message(QString,QString,
unsigned int)));
560 QTimer::singleShot(100, paymentServer, SLOT(uiReady()));
569 returnValue = success ? EXIT_SUCCESS : EXIT_FAILURE;
570 qDebug() << __func__ <<
": Shutdown result: " <<
returnValue;
576 QMessageBox::critical(0,
"Runaway exception", RavenGUI::tr(
"A fatal error occurred. Raven can no longer continue safely and will quit.") + QString(
"\n\n") + message);
577 ::exit(EXIT_FAILURE);
588 #ifndef RAVEN_QT_TEST 589 int main(
int argc,
char *argv[])
600 #if QT_VERSION < 0x050000 602 QTextCodec::setCodecForTr(QTextCodec::codecForName(
"UTF-8"));
603 QTextCodec::setCodecForCStrings(QTextCodec::codecForTr());
606 Q_INIT_RESOURCE(raven);
607 Q_INIT_RESOURCE(raven_locale);
610 #if QT_VERSION > 0x050100 612 QApplication::setAttribute(Qt::AA_UseHighDpiPixmaps);
614 #if QT_VERSION >= 0x050600 615 QGuiApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
618 QApplication::setAttribute(Qt::AA_DontShowIconsInMenus);
620 #if QT_VERSION >= 0x050500 623 QSslConfiguration sslconf = QSslConfiguration::defaultConfiguration();
624 sslconf.setProtocol(QSsl::TlsV1_0OrLater);
625 QSslConfiguration::setDefaultConfiguration(sslconf);
629 qRegisterMetaType< bool* >();
632 qRegisterMetaType< CAmount >(
"CAmount");
633 qRegisterMetaType< std::function<void(void)> >(
"std::function<void(void)>");
645 QTranslator qtTranslatorBase, qtTranslator, translatorBase, translator;
646 initTranslations(qtTranslatorBase, qtTranslator, translatorBase, translator);
668 QObject::tr(
"Error: Specified data directory \"%1\" does not exist.").arg(QString::fromStdString(
gArgs.
GetArg(
"-datadir",
""))));
673 }
catch (
const std::exception& e) {
675 QObject::tr(
"Error: Cannot parse configuration file: %1. Only use key=value syntax.").arg(e.what()));
688 }
catch(std::exception &e) {
689 QMessageBox::critical(0, QObject::tr(
PACKAGE_NAME), QObject::tr(
"Error: %1").arg(e.what()));
698 assert(!networkStyle.isNull());
700 QApplication::setApplicationName(networkStyle->getAppName());
702 initTranslations(qtTranslatorBase, qtTranslator, translatorBase, translator);
716 app.createPaymentServer();
722 #if QT_VERSION < 0x050000 726 #if defined(Q_OS_WIN) 728 qApp->installNativeEventFilter(
new WinShutdownMonitor());
751 int rv = EXIT_SUCCESS;
760 #if defined(Q_OS_WIN) && QT_VERSION >= 0x050000 761 WinShutdownMonitor::registerShutdownBlockReason(QObject::tr(
"%1 didn't yet exit safely...").arg(QObject::tr(
PACKAGE_NAME)), (HWND)app.
getMainWinId());
771 }
catch (
const std::exception& e) {
780 #endif // RAVEN_QT_TEST void shutdownResult(bool success)
void SubstituteFonts(const QString &language)
OptionsModel * getOptionsModel() const
static void LoadRootCAs(X509_STORE *store=nullptr)
bool IsArgSet(const std::string &strArg) const
Return true if the given argument has been manually set.
const char *const RAVEN_CONF_FILENAME
void ParseParameters(int argc, const char *const argv[])
void InitLogging()
Initialize the logging infrastructure.
Class for the splashscreen with information of the running client.
void setClientModel(ClientModel *clientModel)
Set the client model.
void handleRunawayException(const QString &message)
Handle runaway exceptions. Shows a message box with the problem and quits the program.
OptionsModel * optionsModel
Main Raven application object.
std::vector< CWalletRef > vpwallets
void PrintExceptionContinue(const std::exception *pex, const char *pszThread)
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.
std::string GetWarnings(const std::string &strFor)
Format a string that describes several potential problems detected by the core.
bool AppInitBasicSetup()
Initialize raven core: Basic context setup.
void ReadConfigFile(const std::string &confPath)
void PrepareShutdown()
Preparing steps before shutting down or restarting the wallet.
static void ipcParseCommandLine(int argc, char *argv[])
QTimer * pollShutdownTimer
RavenApplication(int &argc, char **argv)
static bool ipcSendCommandLine()
int64_t CAmount
Amount in corbies (Can be negative)
void InitParameterInteraction()
Parameter interaction: change current parameters depending on various rules.
CTranslationInterface translationInterface
bool AppInitSanityChecks()
Initialization sanity checks: ecc init, sanity checks, dir lock.
static const QString DEFAULT_WALLET
Display name for default wallet name.
static QWidget * showShutdownWindow(RavenGUI *window)
static const std::string DEFAULT_UIPLATFORM
void Interrupt(boost::thread_group &threadGroup)
Interrupt threads.
static bool baseInitialize()
Basic initialization, before starting initialization/shutdown thread.
void SelectParams(const std::string &network)
Sets the params returned by Params() to those for the given BIP70 chain name.
void initializeResult(bool success)
boost::signals2::signal< std::string(const char *psz)> Translate
Translate a message to the native language of the user.
void Shutdown()
Shutdown is split into 2 parts: Part 1: shut down everything but the main wallet instance (done in Pr...
void DebugMessageHandler(QtMsgType type, const char *msg)
const PlatformStyle * platformStyle
void requestShutdown()
Request core shutdown.
UniValue help(const JSONRPCRequest &jsonRequest)
int main(int argc, char *argv[])
WId getMainWinId() const
Get window identifier of QMainWindow (RavenGUI)
std::unique_ptr< QWidget > shutdownWindow
Model for Raven network client.
Class encapsulating Raven Core startup and shutdown.
void initializeResult(bool success)
int getReturnValue() const
Get process return value.
bool AppInitParameterInteraction()
Initialization: parameter interaction.
#define LogPrint(category,...)
#define QAPP_APP_NAME_DEFAULT
void createWindow(const NetworkStyle *networkStyle)
Create main window.
Interface from Qt to configuration data structure for Raven client.
void shutdownResult(bool success)
const CChainParams & Params()
Return the currently selected parameters.
Interface to Raven wallet from Qt view code.
void createOptionsModel(bool resetSettings)
Create options model.
void restart(QStringList args)
std::string GetArg(const std::string &strArg, const std::string &strDefault) const
Return string argument or default value.
void parameterSetup()
parameter interaction/setup based on rules
void splashFinished(QWidget *window)
std::string ChainNameFromCommandLine()
Looks for -regtest, -testnet and returns the appropriate BIP70 chain name.
void requestInitialize()
Request core initialization.
A CWallet is an extension of a keystore, which also maintains a set of transactions and balances...
void runawayException(const QString &message)
"Help message" dialog box
const fs::path & GetDataDir(bool fNetSpecific)
ClientModel * clientModel
void requestedInitialize()
bool AppInitLockDataDirectory()
Lock raven core data directory.
CClientUIInterface uiInterface
bool AppInitMain(boost::thread_group &threadGroup, CScheduler &scheduler)
Raven core main initialization.
static void callCleanup()
bool getDarkModeEnabled() const
void handleRunawayException(const std::exception *e)
Pass fatal exception message to UI thread.
boost::thread_group threadGroup
static bool pickDataDirectory()
Determine data directory.
void createSplashScreen(const NetworkStyle *networkStyle)
Create splash screen.
boost::signals2::signal< void(const std::string &message)> InitMessage
Progress message during initialization.
static const NetworkStyle * instantiate(const QString &networkId)
Get style associated with provided BIP70 network id, or 0 if not known.
void requestedRestart(QStringList args)