Support more than one CScheduler thread for serial clients
[bitcoinplatinum.git] / src / qt / bitcoingui.h
blob8731caafc7757f3032cd413454d44d57e7606785
1 // Copyright (c) 2011-2016 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.
5 #ifndef BITCOIN_QT_BITCOINGUI_H
6 #define BITCOIN_QT_BITCOINGUI_H
8 #if defined(HAVE_CONFIG_H)
9 #include "config/bitcoin-config.h"
10 #endif
12 #include "amount.h"
14 #include <QLabel>
15 #include <QMainWindow>
16 #include <QMap>
17 #include <QMenu>
18 #include <QPoint>
19 #include <QSystemTrayIcon>
21 class ClientModel;
22 class NetworkStyle;
23 class Notificator;
24 class OptionsModel;
25 class PlatformStyle;
26 class RPCConsole;
27 class SendCoinsRecipient;
28 class UnitDisplayStatusBarControl;
29 class WalletFrame;
30 class WalletModel;
31 class HelpMessageDialog;
32 class ModalOverlay;
34 QT_BEGIN_NAMESPACE
35 class QAction;
36 class QProgressBar;
37 class QProgressDialog;
38 QT_END_NAMESPACE
40 /**
41 Bitcoin GUI main class. This class represents the main window of the Bitcoin UI. It communicates with both the client and
42 wallet models to give the user an up-to-date view of the current core state.
44 class BitcoinGUI : public QMainWindow
46 Q_OBJECT
48 public:
49 static const QString DEFAULT_WALLET;
50 static const std::string DEFAULT_UIPLATFORM;
52 explicit BitcoinGUI(const PlatformStyle *platformStyle, const NetworkStyle *networkStyle, QWidget *parent = 0);
53 ~BitcoinGUI();
55 /** Set the client model.
56 The client model represents the part of the core that communicates with the P2P network, and is wallet-agnostic.
58 void setClientModel(ClientModel *clientModel);
60 #ifdef ENABLE_WALLET
61 /** Set the wallet model.
62 The wallet model represents a bitcoin wallet, and offers access to the list of transactions, address book and sending
63 functionality.
65 bool addWallet(const QString& name, WalletModel *walletModel);
66 bool setCurrentWallet(const QString& name);
67 void removeAllWallets();
68 #endif // ENABLE_WALLET
69 bool enableWallet;
71 protected:
72 void changeEvent(QEvent *e);
73 void closeEvent(QCloseEvent *event);
74 void showEvent(QShowEvent *event);
75 void dragEnterEvent(QDragEnterEvent *event);
76 void dropEvent(QDropEvent *event);
77 bool eventFilter(QObject *object, QEvent *event);
79 private:
80 ClientModel *clientModel;
81 WalletFrame *walletFrame;
83 UnitDisplayStatusBarControl *unitDisplayControl;
84 QLabel *labelWalletEncryptionIcon;
85 QLabel *labelWalletHDStatusIcon;
86 QLabel *connectionsControl;
87 QLabel *labelBlocksIcon;
88 QLabel *progressBarLabel;
89 QProgressBar *progressBar;
90 QProgressDialog *progressDialog;
92 QMenuBar *appMenuBar;
93 QAction *overviewAction;
94 QAction *historyAction;
95 QAction *quitAction;
96 QAction *sendCoinsAction;
97 QAction *sendCoinsMenuAction;
98 QAction *usedSendingAddressesAction;
99 QAction *usedReceivingAddressesAction;
100 QAction *signMessageAction;
101 QAction *verifyMessageAction;
102 QAction *aboutAction;
103 QAction *receiveCoinsAction;
104 QAction *receiveCoinsMenuAction;
105 QAction *optionsAction;
106 QAction *toggleHideAction;
107 QAction *encryptWalletAction;
108 QAction *backupWalletAction;
109 QAction *changePassphraseAction;
110 QAction *aboutQtAction;
111 QAction *openRPCConsoleAction;
112 QAction *openAction;
113 QAction *showHelpMessageAction;
115 QSystemTrayIcon *trayIcon;
116 QMenu *trayIconMenu;
117 Notificator *notificator;
118 RPCConsole *rpcConsole;
119 HelpMessageDialog *helpMessageDialog;
120 ModalOverlay *modalOverlay;
122 /** Keep track of previous number of blocks, to detect progress */
123 int prevBlocks;
124 int spinnerFrame;
126 const PlatformStyle *platformStyle;
128 /** Create the main UI actions. */
129 void createActions();
130 /** Create the menu bar and sub-menus. */
131 void createMenuBar();
132 /** Create the toolbars */
133 void createToolBars();
134 /** Create system tray icon and notification */
135 void createTrayIcon(const NetworkStyle *networkStyle);
136 /** Create system tray menu (or setup the dock menu) */
137 void createTrayIconMenu();
139 /** Enable or disable all wallet-related actions */
140 void setWalletActionsEnabled(bool enabled);
142 /** Connect core signals to GUI client */
143 void subscribeToCoreSignals();
144 /** Disconnect core signals from GUI client */
145 void unsubscribeFromCoreSignals();
147 /** Update UI with latest network info from model. */
148 void updateNetworkState();
150 void updateHeadersSyncProgressLabel();
152 Q_SIGNALS:
153 /** Signal raised when a URI was entered or dragged to the GUI */
154 void receivedURI(const QString &uri);
156 public Q_SLOTS:
157 /** Set number of connections shown in the UI */
158 void setNumConnections(int count);
159 /** Set network state shown in the UI */
160 void setNetworkActive(bool networkActive);
161 /** Set number of blocks and last block date shown in the UI */
162 void setNumBlocks(int count, const QDateTime& blockDate, double nVerificationProgress, bool headers);
164 /** Notify the user of an event from the core network or transaction handling code.
165 @param[in] title the message box / notification title
166 @param[in] message the displayed text
167 @param[in] style modality and style definitions (icon and used buttons - buttons only for message boxes)
168 @see CClientUIInterface::MessageBoxFlags
169 @param[in] ret pointer to a bool that will be modified to whether Ok was clicked (modal only)
171 void message(const QString &title, const QString &message, unsigned int style, bool *ret = NULL);
173 #ifdef ENABLE_WALLET
174 /** Set the encryption status as shown in the UI.
175 @param[in] status current encryption status
176 @see WalletModel::EncryptionStatus
178 void setEncryptionStatus(int status);
180 /** Set the hd-enabled status as shown in the UI.
181 @param[in] status current hd enabled status
182 @see WalletModel::EncryptionStatus
184 void setHDStatus(int hdEnabled);
186 bool handlePaymentRequest(const SendCoinsRecipient& recipient);
188 /** Show incoming transaction notification for new transactions. */
189 void incomingTransaction(const QString& date, int unit, const CAmount& amount, const QString& type, const QString& address, const QString& label);
190 #endif // ENABLE_WALLET
192 private Q_SLOTS:
193 #ifdef ENABLE_WALLET
194 /** Switch to overview (home) page */
195 void gotoOverviewPage();
196 /** Switch to history (transactions) page */
197 void gotoHistoryPage();
198 /** Switch to receive coins page */
199 void gotoReceiveCoinsPage();
200 /** Switch to send coins page */
201 void gotoSendCoinsPage(QString addr = "");
203 /** Show Sign/Verify Message dialog and switch to sign message tab */
204 void gotoSignMessageTab(QString addr = "");
205 /** Show Sign/Verify Message dialog and switch to verify message tab */
206 void gotoVerifyMessageTab(QString addr = "");
208 /** Show open dialog */
209 void openClicked();
210 #endif // ENABLE_WALLET
211 /** Show configuration dialog */
212 void optionsClicked();
213 /** Show about dialog */
214 void aboutClicked();
215 /** Show debug window */
216 void showDebugWindow();
217 /** Show debug window and set focus to the console */
218 void showDebugWindowActivateConsole();
219 /** Show help message dialog */
220 void showHelpMessageClicked();
221 #ifndef Q_OS_MAC
222 /** Handle tray icon clicked */
223 void trayIconActivated(QSystemTrayIcon::ActivationReason reason);
224 #endif
226 /** Show window if hidden, unminimize when minimized, rise when obscured or show if hidden and fToggleHidden is true */
227 void showNormalIfMinimized(bool fToggleHidden = false);
228 /** Simply calls showNormalIfMinimized(true) for use in SLOT() macro */
229 void toggleHidden();
231 /** called by a timer to check if fRequestShutdown has been set **/
232 void detectShutdown();
234 /** Show progress dialog e.g. for verifychain */
235 void showProgress(const QString &title, int nProgress);
237 /** When hideTrayIcon setting is changed in OptionsModel hide or show the icon accordingly. */
238 void setTrayIconVisible(bool);
240 /** Toggle networking */
241 void toggleNetworkActive();
243 void showModalOverlay();
246 class UnitDisplayStatusBarControl : public QLabel
248 Q_OBJECT
250 public:
251 explicit UnitDisplayStatusBarControl(const PlatformStyle *platformStyle);
252 /** Lets the control know about the Options Model (and its signals) */
253 void setOptionsModel(OptionsModel *optionsModel);
255 protected:
256 /** So that it responds to left-button clicks */
257 void mousePressEvent(QMouseEvent *event);
259 private:
260 OptionsModel *optionsModel;
261 QMenu* menu;
263 /** Shows context menu with Display Unit options by the mouse coordinates */
264 void onDisplayUnitsClicked(const QPoint& point);
265 /** Creates context menu, its actions, and wires up all the relevant signals for mouse events. */
266 void createContextMenu();
268 private Q_SLOTS:
269 /** When Display Units are changed on OptionsModel it will refresh the display text of the control on the status bar */
270 void updateDisplayUnit(int newUnits);
271 /** Tells underlying optionsModel to update its current display unit. */
272 void onMenuSelection(QAction* action);
275 #endif // BITCOIN_QT_BITCOINGUI_H