7 #if defined(HAVE_CONFIG_H)
44 #include <QApplication>
45 #include <QLibraryInfo>
47 #include <QMessageBox>
52 #include <QTranslator>
54 #if defined(QT_STATICPLUGIN)
56 #if defined(QT_QPA_PLATFORM_XCB)
57 Q_IMPORT_PLUGIN(QXcbIntegrationPlugin);
58 #elif defined(QT_QPA_PLATFORM_WINDOWS)
59 Q_IMPORT_PLUGIN(QWindowsIntegrationPlugin);
60 #elif defined(QT_QPA_PLATFORM_COCOA)
61 Q_IMPORT_PLUGIN(QCocoaIntegrationPlugin);
63 Q_IMPORT_PLUGIN(QSvgPlugin);
64 Q_IMPORT_PLUGIN(QSvgIconPlugin);
65 Q_IMPORT_PLUGIN(QGifPlugin);
74 static
void InitMessage(const
std::
string& message)
76 LogPrintf(
"init message: %s\n", message);
82 static std::string Translate(
const char* psz)
84 return QCoreApplication::translate(
"pivx-core", psz).toStdString();
87 static QString GetLangTerritory(
bool forceLangFromSetting =
false)
92 QString lang_territory = QLocale::system().name();
94 QString lang_territory_qsettings =
settings.value(
"language",
"").toString();
95 if (!lang_territory_qsettings.isEmpty())
96 lang_territory = lang_territory_qsettings;
98 lang_territory = QString::fromStdString(
gArgs.
GetArg(
"-lang", lang_territory.toStdString()));
99 return (forceLangFromSetting) ? lang_territory_qsettings : lang_territory;
103 static void initTranslations(QTranslator& qtTranslatorBase, QTranslator& qtTranslator, QTranslator& translatorBase, QTranslator& translator,
bool forceLangFromSettings =
false)
106 QApplication::removeTranslator(&qtTranslatorBase);
107 QApplication::removeTranslator(&qtTranslator);
108 QApplication::removeTranslator(&translatorBase);
109 QApplication::removeTranslator(&translator);
113 QString lang_territory = GetLangTerritory(forceLangFromSettings);
116 QString lang = lang_territory;
117 lang.truncate(lang_territory.lastIndexOf(
'_'));
124 if (qtTranslatorBase.load(
"qt_" + lang, QLibraryInfo::location(QLibraryInfo::TranslationsPath)))
125 QApplication::installTranslator(&qtTranslatorBase);
128 if (qtTranslator.load(
"qt_" + lang_territory, QLibraryInfo::location(QLibraryInfo::TranslationsPath)))
129 QApplication::installTranslator(&qtTranslator);
132 if (translatorBase.load(lang,
":/translations/"))
133 QApplication::installTranslator(&translatorBase);
136 if (translator.load(lang_territory,
":/translations/"))
137 QApplication::installTranslator(&translator);
144 if (type == QtDebugMsg) {
147 LogPrintf(
"GUI: %s\n", msg.toStdString());
164 void restart(
const QStringList& args);
186 void createPaymentServer();
258 qDebug() << __func__ <<
": Running AppInit2 in thread";
273 }
catch (
const std::exception& e) {
282 static std::atomic<bool> restartAvailable{
true};
283 if (restartAvailable.exchange(
false)) {
285 qDebug() << __func__ <<
": Restart failed...";
291 QProcess::startDetached(QApplication::applicationFilePath(), args);
292 qDebug() << __func__ <<
": Restart initiated...";
293 QApplication::quit();
305 qDebug() << __func__ <<
": Running "+type+
" in thread";
308 qDebug() << __func__ <<
": "+type+
" finished";
311 }
catch (
const std::exception& e) {
321 optionsModel(nullptr),
322 clientModel(nullptr),
324 pollShutdownTimer(nullptr),
326 paymentServer(nullptr),
327 walletModel(nullptr),
331 setQuitOnLastWindowClosed(
false);
337 qDebug() << __func__ <<
": Stopping thread";
340 qDebug() << __func__ <<
": Stopped thread";
346 delete paymentServer;
347 paymentServer =
nullptr;
360 void BitcoinApplication::createPaymentServer()
384 splash->setAttribute(Qt::WA_DeleteOnClose);
399 bool ret = widget->
isOk;
400 widget->deleteLater();
406 initTranslations(this->qtTranslatorBase, this->qtTranslator, this->translatorBase, this->translator, forceLangFromSettings);
443 qDebug() << __func__ <<
": Requesting initialize";
450 qDebug() << __func__ <<
": Requesting shutdown";
453 if (govModel) govModel->stop();
454 if (walletModel) walletModel->stop();
459 window->removeAllWallets();
461 walletModel =
nullptr;
477 qDebug() << __func__ <<
": Initialization result: " << retval;
495 mnModel->setWalletModel(walletModel);
496 govModel->setWalletModel(walletModel);
500 window->setGovModel(govModel);
503 window->setMNModel(mnModel);
520 connect(paymentServer, &
PaymentServer::message, [
this](
const QString& title,
const QString& message,
unsigned int style) {
533 qDebug() << __func__ <<
": Shutdown result: " << retval;
539 QMessageBox::critical(
nullptr,
"Runaway exception", QObject::tr(
"A fatal error occurred. PIVX can no longer continue safely and will quit.") + QString(
"\n\n") + message);
540 ::exit(EXIT_FAILURE);
551 #ifndef BITCOIN_QT_TEST
555 util::WinCmdLineArgs winArgs;
556 std::tie(argc,
argv) = winArgs.get();
567 Q_INIT_RESOURCE(pivx_locale);
568 Q_INIT_RESOURCE(pivx);
571 QApplication::setAttribute(Qt::AA_UseHighDpiPixmaps);
572 #if QT_VERSION >= 0x050600
573 QGuiApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
576 QApplication::setAttribute(Qt::AA_DontShowIconsInMenus);
581 qRegisterMetaType<bool*>();
584 qRegisterMetaType<CAmount>(
"CAmount");
585 qRegisterMetaType<CAmount>(
"interfaces::WalletBalances");
586 qRegisterMetaType<size_t>(
"size_t");
618 QObject::tr(
"Error: Specified data directory \"%1\" does not exist.").arg(QString::fromStdString(
gArgs.
GetArg(
"-datadir",
""))));
623 }
catch (
const std::exception& e) {
625 QObject::tr(
"Error: Cannot parse configuration file: %1. Only use key=value syntax.").arg(e.what()));
638 }
catch(
const std::exception& e) {
639 QMessageBox::critical(
nullptr,
PACKAGE_NAME, QObject::tr(
"Error: %1").arg(e.what()));
648 assert(!networkStyle.isNull());
650 QApplication::setApplicationName(networkStyle->getAppName());
666 app.createPaymentServer();
672 #if defined(Q_OS_WIN)
674 qApp->installNativeEventFilter(
new WinShutdownMonitor());
689 bool createTutorial{
true};
692 for (
const std::string& wallet_name :
gArgs.
GetArgs(
"-wallet")) {
694 if (!opRes)
throw std::runtime_error(opRes.getError());
695 fs::path wallet_path = fs::absolute(wallet_name, wallet_dir);
696 if (!fs::is_regular_file(wallet_path)) {
697 wallet_path /=
"wallet.dat";
699 if (createTutorial && fs::exists(wallet_path)) {
701 createTutorial =
false;
704 if (createTutorial) {
719 #if defined(Q_OS_WIN)
720 WinShutdownMonitor::registerShutdownBlockReason(QObject::tr(
"%1 didn't yet exit safely...").arg(
PACKAGE_NAME), (HWND)app.
getMainWinId());
725 }
catch (
const std::exception& e) {
int64_t CAmount
Amount in PIV (Can be negative)
void SelectParams(const std::string &network)
Sets the params returned by Params() to those for the given chain name.
const CChainParams & Params()
Return the currently selected parameters.
void ReadConfigFile(const std::string &confPath)
void ParseParameters(int argc, const char *const argv[])
std::vector< std::string > GetArgs(const std::string &strArg) const
Return a vector of strings of the given argument.
bool SoftSetArg(const std::string &strArg, const std::string &strValue)
Set an argument if it doesn't already have a value.
bool IsArgSet(const std::string &strArg) const
Return true if the given argument has been manually set.
std::string GetArg(const std::string &strArg, const std::string &strDefault) const
Return string argument or default value.
bool SoftSetBoolArg(const std::string &strArg, bool fValue)
Set a boolean argument if it doesn't already have a value.
bool GetBoolArg(const std::string &strArg, bool fDefault) const
Return boolean argument or default value.
std::string GetChainName() const
Looks for -regtest, -testnet and returns the appropriate BIP70 chain name.
Main PIVX application object.
void requestedRestart(QStringList args)
void requestedInitialize()
ClientModel * clientModel
void splashFinished(QWidget *window)
void createSplashScreen(const NetworkStyle *networkStyle)
Create splash screen.
void requestShutdown()
Request core shutdown.
QTranslator qtTranslatorBase
QTimer * pollShutdownTimer
bool createTutorialScreen()
Create tutorial screen.
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.
QTranslator translatorBase
OptionsModel * optionsModel
int getReturnValue()
Get process return value.
void shutdownResult(int retval)
void updateTranslation(bool forceLangFromSettings=false)
void createOptionsModel()
Create options model.
void initializeResult(int retval)
void requestInitialize()
Request core initialization.
WId getMainWinId() const
Get window identifier of QMainWindow (PIVXGUI)
BitcoinApplication(int &argc, char **argv)
Class encapsulating PIVX Core startup and shutdown.
void shutdownResult(int retval)
void initializeResult(int retval)
void runawayException(const QString &message)
void handleRunawayException(const std::exception *e)
Pass fatal exception message to UI thread.
bool shutdownFromThread(const QString &type="Shutdown")
void restart(const QStringList &args)
boost::signals2::signal< void(const std::string &message)> InitMessage
Progress message during initialization.
static void callCleanup()
boost::signals2::signal< std::string(const char *psz)> Translate
Translate a message to the native language of the user.
Model for PIVX 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 network id, or 0 if not known.
Interface from Qt to configuration data structure for PIVX client.
void requestedRestart(QStringList args)
Restart handling.
void detectShutdown()
called by a timer to check if ShutdownRequested()
void receivedURI(const QString &uri)
Signal raised when a URI was entered or dragged to the GUI.
void message(const QString &title, const QString &message, unsigned int style, bool *ret=nullptr)
Notify the user of an event from the core network or transaction handling code.
static const QString DEFAULT_WALLET
void setClientModel(ClientModel *clientModel)
Set the client model.
static bool ipcSendCommandLine()
void message(const QString &title, const QString &message, unsigned int style)
static void ipcParseCommandLine(int argc, char *argv[])
void handleURIOrFile(const QString &s)
static void showShutdownWindow(QMainWindow *window)
void slotFinish(QWidget *mainWin)
Slot to call finish() method as it's not defined as slot.
Interface to PIVX wallet from Qt view code.
void onLanguageSelected()
#define QAPP_APP_NAME_DEFAULT
CClientUIInterface uiInterface
void InitParameterInteraction()
Parameter interaction: change current parameters depending on various rules.
bool AppInitMain()
Bitcoin core main initialization.
bool AppInitParameterInteraction()
Initialization: parameter interaction.
bool AppInitBasicSetup()
Initialize PIVX core: Basic context setup.
bool AppInitSanityChecks()
Initialization sanity checks: ecc init, sanity checks, dir lock.
void InitLogging()
Initialize the logging infrastructure.
void Interrupt()
Interrupt threads.
#define LogPrint(category,...)
int main(int argc, char *argv[])
Q_DECLARE_METATYPE(interfaces::WalletBalances)
void DebugMessageHandler(QtMsgType type, const QMessageLogContext &context, const QString &msg)
UniValue help(const JSONRPCRequest &jsonRequest)
CTranslationInterface translationInterface
const char *const PIVX_CONF_FILENAME
bool CheckDataDirOption()
void ReleaseDirectoryLocks()
Release all directory locks.
void PrintExceptionContinue(const std::exception *pex, const char *pszThread)
std::vector< CWalletRef > vpwallets
fs::path GetWalletDir()
Get the path of the wallet directory.
OperationResult VerifyWalletPath(const std::string &walletFile)
Verify the wallet db's path.
std::string GetWarnings(const std::string &strFor)