30
30
#include < QSettings>
31
31
#include < QTimer>
32
32
#include < QTranslator>
33
- #include < QWeakPointer>
34
33
#include < QThread>
35
34
#include < QVBoxLayout>
36
35
#include < QLabel>
@@ -56,43 +55,8 @@ Q_IMPORT_PLUGIN(QWindowsIntegrationPlugin);
56
55
// Declare meta types used for QMetaObject::invokeMethod
57
56
Q_DECLARE_METATYPE (bool *)
58
57
59
- // Need a global reference for the notifications to find the GUI and splash screen
60
- static QWeakPointer<BitcoinGUI> guiref;
61
- static QWeakPointer<SplashScreen> splashref;
62
-
63
- static bool ThreadSafeMessageBox (const std::string& message, const std::string& caption, unsigned int style)
64
- {
65
- if (!guiref.isNull ())
66
- {
67
- bool modal = (style & CClientUIInterface::MODAL);
68
- bool ret = false ;
69
- // In case of modal message, use blocking connection to wait for user to click a button
70
- QMetaObject::invokeMethod (guiref.data (), " message" ,
71
- modal ? GUIUtil::blockingGUIThreadConnection () : Qt::QueuedConnection,
72
- Q_ARG (QString, QString::fromStdString (caption)),
73
- Q_ARG (QString, QString::fromStdString (message)),
74
- Q_ARG (unsigned int , style),
75
- Q_ARG (bool *, &ret));
76
- return ret;
77
- }
78
- else
79
- {
80
- LogPrintf (" %s: %s\n " , caption.c_str (), message.c_str ());
81
- fprintf (stderr, " %s: %s\n " , caption.c_str (), message.c_str ());
82
- return false ;
83
- }
84
- }
85
-
86
58
static void InitMessage(const std::string &message)
87
59
{
88
- if (!splashref.isNull ())
89
- {
90
- QMetaObject::invokeMethod (splashref.data (), " showMessage" ,
91
- Qt::QueuedConnection,
92
- Q_ARG (QString, QString::fromStdString (message)),
93
- Q_ARG (int , Qt::AlignBottom|Qt::AlignHCenter),
94
- Q_ARG (QColor, QColor (55 ,55 ,55 )));
95
- }
96
60
LogPrintf (" init message: %s\n " , message.c_str ());
97
61
}
98
62
@@ -199,6 +163,8 @@ class BitcoinApplication: public QApplication
199
163
void createOptionsModel ();
200
164
// / Create main window
201
165
void createWindow (bool isaTestNet);
166
+ // / Create splash screen
167
+ void createSplashScreen (bool isaTestNet);
202
168
203
169
// / Request core initialization
204
170
void requestInitialize ();
@@ -218,6 +184,7 @@ public slots:
218
184
void requestedInitialize ();
219
185
void requestedShutdown ();
220
186
void stopThread ();
187
+ void splashFinished (QWidget *window);
221
188
222
189
private:
223
190
QThread *coreThread;
@@ -295,6 +262,10 @@ BitcoinApplication::~BitcoinApplication()
295
262
emit stopThread ();
296
263
coreThread->wait ();
297
264
LogPrintf (" Stopped thread\n " );
265
+
266
+ delete window;
267
+ delete paymentServer;
268
+ delete optionsModel;
298
269
}
299
270
300
271
void BitcoinApplication::createPaymentServer ()
@@ -310,13 +281,20 @@ void BitcoinApplication::createOptionsModel()
310
281
void BitcoinApplication::createWindow (bool isaTestNet)
311
282
{
312
283
window = new BitcoinGUI (isaTestNet, 0 );
313
- guiref = window;
314
284
315
285
QTimer* pollShutdownTimer = new QTimer (window);
316
286
connect (pollShutdownTimer, SIGNAL (timeout ()), window, SLOT (detectShutdown ()));
317
287
pollShutdownTimer->start (200 );
318
288
}
319
289
290
+ void BitcoinApplication::createSplashScreen (bool isaTestNet)
291
+ {
292
+ SplashScreen *splash = new SplashScreen (QPixmap (), 0 , isaTestNet);
293
+ splash->setAttribute (Qt::WA_DeleteOnClose);
294
+ splash->show ();
295
+ connect (this , SIGNAL (splashFinished (QWidget*)), splash, SLOT (slotFinish (QWidget*)));
296
+ }
297
+
320
298
void BitcoinApplication::startThread ()
321
299
{
322
300
coreThread = new QThread (this );
@@ -348,9 +326,11 @@ void BitcoinApplication::requestShutdown()
348
326
window->hide ();
349
327
window->setClientModel (0 );
350
328
window->removeAllWallets ();
351
- guiref.clear ();
352
329
353
330
delete walletModel;
331
+ walletModel = 0 ;
332
+ delete clientModel;
333
+ clientModel = 0 ;
354
334
355
335
// Show a simple window indicating shutdown status
356
336
QWidget *shutdownWindow = new QWidget ();
@@ -382,8 +362,7 @@ void BitcoinApplication::initializeResult(int retval)
382
362
PaymentServer::LoadRootCAs ();
383
363
paymentServer->setOptionsModel (optionsModel);
384
364
385
- if (!splashref.isNull ())
386
- splashref.data ()->finish (window);
365
+ emit splashFinished (window);
387
366
388
367
clientModel = new ClientModel (optionsModel);
389
368
window->setClientModel (clientModel);
@@ -489,6 +468,7 @@ int main(int argc, char *argv[])
489
468
// Now that QSettings are accessible, initialize translations
490
469
QTranslator qtTranslatorBase, qtTranslator, translatorBase, translator;
491
470
initTranslations (qtTranslatorBase, qtTranslator, translatorBase, translator);
471
+ uiInterface.Translate .connect (Translate);
492
472
493
473
// Show help message immediately after parsing command-line options (for "-lang") and setting locale,
494
474
// but before showing splash screen.
@@ -543,9 +523,7 @@ int main(int argc, char *argv[])
543
523
app.createOptionsModel ();
544
524
545
525
// Subscribe to global signals from core
546
- uiInterface.ThreadSafeMessageBox .connect (ThreadSafeMessageBox);
547
526
uiInterface.InitMessage .connect (InitMessage);
548
- uiInterface.Translate .connect (Translate);
549
527
550
528
// Show help message immediately after parsing command-line options (for "-lang") and setting locale,
551
529
// but before showing splash screen.
@@ -557,12 +535,7 @@ int main(int argc, char *argv[])
557
535
}
558
536
559
537
if (GetBoolArg (" -splash" , true ) && !GetBoolArg (" -min" , false ))
560
- {
561
- SplashScreen *splash = new SplashScreen (QPixmap (), 0 , isaTestNet);
562
- splash->setAttribute (Qt::WA_DeleteOnClose);
563
- splash->show ();
564
- splashref = splash;
565
- }
538
+ app.createSplashScreen (isaTestNet);
566
539
567
540
try
568
541
{
0 commit comments