6 #include "qt/settings/forms/ui_consolewidget.h"
29 #include <QGraphicsDropShadowEffect>
33 #include <QSignalMapper>
36 #include <QStringList>
44 {
"cmd-request",
":/icons/ic-transaction-received"},
45 {
"cmd-reply",
":/icons/ic-transaction-sent"},
46 {
"cmd-error",
":/icons/ic-transaction-sent"},
47 {
"misc",
":/icons/ic-transaction-staked"},
56 this->setStyleSheet(parent->styleSheet());
60 ui->left->setContentsMargins(10,10,10,10);
61 ui->messagesWidget->setReadOnly(
true);
62 ui->messagesWidget->setTextInteractionFlags(Qt::TextInteractionFlag::TextSelectableByMouse);
72 ui->lineEdit->setPlaceholderText(tr(
"Console input"));
76 ui->pushButton->setProperty(
"cssClass",
"ic-arrow");
82 connect(
ui->pushButtonClear, &QPushButton::clicked, [
this]{ clear(false); });
83 connect(
ui->pushButtonOpenDebug, &QPushButton::clicked, [
this](){
84 if (!GUIUtil::openDebugLogfile()) {
85 inform(tr(
"Cannot open debug file.\nVerify that you have installed a predetermined text editor."));
91 ui->lineEdit->installEventFilter(
this);
92 ui->messagesWidget->installEventFilter(
this);
116 if (event->type() == QEvent::KeyPress)
118 QKeyEvent* keyevt =
static_cast<QKeyEvent*
>(event);
119 int key = keyevt->key();
120 Qt::KeyboardModifiers mod = keyevt->modifiers();
123 if (obj ==
ui->lineEdit) {
129 if (obj ==
ui->lineEdit) {
135 case Qt::Key_PageDown:
136 if (obj ==
ui->lineEdit) {
137 QApplication::postEvent(
ui->messagesWidget,
new QKeyEvent(*keyevt));
145 QApplication::postEvent(
ui->lineEdit,
new QKeyEvent(*keyevt));
152 if (obj ==
ui->messagesWidget && ((!mod && !keyevt->text().isEmpty() && key != Qt::Key_Tab) ||
153 ((mod & Qt::ControlModifier) && key == Qt::Key_V) ||
154 ((mod & Qt::ShiftModifier) && key == Qt::Key_Insert))) {
155 ui->lineEdit->setFocus();
156 QApplication::postEvent(
ui->lineEdit,
new QKeyEvent(*keyevt));
159 if (mod == Qt::ControlModifier && key == Qt::Key_L)
163 return QWidget::eventFilter(obj, event);
171 QStringList wordList;
173 for (
size_t i = 0; i < commandList.size(); ++i)
175 wordList << commandList[i].c_str();
176 wordList << (
"help " + commandList[i]).c_str();
179 wordList <<
"help-console";
182 autoCompleter->setModelSorting(QCompleter::CaseSensitivelySortedModel);
192 if (
ui->lineEdit)
ui->lineEdit->setFocus();
197 ui->messagesWidget->clear();
202 ui->lineEdit->clear();
203 ui->lineEdit->setFocus();
208 ui->messagesWidget->document()->addResource(
209 QTextDocument::ImageResource,
218 QString clsKey =
"(⌘)-L";
220 QString clsKey =
"Ctrl-L";
224 tr(
"Use up and down arrows to navigate history, and %1 to clear screen.").arg(
"<b>"+clsKey+
"</b>") +
"<br>" +
225 tr(
"Type %1 for an overview of available commands.").arg(
"<b>help</b>") +
"<br>" +
226 tr(
"For more information on using this console type %1.").arg(
"<b>help-console</b>") +
227 "<br><span class=\"secwarning\"><br>" +
228 tr(
"WARNING: Scammers have been active, telling users to type commands here, stealing their wallet contents. Do not use this console without fully understanding the ramifications of a command.") +
235 QTime time = QTime::currentTime();
236 QString timeString = time.toString();
238 out +=
"<table><tr><td class=\"time\" width=\"65\">" + timeString +
"</td>";
245 out +=
"</td></tr></table>";
246 ui->messagesWidget->append(out);
249 static bool PotentiallyDangerousCommand(
const QString& cmd)
251 if (cmd.size() >= 12 && cmd.leftRef(10) ==
"dumpwallet") {
255 if (cmd.size() >= 13 && cmd.leftRef(11) ==
"dumpprivkey") {
258 if (cmd.size() >= 18 && cmd.leftRef(16) ==
"exportsaplingkey") {
266 QString cmd =
ui->lineEdit->text();
267 ui->lineEdit->clear();
269 if (!cmd.isEmpty()) {
272 if (PotentiallyDangerousCommand(cmd) &&
273 !
ask(
"DANGER!",
"Your coins will be STOLEN if you give\nthe info to anyone!\n\nAre you sure?\n")) {
304 ui->lineEdit->setText(cmd);
309 QThread* thread =
new QThread;
311 executor->moveToThread(thread);
324 connect(thread, &QThread::finished, thread, &QThread::deleteLater);
333 QScrollBar* scrollbar =
ui->messagesWidget->verticalScrollBar();
334 scrollbar->setValue(scrollbar->maximum());
342 ui->messagesWidget->document()->setDefaultStyleSheet(
343 "table { color: #707070; }"
344 "td.time { color: #808080; padding-top: 3px; } "
345 "td.message { color: #707070;font-family: Courier, Courier New, Lucida Console, monospace; font-size: 12px; } "
346 "td.cmd-request { color: #006060; } "
347 "td.cmd-error { color: red; } "
348 ".secwarning { color: red; }"
349 "b { color: #707070; } ");
351 ui->messagesWidget->document()->setDefaultStyleSheet(
352 "table { color: #FFFFFF; }"
353 "td.time { color: #808080; padding-top: 3px; } "
354 "td.message { color: #FFFFFF;font-family: Courier, Courier New, Lucida Console, monospace; font-size: 12px; } "
355 "td.cmd-request { color: #006060; } "
356 "td.cmd-error { color: red; } "
357 ".secwarning { color: red; }"
358 "b { color: #FFFFFF; } ");
std::vector< std::string > listCommands() const
Returns a list of registered commands.
"Help message" dialog box
void reply(int category, const QString &command)
void request(const QString &command)
static QString categoryClass(int category)
QString HtmlEscape(const QString &str, bool fMultiLine)
void saveWindowGeometry(const QString &strSetting, QWidget *parent)
Save window size and position.
void setCssTitleScreen(QLabel *label)
void initCssEditLine(QLineEdit *edit, bool isDialog)
void setShadow(QWidget *edit)
void setCssProperty(std::initializer_list< QWidget * > args, const QString &value)
void setCssBtnSecondary(QPushButton *btn, bool forceUpdate)
void updateStyle(QWidget *widget)
void RPCSetTimerInterfaceIfUnset(RPCTimerInterface *iface)
Set factory function for timers, but only if unset.
void RPCUnsetTimerInterface(RPCTimerInterface *iface)
Unset factory function for timers.