Line data Source code
1 : // Copyright (c) 2011-2014 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.
4 :
5 : #ifndef BITCOIN_QT_RPCCONSOLE_H
6 : #define BITCOIN_QT_RPCCONSOLE_H
7 :
8 : #include "guiutil.h"
9 : #include "peertablemodel.h"
10 :
11 : #include "net.h"
12 :
13 : #include <QWidget>
14 :
15 : class ClientModel;
16 : class PlatformStyle;
17 : class RPCTimerInterface;
18 :
19 : namespace Ui {
20 : class RPCConsole;
21 : }
22 :
23 : QT_BEGIN_NAMESPACE
24 : class QMenu;
25 : class QItemSelection;
26 : QT_END_NAMESPACE
27 :
28 : /** Local Bitcoin RPC console. */
29 : class RPCConsole: public QWidget
30 : {
31 0 : Q_OBJECT
32 :
33 : public:
34 : explicit RPCConsole(const PlatformStyle *platformStyle, QWidget *parent);
35 : ~RPCConsole();
36 :
37 : void setClientModel(ClientModel *model);
38 :
39 : enum MessageClass {
40 : MC_ERROR,
41 : MC_DEBUG,
42 : CMD_REQUEST,
43 : CMD_REPLY,
44 : CMD_ERROR
45 : };
46 :
47 : protected:
48 : virtual bool eventFilter(QObject* obj, QEvent *event);
49 : void keyPressEvent(QKeyEvent *);
50 :
51 : private Q_SLOTS:
52 : void on_lineEdit_returnPressed();
53 : void on_tabWidget_currentChanged(int index);
54 : /** open the debug.log from the current datadir */
55 : void on_openDebugLogfileButton_clicked();
56 : /** change the time range of the network traffic graph */
57 : void on_sldGraphRange_valueChanged(int value);
58 : /** update traffic statistics */
59 : void updateTrafficStats(quint64 totalBytesIn, quint64 totalBytesOut);
60 : void resizeEvent(QResizeEvent *event);
61 : void showEvent(QShowEvent *event);
62 : void hideEvent(QHideEvent *event);
63 : /** Show custom context menu on Peers tab */
64 : void showPeersTableContextMenu(const QPoint& point);
65 : /** Show custom context menu on Bans tab */
66 : void showBanTableContextMenu(const QPoint& point);
67 : /** Hides ban table if no bans are present */
68 : void showOrHideBanTableIfRequired();
69 : /** clear the selected node */
70 : void clearSelectedNode();
71 :
72 : public Q_SLOTS:
73 : void clear();
74 : void message(int category, const QString &message, bool html = false);
75 : /** Set number of connections shown in the UI */
76 : void setNumConnections(int count);
77 : /** Set number of blocks and last block date shown in the UI */
78 : void setNumBlocks(int count, const QDateTime& blockDate);
79 : /** Go forward or back in history */
80 : void browseHistory(int offset);
81 : /** Scroll console view to end */
82 : void scrollToEnd();
83 : /** Handle selection of peer in peers list */
84 : void peerSelected(const QItemSelection &selected, const QItemSelection &deselected);
85 : /** Handle updated peer information */
86 : void peerLayoutChanged();
87 : /** Disconnect a selected node on the Peers tab */
88 : void disconnectSelectedNode();
89 : /** Ban a selected node on the Peers tab */
90 : void banSelectedNode(int bantime);
91 : /** Unban a selected node on the Bans tab */
92 : void unbanSelectedNode();
93 :
94 : Q_SIGNALS:
95 : // For RPC command executor
96 : void stopExecutor();
97 : void cmdRequest(const QString &command);
98 :
99 : private:
100 : static QString FormatBytes(quint64 bytes);
101 : void startExecutor();
102 : void setTrafficGraphRange(int mins);
103 : /** show detailed information on ui about selected node */
104 : void updateNodeDetail(const CNodeCombinedStats *stats);
105 :
106 : enum ColumnWidths
107 : {
108 : ADDRESS_COLUMN_WIDTH = 200,
109 : SUBVERSION_COLUMN_WIDTH = 100,
110 : PING_COLUMN_WIDTH = 80,
111 : BANSUBNET_COLUMN_WIDTH = 200,
112 : BANTIME_COLUMN_WIDTH = 250
113 :
114 : };
115 :
116 : Ui::RPCConsole *ui;
117 : ClientModel *clientModel;
118 : QStringList history;
119 : int historyPtr;
120 : NodeId cachedNodeid;
121 : const PlatformStyle *platformStyle;
122 : RPCTimerInterface *rpcTimerInterface;
123 : QMenu *peersTableContextMenu;
124 : QMenu *banTableContextMenu;
125 : };
126 :
127 : #endif // BITCOIN_QT_RPCCONSOLE_H
|