Skip to content

Commit 46405d6

Browse files
committed
Modifies flow in bitcoin.cpp to support Intro class
This commit implements necessary modifications to Gridcoin's GUI startup to support the ported Bitcoin Intro class. Note that Bitcoin's startup has diverged significantly from Gridcoin over the last few years, so I had to make some adjustments/simplifications to avoid rewriting the whole thing.
1 parent 3f73745 commit 46405d6

File tree

1 file changed

+85
-71
lines changed

1 file changed

+85
-71
lines changed

src/qt/bitcoin.cpp

Lines changed: 85 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#include "researcher/researchermodel.h"
1515
#include "optionsmodel.h"
1616
#include "guiutil.h"
17+
#include "qt/intro.h"
1718
#include "guiconstants.h"
1819
#include "init.h"
1920
#include "ui_interface.h"
@@ -67,7 +68,7 @@ extern bool bGridcoinCoreInitComplete;
6768
static BitcoinGUI *guiref;
6869
static QSplashScreen *splashref;
6970

70-
int StartGridcoinQt(int argc, char *argv[], OptionsModel &optionsModel);
71+
int StartGridcoinQt(int argc, char *argv[], QApplication& app);
7172

7273
static void ThreadSafeMessageBox(const std::string& message, const std::string& caption, int style)
7374
{
@@ -232,10 +233,86 @@ int main(int argc, char *argv[])
232233
ParseParameters(argc, argv);
233234
SelectParams(CBaseChainParams::MAIN);
234235

235-
// We need to early load the optionsModel to get the dataDir that could be stored there.
236-
OptionsModel optionsModel;
236+
// Initiate the app here to support choosing the data directory.
237+
Q_INIT_RESOURCE(bitcoin);
238+
Q_INIT_RESOURCE(bitcoin_locale);
239+
QApplication app(argc, argv);
240+
//uint SEM_FAILCRITICALERRORS= 0x0001;
241+
//uint SEM_NOGPFAULTERRORBOX = 0x0002;
242+
#if defined(WIN32) && defined(QT_GUI)
243+
SetErrorMode(SEM_FAILCRITICALERRORS | SEM_NOGPFAULTERRORBOX);
244+
#endif
245+
246+
// Application identification (must be set before OptionsModel is initialized,
247+
// as it is used to locate QSettings)
248+
app.setOrganizationName("Gridcoin");
249+
//XXX app.setOrganizationDomain("");
250+
if(GetBoolArg("-testnet")) // Separate UI settings for testnet
251+
app.setApplicationName("Gridcoin-Qt-testnet");
252+
else
253+
app.setApplicationName("Gridcoin-Qt");
254+
255+
// Install global event filter that makes sure that long tooltips can be word-wrapped
256+
app.installEventFilter(new GUIUtil::ToolTipToRichTextFilter(TOOLTIP_WRAP_THRESHOLD, &app));
257+
258+
// Install global event filter that suppresses help context question mark
259+
app.installEventFilter(new GUIUtil::WindowContextHelpButtonHintFilter(&app));
260+
261+
#if defined(WIN32) && QT_VERSION >= 0x050000
262+
// Install global event filter for processing Windows session related Windows messages (WM_QUERYENDSESSION and WM_ENDSESSION)
263+
app.installNativeEventFilter(new WinShutdownMonitor());
264+
#endif
265+
266+
// Get desired locale (e.g. "de_DE") from command line or use system locale
267+
QString lang_territory = QString::fromStdString(GetArg("-lang", QLocale::system().name().toStdString()));
268+
QString lang = lang_territory;
269+
// Convert to "de" only by truncating "_DE"
270+
lang.truncate(lang_territory.lastIndexOf('_'));
271+
272+
QTranslator qtTranslatorBase, qtTranslator, translatorBase, translator;
273+
// Load language files for configured locale:
274+
// - First load the translator for the base language, without territory
275+
// - Then load the more specific locale translator
276+
277+
// Load e.g. qt_de.qm
278+
if (qtTranslatorBase.load("qt_" + lang, QLibraryInfo::location(QLibraryInfo::TranslationsPath)))
279+
app.installTranslator(&qtTranslatorBase);
280+
281+
// Load e.g. qt_de_DE.qm
282+
if (qtTranslator.load("qt_" + lang_territory, QLibraryInfo::location(QLibraryInfo::TranslationsPath)))
283+
app.installTranslator(&qtTranslator);
284+
285+
// Load e.g. bitcoin_de.qm (shortcut "de" needs to be defined in bitcoin.qrc)
286+
if (translatorBase.load(lang, ":/translations/"))
287+
app.installTranslator(&translatorBase);
288+
289+
// Load e.g. bitcoin_de_DE.qm (shortcut "de_DE" needs to be defined in bitcoin.qrc)
290+
if (translator.load(lang_territory, ":/translations/"))
291+
app.installTranslator(&translator);
292+
293+
// Now that settings and translations are available, ask user for data directory
294+
bool did_show_intro = false;
295+
// Gracefully exit if the user cancels
296+
if (!Intro::showIfNeeded(did_show_intro)) return EXIT_SUCCESS;
297+
298+
// Determine availability of data directory and parse gridcoinresearch.conf
299+
// Do not call GetDataDir(true) before this step finishes
300+
if (!CheckDataDirOption()) {
301+
ThreadSafeMessageBox(strprintf("Specified data directory \"%s\" does not exist.\n", GetArg("-datadir", "")),
302+
"", CClientUIInterface::ICON_ERROR | CClientUIInterface::OK | CClientUIInterface::MODAL);
303+
QMessageBox::critical(nullptr, PACKAGE_NAME,
304+
QObject::tr("Error: Specified data directory \"%1\" does not exist.")
305+
.arg(QString::fromStdString(GetArg("-datadir", ""))));
306+
return EXIT_FAILURE;
307+
}
308+
if (!ReadConfigFile(mapArgs, mapMultiArgs)) {
309+
ThreadSafeMessageBox(strprintf("Error reading configuration file.\n"),
310+
"", CClientUIInterface::ICON_ERROR | CClientUIInterface::OK | CClientUIInterface::MODAL);
311+
QMessageBox::critical(nullptr, PACKAGE_NAME,
312+
QObject::tr("Error: Cannot parse configuration file."));
313+
return EXIT_FAILURE;
314+
}
237315

238-
ReadConfigFile(mapArgs, mapMultiArgs);
239316
SelectParams(mapArgs.count("-testnet") ? CBaseChainParams::TESTNET : CBaseChainParams::MAIN);
240317

241318
// Initialize logging as early as possible.
@@ -279,7 +356,7 @@ int main(int argc, char *argv[])
279356
}
280357

281358
/** Start Qt as normal before it was moved into this function **/
282-
StartGridcoinQt(argc, argv, optionsModel);
359+
StartGridcoinQt(argc, argv, app);
283360

284361
// We got a request to apply snapshot from GUI Menu selection
285362
// We got this request and everything should be shutdown now.
@@ -325,28 +402,13 @@ int main(int argc, char *argv[])
325402
return 0;
326403
}
327404

328-
int StartGridcoinQt(int argc, char *argv[], OptionsModel& optionsModel)
405+
int StartGridcoinQt(int argc, char *argv[], QApplication& app)
329406
{
330407
// Set global boolean to indicate intended presence of GUI to core.
331408
fQtActive = true;
332409

333410
std::shared_ptr<ThreadHandler> threads = std::make_shared<ThreadHandler>();
334411

335-
Q_INIT_RESOURCE(bitcoin);
336-
Q_INIT_RESOURCE(bitcoin_locale);
337-
QApplication app(argc, argv);
338-
//uint SEM_FAILCRITICALERRORS= 0x0001;
339-
//uint SEM_NOGPFAULTERRORBOX = 0x0002;
340-
#if defined(WIN32) && defined(QT_GUI)
341-
SetErrorMode(SEM_FAILCRITICALERRORS | SEM_NOGPFAULTERRORBOX);
342-
#endif
343-
344-
// Install global event filter that makes sure that long tooltips can be word-wrapped
345-
app.installEventFilter(new GUIUtil::ToolTipToRichTextFilter(TOOLTIP_WRAP_THRESHOLD, &app));
346-
347-
// Install global event filter that suppresses help context question mark
348-
app.installEventFilter(new GUIUtil::WindowContextHelpButtonHintFilter(&app));
349-
350412
#if QT_VERSION < 0x050000
351413
// Install qDebug() message handler to route to debug.log
352414
qInstallMsgHandler(DebugMessageHandler);
@@ -355,56 +417,8 @@ int StartGridcoinQt(int argc, char *argv[], OptionsModel& optionsModel)
355417
qInstallMessageHandler(DebugMessageHandler);
356418
#endif
357419

358-
#if defined(WIN32) && QT_VERSION >= 0x050000
359-
// Install global event filter for processing Windows session related Windows messages (WM_QUERYENDSESSION and WM_ENDSESSION)
360-
app.installNativeEventFilter(new WinShutdownMonitor());
361-
#endif
362-
363-
if (!fs::is_directory(GetDataDir(false)))
364-
{
365-
QMessageBox::critical(0, "Gridcoin",
366-
QString("Error: Specified data directory \"%1\" does not exist.").arg(QString::fromStdString(mapArgs["-datadir"])));
367-
return 1;
368-
}
369-
370-
// Application identification (must be set before OptionsModel is initialized,
371-
// as it is used to locate QSettings)
372-
app.setOrganizationName("Gridcoin");
373-
//XXX app.setOrganizationDomain("");
374-
if(GetBoolArg("-testnet")) // Separate UI settings for testnet
375-
app.setApplicationName("Gridcoin-Qt-testnet");
376-
else
377-
app.setApplicationName("Gridcoin-Qt");
378-
379-
// ... then GUI settings:
380-
//OptionsModel optionsModel;
381-
382-
// Get desired locale (e.g. "de_DE") from command line or use system locale
383-
QString lang_territory = QString::fromStdString(GetArg("-lang", QLocale::system().name().toStdString()));
384-
QString lang = lang_territory;
385-
// Convert to "de" only by truncating "_DE"
386-
lang.truncate(lang_territory.lastIndexOf('_'));
387-
388-
QTranslator qtTranslatorBase, qtTranslator, translatorBase, translator;
389-
// Load language files for configured locale:
390-
// - First load the translator for the base language, without territory
391-
// - Then load the more specific locale translator
392-
393-
// Load e.g. qt_de.qm
394-
if (qtTranslatorBase.load("qt_" + lang, QLibraryInfo::location(QLibraryInfo::TranslationsPath)))
395-
app.installTranslator(&qtTranslatorBase);
396-
397-
// Load e.g. qt_de_DE.qm
398-
if (qtTranslator.load("qt_" + lang_territory, QLibraryInfo::location(QLibraryInfo::TranslationsPath)))
399-
app.installTranslator(&qtTranslator);
400-
401-
// Load e.g. bitcoin_de.qm (shortcut "de" needs to be defined in bitcoin.qrc)
402-
if (translatorBase.load(lang, ":/translations/"))
403-
app.installTranslator(&translatorBase);
404-
405-
// Load e.g. bitcoin_de_DE.qm (shortcut "de_DE" needs to be defined in bitcoin.qrc)
406-
if (translator.load(lang_territory, ":/translations/"))
407-
app.installTranslator(&translator);
420+
// Load the optionsModel.
421+
OptionsModel optionsModel;
408422

409423
// Subscribe to global signals from core
410424
uiInterface.ThreadSafeMessageBox.connect(ThreadSafeMessageBox);

0 commit comments

Comments
 (0)