limenka.h raw
1 // Copyright (c) 2011-2022 The Limenka 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 #ifndef LIMENKA_QT_LIMENKA_H
6 #define LIMENKA_QT_LIMENKA_H
7
8 #include <limenka-build-config.h> // IWYU pragma: keep
9
10 #include <interfaces/chain.h>
11 #include <interfaces/node.h>
12 #include <qt/initexecutor.h>
13
14 #include <assert.h>
15 #include <memory>
16 #include <optional>
17
18 #include <QApplication>
19
20 class LimenkaGUI;
21 class ClientModel;
22 class NetworkStyle;
23 class OptionsModel;
24 class PaymentServer;
25 class PlatformStyle;
26 class SplashScreen;
27 class WalletController;
28 class WalletModel;
29 namespace interfaces {
30 class Init;
31 } // namespace interfaces
32
33
34 /** Main Limenka application object */
35 class LimenkaApplication: public QApplication
36 {
37 Q_OBJECT
38 public:
39 explicit LimenkaApplication();
40 ~LimenkaApplication();
41
42 #ifdef ENABLE_WALLET
43 /// Create payment server
44 void createPaymentServer();
45 #endif
46 /// parameter interaction/setup based on rules
47 void parameterSetup();
48 /// Create options model
49 [[nodiscard]] bool createOptionsModel(bool resetSettings);
50 /// Initialize prune setting
51 void InitPruneSetting(int64_t prune_MiB);
52 /// Create main window
53 void createWindow(const NetworkStyle *networkStyle);
54 /// Create splash screen
55 void createSplashScreen(const NetworkStyle *networkStyle);
56 /// Create or spawn node
57 void createNode(interfaces::Init& init);
58 /// Basic initialization, before starting initialization/shutdown thread. Return true on success.
59 bool baseInitialize();
60
61 /// Request core initialization
62 void requestInitialize();
63
64 /// Get window identifier of QMainWindow (LimenkaGUI)
65 WId getMainWinId() const;
66
67 /// Setup platform style
68 void setupPlatformStyle();
69
70 interfaces::Node& node() const { assert(m_node); return *m_node; }
71
72 public Q_SLOTS:
73 void initializeResult(bool success, interfaces::BlockAndHeaderTipInfo tip_info);
74 /// Request core shutdown
75 void requestShutdown();
76 /// Handle runaway exceptions. Shows a message box with the problem and quits the program.
77 void handleRunawayException(const QString &message);
78
79 /**
80 * A helper function that shows a message box
81 * with details about a non-fatal exception.
82 */
83 void handleNonFatalException(const QString& message);
84
85 Q_SIGNALS:
86 void requestedInitialize();
87 void requestedShutdown();
88 void windowShown(LimenkaGUI* window);
89
90 protected:
91 bool event(QEvent* e) override;
92
93 private:
94 std::optional<InitExecutor> m_executor;
95 OptionsModel* optionsModel{nullptr};
96 ClientModel* clientModel{nullptr};
97 LimenkaGUI* window{nullptr};
98 QTimer* pollShutdownTimer{nullptr};
99 #ifdef ENABLE_WALLET
100 PaymentServer* paymentServer{nullptr};
101 WalletController* m_wallet_controller{nullptr};
102 #endif
103 const PlatformStyle* platformStyle{nullptr};
104 std::unique_ptr<QWidget> shutdownWindow;
105 SplashScreen* m_splash = nullptr;
106 std::unique_ptr<interfaces::Node> m_node;
107
108 void startThread();
109 };
110
111 int GuiMain(int argc, char* argv[]);
112
113 #endif // LIMENKA_QT_LIMENKA_H
114