Inside Bitcoin
Opening the selected file…
Inside Bitcoin
Opening the selected file…
The code behind the network, with room to understand it.
Release published 2026-10-28 · Snapshot fetched 2026-11-01. Latest stable release at fetch time; development branches and Git history are excluded. Only the selected code window and visible folders load here.
251QString escaped = str.toHtmlEscaped();252if(fMultiLine)253{254escaped = escaped.replace("\n", "<br>\n");255}256return escaped;257}259QString HtmlEscape(const std::string& str, bool fMultiLine)260{261return HtmlEscape(QString::fromStdString(str), fMultiLine);262}264void copyEntryData(const QAbstractItemView *view, int column, int role)265{266if(!view || !view->selectionModel())267return;268QModelIndexList selection = view->selectionModel()->selectedRows(column);270if(!selection.isEmpty())271{272// Copy first item273setClipboard(selection.at(0).data(role).toString());274}275}277QList<QModelIndex> getEntryData(const QAbstractItemView *view, int column)278{279if(!view || !view->selectionModel())280return QList<QModelIndex>();281return view->selectionModel()->selectedRows(column);282}284bool hasEntryData(const QAbstractItemView *view, int column, int role)285{286QModelIndexList selection = getEntryData(view, column);287if (selection.isEmpty()) return false;288return !selection.at(0).data(role).toString().isEmpty();289}291void LoadFont(const QString& file_name)292{293// The qminimal plugin does not provide font loading support.294if (QApplication::platformName() == "minimal") return;295const int id = QFontDatabase::addApplicationFont(file_name);296assert(id != -1);297}299QString getDefaultDataDirectory()300{301return PathToQString(GetDefaultDataDir());302}304QString ExtractFirstSuffixFromFilter(const QString& filter)305{306QRegularExpression filter_re(QStringLiteral(".* \\(\\*\\.(.*)[ \\)]"), QRegularExpression::InvertedGreedinessOption);307QString suffix;308QRegularExpressionMatch m = filter_re.match(filter);309if (m.hasMatch()) {310suffix = m.captured(1);311}312return suffix;313}315QString getSaveFileName(QWidget *parent, const QString &caption, const QString &dir,316const QString &filter,317QString *selectedSuffixOut)318{319QString selectedFilter;320QString myDir;321if(dir.isEmpty()) // Default to user documents location322{323myDir = QStandardPaths::writableLocation(QStandardPaths::DocumentsLocation);324}325else326{327myDir = dir;328}329/* Directly convert path to native OS path separators */330QString result = QDir::toNativeSeparators(QFileDialog::getSaveFileName(parent, caption, myDir, filter, &selectedFilter));332QString selectedSuffix = ExtractFirstSuffixFromFilter(selectedFilter);334/* Add suffix if needed */335QFileInfo info(result);336if(!result.isEmpty())337{338if(info.suffix().isEmpty() && !selectedSuffix.isEmpty())339{340/* No suffix specified, add selected suffix */341if(!result.endsWith("."))342result.append(".");343result.append(selectedSuffix);344}345}347/* Return selected suffix if asked to */348if(selectedSuffixOut)349{350*selectedSuffixOut = selectedSuffix;351}352return result;353}355QString getOpenFileName(QWidget *parent, const QString &caption, const QString &dir,356const QString &filter,357QString *selectedSuffixOut)358{359QString selectedFilter;360QString myDir;361if(dir.isEmpty()) // Default to user documents location362{363myDir = QStandardPaths::writableLocation(QStandardPaths::DocumentsLocation);364}365else366{367myDir = dir;368}369/* Directly convert path to native OS path separators */370QString result = QDir::toNativeSeparators(QFileDialog::getOpenFileName(parent, caption, myDir, filter, &selectedFilter));372if(selectedSuffixOut)373{374*selectedSuffixOut = ExtractFirstSuffixFromFilter(selectedFilter);375;376}377return result;378}380Qt::ConnectionType blockingGUIThreadConnection()381{382if(QThread::currentThread() != qApp->thread())383{384return Qt::BlockingQueuedConnection;385}386else387{388return Qt::DirectConnection;389}390}392bool checkPoint(const QPoint &p, const QWidget *w)393{394QWidget *atW = QApplication::widgetAt(w->mapToGlobal(p));395if (!atW) return false;396return atW->window() == w;397}399bool isObscured(QWidget *w)400{401return !(checkPoint(QPoint(0, 0), w)402&& checkPoint(QPoint(w->width() - 1, 0), w)403&& checkPoint(QPoint(0, w->height() - 1), w)404&& checkPoint(QPoint(w->width() - 1, w->height() - 1), w)405&& checkPoint(QPoint(w->width() / 2, w->height() / 2), w));406}408void bringToFront(QWidget* w)409{410#ifdef Q_OS_MACOS411ForceActivation();412#endif414if (w) {415// activateWindow() (sometimes) helps with keyboard focus on Windows416if (w->isMinimized()) {417w->showNormal();418} else {419w->show();420}421w->activateWindow();422w->raise();423}424}426void handleCloseWindowShortcut(QWidget* w)427{428QObject::connect(new QShortcut(QKeySequence(QObject::tr("Ctrl+W")), w), &QShortcut::activated, w, &QWidget::close);429}431void openDebugLogfile()432{433fs::path pathDebug = LogInstance().m_file_path;435/* Open debug.log with the associated application */436if (fs::exists(pathDebug))437QDesktopServices::openUrl(QUrl::fromLocalFile(PathToQString(pathDebug)));438}440bool openBitcoinConf()441{442fs::path pathConfig = gArgs.GetConfigFilePath();444/* Create the file */445std::ofstream configFile{pathConfig.std_path(), std::ios_base::app};447if (!configFile.good())448return false;450configFile.close();452/* Open bitcoin.conf with the associated application */453bool res = QDesktopServices::openUrl(QUrl::fromLocalFile(PathToQString(pathConfig)));454#ifdef Q_OS_MACOS455// Workaround for macOS-specific behavior; see #15409.456if (!res) {457res = QProcess::startDetached("/usr/bin/open", QStringList{"-t", PathToQString(pathConfig)});458}459#endif461return res;462}464ToolTipToRichTextFilter::ToolTipToRichTextFilter(int _size_threshold, QObject *parent) :465QObject(parent),466size_threshold(_size_threshold)467{469}471bool ToolTipToRichTextFilter::eventFilter(QObject *obj, QEvent *evt)472{473if(evt->type() == QEvent::ToolTipChange)474{475QWidget *widget = static_cast<QWidget*>(obj);476QString tooltip = widget->toolTip();477if(tooltip.size() > size_threshold && !tooltip.startsWith("<qt") && !Qt::mightBeRichText(tooltip))478{479// Envelop with <qt></qt> to make sure Qt detects this as rich text480// Escape the current message as HTML and replace \n by <br>481tooltip = "<qt>" + HtmlEscape(tooltip, true) + "</qt>";482widget->setToolTip(tooltip);483return true;484}485}486return QObject::eventFilter(obj, evt);487}489LabelOutOfFocusEventFilter::LabelOutOfFocusEventFilter(QObject* parent)490: QObject(parent)491{492}494bool LabelOutOfFocusEventFilter::eventFilter(QObject* watched, QEvent* event)495{496if (event->type() == QEvent::FocusOut) {497auto focus_out = static_cast<QFocusEvent*>(event);498if (focus_out->reason() != Qt::PopupFocusReason) {499auto label = qobject_cast<QLabel*>(watched);500if (label) {
Independent explanations by MyBitcoinExplorer. Not affiliated with or endorsed by Bitcoin Core. Guides are educational and do not replace the source or its tests.
Bitcoin Core source © its contributors, distributed under the MIT license. Original notices and bundled third-party licenses are retained in the source tree.