|
6 | 6 | #include <config/bitcoin-config.h>
|
7 | 7 | #endif
|
8 | 8 |
|
| 9 | +#include <qt/bitcoin.h> |
9 | 10 | #include <qt/bitcoingui.h>
|
10 | 11 |
|
11 | 12 | #include <chainparams.h>
|
@@ -71,11 +72,6 @@ Q_DECLARE_METATYPE(bool*)
|
71 | 72 | Q_DECLARE_METATYPE(CAmount)
|
72 | 73 | Q_DECLARE_METATYPE(uint256)
|
73 | 74 |
|
74 |
| -/** Translate string to current locale using Qt. */ |
75 |
| -const std::function<std::string(const char*)> G_TRANSLATION_FUN = [](const char* psz) { |
76 |
| - return QCoreApplication::translate("bitcoin-core", psz).toStdString(); |
77 |
| -}; |
78 |
| - |
79 | 75 | static QString GetLangTerritory()
|
80 | 76 | {
|
81 | 77 | QSettings settings;
|
@@ -140,101 +136,6 @@ void DebugMessageHandler(QtMsgType type, const QMessageLogContext& context, cons
|
140 | 136 | }
|
141 | 137 | }
|
142 | 138 |
|
143 |
| -/** Class encapsulating Bitcoin Core startup and shutdown. |
144 |
| - * Allows running startup and shutdown in a different thread from the UI thread. |
145 |
| - */ |
146 |
| -class BitcoinCore: public QObject |
147 |
| -{ |
148 |
| - Q_OBJECT |
149 |
| -public: |
150 |
| - explicit BitcoinCore(interfaces::Node& node); |
151 |
| - |
152 |
| -public Q_SLOTS: |
153 |
| - void initialize(); |
154 |
| - void shutdown(); |
155 |
| - |
156 |
| -Q_SIGNALS: |
157 |
| - void initializeResult(bool success); |
158 |
| - void shutdownResult(); |
159 |
| - void runawayException(const QString &message); |
160 |
| - |
161 |
| -private: |
162 |
| - /// Pass fatal exception message to UI thread |
163 |
| - void handleRunawayException(const std::exception *e); |
164 |
| - |
165 |
| - interfaces::Node& m_node; |
166 |
| -}; |
167 |
| - |
168 |
| -/** Main Bitcoin application object */ |
169 |
| -class BitcoinApplication: public QApplication |
170 |
| -{ |
171 |
| - Q_OBJECT |
172 |
| -public: |
173 |
| - explicit BitcoinApplication(interfaces::Node& node, int &argc, char **argv); |
174 |
| - ~BitcoinApplication(); |
175 |
| - |
176 |
| -#ifdef ENABLE_WALLET |
177 |
| - /// Create payment server |
178 |
| - void createPaymentServer(); |
179 |
| -#endif |
180 |
| - /// parameter interaction/setup based on rules |
181 |
| - void parameterSetup(); |
182 |
| - /// Create options model |
183 |
| - void createOptionsModel(bool resetSettings); |
184 |
| - /// Create main window |
185 |
| - void createWindow(const NetworkStyle *networkStyle); |
186 |
| - /// Create splash screen |
187 |
| - void createSplashScreen(const NetworkStyle *networkStyle); |
188 |
| - |
189 |
| - /// Request core initialization |
190 |
| - void requestInitialize(); |
191 |
| - /// Request core shutdown |
192 |
| - void requestShutdown(); |
193 |
| - |
194 |
| - /// Get process return value |
195 |
| - int getReturnValue() const { return returnValue; } |
196 |
| - |
197 |
| - /// Get window identifier of QMainWindow (BitcoinGUI) |
198 |
| - WId getMainWinId() const; |
199 |
| - |
200 |
| - /// Setup platform style |
201 |
| - void setupPlatformStyle(); |
202 |
| - |
203 |
| -public Q_SLOTS: |
204 |
| - void initializeResult(bool success); |
205 |
| - void shutdownResult(); |
206 |
| - /// Handle runaway exceptions. Shows a message box with the problem and quits the program. |
207 |
| - void handleRunawayException(const QString &message); |
208 |
| - void addWallet(WalletModel* walletModel); |
209 |
| - void removeWallet(); |
210 |
| - |
211 |
| -Q_SIGNALS: |
212 |
| - void requestedInitialize(); |
213 |
| - void requestedShutdown(); |
214 |
| - void stopThread(); |
215 |
| - void splashFinished(); |
216 |
| - |
217 |
| -private: |
218 |
| - QThread *coreThread; |
219 |
| - interfaces::Node& m_node; |
220 |
| - OptionsModel *optionsModel; |
221 |
| - ClientModel *clientModel; |
222 |
| - BitcoinGUI *window; |
223 |
| - QTimer *pollShutdownTimer; |
224 |
| -#ifdef ENABLE_WALLET |
225 |
| - PaymentServer* paymentServer; |
226 |
| - std::vector<WalletModel*> m_wallet_models; |
227 |
| - std::unique_ptr<interfaces::Handler> m_handler_load_wallet; |
228 |
| -#endif |
229 |
| - int returnValue; |
230 |
| - const PlatformStyle *platformStyle; |
231 |
| - std::unique_ptr<QWidget> shutdownWindow; |
232 |
| - |
233 |
| - void startThread(); |
234 |
| -}; |
235 |
| - |
236 |
| -#include <qt/bitcoin.moc> |
237 |
| - |
238 | 139 | BitcoinCore::BitcoinCore(interfaces::Node& node) :
|
239 | 140 | QObject(), m_node(node)
|
240 | 141 | {
|
@@ -358,6 +259,11 @@ void BitcoinApplication::createSplashScreen(const NetworkStyle *networkStyle)
|
358 | 259 | connect(this, &BitcoinApplication::requestedShutdown, splash, &QWidget::close);
|
359 | 260 | }
|
360 | 261 |
|
| 262 | +bool BitcoinApplication::baseInitialize() |
| 263 | +{ |
| 264 | + return m_node.baseInitialize(); |
| 265 | +} |
| 266 | + |
361 | 267 | void BitcoinApplication::startThread()
|
362 | 268 | {
|
363 | 269 | if(coreThread)
|
@@ -467,7 +373,7 @@ void BitcoinApplication::initializeResult(bool success)
|
467 | 373 | #ifdef ENABLE_BIP70
|
468 | 374 | PaymentServer::LoadRootCAs();
|
469 | 375 | #endif
|
470 |
| - paymentServer->setOptionsModel(optionsModel); |
| 376 | + if (paymentServer) paymentServer->setOptionsModel(optionsModel); |
471 | 377 | #endif
|
472 | 378 |
|
473 | 379 | clientModel = new ClientModel(m_node, optionsModel);
|
@@ -496,16 +402,19 @@ void BitcoinApplication::initializeResult(bool success)
|
496 | 402 | window->show();
|
497 | 403 | }
|
498 | 404 | Q_EMIT splashFinished();
|
| 405 | + Q_EMIT windowShown(window); |
499 | 406 |
|
500 | 407 | #ifdef ENABLE_WALLET
|
501 | 408 | // Now that initialization/startup is done, process any command-line
|
502 | 409 | // bitcoin: URIs or payment requests:
|
503 |
| - connect(paymentServer, &PaymentServer::receivedPaymentRequest, window, &BitcoinGUI::handlePaymentRequest); |
504 |
| - connect(window, &BitcoinGUI::receivedURI, paymentServer, &PaymentServer::handleURIOrFile); |
505 |
| - connect(paymentServer, &PaymentServer::message, [this](const QString& title, const QString& message, unsigned int style) { |
506 |
| - window->message(title, message, style); |
507 |
| - }); |
508 |
| - QTimer::singleShot(100, paymentServer, &PaymentServer::uiReady); |
| 410 | + if (paymentServer) { |
| 411 | + connect(paymentServer, &PaymentServer::receivedPaymentRequest, window, &BitcoinGUI::handlePaymentRequest); |
| 412 | + connect(window, &BitcoinGUI::receivedURI, paymentServer, &PaymentServer::handleURIOrFile); |
| 413 | + connect(paymentServer, &PaymentServer::message, [this](const QString& title, const QString& message, unsigned int style) { |
| 414 | + window->message(title, message, style); |
| 415 | + }); |
| 416 | + QTimer::singleShot(100, paymentServer, &PaymentServer::uiReady); |
| 417 | + } |
509 | 418 | #endif
|
510 | 419 | pollShutdownTimer->start(200);
|
511 | 420 | } else {
|
@@ -548,7 +457,7 @@ static void SetupUIArgs()
|
548 | 457 | }
|
549 | 458 |
|
550 | 459 | #ifndef BITCOIN_QT_TEST
|
551 |
| -int main(int argc, char *argv[]) |
| 460 | +int GuiMain(int argc, char* argv[]) |
552 | 461 | {
|
553 | 462 | #ifdef WIN32
|
554 | 463 | util::WinCmdLineArgs winArgs;
|
@@ -706,7 +615,7 @@ int main(int argc, char *argv[])
|
706 | 615 | // Perform base initialization before spinning up initialization/shutdown thread
|
707 | 616 | // This is acceptable because this function only contains steps that are quick to execute,
|
708 | 617 | // so the GUI thread won't be held up.
|
709 |
| - if (node->baseInitialize()) { |
| 618 | + if (app.baseInitialize()) { |
710 | 619 | app.requestInitialize();
|
711 | 620 | #if defined(Q_OS_WIN)
|
712 | 621 | WinShutdownMonitor::registerShutdownBlockReason(QObject::tr("%1 didn't yet exit safely...").arg(QObject::tr(PACKAGE_NAME)), (HWND)app.getMainWinId());
|
|
0 commit comments