X-Git-Url: https://git.novaco.in/?p=novacoin.git;a=blobdiff_plain;f=src%2Fqt%2Frpcconsole.cpp;h=c793bf9856e675616dd1c69a567e76471f95543f;hp=3d498f017a83a057edf1f5351ac4d7ffde5f629a;hb=ce035e7bc7cbdd5d645d1c63cda6863fc46a39b8;hpb=7ac0ffc894b6a23aa2e3a1e0939a15fe95fe9eca diff --git a/src/qt/rpcconsole.cpp b/src/qt/rpcconsole.cpp index 3d498f0..c793bf9 100644 --- a/src/qt/rpcconsole.cpp +++ b/src/qt/rpcconsole.cpp @@ -15,15 +15,17 @@ #include #include +#include // TODO: make it possible to filter out categories (esp debug messages when implemented) // TODO: receive errors and debug messages through ClientModel -const int CONSOLE_SCROLLBACK = 50; const int CONSOLE_HISTORY = 50; const QSize ICON_SIZE(24, 24); +const int INITIAL_TRAFFIC_GRAPH_MINS = 30; + const struct { const char *url; const char *source; @@ -187,7 +189,7 @@ void RPCExecutor::request(const QString &command) } RPCConsole::RPCConsole(QWidget *parent) : - QDialog(parent, DIALOGWINDOWHINTS), + QWidget(parent), ui(new Ui::RPCConsole), historyPtr(0) { @@ -195,6 +197,7 @@ RPCConsole::RPCConsole(QWidget *parent) : #ifndef Q_OS_MAC ui->openDebugLogfileButton->setIcon(QIcon(":/icons/export")); + ui->openConfigurationfileButton->setIcon(QIcon(":/icons/export")); ui->showCLOptionsButton->setIcon(QIcon(":/icons/options")); #endif @@ -203,11 +206,14 @@ RPCConsole::RPCConsole(QWidget *parent) : ui->messagesWidget->installEventFilter(this); connect(ui->clearButton, SIGNAL(clicked()), this, SLOT(clear())); + connect(ui->btnClearTrafficGraph, SIGNAL(clicked()), ui->trafficGraph, SLOT(clear())); - // set OpenSSL version label + // set library version labels ui->openSSLVersion->setText(SSLeay_version(SSLEAY_VERSION)); + ui->berkeleyDBVersion->setText(DbEnv::version(0, 0, 0)); startExecutor(); + setTrafficGraphRange(INITIAL_TRAFFIC_GRAPH_MINS); clear(); } @@ -251,18 +257,21 @@ bool RPCConsole::eventFilter(QObject* obj, QEvent *event) } } } - return QDialog::eventFilter(obj, event); + return QWidget::eventFilter(obj, event); } void RPCConsole::setClientModel(ClientModel *model) { this->clientModel = model; + ui->trafficGraph->setClientModel(model); if(model) { // Subscribe to information, replies, messages, errors connect(model, SIGNAL(numConnectionsChanged(int)), this, SLOT(setNumConnections(int))); connect(model, SIGNAL(numBlocksChanged(int,int)), this, SLOT(setNumBlocks(int,int))); + updateTrafficStats(model->getTotalBytesRecv(), model->getTotalBytesSent()); + connect(model, SIGNAL(bytesChanged(quint64,quint64)), this, SLOT(updateTrafficStats(quint64, quint64))); // Provide initial values ui->clientVersion->setText(model->formatFullVersion()); ui->clientName->setText(model->clientName()); @@ -290,6 +299,8 @@ static QString categoryClass(int category) void RPCConsole::clear() { ui->messagesWidget->clear(); + history.clear(); + historyPtr = 0; ui->lineEdit->clear(); ui->lineEdit->setFocus(); @@ -307,7 +318,7 @@ void RPCConsole::clear() ui->messagesWidget->document()->setDefaultStyleSheet( "table { }" "td.time { color: #808080; padding-top: 3px; } " - "td.message { font-family: Monospace; font-size: 12px; } " + "td.message { font-family: Monospace; } " "td.cmd-request { color: #006060; } " "td.cmd-error { color: red; } " "b { color: #006060; } " @@ -336,7 +347,14 @@ void RPCConsole::message(int category, const QString &message, bool html) void RPCConsole::setNumConnections(int count) { - ui->numberOfConnections->setText(QString::number(count)); + if (!clientModel) + return; + + QString connections = QString::number(count) + " ("; + connections += tr("Inbound:") + " " + QString::number(clientModel->getNumConnections(CONNECTIONS_IN)) + " / "; + connections += tr("Outbound:") + " " + QString::number(clientModel->getNumConnections(CONNECTIONS_OUT)) + ")"; + + ui->numberOfConnections->setText(connections); } void RPCConsole::setNumBlocks(int count, int countOfPeers) @@ -360,8 +378,8 @@ void RPCConsole::on_lineEdit_returnPressed() { message(CMD_REQUEST, cmd); emit cmdRequest(cmd); - // Truncate history from current position - history.erase(history.begin() + historyPtr, history.end()); + // Remove command, if already in history + history.removeOne(cmd); // Append command to history history.append(cmd); // Enforce maximum history size @@ -425,6 +443,11 @@ void RPCConsole::on_openDebugLogfileButton_clicked() GUIUtil::openDebugLogfile(); } +void RPCConsole::on_openConfigurationfileButton_clicked() +{ + GUIUtil::openConfigfile(); +} + void RPCConsole::scrollToEnd() { QScrollBar *scrollbar = ui->messagesWidget->verticalScrollBar(); @@ -436,3 +459,69 @@ void RPCConsole::on_showCLOptionsButton_clicked() GUIUtil::HelpMessageBox help; help.exec(); } +void RPCConsole::on_sldGraphRange_valueChanged(int value) +{ + const int multiplier = 5; // each position on the slider represents 5 min + int mins = value * multiplier; + setTrafficGraphRange(mins); +} + +QString RPCConsole::FormatBytes(quint64 bytes) +{ + if(bytes < 1024) + return QString(tr("%1 B")).arg(bytes); + if(bytes < 1024 * 1024) + return QString(tr("%1 KB")).arg(bytes / 1024); + if(bytes < 1024 * 1024 * 1024) + return QString(tr("%1 MB")).arg(bytes / 1024 / 1024); + + return QString(tr("%1 GB")).arg(bytes / 1024 / 1024 / 1024); +} + +void RPCConsole::setTrafficGraphRange(int mins) +{ + ui->trafficGraph->setGraphRangeMins(mins); + ui->lblGraphRange->setText(GUIUtil::formatDurationStr(mins * 60)); +} + +void RPCConsole::updateTrafficStats(quint64 totalBytesIn, quint64 totalBytesOut) +{ + ui->lblBytesIn->setText(FormatBytes(totalBytesIn)); + ui->lblBytesOut->setText(FormatBytes(totalBytesOut)); +} + +void RPCConsole::resizeEvent(QResizeEvent *event) +{ + QWidget::resizeEvent(event); +} + +void RPCConsole::showEvent(QShowEvent *event) +{ + QWidget::showEvent(event); + + if (!clientModel) + return; +} + +void RPCConsole::hideEvent(QHideEvent *event) +{ + QWidget::hideEvent(event); + + if (!clientModel) + return; +} + +void RPCConsole::keyPressEvent(QKeyEvent *event) +{ +#ifdef ANDROID + if(windowType() != Qt::Widget && event->key() == Qt::Key_Back) + { + close(); + } +#else + if(windowType() != Qt::Widget && event->key() == Qt::Key_Escape) + { + close(); + } +#endif +}