Fabcoin Core  0.16.2
P2P Digital Currency
fabcoin.cpp
Go to the documentation of this file.
1 // Copyright (c) 2011-2017 The Bitcoin Core developers
2 // Distributed under the MIT software license, see the accompanying
3 // file COPYING or http://www.opensource.org/licenses/mit-license.php.
4 
5 #if defined(HAVE_CONFIG_H)
7 #endif
8 
9 #include <fabcoingui.h>
10 
11 #include <chainparams.h>
12 #include <clientmodel.h>
13 #include <fs.h>
14 #include <guiconstants.h>
15 #include <guiutil.h>
16 #include <intro.h>
17 #include <networkstyle.h>
18 #include <optionsmodel.h>
19 #include <platformstyle.h>
20 #include <splashscreen.h>
21 #include <utilitydialog.h>
22 #include <winshutdownmonitor.h>
23 #include <styleSheet.h>
24 
25 #ifdef ENABLE_WALLET
26 #include <paymentserver.h>
27 #include <walletmodel.h>
28 #endif
29 
30 #include <init.h>
31 #include <rpc/server.h>
32 #include <scheduler.h>
33 #include <ui_interface.h>
34 #include <util.h>
35 #include <warnings.h>
36 
37 #ifdef ENABLE_WALLET
38 #include <wallet/wallet.h>
39 #endif
40 
41 #include <stdint.h>
42 
43 #include <boost/thread.hpp>
44 
45 #include <QApplication>
46 #include <QDebug>
47 #include <QLibraryInfo>
48 #include <QLocale>
49 #include <QMessageBox>
50 #include <QSettings>
51 #include <QThread>
52 #include <QTimer>
53 #include <QTranslator>
54 #include <QSslConfiguration>
55 #include <QFile>
56 #include <QProcess>
57 
58 #if defined(QT_STATICPLUGIN)
59 #include <QtPlugin>
60 #if QT_VERSION < 0x050000
61 Q_IMPORT_PLUGIN(qcncodecs)
62 Q_IMPORT_PLUGIN(qjpcodecs)
63 Q_IMPORT_PLUGIN(qtwcodecs)
64 Q_IMPORT_PLUGIN(qkrcodecs)
65 Q_IMPORT_PLUGIN(qtaccessiblewidgets)
66 #else
67 #if QT_VERSION < 0x050400
68 Q_IMPORT_PLUGIN(AccessibleFactory)
69 #endif
70 #if defined(QT_QPA_PLATFORM_XCB)
71 Q_IMPORT_PLUGIN(QXcbIntegrationPlugin);
72 #elif defined(QT_QPA_PLATFORM_WINDOWS)
73 Q_IMPORT_PLUGIN(QWindowsIntegrationPlugin);
74 #elif defined(QT_QPA_PLATFORM_COCOA)
75 Q_IMPORT_PLUGIN(QCocoaIntegrationPlugin);
76 #endif
77 #endif
78 #endif
79 
80 #if QT_VERSION < 0x050000
81 #include <QTextCodec>
82 #endif
83 
84 // Declare meta types used for QMetaObject::invokeMethod
85 Q_DECLARE_METATYPE(bool*)
86 Q_DECLARE_METATYPE(CAmount)
87 
88 static void InitMessage(const std::string &message)
89 {
90  LogPrintf("init message: %s\n", message);
91 }
92 
93 /*
94  Translate string to current locale using Qt.
95  */
96 static std::string Translate(const char* psz)
97 {
98  return QCoreApplication::translate("fabcoin-core", psz).toStdString();
99 }
100 
101 static QString GetLangTerritory()
102 {
103  QSettings settings;
104  // Get desired locale (e.g. "de_DE")
105  // 1) System default language
106  QString lang_territory = QLocale::system().name();
107  // 2) Language from QSettings
108  QString lang_territory_qsettings = settings.value("language", "").toString();
109  if(!lang_territory_qsettings.isEmpty())
110  lang_territory = lang_territory_qsettings;
111  // 3) -lang command line argument
112  lang_territory = QString::fromStdString(gArgs.GetArg("-lang", lang_territory.toStdString()));
113  return lang_territory;
114 }
115 
117 static void initTranslations(QTranslator &qtTranslatorBase, QTranslator &qtTranslator, QTranslator &translatorBase, QTranslator &translator)
118 {
119  // Remove old translators
120  QApplication::removeTranslator(&qtTranslatorBase);
121  QApplication::removeTranslator(&qtTranslator);
122  QApplication::removeTranslator(&translatorBase);
123  QApplication::removeTranslator(&translator);
124 
125  // Get desired locale (e.g. "de_DE")
126  // 1) System default language
127  QString lang_territory = GetLangTerritory();
128 
129  // Convert to "de" only by truncating "_DE"
130  QString lang = lang_territory;
131  lang.truncate(lang_territory.lastIndexOf('_'));
132 
133  // Load language files for configured locale:
134  // - First load the translator for the base language, without territory
135  // - Then load the more specific locale translator
136 
137  // Load e.g. qt_de.qm
138  if (qtTranslatorBase.load("qt_" + lang, QLibraryInfo::location(QLibraryInfo::TranslationsPath)))
139  QApplication::installTranslator(&qtTranslatorBase);
140 
141  // Load e.g. qt_de_DE.qm
142  if (qtTranslator.load("qt_" + lang_territory, QLibraryInfo::location(QLibraryInfo::TranslationsPath)))
143  QApplication::installTranslator(&qtTranslator);
144 
145  // Load e.g. fabcoin_de.qm (shortcut "de" needs to be defined in fabcoin.qrc)
146  if (translatorBase.load(lang, ":/translations/"))
147  QApplication::installTranslator(&translatorBase);
148 
149  // Load e.g. fabcoin_de_DE.qm (shortcut "de_DE" needs to be defined in fabcoin.qrc)
150  if (translator.load(lang_territory, ":/translations/"))
151  QApplication::installTranslator(&translator);
152 }
153 
154 /* qDebug() message handler --> debug.log */
155 #if QT_VERSION < 0x050000
156 void DebugMessageHandler(QtMsgType type, const char *msg)
157 {
158  if (type == QtDebugMsg) {
159  LogPrint(BCLog::QT, "GUI: %s\n", msg);
160  } else {
161  LogPrintf("GUI: %s\n", msg);
162  }
163 }
164 #else
165 void DebugMessageHandler(QtMsgType type, const QMessageLogContext& context, const QString &msg)
166 {
167  Q_UNUSED(context);
168  if (type == QtDebugMsg) {
169  LogPrint(BCLog::QT, "GUI: %s\n", msg.toStdString());
170  } else {
171  LogPrintf("GUI: %s\n", msg.toStdString());
172  }
173 }
174 #endif
175 
176 void removeParam(QStringList& list, const QString& param)
177 {
178  int index = list.indexOf(param);
179  if(index != -1)
180  {
181  list.removeAt(index);
182  }
183 }
184 
188 class FabcoinCore: public QObject
189 {
190  Q_OBJECT
191 public:
192  explicit FabcoinCore();
196  static bool baseInitialize();
197 
198 public Q_SLOTS:
199  void initialize();
200  void shutdown();
201 
202 Q_SIGNALS:
203  void initializeResult(bool success);
204  void shutdownResult();
205  void runawayException(const QString &message);
206 
207 private:
208  boost::thread_group threadGroup;
210 
212  void handleRunawayException(const std::exception *e);
213 };
214 
216 class FabcoinApplication: public QApplication
217 {
218  Q_OBJECT
219 public:
220  explicit FabcoinApplication(int &argc, char **argv);
222 
223 #ifdef ENABLE_WALLET
224  void createPaymentServer();
226 #endif
227  void parameterSetup();
230  void createOptionsModel(bool resetSettings);
232  void createWindow(const NetworkStyle *networkStyle);
234  void createSplashScreen(const NetworkStyle *networkStyle);
235 
237  void requestInitialize();
239  void requestShutdown();
240 
242  int getReturnValue() { return returnValue; }
243 
245  WId getMainWinId() const;
246 
247  void restoreWallet();
248 
249 public Q_SLOTS:
250  void initializeResult(bool success);
251  void shutdownResult();
253  void handleRunawayException(const QString &message);
254 
255 Q_SIGNALS:
256  void requestedInitialize();
257  void requestedShutdown();
258  void stopThread();
259  void splashFinished(QWidget *window);
260 
261 private:
262  QThread *coreThread;
267 #ifdef ENABLE_WALLET
268  PaymentServer* paymentServer;
269  WalletModel *walletModel;
270 #endif
273  std::unique_ptr<QWidget> shutdownWindow;
274 
275  void startThread();
276 
277  QString restorePath;
278  QString restoreParam;
279 };
280 
281 #include <fabcoin.moc>
282 
284  QObject()
285 {
286 }
287 
288 void FabcoinCore::handleRunawayException(const std::exception *e)
289 {
290  PrintExceptionContinue(e, "Runaway exception");
291  Q_EMIT runawayException(QString::fromStdString(GetWarnings("gui")));
292 }
293 
295 {
296  if (!AppInitBasicSetup())
297  {
298  return false;
299  }
301  {
302  return false;
303  }
304  if (!AppInitSanityChecks())
305  {
306  return false;
307  }
309  {
310  return false;
311  }
312  return true;
313 }
314 
316 {
317  try
318  {
319  qDebug() << __func__ << ": Running initialization in thread";
320  bool rv = AppInitMain(threadGroup, scheduler);
321  Q_EMIT initializeResult(rv);
322  } catch (const std::exception& e) {
324  } catch (...) {
325  handleRunawayException(nullptr);
326  }
327 }
328 
330 {
331  try
332  {
333  qDebug() << __func__ << ": Running Shutdown in thread";
335  threadGroup.join_all();
336  Shutdown();
337  qDebug() << __func__ << ": Shutdown finished";
338  Q_EMIT shutdownResult();
339  } catch (const std::exception& e) {
341  } catch (...) {
342  handleRunawayException(nullptr);
343  }
344 }
345 
347  QApplication(argc, argv),
348  coreThread(0),
349  optionsModel(0),
350  clientModel(0),
351  window(0),
352  pollShutdownTimer(0),
353 #ifdef ENABLE_WALLET
354  paymentServer(0),
355  walletModel(0),
356 #endif
357  returnValue(0)
358 {
359  setQuitOnLastWindowClosed(false);
360 
361  // UI per-platform customization
362  // This must be done inside the FabcoinApplication constructor, or after it, because
363  // PlatformStyle::instantiate requires a QApplication
364  std::string platformName;
365  platformName = gArgs.GetArg("-uiplatform", FabcoinGUI::DEFAULT_UIPLATFORM);
366  platformStyle = PlatformStyle::instantiate(QString::fromStdString(platformName));
367  if (!platformStyle) // Fall back to "other" if specified name not found
370 }
371 
373 {
374  if(coreThread)
375  {
376  qDebug() << __func__ << ": Stopping thread";
377  Q_EMIT stopThread();
378  coreThread->wait();
379  qDebug() << __func__ << ": Stopped thread";
380  }
381 
382  delete window;
383  window = 0;
384 #ifdef ENABLE_WALLET
385  delete paymentServer;
386  paymentServer = 0;
387 #endif
388  delete optionsModel;
389  optionsModel = 0;
390  delete platformStyle;
391  platformStyle = 0;
392 }
393 
394 #ifdef ENABLE_WALLET
395 void FabcoinApplication::createPaymentServer()
396 {
397  paymentServer = new PaymentServer(this);
398 }
399 #endif
400 
402 {
403  optionsModel = new OptionsModel(nullptr, resetSettings);
404 }
405 
407 {
408  window = new FabcoinGUI(platformStyle, networkStyle, 0);
409 
410  pollShutdownTimer = new QTimer(window);
411  connect(pollShutdownTimer, SIGNAL(timeout()), window, SLOT(detectShutdown()));
412  pollShutdownTimer->start(200);
413 }
414 
416 {
417  SplashScreen *splash = new SplashScreen(0, networkStyle);
418  // We don't hold a direct pointer to the splash screen after creation, but the splash
419  // screen will take care of deleting itself when slotFinish happens.
420  splash->show();
421  connect(this, SIGNAL(splashFinished(QWidget*)), splash, SLOT(slotFinish(QWidget*)));
422  connect(this, SIGNAL(requestedShutdown()), splash, SLOT(close()));
423 }
424 
426 {
427  if(coreThread)
428  return;
429  coreThread = new QThread(this);
430  FabcoinCore *executor = new FabcoinCore();
431  executor->moveToThread(coreThread);
432 
433  /* communication to and from thread */
434  connect(executor, SIGNAL(initializeResult(bool)), this, SLOT(initializeResult(bool)));
435  connect(executor, SIGNAL(shutdownResult()), this, SLOT(shutdownResult()));
436  connect(executor, SIGNAL(runawayException(QString)), this, SLOT(handleRunawayException(QString)));
437  connect(this, SIGNAL(requestedInitialize()), executor, SLOT(initialize()));
438  connect(this, SIGNAL(requestedShutdown()), executor, SLOT(shutdown()));
439  /* make sure executor object is deleted in its own thread */
440  connect(this, SIGNAL(stopThread()), executor, SLOT(deleteLater()));
441  connect(this, SIGNAL(stopThread()), coreThread, SLOT(quit()));
442 
443  coreThread->start();
444 }
445 
447 {
448  InitLogging();
450 }
451 
453 {
454  qDebug() << __func__ << ": Requesting initialize";
455  startThread();
456  Q_EMIT requestedInitialize();
457 }
458 
460 {
461  // Show a simple window indicating shutdown status
462  // Do this first as some of the steps may take some time below,
463  // for example the RPC console may still be executing a command.
465 
466  qDebug() << __func__ << ": Requesting shutdown";
467  startThread();
468  window->hide();
470  pollShutdownTimer->stop();
471 
472 #ifdef ENABLE_WALLET
473  if(walletModel)
474  {
475  restoreParam = walletModel->getRestoreParam();
476  restorePath = walletModel->getRestorePath();
477  window->removeAllWallets();
478  delete walletModel;
479  walletModel = 0;
480  }
481 #endif
482  if(clientModel)
483  {
484  delete clientModel;
485  clientModel = 0;
486  }
487 
488  StartShutdown();
489 
490  // Request shutdown from core thread
491  Q_EMIT requestedShutdown();
492 }
493 
495 {
496  qDebug() << __func__ << ": Initialization result: " << success;
497  // Set exit result.
498  returnValue = success ? EXIT_SUCCESS : EXIT_FAILURE;
499  if(success)
500  {
501  // Log this only after AppInitMain finishes, as then logging setup is guaranteed complete
502  qWarning() << "Platform customization:" << platformStyle->getName();
503 #ifdef ENABLE_WALLET
505  paymentServer->setOptionsModel(optionsModel);
506 #endif
507 
510 
511 #ifdef ENABLE_WALLET
512  // TODO: Expose secondary wallets
513  if (!vpwallets.empty())
514  {
515  walletModel = new WalletModel(platformStyle, vpwallets[0], optionsModel);
516 
517  window->addWallet(FabcoinGUI::DEFAULT_WALLET, walletModel);
518  window->setCurrentWallet(FabcoinGUI::DEFAULT_WALLET);
519 
520  connect(walletModel, SIGNAL(coinsSent(CWallet*,SendCoinsRecipient,QByteArray)),
521  paymentServer, SLOT(fetchPaymentACK(CWallet*,const SendCoinsRecipient&,QByteArray)));
522  }
523 #endif
524 
525  // If -min option passed, start window minimized.
526  if(gArgs.GetBoolArg("-min", false))
527  {
528  window->showMinimized();
529  }
530  else
531  {
532  window->show();
533  }
534  Q_EMIT splashFinished(window);
535 
536 #ifdef ENABLE_WALLET
537  // Now that initialization/startup is done, process any command-line
538  // fabcoin: URIs or payment requests:
539  connect(paymentServer, SIGNAL(receivedPaymentRequest(SendCoinsRecipient)),
540  window, SLOT(handlePaymentRequest(SendCoinsRecipient)));
541  connect(window, SIGNAL(receivedURI(QString)),
542  paymentServer, SLOT(handleURIOrFile(QString)));
543  connect(paymentServer, SIGNAL(message(QString,QString,unsigned int)),
544  window, SLOT(message(QString,QString,unsigned int)));
545  QTimer::singleShot(100, paymentServer, SLOT(uiReady()));
546 #endif
547  } else {
548  quit(); // Exit main loop
549  }
550 }
551 
553 {
554  quit(); // Exit main loop after shutdown finished
555 }
556 
557 void FabcoinApplication::handleRunawayException(const QString &message)
558 {
559  QMessageBox::critical(0, "Runaway exception", FabcoinGUI::tr("A fatal error occurred. Fabcoin can no longer continue safely and will quit.") + QString("\n\n") + message);
560  ::exit(EXIT_FAILURE);
561 }
562 
564 {
565  if (!window)
566  return 0;
567 
568  return window->winId();
569 }
570 
572 {
573 #ifdef ENABLE_WALLET
574  // Restart the wallet if needed
575  if(!restorePath.isEmpty())
576  {
577  // Create command line
578  QString commandLine;
579  QStringList arg = arguments();
580  removeParam(arg, "-reindex");
581  removeParam(arg, "-salvagewallet");
582  if(!arg.contains(restoreParam))
583  {
584  arg.append(restoreParam);
585  }
586  commandLine = arg.join(' ');
587 
588  // Copy the new wallet.dat to the data folder
589  fs::path path = GetDataDir() / "wallet.dat";
590  QString pathWallet = QString::fromStdString(path.string());
591  QFile::remove(pathWallet);
592  if(QFile::copy(restorePath, pathWallet))
593  {
594  // Unlock the data folder
596  QThread::currentThread()->sleep(2);
597 
598  // Create new process and start the wallet
599  QProcess *process = new QProcess();
600  process->start(commandLine);
601  }
602  }
603 #endif
604 }
605 
606 #ifndef FABCOIN_QT_TEST
607 int main(int argc, char *argv[])
608 {
610 
612  // Command-line options take precedence:
613  gArgs.ParseParameters(argc, argv);
614 
615  // Do not refer to data directory yet, this can be overridden by Intro::pickDataDirectory
616 
618 #if QT_VERSION < 0x050000
619  // Internal string conversion is all UTF-8
620  QTextCodec::setCodecForTr(QTextCodec::codecForName("UTF-8"));
621  QTextCodec::setCodecForCStrings(QTextCodec::codecForTr());
622 #endif
623 
624  Q_INIT_RESOURCE(fabcoin);
625  Q_INIT_RESOURCE(fabcoin_locale);
626 
627  FabcoinApplication app(argc, argv);
628 #if QT_VERSION > 0x050100
629  // Generate high-dpi pixmaps
630  QApplication::setAttribute(Qt::AA_UseHighDpiPixmaps);
631 #endif
632 #if QT_VERSION >= 0x050600
633  QGuiApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
634 #endif
635 #ifdef Q_OS_MAC
636  QApplication::setAttribute(Qt::AA_DontShowIconsInMenus);
637 #endif
638 #if QT_VERSION >= 0x050500
639  // Because of the POODLE attack it is recommended to disable SSLv3 (https://disablessl3.com/),
640  // so set SSL protocols to TLS1.0+.
641  QSslConfiguration sslconf = QSslConfiguration::defaultConfiguration();
642  sslconf.setProtocol(QSsl::TlsV1_0OrLater);
643  QSslConfiguration::setDefaultConfiguration(sslconf);
644 #endif
645 
646  // Register meta types used for QMetaObject::invokeMethod
647  qRegisterMetaType< bool* >();
648  // Need to pass name here as CAmount is a typedef (see http://qt-project.org/doc/qt-5/qmetatype.html#qRegisterMetaType)
649  // IMPORTANT if it is no longer a typedef use the normal variant above
650  qRegisterMetaType< CAmount >("CAmount");
651  qRegisterMetaType< std::function<void(void)> >("std::function<void(void)>");
652 
654  // must be set before OptionsModel is initialized or translations are loaded,
655  // as it is used to locate QSettings
656  QApplication::setOrganizationName(QAPP_ORG_NAME);
657  QApplication::setOrganizationDomain(QAPP_ORG_DOMAIN);
658  QApplication::setApplicationName(QAPP_APP_NAME_DEFAULT);
659  GUIUtil::SubstituteFonts(GetLangTerritory());
660 
662  // Now that QSettings are accessible, initialize translations
663  QTranslator qtTranslatorBase, qtTranslator, translatorBase, translator;
664  initTranslations(qtTranslatorBase, qtTranslator, translatorBase, translator);
665  translationInterface.Translate.connect(Translate);
666 
667  // Show help message immediately after parsing command-line options (for "-lang") and setting locale,
668  // but before showing splash screen.
669  if (gArgs.IsArgSet("-?") || gArgs.IsArgSet("-h") || gArgs.IsArgSet("-help") || gArgs.IsArgSet("-version"))
670  {
671  HelpMessageDialog help(nullptr, gArgs.IsArgSet("-version"));
672  help.showOrPrint();
673  return EXIT_SUCCESS;
674  }
675 
677  // User language is set up: pick a data directory
679  return EXIT_SUCCESS;
680 
683  if (!fs::is_directory(GetDataDir(false)))
684  {
685  QMessageBox::critical(0, QObject::tr(PACKAGE_NAME),
686  QObject::tr("Error: Specified data directory \"%1\" does not exist.").arg(QString::fromStdString(gArgs.GetArg("-datadir", ""))));
687  return EXIT_FAILURE;
688  }
689  try {
691  } catch (const std::exception& e) {
692  QMessageBox::critical(0, QObject::tr(PACKAGE_NAME),
693  QObject::tr("Error: Cannot parse configuration file: %1. Only use key=value syntax.").arg(e.what()));
694  return EXIT_FAILURE;
695  }
696 
698  // - Do not call Params() before this step
699  // - Do this after parsing the configuration file, as the network can be switched there
700  // - QSettings() will use the new application name after this, resulting in network-specific settings
701  // - Needs to be done before createOptionsModel
702 
703  // Check for -testnet or -regtest parameter (Params() calls are only valid after this clause)
704  try {
706  } catch(std::exception &e) {
707  QMessageBox::critical(0, QObject::tr(PACKAGE_NAME), QObject::tr("Error: %1").arg(e.what()));
708  return EXIT_FAILURE;
709  }
710 #ifdef ENABLE_WALLET
711  // Parse URIs on command line -- this can affect Params()
713 #endif
714 
715  QScopedPointer<const NetworkStyle> networkStyle(NetworkStyle::instantiate(QString::fromStdString(Params().NetworkIDString())));
716  assert(!networkStyle.isNull());
717  // Allow for separate UI settings for testnets
718  QApplication::setApplicationName(networkStyle->getAppName());
719  // Re-initialize translations after changing application name (language in network-specific settings can be different)
720  initTranslations(qtTranslatorBase, qtTranslator, translatorBase, translator);
721 
722 #ifdef ENABLE_WALLET
723  // - Do this early as we don't want to bother initializing if we are just calling IPC
725  // - Do this *after* setting up the data directory, as the data directory hash is used in the name
726  // of the server.
727  // - Do this after creating app and setting up translations, so errors are
728  // translated properly.
730  exit(EXIT_SUCCESS);
731 
732  // Start up the payment server early, too, so impatient users that click on
733  // fabcoin: links repeatedly have their payment requests routed to this process:
734  app.createPaymentServer();
735 #endif
736 
738  // Install global event filter that makes sure that long tooltips can be word-wrapped
739  app.installEventFilter(new GUIUtil::ToolTipToRichTextFilter(TOOLTIP_WRAP_THRESHOLD, &app));
740 #if QT_VERSION < 0x050000
741  // Install qDebug() message handler to route to debug.log
742  qInstallMsgHandler(DebugMessageHandler);
743 #else
744 #if defined(Q_OS_WIN)
745  // Install global event filter for processing Windows session related Windows messages (WM_QUERYENDSESSION and WM_ENDSESSION)
746  qApp->installNativeEventFilter(new WinShutdownMonitor());
747 #endif
748  // Install qDebug() message handler to route to debug.log
749  qInstallMessageHandler(DebugMessageHandler);
750 #endif
751  // Allow parameter interaction before we create the options model
752  app.parameterSetup();
753  // Load GUI settings from QSettings
754  app.createOptionsModel(gArgs.IsArgSet("-resetguisettings"));
755 
756  // Subscribe to global signals from core
757  uiInterface.InitMessage.connect(InitMessage);
758 
759  if (gArgs.GetBoolArg("-splash", DEFAULT_SPLASHSCREEN) && !gArgs.GetBoolArg("-min", false))
760  app.createSplashScreen(networkStyle.data());
761 
762  int rv = EXIT_SUCCESS;
763  try
764  {
765  SetObjectStyleSheet(&app, StyleSheetNames::App);
766 
767  app.createWindow(networkStyle.data());
768  // Perform base initialization before spinning up initialization/shutdown thread
769  // This is acceptable because this function only contains steps that are quick to execute,
770  // so the GUI thread won't be held up.
772  app.requestInitialize();
773 #if defined(Q_OS_WIN) && QT_VERSION >= 0x050000
774  WinShutdownMonitor::registerShutdownBlockReason(QObject::tr("%1 didn't yet exit safely...").arg(QObject::tr(PACKAGE_NAME)), (HWND)app.getMainWinId());
775 #endif
776  app.exec();
777  app.requestShutdown();
778  app.exec();
779  rv = app.getReturnValue();
780  } else {
781  // A dialog with detailed error will have been shown by InitError()
782  rv = EXIT_FAILURE;
783  }
784  } catch (const std::exception& e) {
785  PrintExceptionContinue(&e, "Runaway exception");
786  app.handleRunawayException(QString::fromStdString(GetWarnings("gui")));
787  } catch (...) {
788  PrintExceptionContinue(nullptr, "Runaway exception");
789  app.handleRunawayException(QString::fromStdString(GetWarnings("gui")));
790  }
791  app.restoreWallet();
792  return rv;
793 }
794 #endif // FABCOIN_QT_TEST
void SubstituteFonts(const QString &language)
Definition: guiutil.cpp:447
void UnlockDataDirectory()
Unlock the data directory.
Definition: init.cpp:1840
void handleRunawayException(const QString &message)
Handle runaway exceptions. Shows a message box with the problem and quits the program.
Definition: fabcoin.cpp:557
static void LoadRootCAs(X509_STORE *store=nullptr)
void initializeResult(bool success)
Definition: fabcoin.cpp:494
#define SetObjectStyleSheet(object, name)
Definition: styleSheet.h:10
void help()
Definition: main.cpp:39
std::vector< CWalletRef > vpwallets
Definition: wallet.cpp:41
void ParseParameters(int argc, const char *const argv[])
Definition: util.cpp:454
void InitLogging()
Initialize the logging infrastructure.
Definition: init.cpp:851
QString restoreParam
Definition: fabcoin.cpp:278
bool IsArgSet(const std::string &strArg)
Return true if the given argument has been manually set.
Definition: util.cpp:498
#define PACKAGE_NAME
Class for the splashscreen with information of the running client.
Definition: splashscreen.h:20
void createWindow(const NetworkStyle *networkStyle)
Create main window.
Definition: fabcoin.cpp:406
void restoreWallet()
Definition: fabcoin.cpp:571
void setClientModel(ClientModel *clientModel)
Set the client model.
Definition: fabcoingui.cpp:599
#define ENABLE_WALLET
static const std::string DEFAULT_UIPLATFORM
Definition: fabcoingui.h:57
void shutdownResult()
QTimer * pollShutdownTimer
Definition: fabcoin.cpp:266
void shutdownResult()
Definition: fabcoin.cpp:552
void StartShutdown()
Definition: init.cpp:122
bool GetBoolArg(const std::string &strArg, bool fDefault)
Return boolean argument or default value.
Definition: util.cpp:520
void PrintExceptionContinue(const std::exception *pex, const char *pszThread)
Definition: util.cpp:586
void DebugMessageHandler(QtMsgType type, const char *msg)
Definition: fabcoin.cpp:156
Fabcoin GUI main class.
Definition: fabcoingui.h:51
std::hash for asio::adress
Definition: Common.h:323
assert(len-trim+(2 *lenIndices)<=WIDTH)
Qt event filter that intercepts ToolTipChange events, and replaces the tooltip with a rich text repre...
Definition: guiutil.h:134
void initializeResult(bool success)
Class encapsulating Fabcoin Core startup and shutdown.
Definition: fabcoin.cpp:188
bool AppInitBasicSetup()
Initialize fabcoin core: Basic context setup.
Definition: init.cpp:885
void ReadConfigFile(const std::string &confPath)
Definition: util.cpp:669
void handleRunawayException(const std::exception *e)
Pass fatal exception message to UI thread.
Definition: fabcoin.cpp:288
static void ipcParseCommandLine(int argc, char *argv[])
void runawayException(const QString &message)
void requestedInitialize()
ClientModel * clientModel
Definition: fabcoin.cpp:264
static bool ipcSendCommandLine()
int64_t CAmount
Amount in lius (Can be negative)
Definition: amount.h:15
boost::thread_group threadGroup
Definition: fabcoin.cpp:208
void InitParameterInteraction()
Parameter interaction: change current parameters depending on various rules.
Definition: init.cpp:774
CTranslationInterface translationInterface
Definition: util.cpp:102
WId getMainWinId() const
Get window identifier of QMainWindow (FabcoinGUI)
Definition: fabcoin.cpp:563
void removeParam(QStringList &list, const QString &param)
Definition: fabcoin.cpp:176
bool AppInitSanityChecks()
Initialization sanity checks: ecc init, sanity checks, dir lock.
Definition: init.cpp:1220
static bool baseInitialize()
Basic initialization, before starting initialization/shutdown thread.
Definition: fabcoin.cpp:294
#define QAPP_ORG_NAME
Definition: guiconstants.h:51
#define LogPrintf(...)
Definition: util.h:153
const char *const FABCOIN_CONF_FILENAME
Definition: util.cpp:91
FabcoinApplication(int &argc, char **argv)
Definition: fabcoin.cpp:346
void Interrupt(boost::thread_group &threadGroup)
Interrupt threads.
Definition: init.cpp:159
void SelectParams(const std::string &network)
Sets the params returned by Params() to those for the given BIP70 chain name.
Main Fabcoin application object.
Definition: fabcoin.cpp:216
void parameterSetup()
parameter interaction/setup based on rules
Definition: fabcoin.cpp:446
void requestInitialize()
Request core initialization.
Definition: fabcoin.cpp:452
FabcoinGUI * window
Definition: fabcoin.cpp:265
static QWidget * showShutdownWindow(FabcoinGUI *window)
void Shutdown()
Definition: init.cpp:171
static const QString DEFAULT_WALLET
Display name for default wallet name.
Definition: fabcoingui.h:56
std::string GetWarnings(const std::string &strFor)
Format a string that describes several potential problems detected by the core.
Definition: warnings.cpp:40
QString restorePath
Definition: fabcoin.cpp:277
int main(int argc, char *argv[])
Definition: fabcoin.cpp:607
void requestShutdown()
Request core shutdown.
Definition: fabcoin.cpp:459
Model for Fabcoin network client.
Definition: clientmodel.h:38
const QString & getName() const
Definition: platformstyle.h:19
void splashFinished(QWidget *window)
bool AppInitParameterInteraction()
Initialization: parameter interaction.
Definition: init.cpp:933
#define LogPrint(category,...)
Definition: util.h:164
#define QAPP_APP_NAME_DEFAULT
Definition: guiconstants.h:53
ArgsManager gArgs
Definition: util.cpp:94
static const PlatformStyle * instantiate(const QString &platformId)
Get style associated with provided platform name, or 0 if not known.
PlatformStyle::TableColorType type
Definition: rpcconsole.cpp:61
Interface from Qt to configuration data structure for Fabcoin client.
Definition: optionsmodel.h:22
#define QAPP_ORG_DOMAIN
Definition: guiconstants.h:52
const CChainParams & Params()
Return the currently selected parameters.
QThread * coreThread
Definition: fabcoin.cpp:262
std::string GetArg(const std::string &strArg, const std::string &strDefault)
Return string argument or default value.
Definition: util.cpp:504
boost::signals2::signal< std::string(const char *psz)> Translate
Translate a message to the native language of the user.
Definition: util.h:50
Interface to Fabcoin wallet from Qt view code.
Definition: walletmodel.h:103
CScheduler scheduler
Definition: fabcoin.cpp:209
std::string ChainNameFromCommandLine()
Looks for -regtest, -testnet and returns the appropriate BIP70 chain name.
A CWallet is an extension of a keystore, which also maintains a set of transactions and balances...
Definition: wallet.h:672
#define e(i)
Definition: sha.cpp:733
"Help message" dialog box
Definition: utilitydialog.h:18
const fs::path & GetDataDir(bool fNetSpecific)
Definition: util.cpp:623
std::unique_ptr< QWidget > shutdownWindow
Definition: fabcoin.cpp:273
bool AppInitLockDataDirectory()
Lock fabcoin core data directory.
Definition: init.cpp:1241
void createOptionsModel(bool resetSettings)
Create options model.
Definition: fabcoin.cpp:401
CClientUIInterface uiInterface
Definition: ui_interface.cpp:8
bool AppInitMain(boost::thread_group &threadGroup, CScheduler &scheduler)
Fabcoin core main initialization.
Definition: init.cpp:1253
void initialize()
Definition: fabcoin.cpp:315
OptionsModel * optionsModel
Definition: fabcoin.cpp:263
int getReturnValue()
Get process return value.
Definition: fabcoin.cpp:242
const PlatformStyle * platformStyle
Definition: fabcoin.cpp:272
void SetupEnvironment()
Definition: util.cpp:904
static bool pickDataDirectory()
Determine data directory.
Definition: intro.cpp:189
void shutdown()
Definition: fabcoin.cpp:329
boost::signals2::signal< void(const std::string &message)> InitMessage
Progress message during initialization.
Definition: ui_interface.h:81
void createSplashScreen(const NetworkStyle *networkStyle)
Create splash screen.
Definition: fabcoin.cpp:415
static const NetworkStyle * instantiate(const QString &networkId)
Get style associated with provided BIP70 network id, or 0 if not known.