Skip to content
Open
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
7 changes: 6 additions & 1 deletion src/qt/forms/debugwindow.ui
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@
</widget>
</item>
<item row="7" column="1" colspan="2">
<widget class="QLabel" name="networkName">
<widget class="NetworkName" name="networkName">
<property name="cursor">
<cursorShape>IBeamCursor</cursorShape>
</property>
Expand Down Expand Up @@ -1872,6 +1872,11 @@
<class>PlainCopyTextEdit</class>
<extends>QTextEdit</extends>
</customwidget>
<customwidget>
<class>NetworkName</class>
<extends>QLabel</extends>
<header>qt/rpcconsole.h</header>
</customwidget>
</customwidgets>
<resources>
<include location="../bitcoin.qrc"/>
Expand Down
36 changes: 36 additions & 0 deletions src/qt/rpcconsole.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@ const int INITIAL_TRAFFIC_GRAPH_MINS = 30;
const QSize FONT_RANGE(4, 40);
const char fontSizeSettingsKey[] = "consoleFontSize";

const std::string DEFAULT_CHALLENGE_STRING =
"512103ad5e0edad18cb1f0fc0d28a3d4f1f3e445640337489abb10404f2d1e086be430210359ef5021964fe22d6f8e05b2463c9540ce96883fe3b278760f048f5189f2e6c452ae";

const struct {
const char *url;
const char *source;
Expand Down Expand Up @@ -717,6 +720,39 @@ void RPCConsole::setClientModel(ClientModel *model, int bestblock_height, int64_
ui->blocksDir->setText(model->blocksDir());
ui->startupTime->setText(model->formatClientStartupTime());
ui->networkName->setText(QString::fromStdString(Params().GetChainTypeString()));
ui->networkName->setWordWrap(true);

if (Params().GetChainTypeString() == "signet") {
std::vector<uint8_t> vChallenge = Params().GetConsensus().signet_challenge;
std::string challengeString = HexStr(vChallenge);
if (challengeString != DEFAULT_CHALLENGE_STRING) {
LogDebug(BCLog::QT, "rpcconsole:challengeString=%s\n", challengeString);
if (challengeString.length() > 16) { // a sane minimum
std::string challenge_fingerprint = challengeString.substr(0, 8);
const QString title = tr("Node window - [signet] (%1)").arg(QString::fromStdString(challenge_fingerprint));
// display fingerprint in Node window title
this->setWindowTitle(title);
} else {
// A trivial challenge is supported. Example: signetchallenge=51
std::string challenge_fingerprint = challengeString.substr(0, challengeString.length());
const QString title = tr("Node window - [signet] (%1)").arg(QString::fromStdString(challenge_fingerprint));
// display fingerprint in Node window title
this->setWindowTitle(title);
}
if (challengeString.length() > (size_t)ui->networkName->width()) {
challengeString.insert(0, "\n"); // break after Signet:
challengeString.insert(65, "\n"); // then split at (130/2)
}
ui->networkName->setToolTip(
tr("%1").arg(QString::fromStdString(challengeString)));
ui->networkName->setText(
tr("%1\nChallenge: %2").arg("Signet").arg(QString::fromStdString(challengeString)));
} else {
ui->networkName->setText(tr("Signet: Default"));
ui->networkName->setToolTip(QString());
this->setWindowTitle(tr("[signet] Default"));
}
}

//Setup autocomplete and attach it
QStringList wordList;
Expand Down
54 changes: 54 additions & 0 deletions src/qt/rpcconsole.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@

#include <QByteArray>
#include <QCompleter>
#include <QFontMetrics>
#include <QLabel>
#include <QMimeData>
#include <QTextDocumentFragment>
#include <QTextEdit>
Expand Down Expand Up @@ -210,4 +212,56 @@ class PlainCopyTextEdit : public QTextEdit {
}
};

class NetworkName : public QLabel
{
Q_OBJECT

public:
explicit NetworkName(QWidget *parent = nullptr) : QLabel(parent) {}

void setText(const QString& text) {
m_fullText = text;
recalculateElidedText();
}

const QString& fullText() const { return m_fullText; }
QString selectedText() const {
return m_fullText;
}

protected:
void resizeEvent(QResizeEvent *event) override {
QLabel::resizeEvent(event);
recalculateElidedText();
}

// Provide the full challenge when Copy&Paste
QMimeData* createMimeDataFromSelection() const {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the full challenge should be copy and pasted - please test
cc: @luke-jr @pablomartin4btc

auto md = new QMimeData();
md->setText(m_fullText);
return md;
}

private:
QString m_fullText;

void recalculateElidedText() {
if (m_fullText.isEmpty()) {
QLabel::setText(QString());
return;
}

QFontMetrics fm(font());
int availableWidth = width()-1;
//int availableWidth = contentsRect().width()-1;

QString elidedText = fm.elidedText(m_fullText, Qt::ElideMiddle, availableWidth);

if (QLabel::text() != elidedText) {
QLabel::setText(elidedText);
//QLabel::setText(m_fullText);
}
}
};

#endif // BITCOIN_QT_RPCCONSOLE_H
Loading