You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

starwelsgui.h 9.0KB

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