15#include <chainparams.h>
36#include <QAbstractButton>
37#include <QAbstractItemView>
38#include <QApplication>
41#include <QDesktopServices>
43#include <QDoubleValidator>
46#include <QFontDatabase>
47#include <QFontMetrics>
48#include <QGuiApplication>
51#include <QKeySequence>
52#include <QLatin1String>
58#include <QPluginLoader>
59#include <QProgressDialog>
60#include <QRegularExpression>
65#include <QStandardPaths>
67#include <QTextDocument>
79#if defined(Q_OS_MACOS)
86using namespace std::chrono_literals;
92 return QLocale::system().toString(date.date(), QLocale::ShortFormat) +
QString(
" ") + date.toString(
"hh:mm");
97 return dateTimeStr(QDateTime::fromSecsSinceEpoch(nTime));
103 return {
"Roboto Mono"};
105 return QFontDatabase::systemFont(QFontDatabase::FixedFont);
114 addr =
"bc1p35yvjel7srp783ztf8v6jdra7dhfzk5jaun8xz2qp6ws7z80n4tq2jku9f";
119 addr =
"tb1p35yvjel7srp783ztf8v6jdra7dhfzk5jaun8xz2qp6ws7z80n4tqa6qnlg";
122 addr =
"bcrt1p35yvjel7srp783ztf8v6jdra7dhfzk5jaun8xz2qp6ws7z80n4tqsr2427";
133 parent->setFocusProxy(
widget);
138 widget->setPlaceholderText(QObject::tr(
"Enter a Bitcoin address (e.g. %1)").
arg(
158 if (
rv.address.endsWith(
"/")) {
159 rv.address.truncate(
rv.address.length() - 1);
168 if (i->first.startsWith(
"req-"))
170 i->first.remove(0, 4);
174 if (i->first ==
"label")
176 rv.label = i->second;
179 if (i->first ==
"message")
181 rv.message = i->second;
184 else if (i->first ==
"amount")
186 if(!i->second.isEmpty())
224 if (!info.
label.isEmpty())
266 if(!
view || !
view->selectionModel())
279 if(!
view || !
view->selectionModel())
281 return view->selectionModel()->selectedRows(column);
288 return !
selection.at(0).data(role).toString().isEmpty();
293 const int id = QFontDatabase::addApplicationFont(file_name);
321 myDir = QStandardPaths::writableLocation(QStandardPaths::DocumentsLocation);
334 if(!result.isEmpty())
339 if(!result.endsWith(
"."))
361 myDir = QStandardPaths::writableLocation(QStandardPaths::DocumentsLocation);
380 if(QThread::currentThread() !=
qApp->thread())
382 return Qt::BlockingQueuedConnection;
386 return Qt::DirectConnection;
392 QWidget *
atW = QApplication::widgetAt(
w->mapToGlobal(
p));
393 if (!
atW)
return false;
394 return atW->window() ==
w;
414 if (
w->isMinimized()) {
426 QObject::connect(
new QShortcut(
QKeySequence(QObject::tr(
"Ctrl+W")),
w), &QShortcut::activated,
w, &QWidget::close);
471 if(
evt->type() == QEvent::ToolTipChange)
473 QWidget *
widget =
static_cast<QWidget*
>(
obj);
484 return QObject::eventFilter(
obj,
evt);
494 if (event->type() == QEvent::FocusOut) {
496 if (
focus_out->reason() != Qt::PopupFocusReason) {
499 auto flags = label->textInteractionFlags();
500 label->setTextInteractionFlags(Qt::NoTextInteraction);
501 label->setTextInteractionFlags(
flags);
506 return QObject::eventFilter(
watched, event);
539 reinterpret_cast<void**
>(&
psl));
557 psl->SetArguments(
strArgs.toStdWString().c_str());
579#elif defined(Q_OS_LINUX)
611 if (line.find(
"Hidden") != std::string::npos &&
612 line.find(
"true") != std::string::npos)
664 clipboard->setText(str, QClipboard::Clipboard);
666 clipboard->setText(str, QClipboard::Selection);
677 return QString::fromStdString(path.utf8string());
685 case NET_IPV4:
return QObject::tr(
"IPv4",
"network name");
687 case NET_IPV6:
return QObject::tr(
"IPv6",
"network name");
689 case NET_ONION:
return QObject::tr(
"Onion",
"network name");
691 case NET_I2P:
return QObject::tr(
"I2P",
"network name");
693 case NET_CJDNS:
return QObject::tr(
"CJDNS",
"network name");
707 QObject::tr(
"Inbound") :
710 QObject::tr(
"Outbound") +
" ";
733 const auto d{std::chrono::duration_cast<std::chrono::days>(
dur)};
734 const auto h{std::chrono::duration_cast<std::chrono::hours>(
dur - d)};
735 const auto m{std::chrono::duration_cast<std::chrono::minutes>(
dur - d - h)};
736 const auto s{std::chrono::duration_cast<std::chrono::seconds>(
dur - d - h -
m)};
738 if (
auto d2{d.count()})
str_list.append(QObject::tr(
"%1 d").arg(
d2));
739 if (
auto h2{h.count()})
str_list.append(QObject::tr(
"%1 h").arg(
h2));
740 if (
auto m2{
m.count()})
str_list.append(QObject::tr(
"%1 m").arg(
m2));
741 const auto s2{s.count()};
750 if (age >= 24h)
return QObject::tr(
"%1 d").arg(age / 24h);
751 if (age >= 1h)
return QObject::tr(
"%1 h").arg(age / 1h);
752 if (age >= 1min)
return QObject::tr(
"%1 m").arg(age / 1min);
753 return QObject::tr(
"%1 s").arg(age / 1s);
761 strList.append(QString::fromStdString(flag));
767 return QObject::tr(
"None");
779 return QObject::tr(
"%1 s").arg(QString::number((
int)time_offset, 10));
822 return QObject::tr(
"%1 B").arg(bytes);
823 if (bytes < 1'000'000)
824 return QObject::tr(
"%1 kB").arg(bytes / 1'000);
825 if (bytes < 1'000'000'000)
826 return QObject::tr(
"%1 MB").arg(bytes / 1'000'000);
828 return QObject::tr(
"%1 GB").arg(bytes / 1'000'000'000);
859 if (
e->type() == QEvent::PaletteChange) {
863 QLabel::changeEvent(
e);
888 if (event->type() == QEvent::KeyPress) {
889 if (
static_cast<QKeyEvent*
>(event)->key() == Qt::Key_Escape) {
893 return QItemDelegate::eventFilter(
object, event);
907 dialog->setMinimumDuration(0);
912 return fm.horizontalAdvance(text);
918 const std::string
qt_link{
"static"};
920 const std::string
qt_link{
"dynamic"};
925 LogInfo(
"No static plugins.\n");
938 for (
const QScreen* s : QGuiApplication::screens()) {
939 LogInfo(
"Screen: %s %dx%d, pixel ratio=%.1f\n", s->name().toStdString(), s->size().width(), s->size().height(), s->devicePixelRatio());
946 if (QApplication::platformName() ==
"minimal")
return;
952 return date.startOfDay();
957 return !label->pixmap(Qt::ReturnByValue).isNull();
968 const std::exception* exception,
972 std::string description =
sender->metaObject()->className();
974 description +=
receiver->metaObject()->className();
980 dialog->setAttribute(Qt::WA_DeleteOnClose);
981 dialog->setWindowModality(Qt::ApplicationModal);
987 return name.isEmpty() ?
"[" + QObject::tr(
"default wallet") +
"]" :
name;
CScript GetScriptForDestination(const CTxDestination &dest)
Generate a Bitcoin scriptPubKey for the given CTxDestination.
std::variant< CNoDestination, PubKeyDestination, PKHash, ScriptHash, WitnessV0ScriptHash, WitnessV0KeyHash, WitnessV1Taproot, PayToAnchor, WitnessUnknown > CTxDestination
A txout script categorized into standard templates.
int64_t CAmount
Amount in satoshis (Can be negative)
fs::path GetDefaultDataDir()
const CChainParams & Params()
Return the currently selected parameters.
std::string ChainTypeToString(ChainType chain)
#define Assume(val)
Assume is the identity function.
ChainType GetChainType() const
Returns the appropriate chain type from the program arguments.
std::string GetChainTypeString() const
Returns the appropriate chain type string from the program arguments.
fs::path GetConfigFilePath() const
Return config file path (read-only)
Bitcoin address widget validator, checks for a valid bitcoin address.
Base58 entry widget validator, checks for valid characters and removes some whitespace.
static QString format(Unit unit, const CAmount &amount, bool plussign=false, SeparatorStyle separators=SeparatorStyle::STANDARD, bool justify=false)
Format as string.
static bool parse(Unit unit, const QString &value, CAmount *val_out)
Parse string to coin amount.
CChainParams defines various tweakable parameters of a given instance of the Bitcoin system.
ChainType GetChainType() const
Return the chain type.
Serialized script, used inside transaction inputs and outputs.
An output of a transaction.
void mouseReleaseEvent(QMouseEvent *event) override
ClickableLabel(const PlatformStyle *platform_style, QWidget *parent=nullptr)
void clicked(const QPoint &point)
Emitted when the label is clicked.
void mouseReleaseEvent(QMouseEvent *event) override
void clicked(const QPoint &point)
Emitted when the progressbar is clicked.
bool eventFilter(QObject *object, QEvent *event) override
bool eventFilter(QObject *watched, QEvent *event) override
LabelOutOfFocusEventFilter(QObject *parent)
const PlatformStyle * m_platform_style
void changeEvent(QEvent *e) override
ThemedLabel(const PlatformStyle *platform_style, QWidget *parent=nullptr)
void setThemedPixmap(const QString &image_filename, int width, int height)
void updateThemedPixmap()
bool eventFilter(QObject *obj, QEvent *evt) override
ToolTipToRichTextFilter(int size_threshold, QObject *parent=nullptr)
Line edit that can be marked as "invalid" to show input validation feedback.
Top-level interface for a bitcoin node (bitcoind process).
ConnectionType
Different types of connections to a peer.
@ PRIVATE_BROADCAST
Private broadcast connections are short-lived and only opened to privacy networks (Tor,...
@ BLOCK_RELAY
We use block-relay-only connections to help prevent against partition attacks.
@ MANUAL
We open manual connections to addresses that users explicitly requested via the addnode RPC or the -a...
@ OUTBOUND_FULL_RELAY
These are the default connections that we use to connect with the network.
@ FEELER
Feeler connections are short-lived connections made to check that a node is alive.
@ INBOUND
Inbound connections are those initiated by a peer.
@ ADDR_FETCH
AddrFetch connections are short lived connections used to solicit addresses from peers.
void PrintExceptionContinue(const std::exception *pex, std::string_view thread_name)
static path u8path(std::string_view utf8_str)
static bool exists(const path &p)
bool IsValidDestinationString(const std::string &str, const CChainParams ¶ms)
CTxDestination DecodeDestination(const std::string &str, std::string &error_msg, std::vector< int > *error_locations)
BCLog::Logger & LogInstance()
void ForceActivation()
Force application activation on macOS.
Utility functions used by the Bitcoin Qt UI.
QString NetworkToQString(Network net)
Convert enum Network to QString.
bool isObscured(QWidget *w)
Qt::ConnectionType blockingGUIThreadConnection()
Get connection type to call object slot in GUI thread with invokeMethod.
QString WalletDisplayName(const QString &name)
QString HtmlEscape(const QString &str, bool fMultiLine)
void PopupMenu(QMenu *menu, const QPoint &point, QAction *at_action)
Call QMenu::popup() only on supported QT_QPA_PLATFORM.
QList< QModelIndex > getEntryData(const QAbstractItemView *view, int column)
Return a field of the currently selected entry as a QString.
QFont fixedPitchFont(bool use_embedded_font)
QString formatBytes(uint64_t bytes)
void ShowModalDialogAsynchronously(QDialog *dialog)
Shows a QDialog instance asynchronously, and deletes it on close.
QString formatDurationStr(std::chrono::seconds dur)
Convert seconds into a QString with days, hours, mins, secs.
void AddButtonShortcut(QAbstractButton *button, const QKeySequence &shortcut)
Connects an additional shortcut to a QAbstractButton.
QString MakeHtmlLink(const QString &source, const QString &link)
Replaces a plain text link with an HTML tagged one.
void handleCloseWindowShortcut(QWidget *w)
QString ExtractFirstSuffixFromFilter(const QString &filter)
Extract first suffix from filter pattern "Description (*.foo)" or "Description (*....
void PolishProgressDialog(QProgressDialog *dialog)
bool isDust(interfaces::Node &node, const QString &address, const CAmount &amount)
QString getOpenFileName(QWidget *parent, const QString &caption, const QString &dir, const QString &filter, QString *selectedSuffixOut)
Get open filename, convenience wrapper for QFileDialog::getOpenFileName.
QString getDefaultDataDirectory()
Determine default data directory for operating system.
void copyEntryData(const QAbstractItemView *view, int column, int role)
Copy a field of the currently selected entry of a view to the clipboard.
QString getSaveFileName(QWidget *parent, const QString &caption, const QString &dir, const QString &filter, QString *selectedSuffixOut)
Get save filename, mimics QFileDialog::getSaveFileName, except that it appends a default suffix when ...
QDateTime StartOfDay(const QDate &date)
Returns the start-moment of the day in local time.
bool SetStartOnSystemStartup(bool fAutoStart)
static std::string DummyAddress(const CChainParams ¶ms)
void bringToFront(QWidget *w)
bool HasPixmap(const QLabel *label)
Returns true if pixmap has been set.
void LogQtInfo()
Writes to debug.log short info about the used Qt and the host system.
QString formatPingTime(std::chrono::microseconds ping_time)
Format a CNodeStats.m_last_ping_time into a user-readable string or display N/A, if 0.
QString PathToQString(const fs::path &path)
Convert OS specific boost path to QString through UTF-8.
QString dateTimeStr(const QDateTime &date)
void LoadFont(const QString &file_name)
Loads the font from the file specified by file_name, aborts if it fails.
void PrintSlotException(const std::exception *exception, const QObject *sender, const QObject *receiver)
bool checkPoint(const QPoint &p, const QWidget *w)
QString formatBitcoinURI(const SendCoinsRecipient &info)
QString ConnectionTypeToQString(ConnectionType conn_type, bool prepend_direction)
Convert enum ConnectionType to QString.
QString formatServicesStr(quint64 mask)
Format CNodeStats.nServices bitmask into a user-readable string.
QString formatNiceTimeOffset(qint64 secs)
QString FormatPeerAge(std::chrono::seconds time_connected)
Convert peer connection time to a QString denominated in the most relevant unit.
QString formatTimeOffset(int64_t time_offset)
Format a CNodeStateStats.time_offset into a user-readable string.
bool parseBitcoinURI(const QUrl &uri, SendCoinsRecipient *out)
bool GetStartOnSystemStartup()
int TextWidth(const QFontMetrics &fm, const QString &text)
Returns the distance in pixels appropriate for drawing a subsequent character after text.
void setupAddressWidget(QValidatedLineEdit *widget, QWidget *parent)
void setClipboard(const QString &str)
bool hasEntryData(const QAbstractItemView *view, int column, int role)
Returns true if the specified field of the currently selected view entry is not empty.
fs::path QStringToPath(const QString &path)
Convert QString to OS specific boost path through UTF-8.
qreal calculateIdealFontSize(int width, const QString &text, QFont font, qreal minPointSize, qreal font_size)
@ NET_MAX
Dummy value to indicate the number of NET_* constants.
@ NET_ONION
TOR (v2 or v3)
@ NET_UNROUTABLE
Addresses from these networks are not publicly routable on the global Internet.
@ NET_INTERNAL
A set of addresses that represent the hash of a string or FQDN.
@ SUCCEEDED
RFC1928: Succeeded.
bool IsDust(const CTxOut &txout, const CFeeRate &dustRelayFeeIn)
std::vector< std::string > serviceFlagsToStr(uint64_t flags)
Convert service flags (a bitmask of NODE_*) to human readable strings.
constexpr int64_t count_microseconds(std::chrono::microseconds t)
constexpr auto Ticks(Dur2 d)
Helper to count the seconds of a duration/time_point.