1 // Copyright (c) 2011-2014 The Bitcoin developers
2 // Distributed under the MIT/X11 software license, see the accompanying
3 // file COPYING or http://www.opensource.org/licenses/mit-license.php.
8 #if defined(HAVE_CONFIG_H)
9 #include "config/bitcoin-config.h"
15 #include <QMainWindow>
19 #include <QSystemTrayIcon>
25 class SendCoinsRecipient;
26 class UnitDisplayStatusBarControl;
35 class QProgressDialog;
39 Bitcoin GUI main class. This class represents the main window of the Bitcoin UI. It communicates with both the client and
40 wallet models to give the user an up-to-date view of the current core state.
42 class BitcoinGUI : public QMainWindow
47 static const QString DEFAULT_WALLET;
49 explicit BitcoinGUI(bool fIsTestnet = false, QWidget *parent = 0);
52 /** Set the client model.
53 The client model represents the part of the core that communicates with the P2P network, and is wallet-agnostic.
55 void setClientModel(ClientModel *clientModel);
58 /** Set the wallet model.
59 The wallet model represents a bitcoin wallet, and offers access to the list of transactions, address book and sending
62 bool addWallet(const QString& name, WalletModel *walletModel);
63 bool setCurrentWallet(const QString& name);
64 void removeAllWallets();
68 void changeEvent(QEvent *e);
69 void closeEvent(QCloseEvent *event);
70 void dragEnterEvent(QDragEnterEvent *event);
71 void dropEvent(QDropEvent *event);
72 bool eventFilter(QObject *object, QEvent *event);
75 ClientModel *clientModel;
76 WalletFrame *walletFrame;
78 UnitDisplayStatusBarControl *unitDisplayControl;
79 QLabel *labelEncryptionIcon;
80 QLabel *labelConnectionsIcon;
81 QLabel *labelBlocksIcon;
82 QLabel *progressBarLabel;
83 QProgressBar *progressBar;
84 QProgressDialog *progressDialog;
87 QAction *overviewAction;
88 QAction *historyAction;
90 QAction *sendCoinsAction;
91 QAction *usedSendingAddressesAction;
92 QAction *usedReceivingAddressesAction;
93 QAction *signMessageAction;
94 QAction *verifyMessageAction;
96 QAction *receiveCoinsAction;
97 QAction *optionsAction;
98 QAction *toggleHideAction;
99 QAction *encryptWalletAction;
100 QAction *backupWalletAction;
101 QAction *changePassphraseAction;
102 QAction *aboutQtAction;
103 QAction *openRPCConsoleAction;
105 QAction *showHelpMessageAction;
107 QSystemTrayIcon *trayIcon;
109 Notificator *notificator;
110 RPCConsole *rpcConsole;
112 /** Keep track of previous number of blocks, to detect progress */
116 /** Create the main UI actions. */
117 void createActions(bool fIsTestnet);
118 /** Create the menu bar and sub-menus. */
119 void createMenuBar();
120 /** Create the toolbars */
121 void createToolBars();
122 /** Create system tray icon and notification */
123 void createTrayIcon(bool fIsTestnet);
124 /** Create system tray menu (or setup the dock menu) */
125 void createTrayIconMenu();
127 /** Enable or disable all wallet-related actions */
128 void setWalletActionsEnabled(bool enabled);
130 /** Connect core signals to GUI client */
131 void subscribeToCoreSignals();
132 /** Disconnect core signals from GUI client */
133 void unsubscribeFromCoreSignals();
136 /** Signal raised when a URI was entered or dragged to the GUI */
137 void receivedURI(const QString &uri);
140 /** Set number of connections shown in the UI */
141 void setNumConnections(int count);
142 /** Set number of blocks shown in the UI */
143 void setNumBlocks(int count);
145 /** Notify the user of an event from the core network or transaction handling code.
146 @param[in] title the message box / notification title
147 @param[in] message the displayed text
148 @param[in] style modality and style definitions (icon and used buttons - buttons only for message boxes)
149 @see CClientUIInterface::MessageBoxFlags
150 @param[in] ret pointer to a bool that will be modified to whether Ok was clicked (modal only)
152 void message(const QString &title, const QString &message, unsigned int style, bool *ret = NULL);
155 /** Set the encryption status as shown in the UI.
156 @param[in] status current encryption status
157 @see WalletModel::EncryptionStatus
159 void setEncryptionStatus(int status);
161 bool handlePaymentRequest(const SendCoinsRecipient& recipient);
163 /** Show incoming transaction notification for new transactions. */
164 void incomingTransaction(const QString& date, int unit, const CAmount& amount, const QString& type, const QString& address);
169 /** Switch to overview (home) page */
170 void gotoOverviewPage();
171 /** Switch to history (transactions) page */
172 void gotoHistoryPage();
173 /** Switch to receive coins page */
174 void gotoReceiveCoinsPage();
175 /** Switch to send coins page */
176 void gotoSendCoinsPage(QString addr = "");
178 /** Show Sign/Verify Message dialog and switch to sign message tab */
179 void gotoSignMessageTab(QString addr = "");
180 /** Show Sign/Verify Message dialog and switch to verify message tab */
181 void gotoVerifyMessageTab(QString addr = "");
183 /** Show open dialog */
186 /** Show configuration dialog */
187 void optionsClicked();
188 /** Show about dialog */
190 /** Show help message dialog */
191 void showHelpMessageClicked();
193 /** Handle tray icon clicked */
194 void trayIconActivated(QSystemTrayIcon::ActivationReason reason);
197 /** Show window if hidden, unminimize when minimized, rise when obscured or show if hidden and fToggleHidden is true */
198 void showNormalIfMinimized(bool fToggleHidden = false);
199 /** Simply calls showNormalIfMinimized(true) for use in SLOT() macro */
202 /** called by a timer to check if fRequestShutdown has been set **/
203 void detectShutdown();
205 /** Show progress dialog e.g. for verifychain */
206 void showProgress(const QString &title, int nProgress);
209 class UnitDisplayStatusBarControl : public QLabel
214 explicit UnitDisplayStatusBarControl();
215 /** Lets the control know about the Options Model (and its signals) */
216 void setOptionsModel(OptionsModel *optionsModel);
219 /** So that it responds to left-button clicks */
220 void mousePressEvent(QMouseEvent *event);
223 OptionsModel *optionsModel;
226 /** Shows context menu with Display Unit options by the mouse coordinates */
227 void onDisplayUnitsClicked(const QPoint& point);
228 /** Creates context menu, its actions, and wires up all the relevant signals for mouse events. */
229 void createContextMenu();
232 /** When Display Units are changed on OptionsModel it will refresh the display text of the control on the status bar */
233 void updateDisplayUnit(int newUnits);
234 /** Tells underlying optionsModel to update its current display unit. */
235 void onMenuSelection(QAction* action);
238 #endif // BITCOINGUI_H