2 #include "ui_rpcconsole.h"
11 #if QT_VERSION < 0x050000
16 #include <openssl/crypto.h>
29 {
"cmd-request",
":/icons/tx_input"},
30 {
"cmd-reply",
":/icons/tx_output"},
31 {
"cmd-error",
":/icons/tx_output"},
32 {
"misc",
":/icons/tx_inout"},
43 void request(
const QString &command);
46 void reply(
int category,
const QString &command);
49 #include "rpcconsole.moc"
74 STATE_ESCAPE_DOUBLEQUOTED
75 }
state = STATE_EATING_SPACES;
77 foreach(
char ch, strCommand)
82 case STATE_EATING_SPACES:
85 case '"':
state = STATE_DOUBLEQUOTED;
break;
86 case '\'':
state = STATE_SINGLEQUOTED;
break;
87 case '\\':
state = STATE_ESCAPE_OUTER;
break;
88 case ' ':
case '\n':
case '\t':
89 if(
state == STATE_ARGUMENT)
91 args.push_back(curarg);
94 state = STATE_EATING_SPACES;
96 default: curarg += ch;
state = STATE_ARGUMENT;
99 case STATE_SINGLEQUOTED:
102 case '\'':
state = STATE_ARGUMENT;
break;
103 default: curarg += ch;
106 case STATE_DOUBLEQUOTED:
109 case '"':
state = STATE_ARGUMENT;
break;
110 case '\\':
state = STATE_ESCAPE_DOUBLEQUOTED;
break;
111 default: curarg += ch;
114 case STATE_ESCAPE_OUTER:
115 curarg += ch;
state = STATE_ARGUMENT;
117 case STATE_ESCAPE_DOUBLEQUOTED:
118 if(ch !=
'"' && ch !=
'\\') curarg +=
'\\';
119 curarg += ch;
state = STATE_DOUBLEQUOTED;
125 case STATE_EATING_SPACES:
128 args.push_back(curarg);
137 std::vector<std::string> args;
147 std::string strPrint;
152 RPCConvertValues(args[0], std::vector<std::string>(args.begin() + 1, args.end())));
168 int code =
find_value(objError,
"code").get_int();
169 std::string message =
find_value(objError,
"message").get_str();
172 catch(std::runtime_error &)
177 catch (std::exception& e)
192 ui->openDebugLogfileButton->setIcon(QIcon(
":/icons/export"));
193 ui->showCLOptionsButton->setIcon(QIcon(
":/icons/options"));
197 ui->lineEdit->installEventFilter(
this);
198 ui->messagesWidget->installEventFilter(
this);
200 connect(
ui->clearButton, SIGNAL(clicked()),
this, SLOT(
clear()));
203 ui->openSSLVersion->setText(SSLeay_version(SSLEAY_VERSION));
218 if(event->type() == QEvent::KeyPress)
220 QKeyEvent *keyevt =
static_cast<QKeyEvent*
>(event);
221 int key = keyevt->key();
222 Qt::KeyboardModifiers mod = keyevt->modifiers();
225 case Qt::Key_Up:
if(obj ==
ui->lineEdit) {
browseHistory(-1);
return true; }
break;
226 case Qt::Key_Down:
if(obj ==
ui->lineEdit) {
browseHistory(1);
return true; }
break;
228 case Qt::Key_PageDown:
229 if(obj ==
ui->lineEdit)
231 QApplication::postEvent(
ui->messagesWidget,
new QKeyEvent(*keyevt));
238 if(obj ==
ui->messagesWidget && (
239 (!mod && !keyevt->text().isEmpty() && key != Qt::Key_Tab) ||
240 ((mod & Qt::ControlModifier) && key == Qt::Key_V) ||
241 ((mod & Qt::ShiftModifier) && key == Qt::Key_Insert)))
243 ui->lineEdit->setFocus();
244 QApplication::postEvent(
ui->lineEdit,
new QKeyEvent(*keyevt));
249 return QDialog::eventFilter(obj, event);
258 connect(model, SIGNAL(numConnectionsChanged(
int)),
this, SLOT(
setNumConnections(
int)));
259 connect(model, SIGNAL(numBlocksChanged(
int,
int)),
this, SLOT(
setNumBlocks(
int,
int)));
272 static QString categoryClass(
int category)
279 default:
return "misc";
285 ui->messagesWidget->clear();
288 ui->lineEdit->clear();
289 ui->lineEdit->setFocus();
295 ui->messagesWidget->document()->addResource(
296 QTextDocument::ImageResource,
302 ui->messagesWidget->document()->setDefaultStyleSheet(
304 "td.time { color: #808080; padding-top: 3px; } "
305 "td.message { font-family: Monospace; font-size: 12px; } "
306 "td.cmd-request { color: #006060; } "
307 "td.cmd-error { color: red; } "
308 "b { color: #006060; } "
311 message(
CMD_REPLY, (tr(
"Welcome to the Feathercoin RPC console.") +
"<br>" +
312 tr(
"Use up and down arrows to navigate history, and <b>Ctrl-L</b> to clear screen.") +
"<br>" +
313 tr(
"Type <b>help</b> for an overview of available commands.")),
true);
318 QTime time = QTime::currentTime();
319 QString timeString = time.toString();
321 out +=
"<table><tr><td class=\"time\" width=\"65\">" + timeString +
"</td>";
322 out +=
"<td class=\"icon\" width=\"32\"><img src=\"" + categoryClass(category) +
"\"></td>";
323 out +=
"<td class=\"message " + categoryClass(category) +
"\" valign=\"middle\">";
328 out +=
"</td></tr></table>";
329 ui->messagesWidget->append(out);
334 ui->numberOfConnections->setText(QString::number(count));
339 ui->numberOfBlocks->setText(QString::number(count));
341 ui->totalBlocks->setText(countOfPeers == 0 ? tr(
"N/A") : QString::number(countOfPeers));
348 QString cmd =
ui->lineEdit->text();
349 ui->lineEdit->clear();
379 ui->lineEdit->setText(cmd);
384 QThread *thread =
new QThread;
386 executor->moveToThread(thread);
389 connect(executor, SIGNAL(reply(
int,QString)),
this, SLOT(
message(
int,QString)));
391 connect(
this, SIGNAL(
cmdRequest(QString)), executor, SLOT(request(QString)));
396 connect(
this, SIGNAL(
stopExecutor()), executor, SLOT(deleteLater()));
397 connect(
this, SIGNAL(
stopExecutor()), thread, SLOT(quit()));
399 connect(thread, SIGNAL(finished()), thread, SLOT(deleteLater()));
408 if(
ui->tabWidget->widget(index) ==
ui->tab_console)
410 ui->lineEdit->setFocus();
421 QScrollBar *scrollbar =
ui->messagesWidget->verticalScrollBar();
422 scrollbar->setValue(scrollbar->maximum());
void setNumBlocks(int count, int countOfPeers)
Set number of blocks shown in the UI.
Local Bitcoin RPC console.
void on_lineEdit_returnPressed()
Value help(const Array ¶ms, bool fHelp)
void message(int category, const QString &message, bool html=false)
const struct @14 ICON_MAPPING[]
bool parseCommandLine(std::vector< std::string > &args, const std::string &strCommand)
Split shell command line into a list of arguments.
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)
QString formatClientStartupTime() const
void on_tabWidget_currentChanged(int index)
Config::Object_type Object
Array RPCConvertValues(const std::string &strMethod, const std::vector< std::string > &strParams)
Convert parameter values for RPC call from strings to command-specific JSON objects.
void on_showCLOptionsButton_clicked()
display messagebox with program parameters (same as bitcoin-qt –help)
void setClientModel(ClientModel *model)
void reply(int category, const QString &command)
int getNumConnections() const
void browseHistory(int offset)
Go forward or back in history.
const QSize ICON_SIZE(24, 24)
const int CONSOLE_HISTORY
QDateTime getLastBlockDate() const
const Object_type::value_type::Value_type & find_value(const Object_type &obj, const String_type &name)
void request(const QString &command)
QString clientName() const
const String_type & get_str() const
QString formatBuildDate() const
void on_openDebugLogfileButton_clicked()
open the debug.log from the current datadir
Model for Bitcoin network client.
ClientModel * clientModel
virtual bool eventFilter(QObject *obj, QEvent *event)
Value_type::String_type write_string(const Value_type &value, bool pretty)
void setNumConnections(int count)
Set number of connections shown in the UI.
bool isTestNet() const
Return true if client connected to testnet.
Help message for Bitcoin-Qt, shown with –help.
RPCConsole(QWidget *parent=0)
QString formatFullVersion() const
void cmdRequest(const QString &command)