PIVX Core  5.6.99
P2P Digital Currency
guiutil.cpp
Go to the documentation of this file.
1 // Copyright (c) 2011-2014 The Bitcoin developers
2 // Copyright (c) 2014-2015 The Dash developers
3 // Copyright (c) 2015-2021 The PIVX Core developers
4 // Distributed under the MIT/X11 software license, see the accompanying
5 // file COPYING or http://www.opensource.org/licenses/mit-license.php.
6 
7 #include "guiutil.h"
8 
10 #include "bitcoinunits.h"
11 #include "qvalidatedlineedit.h"
12 #include "walletmodel.h"
13 
14 #include "policy/policy.h"
15 #include "primitives/transaction.h"
16 #include "protocol.h"
17 #include "script/script.h"
18 #include "script/standard.h"
19 #include "util/system.h"
20 
21 #ifdef WIN32
22 #ifdef _WIN32_WINNT
23 #undef _WIN32_WINNT
24 #endif
25 #define _WIN32_WINNT 0x0501
26 #ifdef _WIN32_IE
27 #undef _WIN32_IE
28 #endif
29 #define _WIN32_IE 0x0501
30 #define WIN32_LEAN_AND_MEAN 1
31 #ifndef NOMINMAX
32 #define NOMINMAX
33 #endif
34 #include "shellapi.h"
35 #include "shlobj.h"
36 #include "shlwapi.h"
37 #endif
38 
39 #include <QAbstractItemView>
40 #include <QApplication>
41 #include <QClipboard>
42 #include <QDateTime>
43 #include <QDesktopServices>
44 #include <QDesktopWidget>
45 #include <QRegExp>
46 #include <QRegularExpression>
47 #include <QRegularExpressionValidator>
48 #include <QFileDialog>
49 #include <QFont>
50 #include <QLineEdit>
51 #include <QScreen>
52 #include <QSettings>
53 #include <QTextDocument> // for Qt::mightBeRichText
54 #include <QThread>
55 #include <QUrlQuery>
56 #include <QMouseEvent>
57 
58 #define URI_SCHEME "pivx"
59 
60 #if defined(Q_OS_MAC)
61 
62 #include <QProcess>
63 
64 void ForceActivation();
65 #endif
66 
67 namespace GUIUtil
68 {
69 QString dateTimeStr(const QDateTime& date)
70 {
71  return date.date().toString(Qt::SystemLocaleShortDate) + QString(" ") + date.toString("hh:mm");
72 }
73 
74 QString dateTimeStrWithSeconds(const QDateTime& date)
75 {
76  return date.date().toString(Qt::SystemLocaleShortDate) + QString(" ") + date.toString("hh:mm:ss");
77 }
78 
79 QString dateTimeStr(qint64 nTime)
80 {
81  return dateTimeStr(QDateTime::fromTime_t((qint32)nTime));
82 }
83 
85 {
86  QFont font("Monospace");
87  font.setStyleHint(QFont::Monospace);
88  return font;
89 }
90 
96 static CAmount parseValue(const QString& text, int displayUnit, bool* valid_out)
97 {
98  CAmount val = 0;
99  bool valid = BitcoinUnits::parse(displayUnit, text, &val);
100  if (valid) {
101  if (val < 0 || val > BitcoinUnits::maxMoney())
102  valid = false;
103  }
104  if (valid_out)
105  *valid_out = valid;
106  return valid ? val : 0;
107 }
108 
112 CAmount parseValue(const QString& amount, int displayUnit)
113 {
114  bool isValid = false;
115  CAmount value = GUIUtil::parseValue(amount, displayUnit, &isValid);
116  return isValid ? value : 0;
117 }
118 
119 QString formatBalance(CAmount amount, int nDisplayUnit, bool isZpiv)
120 {
121  return (amount == 0) ? ("0.00 " + BitcoinUnits::name(nDisplayUnit, isZpiv)) : BitcoinUnits::floorHtmlWithUnit(nDisplayUnit, amount, false, BitcoinUnits::separatorAlways, true, isZpiv);
122 }
123 
124 QString formatBalanceWithoutHtml(CAmount amount, int nDisplayUnit, bool isZpiv)
125 {
126  return (amount == 0) ? ("0.00 " + BitcoinUnits::name(nDisplayUnit, isZpiv)) : BitcoinUnits::floorWithUnit(nDisplayUnit, amount, false, BitcoinUnits::separatorAlways, true, isZpiv);
127 }
128 
129 void setupAddressWidget(QValidatedLineEdit* widget, QWidget* parent)
130 {
131  parent->setFocusProxy(widget);
132 
133  widget->setFont(bitcoinAddressFont());
134  // We don't want translators to use own addresses in translations
135  // and this is the only place, where this address is supplied.
136  widget->setPlaceholderText(QObject::tr("Enter PIVX address (e.g. %1)").arg("D7VFR83SQbiezrW72hjcWJtcfip5krte2Z"));
137  widget->setValidator(new BitcoinAddressEntryValidator(parent));
138  widget->setCheckValidator(new BitcoinAddressCheckValidator(parent));
139 }
140 
141 void setupAmountWidget(QLineEdit* widget, QWidget* parent)
142 {
143  QRegularExpression rx("^(\\d{0,8})((\\.|,)\\d{1,8})?$");
144  QValidator *validator = new QRegularExpressionValidator(rx, widget);
145  widget->setValidator(validator);
146 }
147 
148 void updateWidgetTextAndCursorPosition(QLineEdit* widget, const QString& str)
149 {
150  const int cpos = widget->cursorPosition();
151  widget->setText(str);
152  if (cpos > str.size()) return;
153  widget->setCursorPosition(cpos);
154 }
155 
156 bool parseBitcoinURI(const QUrl& uri, SendCoinsRecipient* out)
157 {
158  // return if URI is not valid or is no PIVX: URI
159  if (!uri.isValid() || uri.scheme() != QString(URI_SCHEME))
160  return false;
161 
163  rv.address = uri.path();
164  // Trim any following forward slash which may have been added by the OS
165  if (rv.address.endsWith("/")) {
166  rv.address.truncate(rv.address.length() - 1);
167  }
168  rv.amount = 0;
169 
170  QUrlQuery uriQuery(uri);
171  QList<QPair<QString, QString> > items = uriQuery.queryItems();
172  for (QList<QPair<QString, QString> >::iterator i = items.begin(); i != items.end(); i++)
173  {
174  bool fShouldReturnFalse = false;
175  if (i->first.startsWith("req-")) {
176  i->first.remove(0, 4);
177  fShouldReturnFalse = true;
178  }
179 
180  if (i->first == "label") {
181  rv.label = i->second;
182  fShouldReturnFalse = false;
183  }
184  if (i->first == "message") {
185  rv.message = i->second;
186  fShouldReturnFalse = false;
187  } else if (i->first == "amount") {
188  if (!i->second.isEmpty()) {
189  if (!BitcoinUnits::parse(BitcoinUnits::PIV, i->second, &rv.amount)) {
190  return false;
191  }
192  }
193  fShouldReturnFalse = false;
194  }
195 
196  if (fShouldReturnFalse)
197  return false;
198  }
199  if (out) {
200  *out = rv;
201  }
202  return true;
203 }
204 
205 bool parseBitcoinURI(QString uri, SendCoinsRecipient* out)
206 {
207  // Convert pivx:// to pivx:
208  //
209  // Cannot handle this later, because pivx:// will cause Qt to see the part after // as host,
210  // which will lower-case it (and thus invalidate the address).
211  if (uri.startsWith(URI_SCHEME "://", Qt::CaseInsensitive)) {
212  uri.replace(0, std::strlen(URI_SCHEME) + 3, URI_SCHEME ":");
213  }
214  QUrl uriInstance(uri);
215  return parseBitcoinURI(uriInstance, out);
216 }
217 
219 {
220  QString ret = QString(URI_SCHEME ":%1").arg(info.address);
221  int paramCount = 0;
222 
223  if (info.amount) {
224  ret += QString("?amount=%1").arg(BitcoinUnits::format(BitcoinUnits::PIV, info.amount, false, BitcoinUnits::separatorNever));
225  paramCount++;
226  }
227 
228  if (!info.label.isEmpty()) {
229  QString lbl(QUrl::toPercentEncoding(info.label));
230  ret += QString("%1label=%2").arg(paramCount == 0 ? "?" : "&").arg(lbl);
231  paramCount++;
232  }
233 
234  if (!info.message.isEmpty()) {
235  QString msg(QUrl::toPercentEncoding(info.message));
236  ret += QString("%1message=%2").arg(paramCount == 0 ? "?" : "&").arg(msg);
237  paramCount++;
238  }
239 
240  return ret;
241 }
242 
243 bool isDust(const QString& address, const CAmount& amount)
244 {
245  CTxDestination dest = DecodeDestination(address.toStdString());
246  CScript script = GetScriptForDestination(dest);
247  CTxOut txOut(amount, script);
248  return IsDust(txOut, dustRelayFee);
249 }
250 
251 QString HtmlEscape(const QString& str, bool fMultiLine)
252 {
253  QString escaped = str.toHtmlEscaped();
254  escaped = escaped.replace(" ", "&nbsp;");
255  if (fMultiLine) {
256  escaped = escaped.replace("\n", "<br>\n");
257  }
258  return escaped;
259 }
260 
261 QString HtmlEscape(const std::string& str, bool fMultiLine)
262 {
263  return HtmlEscape(QString::fromStdString(str), fMultiLine);
264 }
265 
266 void copyEntryData(QAbstractItemView* view, int column, int role)
267 {
268  if (!view || !view->selectionModel())
269  return;
270  QModelIndexList selection = view->selectionModel()->selectedRows(column);
271 
272  if (!selection.isEmpty()) {
273  // Copy first item
274  setClipboard(selection.at(0).data(role).toString());
275  }
276 }
277 
278 QVariant getEntryData(QAbstractItemView *view, int column, int role)
279 {
280  if (!view || !view->selectionModel())
281  return QVariant();
282  QModelIndexList selection = view->selectionModel()->selectedRows(column);
283 
284  if (!selection.isEmpty()) {
285  // Return first item
286  return (selection.at(0).data(role));
287  }
288  return QVariant();
289 }
290 
291 QString getSaveFileName(QWidget* parent, const QString& caption, const QString& dir, const QString& filter, QString* selectedSuffixOut)
292 {
293  QString selectedFilter;
294  QString myDir;
295  if (dir.isEmpty()) // Default to user documents location
296  {
297  myDir = QStandardPaths::writableLocation(QStandardPaths::DocumentsLocation);
298  }
299  else
300  {
301  myDir = dir;
302  }
303  /* Directly convert path to native OS path separators */
304  QString result = QDir::toNativeSeparators(QFileDialog::getSaveFileName(parent, caption, myDir, filter, &selectedFilter));
305 
306  /* Extract first suffix from filter pattern "Description (*.foo)" or "Description (*.foo *.bar ...) */
307  QRegExp filter_re(".* \\(\\*\\.(.*)[ \\)]");
308  QString selectedSuffix;
309  if (filter_re.exactMatch(selectedFilter)) {
310  selectedSuffix = filter_re.cap(1);
311  }
312 
313  /* Add suffix if needed */
314  QFileInfo info(result);
315  if (!result.isEmpty()) {
316  if (info.suffix().isEmpty() && !selectedSuffix.isEmpty()) {
317  /* No suffix specified, add selected suffix */
318  if (!result.endsWith("."))
319  result.append(".");
320  result.append(selectedSuffix);
321  }
322  }
323 
324  /* Return selected suffix if asked to */
325  if (selectedSuffixOut) {
326  *selectedSuffixOut = selectedSuffix;
327  }
328  return result;
329 }
330 
331 QString getOpenFileName(QWidget* parent, const QString& caption, const QString& dir, const QString& filter, QString* selectedSuffixOut)
332 {
333  QString selectedFilter;
334  QString myDir;
335  if (dir.isEmpty()) // Default to user documents location
336  {
337  myDir = QStandardPaths::writableLocation(QStandardPaths::DocumentsLocation);
338  }
339  else
340  {
341  myDir = dir;
342  }
343  /* Directly convert path to native OS path separators */
344  QString result = QDir::toNativeSeparators(QFileDialog::getOpenFileName(parent, caption, myDir, filter, &selectedFilter));
345 
346  if (selectedSuffixOut) {
347  /* Extract first suffix from filter pattern "Description (*.foo)" or "Description (*.foo *.bar ...) */
348  QRegExp filter_re(".* \\(\\*\\.(.*)[ \\)]");
349  QString selectedSuffix;
350  if (filter_re.exactMatch(selectedFilter)) {
351  selectedSuffix = filter_re.cap(1);
352  }
353  *selectedSuffixOut = selectedSuffix;
354  }
355  return result;
356 }
357 
358 Qt::ConnectionType blockingGUIThreadConnection()
359 {
360  if (QThread::currentThread() != qApp->thread()) {
361  return Qt::BlockingQueuedConnection;
362  } else {
363  return Qt::DirectConnection;
364  }
365 }
366 
367 bool checkPoint(const QPoint& p, const QWidget* w)
368 {
369  QWidget* atW = QApplication::widgetAt(w->mapToGlobal(p));
370  if (!atW) return false;
371  return atW->window() == w;
372 }
373 
374 bool isObscured(QWidget* w)
375 {
376  return !(checkPoint(QPoint(0, 0), w) && checkPoint(QPoint(w->width() - 1, 0), w) && checkPoint(QPoint(0, w->height() - 1), w) && checkPoint(QPoint(w->width() - 1, w->height() - 1), w) && checkPoint(QPoint(w->width() / 2, w->height() / 2), w));
377 }
378 
379 void bringToFront(QWidget* w)
380 {
381 #ifdef Q_OS_MAC
382  ForceActivation();
383 #endif
384 
385  if (w) {
386  // activateWindow() (sometimes) helps with keyboard focus on Windows
387  if (w->isMinimized()) {
388  w->showNormal();
389  } else {
390  w->show();
391  }
392  w->activateWindow();
393  w->raise();
394  }
395 }
396 
397 /* Open file with the associated application */
398 bool openFile(fs::path path, bool isTextFile)
399 {
400  bool ret = false;
401  if (fs::exists(path)) {
402  ret = QDesktopServices::openUrl(QUrl::fromLocalFile(boostPathToQString(path)));
403 #ifdef Q_OS_MAC
404  // Workaround for macOS-specific behavior; see btc@15409.
405  if (isTextFile && !ret) {
406  ret = QProcess::startDetached("/usr/bin/open", QStringList{"-t", boostPathToQString(path)});
407  }
408 #endif
409  }
410  return ret;
411 }
412 
414 {
415  return openFile(GetDataDir() / "debug.log", true);
416 }
417 
419 {
420  return openFile(GetConfigFile(gArgs.GetArg("-conf", PIVX_CONF_FILENAME)), true);
421 }
422 
424 {
425  return openFile(GetMasternodeConfigFile(), true);
426 }
427 
429 {
430  return openFile(GetDataDir() / "backups", false);
431 }
432 
433 ToolTipToRichTextFilter::ToolTipToRichTextFilter(int size_threshold, QObject* parent) : QObject(parent),
434  size_threshold(size_threshold)
435 {
436 }
437 
438 bool ToolTipToRichTextFilter::eventFilter(QObject* obj, QEvent* evt)
439 {
440  if (evt->type() == QEvent::ToolTipChange) {
441  QWidget* widget = static_cast<QWidget*>(obj);
442  QString tooltip = widget->toolTip();
443  if (tooltip.size() > size_threshold && !tooltip.startsWith("<qt")) {
444  // Escape the current message as HTML and replace \n by <br> if it's not rich text
445  if (!Qt::mightBeRichText(tooltip))
446  tooltip = HtmlEscape(tooltip, true);
447  // Envelop with <qt></qt> to make sure Qt detects every tooltip as rich text
448  // and style='white-space:pre' to preserve line composition
449  tooltip = "<qt style='white-space:pre'>" + tooltip + "</qt>";
450  widget->setToolTip(tooltip);
451  return true;
452  }
453  }
454  return QObject::eventFilter(obj, evt);
455 }
456 
457 #ifdef WIN32
458 fs::path static StartupShortcutPath()
459 {
460  std::string chain = gArgs.GetChainName();
461  if (chain == CBaseChainParams::TESTNET)
462  return GetSpecialFolderPath(CSIDL_STARTUP) / "PIVX (testnet).lnk";
463  else if (chain == CBaseChainParams::REGTEST)
464  return GetSpecialFolderPath(CSIDL_STARTUP) / "PIVX (regtest).lnk";
465 
466  return GetSpecialFolderPath(CSIDL_STARTUP) / "PIVX.lnk";
467 }
468 
470 {
471  // check for PIVX*.lnk
472  return fs::exists(StartupShortcutPath());
473 }
474 
475 bool SetStartOnSystemStartup(bool fAutoStart)
476 {
477  // If the shortcut exists already, remove it for updating
478  fs::remove(StartupShortcutPath());
479 
480  if (fAutoStart) {
481  CoInitialize(nullptr);
482 
483  // Get a pointer to the IShellLink interface.
484  IShellLinkW* psl = nullptr;
485  HRESULT hres = CoCreateInstance(CLSID_ShellLink, nullptr,
486  CLSCTX_INPROC_SERVER, IID_IShellLinkW,
487  reinterpret_cast<void**>(&psl));
488 
489  if (SUCCEEDED(hres)) {
490  // Get the current executable path
491  WCHAR pszExePath[MAX_PATH];
492  GetModuleFileNameW(nullptr, pszExePath, ARRAYSIZE(pszExePath));
493 
494  // Start client minimized
495  QString strArgs = "-min";
496  // Set -testnet /-regtest options
497  strArgs += QString::fromStdString(strprintf(" -testnet=%d -regtest=%d", gArgs.GetBoolArg("-testnet", false), gArgs.GetBoolArg("-regtest", false)));
498 
499  // Set the path to the shortcut target
500  psl->SetPath(pszExePath);
501  PathRemoveFileSpecW(pszExePath);
502  psl->SetWorkingDirectory(pszExePath);
503  psl->SetShowCmd(SW_SHOWMINNOACTIVE);
504  psl->SetArguments(strArgs.toStdWString().c_str());
505 
506  // Query IShellLink for the IPersistFile interface for
507  // saving the shortcut in persistent storage.
508  IPersistFile* ppf = nullptr;
509  hres = psl->QueryInterface(IID_IPersistFile, reinterpret_cast<void**>(&ppf));
510  if (SUCCEEDED(hres)) {
511  // Save the link by calling IPersistFile::Save.
512  hres = ppf->Save(StartupShortcutPath().wstring().c_str(), TRUE);
513  ppf->Release();
514  psl->Release();
515  CoUninitialize();
516  return true;
517  }
518  psl->Release();
519  }
520  CoUninitialize();
521  return false;
522  }
523  return true;
524 }
525 
526 #elif defined(Q_OS_LINUX)
527 
528 // Follow the Desktop Application Autostart Spec:
529 // http://standards.freedesktop.org/autostart-spec/autostart-spec-latest.html
530 
531 fs::path static GetAutostartDir()
532 {
533  char* pszConfigHome = getenv("XDG_CONFIG_HOME");
534  if (pszConfigHome) return fs::path(pszConfigHome) / "autostart";
535  char* pszHome = getenv("HOME");
536  if (pszHome) return fs::path(pszHome) / ".config" / "autostart";
537  return fs::path();
538 }
539 
540 fs::path static GetAutostartFilePath()
541 {
542  return GetAutostartDir() / "pivx.desktop";
543 }
544 
546 {
547  fsbridge::ifstream optionFile(GetAutostartFilePath());
548  if (!optionFile.good())
549  return false;
550  // Scan through file for "Hidden=true":
551  std::string line;
552  while (!optionFile.eof()) {
553  getline(optionFile, line);
554  if (line.find("Hidden") != std::string::npos &&
555  line.find("true") != std::string::npos)
556  return false;
557  }
558  optionFile.close();
559 
560  return true;
561 }
562 
563 bool SetStartOnSystemStartup(bool fAutoStart)
564 {
565  if (!fAutoStart) {
566  fs::remove(GetAutostartFilePath());
567  } else {
568  char pszExePath[MAX_PATH+1];
569  ssize_t r = readlink("/proc/self/exe", pszExePath, sizeof(pszExePath) - 1);
570  if (r == -1)
571  return false;
572  pszExePath[r] = '\0';
573 
574  fs::create_directories(GetAutostartDir());
575 
576  fsbridge::ofstream optionFile(GetAutostartFilePath(), std::ios_base::out | std::ios_base::trunc);
577  if (!optionFile.good())
578  return false;
579  // Write a pivx.desktop file to the autostart directory:
580  optionFile << "[Desktop Entry]\n";
581  optionFile << "Type=Application\n";
582  if (gArgs.GetBoolArg("-testnet", false))
583  optionFile << "Name=PIVX (testnet)\n";
584  else if (gArgs.GetBoolArg("-regtest", false))
585  optionFile << "Name=PIVX (regtest)\n";
586  else
587  optionFile << "Name=PIVX\n";
588  optionFile << "Exec=" << pszExePath << strprintf(" -min -testnet=%d -regtest=%d\n", gArgs.GetBoolArg("-testnet", false), gArgs.GetBoolArg("-regtest", false));
589  optionFile << "Terminal=false\n";
590  optionFile << "Hidden=false\n";
591  optionFile.close();
592  }
593  return true;
594 }
595 
596 #else
597 
599 {
600  return false;
601 }
602 bool SetStartOnSystemStartup(bool fAutoStart) { return false; }
603 
604 #endif
605 
606 void saveWindowGeometry(const QString& strSetting, QWidget* parent)
607 {
608  QSettings settings;
609  settings.setValue(strSetting + "Pos", parent->pos());
610  settings.setValue(strSetting + "Size", parent->size());
611 }
612 
613 void restoreWindowGeometry(const QString& strSetting, const QSize& defaultSize, QWidget* parent)
614 {
615  QSettings settings;
616  QPoint pos = settings.value(strSetting + "Pos").toPoint();
617  QSize size = settings.value(strSetting + "Size", defaultSize).toSize();
618 
619  if (!pos.x() && !pos.y()) {
620  QRect screen = QGuiApplication::primaryScreen()->geometry();
621  pos.setX((screen.width() - size.width()) / 2);
622  pos.setY((screen.height() - size.height()) / 2);
623  }
624 
625  parent->resize(size);
626  parent->move(pos);
627 }
628 
629 // Check whether a theme is not built-in
630 bool isExternal(QString theme)
631 {
632  if (theme.isEmpty())
633  return false;
634 
635  return (theme.operator!=("default") && theme.operator!=("default-dark"));
636 }
637 
638 // Open CSS when configured
639 QString loadStyleSheet()
640 {
641  QString styleSheet;
642  QSettings settings;
643  QString cssName;
644  QString theme = settings.value("theme", "").toString();
645 
646  if (isExternal(theme)) {
647  // External CSS
648  settings.setValue("fCSSexternal", true);
649  fs::path pathAddr = GetDataDir() / "themes/";
650  cssName = pathAddr.string().c_str() + theme + "/css/theme.css";
651  } else {
652  // Built-in CSS
653  settings.setValue("fCSSexternal", false);
654  if (!theme.isEmpty()) {
655  cssName = QString(":/css/") + theme;
656  } else {
657  cssName = QString(":/css/default");
658  settings.setValue("theme", "default");
659  }
660  }
661 
662  QFile qFile(cssName);
663  if (qFile.open(QFile::ReadOnly)) {
664  styleSheet = QLatin1String(qFile.readAll());
665  }
666 
667  return styleSheet;
668 }
669 
670 void setClipboard(const QString& str)
671 {
672  QApplication::clipboard()->setText(str, QClipboard::Clipboard);
673  QApplication::clipboard()->setText(str, QClipboard::Selection);
674 }
675 
676 fs::path qstringToBoostPath(const QString& path)
677 {
678  return fs::path(path.toStdString());
679 }
680 
681 QString boostPathToQString(const fs::path& path)
682 {
683  return QString::fromStdString(path.string());
684 }
685 
686 QString formatDurationStr(int secs)
687 {
688  QStringList strList;
689  int days = secs / 86400;
690  int hours = (secs % 86400) / 3600;
691  int mins = (secs % 3600) / 60;
692  int seconds = secs % 60;
693 
694  if (days)
695  strList.append(QString(QObject::tr("%1 d")).arg(days));
696  if (hours)
697  strList.append(QString(QObject::tr("%1 h")).arg(hours));
698  if (mins)
699  strList.append(QString(QObject::tr("%1 m")).arg(mins));
700  if (seconds || (!days && !hours && !mins))
701  strList.append(QString(QObject::tr("%1 s")).arg(seconds));
702 
703  return strList.join(" ");
704 }
705 
706 QString formatServicesStr(quint64 mask)
707 {
708  QStringList strList;
709 
710  // Just scan the last 8 bits for now.
711  for (int i = 0; i < 8; i++) {
712  uint64_t check = 1 << i;
713  if (mask & check) {
714  switch (check) {
715  case NODE_NETWORK:
716  strList.append(QObject::tr("NETWORK"));
717  break;
718  case NODE_BLOOM:
720  strList.append(QObject::tr("BLOOM"));
721  break;
722  default:
723  strList.append(QString("%1[%2]").arg(QObject::tr("UNKNOWN")).arg(check));
724  }
725  }
726  }
727 
728  if (strList.size())
729  return strList.join(" & ");
730  else
731  return QObject::tr("None");
732 }
733 
734 QString formatPingTime(double dPingTime)
735 {
736  return dPingTime == 0 ? QObject::tr("N/A") : QString(QObject::tr("%1 ms")).arg(QString::number((int)(dPingTime * 1000), 10));
737 }
738 
739 QString formatTimeOffset(int64_t nTimeOffset)
740 {
741  return QString(QObject::tr("%1 s")).arg(QString::number((int)nTimeOffset, 10));
742 }
743 
744 } // namespace GUIUtil
int64_t CAmount
Amount in PIV (Can be negative)
Definition: amount.h:13
std::string GetArg(const std::string &strArg, const std::string &strDefault) const
Return string argument or default value.
Definition: system.cpp:449
bool GetBoolArg(const std::string &strArg, bool fDefault) const
Return boolean argument or default value.
Definition: system.cpp:465
std::string GetChainName() const
Looks for -regtest, -testnet and returns the appropriate BIP70 chain name.
Definition: system.cpp:861
Bitcoin address widget validator, checks for a valid bitcoin address.
Base58 entry widget validator, checks for valid characters and removes some whitespace.
static bool parse(int unit, const QString &value, CAmount *val_out)
Parse string to coin amount.
static CAmount maxMoney()
Return maximum number of base units (Satoshis)
static QString floorHtmlWithUnit(int unit, const CAmount &amount, bool plussign=false, SeparatorStyle separators=separatorStandard, bool cleanRemainderZeros=false, bool isZPIV=false)
static QString floorWithUnit(int unit, const CAmount &amount, bool plussign=false, SeparatorStyle separators=separatorStandard, bool cleanRemainderZeros=false, bool isZPIV=false)
Format as string (with unit) but floor value up to "digits" settings.
static QString format(int unit, const CAmount &amount, bool plussign=false, SeparatorStyle separators=separatorStandard, bool cleanRemainderZeros=true)
Format as string.
static QString name(int unit, bool isZpiv=false)
Short name.
static const std::string REGTEST
static const std::string TESTNET
Serialized script, used inside transaction inputs and outputs.
Definition: script.h:381
An output of a transaction.
Definition: transaction.h:137
bool eventFilter(QObject *obj, QEvent *evt)
Definition: guiutil.cpp:438
ToolTipToRichTextFilter(int size_threshold, QObject *parent=0)
Definition: guiutil.cpp:433
Line edit that can be marked as "invalid" to show input validation feedback.
void setCheckValidator(const QValidator *v)
#define MAX_PATH
Definition: compat.h:74
#define URI_SCHEME
Definition: guiutil.cpp:58
void ForceActivation()
Force application activation on macOS.
Utility functions used by the PIVX Qt UI.
Definition: guiutil.cpp:68
bool openDebugLogfile()
Definition: guiutil.cpp:413
fs::path qstringToBoostPath(const QString &path)
Definition: guiutil.cpp:676
bool isObscured(QWidget *w)
Definition: guiutil.cpp:374
QString formatBalanceWithoutHtml(CAmount amount, int nDisplayUnit, bool isZpiv)
Definition: guiutil.cpp:124
void setupAmountWidget(QLineEdit *widget, QWidget *parent)
Definition: guiutil.cpp:141
Qt::ConnectionType blockingGUIThreadConnection()
Get connection type to call object slot in GUI thread with invokeMethod.
Definition: guiutil.cpp:358
void updateWidgetTextAndCursorPosition(QLineEdit *widget, const QString &str)
Definition: guiutil.cpp:148
QString HtmlEscape(const QString &str, bool fMultiLine)
Definition: guiutil.cpp:251
bool isExternal(QString theme)
Check whether a theme is not built-in.
Definition: guiutil.cpp:630
QString loadStyleSheet()
Load global CSS theme.
Definition: guiutil.cpp:639
bool showBackups()
Definition: guiutil.cpp:428
QString formatPingTime(double dPingTime)
Definition: guiutil.cpp:734
bool openConfigfile()
Definition: guiutil.cpp:418
void saveWindowGeometry(const QString &strSetting, QWidget *parent)
Save window size and position.
Definition: guiutil.cpp:606
bool openMNConfigfile()
Definition: guiutil.cpp:423
QString dateTimeStrWithSeconds(const QDateTime &date)
Definition: guiutil.cpp:74
QString getOpenFileName(QWidget *parent, const QString &caption, const QString &dir, const QString &filter, QString *selectedSuffixOut)
Get open filename, convenience wrapper for QFileDialog::getOpenFileName.
Definition: guiutil.cpp:331
QFont bitcoinAddressFont()
Definition: guiutil.cpp:84
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 ...
Definition: guiutil.cpp:291
QString boostPathToQString(const fs::path &path)
Definition: guiutil.cpp:681
bool SetStartOnSystemStartup(bool fAutoStart)
Definition: guiutil.cpp:602
void bringToFront(QWidget *w)
Definition: guiutil.cpp:379
void restoreWindowGeometry(const QString &strSetting, const QSize &defaultSize, QWidget *parent)
Restore window size and position.
Definition: guiutil.cpp:613
QString dateTimeStr(const QDateTime &date)
Definition: guiutil.cpp:69
QString formatDurationStr(int secs)
Definition: guiutil.cpp:686
QVariant getEntryData(QAbstractItemView *view, int column, int role)
Return a field of the currently selected entry as a QString.
Definition: guiutil.cpp:278
bool checkPoint(const QPoint &p, const QWidget *w)
Definition: guiutil.cpp:367
QString formatBitcoinURI(const SendCoinsRecipient &info)
Definition: guiutil.cpp:218
QString formatTimeOffset(int64_t nTimeOffset)
Definition: guiutil.cpp:739
QString formatServicesStr(quint64 mask)
Definition: guiutil.cpp:706
bool openFile(fs::path path, bool isTextFile)
Definition: guiutil.cpp:398
QString formatBalance(CAmount amount, int nDisplayUnit, bool isZpiv)
Definition: guiutil.cpp:119
bool parseBitcoinURI(const QUrl &uri, SendCoinsRecipient *out)
Definition: guiutil.cpp:156
bool GetStartOnSystemStartup()
Definition: guiutil.cpp:598
void copyEntryData(QAbstractItemView *view, int column, int role)
Copy a field of the currently selected entry of a view to the clipboard.
Definition: guiutil.cpp:266
void setupAddressWidget(QValidatedLineEdit *widget, QWidget *parent)
Definition: guiutil.cpp:129
void setClipboard(const QString &str)
Definition: guiutil.cpp:670
bool isDust(const QString &address, const CAmount &amount)
Definition: guiutil.cpp:243
CWDestination DecodeDestination(const std::string &strAddress)
fs::ofstream ofstream
Definition: fs.h:93
fs::ifstream ifstream
Definition: fs.h:92
@ SUCCEEDED
Definition: netbase.cpp:253
bool IsDust(const CTxOut &txout, const CFeeRate &dustRelayFeeIn)
Definition: policy.cpp:45
CFeeRate dustRelayFee
Definition: policy.cpp:19
@ NODE_BLOOM
Definition: protocol.h:321
@ NODE_NETWORK
Definition: protocol.h:318
@ NODE_BLOOM_WITHOUT_MN
Definition: protocol.h:325
QSettings * settings
Definition: qtutils.cpp:197
CScript GetScriptForDestination(const CTxDestination &dest)
Generate a PIVX scriptPubKey for the given CTxDestination.
Definition: standard.cpp:278
boost::variant< CNoDestination, CKeyID, CScriptID, CExchangeKeyID > CTxDestination
A txout script template with a specific destination.
Definition: standard.h:72
const char *const PIVX_CONF_FILENAME
Definition: system.cpp:81
const fs::path & GetDataDir(bool fNetSpecific)
Definition: system.cpp:724
ArgsManager gArgs
Definition: system.cpp:89
fs::path GetConfigFile(const std::string &confPath)
Definition: system.cpp:770
fs::path GetMasternodeConfigFile()
Definition: system.cpp:776
#define strprintf
Definition: tinyformat.h:1056