2015-12-13 08:58:29 -08:00
|
|
|
// Copyright (c) 2011-2015 The Bitcoin Core developers
|
2014-12-12 20:09:33 -08:00
|
|
|
// Distributed under the MIT software license, see the accompanying
|
2013-11-04 07:20:43 -08:00
|
|
|
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
|
|
|
|
2014-11-03 07:16:40 -08:00
|
|
|
#ifndef BITCOIN_QT_RPCCONSOLE_H
|
|
|
|
#define BITCOIN_QT_RPCCONSOLE_H
|
2012-04-09 12:07:25 -07:00
|
|
|
|
2014-05-23 10:09:59 -07:00
|
|
|
#include "guiutil.h"
|
|
|
|
#include "peertablemodel.h"
|
|
|
|
|
2014-06-03 05:42:20 -07:00
|
|
|
#include "net.h"
|
|
|
|
|
2014-11-10 07:41:57 -08:00
|
|
|
#include <QWidget>
|
2016-02-26 19:57:12 -08:00
|
|
|
#include <QCompleter>
|
2016-11-18 07:35:14 -08:00
|
|
|
#include <QThread>
|
2012-04-09 12:07:25 -07:00
|
|
|
|
2013-04-12 22:13:08 -07:00
|
|
|
class ClientModel;
|
2015-07-28 06:20:14 -07:00
|
|
|
class PlatformStyle;
|
2015-08-28 07:46:20 -07:00
|
|
|
class RPCTimerInterface;
|
2013-04-12 22:13:08 -07:00
|
|
|
|
2012-04-09 12:07:25 -07:00
|
|
|
namespace Ui {
|
|
|
|
class RPCConsole;
|
|
|
|
}
|
|
|
|
|
2014-09-05 04:18:35 -07:00
|
|
|
QT_BEGIN_NAMESPACE
|
2015-06-01 06:32:25 -07:00
|
|
|
class QMenu;
|
2014-09-05 04:18:35 -07:00
|
|
|
class QItemSelection;
|
|
|
|
QT_END_NAMESPACE
|
|
|
|
|
2012-05-13 07:09:14 -07:00
|
|
|
/** Local Bitcoin RPC console. */
|
2014-11-10 07:41:57 -08:00
|
|
|
class RPCConsole: public QWidget
|
2012-04-09 12:07:25 -07:00
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
public:
|
2015-07-28 06:20:14 -07:00
|
|
|
explicit RPCConsole(const PlatformStyle *platformStyle, QWidget *parent);
|
2012-04-09 12:07:25 -07:00
|
|
|
~RPCConsole();
|
|
|
|
|
2016-08-20 02:19:35 -07:00
|
|
|
static bool RPCExecuteCommandLine(std::string &strResult, const std::string &strCommand);
|
|
|
|
|
2012-04-09 12:07:25 -07:00
|
|
|
void setClientModel(ClientModel *model);
|
|
|
|
|
|
|
|
enum MessageClass {
|
|
|
|
MC_ERROR,
|
|
|
|
MC_DEBUG,
|
|
|
|
CMD_REQUEST,
|
|
|
|
CMD_REPLY,
|
|
|
|
CMD_ERROR
|
|
|
|
};
|
|
|
|
|
2015-11-12 03:59:26 -08:00
|
|
|
enum TabTypes {
|
|
|
|
TAB_INFO = 0,
|
|
|
|
TAB_CONSOLE = 1,
|
|
|
|
TAB_GRAPH = 2,
|
|
|
|
TAB_PEERS = 3
|
|
|
|
};
|
|
|
|
|
2012-04-09 12:07:25 -07:00
|
|
|
protected:
|
|
|
|
virtual bool eventFilter(QObject* obj, QEvent *event);
|
2014-11-10 07:41:57 -08:00
|
|
|
void keyPressEvent(QKeyEvent *);
|
2012-04-09 12:07:25 -07:00
|
|
|
|
2015-07-14 04:59:05 -07:00
|
|
|
private Q_SLOTS:
|
2012-04-09 12:07:25 -07:00
|
|
|
void on_lineEdit_returnPressed();
|
2012-05-09 08:12:05 -07:00
|
|
|
void on_tabWidget_currentChanged(int index);
|
2012-05-18 05:11:55 -07:00
|
|
|
/** open the debug.log from the current datadir */
|
2012-05-09 13:07:00 -07:00
|
|
|
void on_openDebugLogfileButton_clicked();
|
2013-08-22 09:09:32 -07:00
|
|
|
/** change the time range of the network traffic graph */
|
|
|
|
void on_sldGraphRange_valueChanged(int value);
|
|
|
|
/** update traffic statistics */
|
|
|
|
void updateTrafficStats(quint64 totalBytesIn, quint64 totalBytesOut);
|
2014-05-23 10:09:59 -07:00
|
|
|
void resizeEvent(QResizeEvent *event);
|
|
|
|
void showEvent(QShowEvent *event);
|
|
|
|
void hideEvent(QHideEvent *event);
|
2015-06-01 06:32:25 -07:00
|
|
|
/** Show custom context menu on Peers tab */
|
2015-06-20 11:55:21 -07:00
|
|
|
void showPeersTableContextMenu(const QPoint& point);
|
|
|
|
/** Show custom context menu on Bans tab */
|
|
|
|
void showBanTableContextMenu(const QPoint& point);
|
2015-06-20 12:48:10 -07:00
|
|
|
/** Hides ban table if no bans are present */
|
|
|
|
void showOrHideBanTableIfRequired();
|
2015-06-26 01:23:51 -07:00
|
|
|
/** clear the selected node */
|
|
|
|
void clearSelectedNode();
|
2012-05-09 08:12:05 -07:00
|
|
|
|
2015-07-14 04:59:05 -07:00
|
|
|
public Q_SLOTS:
|
2016-03-11 08:57:10 -08:00
|
|
|
void clear(bool clearHistory = true);
|
2016-01-22 09:00:36 -08:00
|
|
|
void fontBigger();
|
|
|
|
void fontSmaller();
|
|
|
|
void setFontSize(int newSize);
|
2015-10-22 04:33:58 -07:00
|
|
|
/** Append the message to the message widget */
|
2012-05-12 03:30:07 -07:00
|
|
|
void message(int category, const QString &message, bool html = false);
|
2012-04-09 12:07:25 -07:00
|
|
|
/** Set number of connections shown in the UI */
|
|
|
|
void setNumConnections(int count);
|
2013-03-25 19:07:06 -07:00
|
|
|
/** Set network state shown in the UI */
|
|
|
|
void setNetworkActive(bool networkActive);
|
2015-02-09 02:19:01 -08:00
|
|
|
/** Set number of blocks and last block date shown in the UI */
|
2016-04-28 07:18:45 -07:00
|
|
|
void setNumBlocks(int count, const QDateTime& blockDate, double nVerificationProgress, bool headers);
|
2015-11-09 02:45:07 -08:00
|
|
|
/** Set size (number of transactions and memory usage) of the mempool in the UI */
|
|
|
|
void setMempoolSize(long numberOfTxs, size_t dynUsage);
|
2012-04-09 12:07:25 -07:00
|
|
|
/** Go forward or back in history */
|
|
|
|
void browseHistory(int offset);
|
2012-05-14 09:17:12 -07:00
|
|
|
/** Scroll console view to end */
|
|
|
|
void scrollToEnd();
|
2014-05-23 10:09:59 -07:00
|
|
|
/** Handle selection of peer in peers list */
|
|
|
|
void peerSelected(const QItemSelection &selected, const QItemSelection &deselected);
|
2016-11-08 07:41:23 -08:00
|
|
|
/** Handle selection caching before update */
|
|
|
|
void peerLayoutAboutToChange();
|
2014-05-23 10:09:59 -07:00
|
|
|
/** Handle updated peer information */
|
|
|
|
void peerLayoutChanged();
|
2015-06-06 01:38:15 -07:00
|
|
|
/** Disconnect a selected node on the Peers tab */
|
2015-06-01 06:32:25 -07:00
|
|
|
void disconnectSelectedNode();
|
2015-06-19 04:24:34 -07:00
|
|
|
/** Ban a selected node on the Peers tab */
|
|
|
|
void banSelectedNode(int bantime);
|
2015-06-20 11:55:21 -07:00
|
|
|
/** Unban a selected node on the Bans tab */
|
|
|
|
void unbanSelectedNode();
|
2015-11-12 03:59:26 -08:00
|
|
|
/** set which tab has the focus (is visible) */
|
|
|
|
void setTabFocus(enum TabTypes tabType);
|
2013-11-07 23:13:08 -08:00
|
|
|
|
2015-07-14 04:59:05 -07:00
|
|
|
Q_SIGNALS:
|
2012-04-09 12:07:25 -07:00
|
|
|
// For RPC command executor
|
|
|
|
void stopExecutor();
|
|
|
|
void cmdRequest(const QString &command);
|
|
|
|
|
|
|
|
private:
|
2013-08-22 09:09:32 -07:00
|
|
|
static QString FormatBytes(quint64 bytes);
|
2014-06-04 03:06:18 -07:00
|
|
|
void startExecutor();
|
2013-08-22 09:09:32 -07:00
|
|
|
void setTrafficGraphRange(int mins);
|
2014-06-04 03:06:18 -07:00
|
|
|
/** show detailed information on ui about selected node */
|
|
|
|
void updateNodeDetail(const CNodeCombinedStats *stats);
|
|
|
|
|
|
|
|
enum ColumnWidths
|
|
|
|
{
|
|
|
|
ADDRESS_COLUMN_WIDTH = 200,
|
2016-01-20 14:02:24 -08:00
|
|
|
SUBVERSION_COLUMN_WIDTH = 150,
|
2015-06-20 12:48:10 -07:00
|
|
|
PING_COLUMN_WIDTH = 80,
|
2015-06-26 05:55:52 -07:00
|
|
|
BANSUBNET_COLUMN_WIDTH = 200,
|
|
|
|
BANTIME_COLUMN_WIDTH = 250
|
2015-06-20 12:48:10 -07:00
|
|
|
|
2014-06-04 03:06:18 -07:00
|
|
|
};
|
2013-08-22 09:09:32 -07:00
|
|
|
|
2012-04-09 12:07:25 -07:00
|
|
|
Ui::RPCConsole *ui;
|
|
|
|
ClientModel *clientModel;
|
|
|
|
QStringList history;
|
|
|
|
int historyPtr;
|
2016-11-08 07:41:23 -08:00
|
|
|
QList<NodeId> cachedNodeids;
|
2015-07-28 06:20:14 -07:00
|
|
|
const PlatformStyle *platformStyle;
|
2015-08-28 07:46:20 -07:00
|
|
|
RPCTimerInterface *rpcTimerInterface;
|
2015-06-20 11:55:21 -07:00
|
|
|
QMenu *peersTableContextMenu;
|
|
|
|
QMenu *banTableContextMenu;
|
2016-01-22 09:00:36 -08:00
|
|
|
int consoleFontSize;
|
2016-02-26 19:57:12 -08:00
|
|
|
QCompleter *autoCompleter;
|
2016-11-18 07:35:14 -08:00
|
|
|
QThread thread;
|
2013-03-25 19:07:06 -07:00
|
|
|
|
|
|
|
/** Update UI with latest network info from model. */
|
|
|
|
void updateNetworkState();
|
2012-04-09 12:07:25 -07:00
|
|
|
};
|
|
|
|
|
2014-11-03 07:16:40 -08:00
|
|
|
#endif // BITCOIN_QT_RPCCONSOLE_H
|