Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
71 changes: 58 additions & 13 deletions src/qt/rpcconsole.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@ const struct {
const char *source;
} ICON_MAPPING[] = {
{"cmd-request", ":/icons/tx_input"},
{"cmd-reply", ":/icons/tx_output"},
{"cmd-error", ":/icons/tx_output"},
{"misc", ":/icons/tx_inout"},
{"cmd-reply", ":/icons/tx_output"},
{"cmd-error", ":/icons/tx_output"},
{"misc", ":/icons/tx_inout"},
{NULL, NULL}
};

Expand Down Expand Up @@ -87,7 +87,7 @@ bool parseCommandLine(std::vector<std::string> &args, const std::string &strComm
case STATE_EATING_SPACES: // Handle runs of whitespace
switch(ch)
{
case '"': state = STATE_DOUBLEQUOTED; break;
case '"': state = STATE_DOUBLEQUOTED; break;
case '\'': state = STATE_SINGLEQUOTED; break;
case '\\': state = STATE_ESCAPE_OUTER; break;
case ' ': case '\n': case '\t':
Expand Down Expand Up @@ -230,8 +230,8 @@ bool RPCConsole::eventFilter(QObject* obj, QEvent *event)
Qt::KeyboardModifiers mod = keyevt->modifiers();
switch(key)
{
case Qt::Key_Up: if(obj == ui->lineEdit) { browseHistory(-1); return true; } break;
case Qt::Key_Down: if(obj == ui->lineEdit) { browseHistory(1); return true; } break;
case Qt::Key_Up: if(obj == ui->lineEdit) { browseHistory(-1); return true; } break;
case Qt::Key_Down: if(obj == ui->lineEdit) { browseHistory(1); return true; } break;
case Qt::Key_PageUp: /* pass paging keys to messages widget */
case Qt::Key_PageDown:
if(obj == ui->lineEdit)
Expand All @@ -240,13 +240,44 @@ bool RPCConsole::eventFilter(QObject* obj, QEvent *event)
return true;
}
break;

case Qt::Key_Return:
case Qt::Key_Enter:
if(obj == autoCompleter->popup())
{
QApplication::postEvent(ui->lineEdit, new QKeyEvent(*keyevt));
return true;
}
break;

case Qt::Key_Tab:
case Qt::Key_Backtab:
// Provides tab completion in the console
if (obj == autoCompleter->popup())
{
QModelIndex curIndex = autoCompleter->popup()->currentIndex();
QModelIndex newIndex;

if (curIndex.row() == -1)
newIndex = autoCompleter->popup()->model()->index(0, 0);
else if(key == Qt::Key_Backtab)
newIndex = autoCompleter->popup()->model()->index(curIndex.row() - 1, curIndex.column());
else
newIndex = autoCompleter->popup()->model()->index(curIndex.row() + 1, curIndex.column());

autoCompleter->popup()->setCurrentIndex(newIndex);

return true;
}
break;

default:
// Typing in messages widget brings focus to line edit, and redirects key there
// Exclude most combinations and keys that emit no text, except paste shortcuts
if(obj == ui->messagesWidget && (
(!mod && !keyevt->text().isEmpty() && key != Qt::Key_Tab) ||
((mod & Qt::ControlModifier) && key == Qt::Key_V) ||
((mod & Qt::ShiftModifier) && key == Qt::Key_Insert)))
((mod & Qt::ControlModifier) && key == Qt::Key_V) ||
((mod & Qt::ShiftModifier) && key == Qt::Key_Insert)))
{
ui->lineEdit->setFocus();
QApplication::postEvent(ui->lineEdit, new QKeyEvent(*keyevt));
Expand Down Expand Up @@ -280,17 +311,31 @@ void RPCConsole::setClientModel(ClientModel *model)
ui->startupTime->setText(model->formatClientStartupTime());

ui->networkName->setText(model->getNetworkName());

//Completion
QStringList wordList;
std::vector<std::string> commandList = tableRPC.listCommands();
for (size_t i = 0; i < commandList.size(); ++i)
{
wordList << commandList[i].c_str();
}

autoCompleter = new QCompleter(wordList, this);
ui->lineEdit->setCompleter(autoCompleter);

// clear the lineEdit after activating from QCompleter
autoCompleter->popup()->installEventFilter(this);
}
}

static QString categoryClass(int category)
{
switch(category)
{
case RPCConsole::CMD_REQUEST: return "cmd-request"; break;
case RPCConsole::CMD_REPLY: return "cmd-reply"; break;
case RPCConsole::CMD_ERROR: return "cmd-error"; break;
default: return "misc";
case RPCConsole::CMD_REQUEST: return "cmd-request";
case RPCConsole::CMD_REPLY: return "cmd-reply";
case RPCConsole::CMD_ERROR: return "cmd-error";
default: return "misc";
}
}

Expand Down Expand Up @@ -356,7 +401,7 @@ void RPCConsole::setNumConnections(int count)
return;

QString connections = QString::number(count) + " (";
connections += tr("In:") + " " + QString::number(clientModel->getNumConnections(CONNECTIONS_IN)) + " / ";
connections += tr("In:") + " " + QString::number(clientModel->getNumConnections(CONNECTIONS_IN)) + " / ";
connections += tr("Out:") + " " + QString::number(clientModel->getNumConnections(CONNECTIONS_OUT)) + ")";

ui->numberOfConnections->setText(connections);
Expand Down
3 changes: 3 additions & 0 deletions src/qt/rpcconsole.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#define RPCCONSOLE_H

#include <QDialog>
#include <QCompleter>

class ClientModel;

Expand Down Expand Up @@ -73,6 +74,8 @@ public slots:
int historyPtr;

void startExecutor();

QCompleter *autoCompleter;
};

#endif // RPCCONSOLE_H
10 changes: 10 additions & 0 deletions src/rpcserver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -931,6 +931,16 @@ json_spirit::Value CRPCTable::execute(const std::string &strMethod, const json_s
}
}

std::vector <std::string> CRPCTable::listCommands() const {
std::vector <std::string> commandList;
typedef std::map<std::string, const CRPCCommand *> commandMap;

std::transform(mapCommands.begin(), mapCommands.end(),
std::back_inserter(commandList),
boost::bind(&commandMap::value_type::first, _1));
return commandList;
}

std::string HelpExampleCli(string methodname, string args){
return "> smileycoin-cli " + methodname + " " + args + "\n";
}
Expand Down
1 change: 1 addition & 0 deletions src/rpcserver.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ class CRPCTable
CRPCTable();
const CRPCCommand* operator[](std::string name) const;
std::string help(std::string name) const;
std::vector<std::string> listCommands() const;

/**
* Execute a method.
Expand Down