7 #if defined(HAVE_CONFIG_H)
25 #include "json/json_spirit_value.h"
26 #include <openssl/crypto.h>
37 #if QT_VERSION < 0x050000
54 {
"cmd-request",
":/icons/tx_input"},
55 {
"cmd-reply",
":/icons/tx_output"},
56 {
"cmd-error",
":/icons/tx_output"},
57 {
"misc",
":/icons/tx_inout"},
68 void request(
const QString &command);
71 void reply(
int category,
const QString &command);
74 #include "rpcconsole.moc"
99 STATE_ESCAPE_DOUBLEQUOTED
100 } state = STATE_EATING_SPACES;
102 foreach(
char ch, strCommand)
107 case STATE_EATING_SPACES:
110 case '"': state = STATE_DOUBLEQUOTED;
break;
111 case '\'': state = STATE_SINGLEQUOTED;
break;
112 case '\\': state = STATE_ESCAPE_OUTER;
break;
113 case ' ':
case '\n':
case '\t':
114 if(state == STATE_ARGUMENT)
116 args.push_back(curarg);
119 state = STATE_EATING_SPACES;
121 default: curarg += ch; state = STATE_ARGUMENT;
124 case STATE_SINGLEQUOTED:
127 case '\'': state = STATE_ARGUMENT;
break;
128 default: curarg += ch;
131 case STATE_DOUBLEQUOTED:
134 case '"': state = STATE_ARGUMENT;
break;
135 case '\\': state = STATE_ESCAPE_DOUBLEQUOTED;
break;
136 default: curarg += ch;
139 case STATE_ESCAPE_OUTER:
140 curarg += ch; state = STATE_ARGUMENT;
142 case STATE_ESCAPE_DOUBLEQUOTED:
143 if(ch !=
'"' && ch !=
'\\') curarg +=
'\\';
144 curarg += ch; state = STATE_DOUBLEQUOTED;
150 case STATE_EATING_SPACES:
153 args.push_back(curarg);
162 std::vector<std::string> args;
172 std::string strPrint;
177 RPCConvertValues(args[0], std::vector<std::string>(args.begin() + 1, args.end())));
180 if (result.type() == json_spirit::null_type)
182 else if (result.type() == json_spirit::str_type)
183 strPrint = result.get_str();
185 strPrint = write_string(result,
true);
189 catch (json_spirit::Object& objError)
193 int code = find_value(objError,
"code").get_int();
194 std::string message = find_value(objError,
"message").get_str();
197 catch(std::runtime_error &)
202 catch (std::exception& e)
244 ui->
peerHeading->setText(tr(
"Select a peer to view detailed information."));
258 if(event->type() == QEvent::KeyPress)
260 QKeyEvent *keyevt =
static_cast<QKeyEvent*
>(event);
261 int key = keyevt->key();
262 Qt::KeyboardModifiers mod = keyevt->modifiers();
268 case Qt::Key_PageDown:
279 (!mod && !keyevt->text().isEmpty() && key != Qt::Key_Tab) ||
280 ((mod & Qt::ControlModifier) && key == Qt::Key_V) ||
281 ((mod & Qt::ShiftModifier) && key == Qt::Key_Insert)))
284 QApplication::postEvent(
ui->
lineEdit,
new QKeyEvent(*keyevt));
289 return QDialog::eventFilter(obj, event);
300 connect(model, SIGNAL(numConnectionsChanged(
int)),
this, SLOT(
setNumConnections(
int)));
303 connect(model, SIGNAL(numBlocksChanged(
int)),
this, SLOT(
setNumBlocks(
int)));
306 connect(model, SIGNAL(bytesChanged(quint64,quint64)),
this, SLOT(
updateTrafficStats(quint64, quint64)));
311 ui->
peerWidget->setEditTriggers(QAbstractItemView::NoEditTriggers);
312 ui->
peerWidget->setSelectionBehavior(QAbstractItemView::SelectRows);
313 ui->
peerWidget->setSelectionMode(QAbstractItemView::SingleSelection);
319 connect(
ui->
peerWidget->selectionModel(), SIGNAL(selectionChanged(
const QItemSelection &,
const QItemSelection &)),
320 this, SLOT(
peerSelected(
const QItemSelection &,
const QItemSelection &)));
334 static QString categoryClass(
int category)
341 default:
return "misc";
358 QTextDocument::ImageResource,
366 "td.time { color: #808080; padding-top: 3px; } "
367 "td.message { font-family: monospace; font-size: 12px; } "
368 "td.cmd-request { color: #006060; } "
369 "td.cmd-error { color: red; } "
370 "b { color: #006060; } "
374 tr(
"Use up and down arrows to navigate history, and <b>Ctrl-L</b> to clear screen.") +
"<br>" +
375 tr(
"Type <b>help</b> for an overview of available commands.")),
true);
381 if(windowType() != Qt::Widget)
387 QTime time = QTime::currentTime();
388 QString timeString = time.toString();
390 out +=
"<table><tr><td class=\"time\" width=\"65\">" + timeString +
"</td>";
391 out +=
"<td class=\"icon\" width=\"32\"><img src=\"" + categoryClass(category) +
"\"></td>";
392 out +=
"<td class=\"message " + categoryClass(category) +
"\" valign=\"middle\">";
397 out +=
"</td></tr></table>";
406 QString connections = QString::number(count) +
" (";
458 QThread *thread =
new QThread;
460 executor->moveToThread(thread);
463 connect(executor, SIGNAL(reply(
int,QString)),
this, SLOT(
message(
int,QString)));
465 connect(
this, SIGNAL(
cmdRequest(QString)), executor, SLOT(request(QString)));
470 connect(
this, SIGNAL(
stopExecutor()), executor, SLOT(deleteLater()));
471 connect(
this, SIGNAL(
stopExecutor()), thread, SLOT(quit()));
473 connect(thread, SIGNAL(finished()), thread, SLOT(deleteLater()));
496 scrollbar->setValue(scrollbar->maximum());
501 const int multiplier = 5;
502 int mins = value * multiplier;
509 return QString(tr(
"%1 B")).arg(bytes);
510 if(bytes < 1024 * 1024)
511 return QString(tr(
"%1 KB")).arg(bytes / 1024);
512 if(bytes < 1024 * 1024 * 1024)
513 return QString(tr(
"%1 MB")).arg(bytes / 1024 / 1024);
515 return QString(tr(
"%1 GB")).arg(bytes / 1024 / 1024 / 1024);
524 int hours = mins / 60;
525 int minsLeft = mins % 60;
529 ui->
lblGraphRange->setText(QString(tr(
"%1 h %2 m")).arg(hours).arg(minsLeft));
542 Q_UNUSED(deselected);
558 bool fUnselect =
false;
559 bool fReselect =
false;
566 QModelIndexList selectedModelIndex =
ui->
peerWidget->selectionModel()->selectedIndexes();
567 if (selectedModelIndex.isEmpty())
570 selectedRow = selectedModelIndex.first().row();
576 if (detailNodeRow < 0)
582 ui->
peerHeading->setText(tr(
"Select a peer to view detailed information."));
586 if (detailNodeRow != selectedRow)
597 if (fUnselect && selectedRow >= 0)
599 ui->
peerWidget->selectionModel()->select(QItemSelection(selectedModelIndex.first(), selectedModelIndex.last()),
600 QItemSelectionModel::Deselect);
620 peerAddrDetails +=
"<br />" + tr(
"via %1").arg(QString::fromStdString(stats->
nodeStats.
addrLocal));
655 QWidget::resizeEvent(event);
660 QWidget::showEvent(event);
671 QWidget::hideEvent(event);
int getRowByNodeId(NodeId nodeid)
Local Anoncoin RPC console.
QLabel * berkeleyDBVersion
CNodeStateStats nodeStateStats
static QString FormatBytes(quint64 bytes)
void showEvent(QShowEvent *event)
QPushButton * openDebugLogfileButton
void on_lineEdit_returnPressed()
QLabel * numberOfConnections
void message(int category, const QString &message, bool html=false)
quint64 getTotalBytesRecv() const
bool parseCommandLine(std::vector< std::string > &args, const std::string &strCommand)
Split shell command line into a list of arguments.
QTextEdit * messagesWidget
int getNumConnections(unsigned int flags=CONNECTIONS_ALL) const
Return number of connections, default is in- and outbound (total)
void scrollToEnd()
Scroll console view to end.
json_spirit::Value execute(const std::string &method, const json_spirit::Array ¶ms) const
Execute a method.
QString HtmlEscape(const QString &str, bool fMultiLine)
const struct @5 ICON_MAPPING[]
QString formatClientStartupTime() const
PeerTableModel * getPeerTableModel()
void setupUi(QDialog *RPCConsole)
void on_tabWidget_currentChanged(int index)
void updateNodeDetail(const CNodeCombinedStats *stats)
show detailed information on ui about selected node
void saveWindowGeometry(const QString &strSetting, QWidget *parent)
Save window size and position.
QPushButton * btnClearTrafficGraph
void setClientModel(ClientModel *model)
void resizeEvent(QResizeEvent *event)
void reply(int category, const QString &command)
void browseHistory(int offset)
Go forward or back in history.
bool fNodeStateStatsAvailable
const QSize ICON_SIZE(24, 24)
QString formatDurationStr(int secs)
const int CONSOLE_HISTORY
QDateTime getLastBlockDate() const
QPushButton * clearButton
void request(const QString &command)
QString clientName() const
void peerLayoutChanged()
Handle updated peer information.
const CNodeCombinedStats * getNodeStats(int idx)
QString formatBuildDate() const
void on_openDebugLogfileButton_clicked()
open the debug.log from the current datadir
void restoreWindowGeometry(const QString &strSetting, const QSize &defaultSize, QWidget *parent)
Restore window size and position.
Model for Anoncoin network client.
QLabel * label_berkeleyDBVersion
void hideEvent(QHideEvent *event)
ClientModel * clientModel
TrafficGraphWidget * trafficGraph
QString formatPingTime(double dPingTime)
virtual bool eventFilter(QObject *obj, QEvent *event)
void setTrafficGraphRange(int mins)
quint64 getTotalBytesSent() const
RPCConsole(QWidget *parent)
void updateTrafficStats(quint64 totalBytesIn, quint64 totalBytesOut)
update traffic statistics
void setNumConnections(int count)
Set number of connections shown in the UI.
const CChainParams & Params()
Return the currently selected parameters.
QString formatServicesStr(quint64 mask)
void on_sldGraphRange_valueChanged(int value)
change the time range of the network traffic graph
const int INITIAL_TRAFFIC_GRAPH_MINS
void peerSelected(const QItemSelection &selected, const QItemSelection &deselected)
Handle selection of peer in peers list.
void setNumBlocks(int count)
Set number of blocks shown in the UI.
QString formatFullVersion() const
void cmdRequest(const QString &command)
Array RPCConvertValues(const std::string &strMethod, const std::vector< std::string > &strParams)