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.

rpcconsole.h 5.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  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_RPCCONSOLE_H
  5. #define STARWELS_QT_RPCCONSOLE_H
  6. #include "guiutil.h"
  7. #include "peertablemodel.h"
  8. #include "net.h"
  9. #include <QWidget>
  10. #include <QCompleter>
  11. #include <QThread>
  12. class ClientModel;
  13. class PlatformStyle;
  14. class RPCTimerInterface;
  15. namespace Ui {
  16. class RPCConsole;
  17. }
  18. QT_BEGIN_NAMESPACE
  19. class QMenu;
  20. class QItemSelection;
  21. QT_END_NAMESPACE
  22. /** Local Starwels RPC console. */
  23. class RPCConsole: public QWidget
  24. {
  25. Q_OBJECT
  26. public:
  27. explicit RPCConsole(const PlatformStyle *platformStyle, QWidget *parent);
  28. ~RPCConsole();
  29. static bool RPCParseCommandLine(std::string &strResult, const std::string &strCommand, bool fExecute, std::string * const pstrFilteredOut = nullptr);
  30. static bool RPCExecuteCommandLine(std::string &strResult, const std::string &strCommand, std::string * const pstrFilteredOut = nullptr) {
  31. return RPCParseCommandLine(strResult, strCommand, true, pstrFilteredOut);
  32. }
  33. void setClientModel(ClientModel *model);
  34. enum MessageClass {
  35. MC_ERROR,
  36. MC_DEBUG,
  37. CMD_REQUEST,
  38. CMD_REPLY,
  39. CMD_ERROR
  40. };
  41. enum TabTypes {
  42. TAB_INFO = 0,
  43. TAB_CONSOLE = 1,
  44. TAB_GRAPH = 2,
  45. TAB_PEERS = 3
  46. };
  47. protected:
  48. virtual bool eventFilter(QObject* obj, QEvent *event);
  49. void keyPressEvent(QKeyEvent *);
  50. private Q_SLOTS:
  51. void on_lineEdit_returnPressed();
  52. void on_tabWidget_currentChanged(int index);
  53. /** open the debug.log from the current datadir */
  54. void on_openDebugLogfileButton_clicked();
  55. /** change the time range of the network traffic graph */
  56. void on_sldGraphRange_valueChanged(int value);
  57. /** update traffic statistics */
  58. void updateTrafficStats(quint64 totalBytesIn, quint64 totalBytesOut);
  59. void resizeEvent(QResizeEvent *event);
  60. void showEvent(QShowEvent *event);
  61. void hideEvent(QHideEvent *event);
  62. /** Show custom context menu on Peers tab */
  63. void showPeersTableContextMenu(const QPoint& point);
  64. /** Show custom context menu on Bans tab */
  65. void showBanTableContextMenu(const QPoint& point);
  66. /** Hides ban table if no bans are present */
  67. void showOrHideBanTableIfRequired();
  68. /** clear the selected node */
  69. void clearSelectedNode();
  70. public Q_SLOTS:
  71. void clear(bool clearHistory = true);
  72. void fontBigger();
  73. void fontSmaller();
  74. void setFontSize(int newSize);
  75. /** Append the message to the message widget */
  76. void message(int category, const QString &message, bool html = false);
  77. /** Set number of connections shown in the UI */
  78. void setNumConnections(int count);
  79. /** Set network state shown in the UI */
  80. void setNetworkActive(bool networkActive);
  81. /** Set number of blocks and last block date shown in the UI */
  82. void setNumBlocks(int count, const QDateTime& blockDate, double nVerificationProgress, bool headers);
  83. /** Set size (number of transactions and memory usage) of the mempool in the UI */
  84. void setMempoolSize(long numberOfTxs, size_t dynUsage);
  85. /** Go forward or back in history */
  86. void browseHistory(int offset);
  87. /** Scroll console view to end */
  88. void scrollToEnd();
  89. /** Handle selection of peer in peers list */
  90. void peerSelected(const QItemSelection &selected, const QItemSelection &deselected);
  91. /** Handle selection caching before update */
  92. void peerLayoutAboutToChange();
  93. /** Handle updated peer information */
  94. void peerLayoutChanged();
  95. /** Disconnect a selected node on the Peers tab */
  96. void disconnectSelectedNode();
  97. /** Ban a selected node on the Peers tab */
  98. void banSelectedNode(int bantime);
  99. /** Unban a selected node on the Bans tab */
  100. void unbanSelectedNode();
  101. /** set which tab has the focus (is visible) */
  102. void setTabFocus(enum TabTypes tabType);
  103. Q_SIGNALS:
  104. // For RPC command executor
  105. void stopExecutor();
  106. void cmdRequest(const QString &command);
  107. private:
  108. static QString FormatBytes(quint64 bytes);
  109. void startExecutor();
  110. void setTrafficGraphRange(int mins);
  111. /** show detailed information on ui about selected node */
  112. void updateNodeDetail(const CNodeCombinedStats *stats);
  113. enum ColumnWidths
  114. {
  115. ADDRESS_COLUMN_WIDTH = 200,
  116. SUBVERSION_COLUMN_WIDTH = 150,
  117. PING_COLUMN_WIDTH = 80,
  118. BANSUBNET_COLUMN_WIDTH = 200,
  119. BANTIME_COLUMN_WIDTH = 250
  120. };
  121. Ui::RPCConsole *ui;
  122. ClientModel *clientModel;
  123. QStringList history;
  124. int historyPtr;
  125. QString cmdBeforeBrowsing;
  126. QList<NodeId> cachedNodeids;
  127. const PlatformStyle *platformStyle;
  128. RPCTimerInterface *rpcTimerInterface;
  129. QMenu *peersTableContextMenu;
  130. QMenu *banTableContextMenu;
  131. int consoleFontSize;
  132. QCompleter *autoCompleter;
  133. QThread thread;
  134. /** Update UI with laai info from model. */
  135. void updateNetworkState();
  136. };
  137. #endif // STARWELS_QT_RPCCONSOLE_H